2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

事の起こり

昨年末に今まで何度も勉強しようとして挫折していた量子コンピュータの再度始めることにしました。その切っ掛けになったのが、TYTAN SDKというOSSのシミュレーターの勉強会に参加したことでした。しかし、最近忙しさで久しく触っていなかったので、復習も兼ねて再度参加してみることにしました。

第1回の内容

n個の量子ビットのうちm個を1にする

H += (q[0] + q[1] + q[2] + ・・・ + q[n] - m)**2

ライブラリのimport

from tytan import *

n個の量子ビットを用意する

q = symbols_list(n, 'q{}')
n = 3の時
print(q)
[q0 q1 q2]
3個の量子ビットのうち1個を1にする
H = 0
H += (q[0] + q[1] + q[2] - 1)**2 (*)

コンパイル

qubo, offset = Compile(H).get_qubo()
Hが(*)の時
print(qubo)
{('q0', 'q0'): -1.0, ('q1', 'q1'): -1.0, ('q2', 'q2'): -1.0, ('q0', 'q1'): 2.0, ('q0', 'q2'): 2.0, ('q1', 'q2'): 2.0}
Hが(*)の時
print(offset)
1

サンプラーの選択

solver = sampler.SASampler()

サンプリング

results = solver.run(qubo)

結果の表示

for r in results:
    print(r)
上記の例の場合(量子ビットの状態(辞書型), エネルギー, ヒット数)
[{'q0': 0, 'q1': 0, 'q2': 1}, -1.0, 48]
[{'q0': 0, 'q1': 1, 'q2': 0}, -1.0, 23]
[{'q0': 1, 'q1': 0, 'q2': 0}, -1.0, 29]
  • ヒット数の合計 = 100
  • エネルギーは低い順( = 良い順)に出力

Reference

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?