LoginSignup
0
0

More than 3 years have passed since last update.

blueqatで量子ゲート その6

Posted at

概要

blueqatで量子ゲートやってみた。
乗算器作ってみた。

2bit乗算器

mul.jpg

サンプルコード

c0 = Circuit(17).h[0 : 2].h[2 : 4]
c0 = c0.ccx[0, 2, 4]
c0 = c0.ccx[1, 2, 5]
c0 = c0.ccx[1, 3, 11]
c0 = c0.ccx[0, 3, 6]
c0 = c0.cx[5, 10].cx[6, 10].ccx[5, 6, 7]
c0 = c0.cx[4, 9].cx[7, 9].ccx[4, 7, 8]
c0 = c0.m[:].run(shots = 100)
for cnt in c0:
    print("{} * {} = {}".format(int(cnt[0 : 2], 2), int(cnt[2 : 4], 2), int(cnt[8 : 12], 2)))

結果

3 * 2 = 6
0 * 0 = 0
0 * 2 = 0
2 * 3 = 6
2 * 1 = 2
1 * 0 = 0
3 * 0 = 0
1 * 3 = 3
3 * 3 = 9
0 * 3 = 0
3 * 1 = 3
1 * 2 = 2
0 * 1 = 0
1 * 1 = 1
2 * 2 = 4
2 * 0 = 0

以上。

0
0
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
0
0