Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
ShoyaYasuda committed Jun 7, 2023
1 parent 8bd7185 commit b6b74df
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,83 @@ for r in result:
[{'z': 1, 'y': 1, 'x': 1}, 14.0, 9]
```


### サンプルコード2
3ルーク問題は、3×3マスに3つのルーク(飛車)を互いに利きが及ばないように置く方法を探す問題です。2次元配列的な量子ビットの設定方法と、Auto_arrayクラスによる4種の結果可視化方法をご確認ください。
```
from tytan import symbols, Compile, sampler, Auto_array
#量子ビットを用意
q0_a, q0_b, q0_c = symbols('q0_a q0_b q0_c')
q1_a, q1_b, q1_c = symbols('q1_a q1_b q1_c')
q2_a, q2_b, q2_c = symbols('q2_a q2_b q2_c')
#各行に1つだけ1
H = 0
H += (q0_a + q0_b + q0_c - 1)**2
H += (q1_a + q1_b + q1_c - 1)**2
H += (q2_a + q2_b + q2_c - 1)**2
#各列に1つだけ1
H += (q0_a + q1_a + q2_a - 1)**2
H += (q0_b + q1_b + q2_b - 1)**2
H += (q0_c + q1_c + q2_c - 1)**2
#コンパイル
qubo, offset = Compile(H).get_qubo()
#サンプラー選択(乱数シード固定)
solver = sampler.SASampler(seed=0)
#サンプリング(100回)
result = solver.run(qubo, shots=100)
#すべての結果の確認
for r in result:
print(r)
#1つ目の結果を自動配列で確認(ndarray形式)
arr, subs = Auto_array(result[0]).get_ndarray('q{}_{}')
print('get_ndarray')
print(arr)
print(subs)
#1つ目の結果を自動配列で確認(DataFrame形式)
df, subs = Auto_array(result[0]).get_dframe('q{}_{}')
print('get_dframe')
print(df)
#1つ目の結果を自動配列で確認(image形式)
import matplotlib.pyplot as plt
img, subs = Auto_array(result[0]).get_image('q{}_{}')
print('get_image')
plt.imshow(img)
plt.yticks(range(len(subs[0])), subs[0])
plt.xticks(range(len(subs[1])), subs[1])
plt.show()
```

```
[{'q0_a': 0.0, 'q0_b': 0.0, 'q0_c': 1.0, 'q1_a': 0.0, 'q1_b': 1.0, 'q1_c': 0.0, 'q2_a': 1.0, 'q2_b': 0.0, 'q2_c': 0.0}, -6.0, 19]
[{'q0_a': 0.0, 'q0_b': 0.0, 'q0_c': 1.0, 'q1_a': 1.0, 'q1_b': 0.0, 'q1_c': 0.0, 'q2_a': 0.0, 'q2_b': 1.0, 'q2_c': 0.0}, -6.0, 13]
[{'q0_a': 0.0, 'q0_b': 1.0, 'q0_c': 0.0, 'q1_a': 0.0, 'q1_b': 0.0, 'q1_c': 1.0, 'q2_a': 1.0, 'q2_b': 0.0, 'q2_c': 0.0}, -6.0, 21]
[{'q0_a': 0.0, 'q0_b': 1.0, 'q0_c': 0.0, 'q1_a': 1.0, 'q1_b': 0.0, 'q1_c': 0.0, 'q2_a': 0.0, 'q2_b': 0.0, 'q2_c': 1.0}, -6.0, 19]
[{'q0_a': 1.0, 'q0_b': 0.0, 'q0_c': 0.0, 'q1_a': 0.0, 'q1_b': 0.0, 'q1_c': 1.0, 'q2_a': 0.0, 'q2_b': 1.0, 'q2_c': 0.0}, -6.0, 11]
[{'q0_a': 1.0, 'q0_b': 0.0, 'q0_c': 0.0, 'q1_a': 0.0, 'q1_b': 1.0, 'q1_c': 0.0, 'q2_a': 0.0, 'q2_b': 0.0, 'q2_c': 1.0}, -6.0, 17]
get_ndarray
[[0 0 1]
[0 1 0]
[1 0 0]]
[['0', '1', '2'], ['a', 'b', 'c']]
get_dframe
a b c
0 0 0 1
1 0 1 0
2 1 0 0
get_image
```


# サンプラー
サンプラーと呼ばれる計算をしてくれるプログラムが搭載されています。TYTANでは基本的には簡単なソルバーを用意はしていますが、ユーザーごとにソルバーを用意して簡単に繋げられるようにしています。ローカルのサンプラーのように手元のマシンにプログラムとして搭載する以外にも、APIのサンプラーでサーバーに接続する専用サンプラーなど様々な形態に対応できます。

Expand Down

0 comments on commit b6b74df

Please sign in to comment.