概要
- Python の 練習を兼ねて, 量子コンピュータのフレームワーク(Google社)のチュートリアルを確認してみた
- 動作環境は, Google Colaboratory で行った
感想
- チュートリアル(Cirq basics)が, とりあえず完了したので, 引き続きステップアップしていきたいと思う.
- 時間を見つけて, 今後も, チュートリアルの残りの部分を進めていこうと思う.
Decompositions
量子回路を, 分解することが出来るとのこと
- Decompositions の サンプル
- Decompositions の サンプル
- Decompositions の サンプル
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
[編集内容(Decompositions)] import cirq print(cirq.decompose(cirq.X(cirq.LineQubit(0)))) print("") print(cirq.decompose(cirq.Y(cirq.LineQubit(0)))) print("") print(cirq.decompose(cirq.Z(cirq.LineQubit(0)))) print("") print(cirq.decompose(cirq.H(cirq.LineQubit(0)))) print("") print(cirq.decompose(cirq.S(cirq.LineQubit(0)))) print("") print(cirq.decompose(cirq.T(cirq.LineQubit(0)))) print("") print(cirq.decompose(cirq.CNOT(cirq.GridQubit(0, 0), cirq.GridQubit(0, 1)))) print("") print(cirq.decompose(cirq.SWAP(cirq.GridQubit(0, 0), cirq.GridQubit(0, 1)))) print("") print(cirq.decompose(cirq.Circuit(cirq.ISWAP(q, q + 1) for q in cirq.LineQubit.range(3)))) print("") print(cirq.decompose(cirq.CZ(cirq.GridQubit(0, 0), cirq.GridQubit(0, 1)))) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
[出力結果] [cirq.X(cirq.LineQubit(0))] [cirq.Y(cirq.LineQubit(0))] [cirq.Z(cirq.LineQubit(0))] [(cirq.Y**0.5).on(cirq.LineQubit(0)), cirq.XPowGate(exponent=1.0, global_shift=-0.25).on(cirq.LineQubit(0))] [cirq.S(cirq.LineQubit(0))] [cirq.T(cirq.LineQubit(0))] [(cirq.Y**-0.5).on(cirq.GridQubit(0, 1)), cirq.CZ(cirq.GridQubit(0, 0), cirq.GridQubit(0, 1)), (cirq.Y**0.5).on(cirq.GridQubit(0, 1))] [(cirq.Y**-0.5).on(cirq.GridQubit(0, 1)), cirq.CZ(cirq.GridQubit(0, 0), cirq.GridQubit(0, 1)), (cirq.Y**0.5).on(cirq.GridQubit(0, 1)), (cirq.Y**-0.5).on(cirq.GridQubit(0, 0)), cirq.CZ(cirq.GridQubit(0, 1), cirq.GridQubit(0, 0)), (cirq.Y**0.5).on(cirq.GridQubit(0, 0)), (cirq.Y**-0.5).on(cirq.GridQubit(0, 1)), cirq.CZ(cirq.GridQubit(0, 0), cirq.GridQubit(0, 1)), (cirq.Y**0.5).on(cirq.GridQubit(0, 1))] [(cirq.Y**-0.5).on(cirq.LineQubit(1)), cirq.CZ(cirq.LineQubit(0), cirq.LineQubit(1)), (cirq.Y**0.5).on(cirq.LineQubit(1)), (cirq.Y**0.5).on(cirq.LineQubit(0)), cirq.XPowGate(exponent=1.0, global_shift=-0.25).on(cirq.LineQubit(0)), (cirq.Y**-0.5).on(cirq.LineQubit(0)), cirq.CZ(cirq.LineQubit(1), cirq.LineQubit(0)), (cirq.Y**0.5).on(cirq.LineQubit(0)), cirq.S(cirq.LineQubit(0)), (cirq.Y**-0.5).on(cirq.LineQubit(0)), cirq.CZ(cirq.LineQubit(1), cirq.LineQubit(0)), (cirq.Y**0.5).on(cirq.LineQubit(0)), (cirq.S**-1).on(cirq.LineQubit(0)), (cirq.Y**0.5).on(cirq.LineQubit(0)), cirq.XPowGate(exponent=1.0, global_shift=-0.25).on(cirq.LineQubit(0)), (cirq.Y**-0.5).on(cirq.LineQubit(1)), cirq.CZ(cirq.LineQubit(0), cirq.LineQubit(1)), (cirq.Y**0.5).on(cirq.LineQubit(1)), (cirq.Y**-0.5).on(cirq.LineQubit(2)), cirq.CZ(cirq.LineQubit(1), cirq.LineQubit(2)), (cirq.Y**0.5).on(cirq.LineQubit(2)), (cirq.Y**0.5).on(cirq.LineQubit(1)), cirq.XPowGate(exponent=1.0, global_shift=-0.25).on(cirq.LineQubit(1)), (cirq.Y**-0.5).on(cirq.LineQubit(1)), cirq.CZ(cirq.LineQubit(2), cirq.LineQubit(1)), (cirq.Y**0.5).on(cirq.LineQubit(1)), cirq.S(cirq.LineQubit(1)), (cirq.Y**-0.5).on(cirq.LineQubit(1)), cirq.CZ(cirq.LineQubit(2), cirq.LineQubit(1)), (cirq.Y**0.5).on(cirq.LineQubit(1)), (cirq.S**-1).on(cirq.LineQubit(1)), (cirq.Y**0.5).on(cirq.LineQubit(1)), cirq.XPowGate(exponent=1.0, global_shift=-0.25).on(cirq.LineQubit(1)), (cirq.Y**-0.5).on(cirq.LineQubit(2)), cirq.CZ(cirq.LineQubit(1), cirq.LineQubit(2)), (cirq.Y**0.5).on(cirq.LineQubit(2)), (cirq.Y**-0.5).on(cirq.LineQubit(3)), cirq.CZ(cirq.LineQubit(2), cirq.LineQubit(3)), (cirq.Y**0.5).on(cirq.LineQubit(3)), (cirq.Y**0.5).on(cirq.LineQubit(2)), cirq.XPowGate(exponent=1.0, global_shift=-0.25).on(cirq.LineQubit(2)), (cirq.Y**-0.5).on(cirq.LineQubit(2)), cirq.CZ(cirq.LineQubit(3), cirq.LineQubit(2)), (cirq.Y**0.5).on(cirq.LineQubit(2)), cirq.S(cirq.LineQubit(2)), (cirq.Y**-0.5).on(cirq.LineQubit(2)), cirq.CZ(cirq.LineQubit(3), cirq.LineQubit(2)), (cirq.Y**0.5).on(cirq.LineQubit(2)), (cirq.S**-1).on(cirq.LineQubit(2)), (cirq.Y**0.5).on(cirq.LineQubit(2)), cirq.XPowGate(exponent=1.0, global_shift=-0.25).on(cirq.LineQubit(2)), (cirq.Y**-0.5).on(cirq.LineQubit(3)), cirq.CZ(cirq.LineQubit(2), cirq.LineQubit(3)), (cirq.Y**0.5).on(cirq.LineQubit(3))] [cirq.CZ(cirq.GridQubit(0, 0), cirq.GridQubit(0, 1))] |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
[編集内容(Decompositions)] import cirq q0 = cirq.GridQubit(0, 0) print(cirq.Circuit(cirq.decompose(cirq.X(q0)))) print("") print(cirq.Circuit(cirq.decompose(cirq.Y(q0)))) print("") print(cirq.Circuit(cirq.decompose(cirq.Z(q0)))) print("") print(cirq.Circuit(cirq.decompose(cirq.H(q0)))) print("") print(cirq.Circuit(cirq.decompose(cirq.T(q0)))) print("") print(cirq.Circuit(cirq.decompose(cirq.S(q0)))) |
1 2 3 4 5 6 7 8 9 10 11 12 |
[出力結果] (0, 0): ───X─── (0, 0): ───Y─── (0, 0): ───Z─── (0, 0): ───Y^0.5───X─── (0, 0): ───T─── (0, 0): ───S─── |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
[編集内容(Decompositions)] import cirq q0, q1, q2 = cirq.LineQubit.range(3) print(cirq.Circuit(cirq.decompose(cirq.CX(q0, q1)))) print("") print(cirq.Circuit(cirq.decompose(cirq.CZ(q0, q1)))) print("") print(cirq.Circuit(cirq.decompose(cirq.CNOT(q0, q1)))) print("") print(cirq.Circuit(cirq.decompose(cirq.SWAP(q0, q1)))) print("") print(cirq.Circuit(cirq.decompose(cirq.ISWAP(q0, q1)))) print("") print(cirq.Circuit(cirq.decompose(cirq.TOFFOLI(q0, q1, q2)))) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
[出力結果] 0: ────────────@─────────── │ 1: ───Y^-0.5───@───Y^0.5─── 0: ───@─── │ 1: ───@─── 0: ────────────@─────────── │ 1: ───Y^-0.5───@───Y^0.5─── 0: ────────────@───Y^-0.5───@───Y^0.5────@─────────── │ │ │ 1: ───Y^-0.5───@───Y^0.5────@───Y^-0.5───@───Y^0.5─── 0: ────────────@───Y^0.5───X───Y^-0.5───@───Y^0.5───S───Y^-0.5───@───Y^0.5────S^-1───Y^0.5───X───@─────────── │ │ │ │ 1: ───Y^-0.5───@───Y^0.5────────────────@────────────────────────@───Y^-0.5──────────────────────@───Y^0.5─── 0: ───T────────────────@─────────────────────────────────@─────────────────────────────@────────────────────────────@─────────────────────────────────────── │ │ │ │ 1: ───T───────Y^-0.5───@───Y^0.5────@───T^-1────Y^-0.5───@────────Y^0.5───@───Y^-0.5───@──────Y^0.5────@───Y^-0.5───@──────Y^0.5────@─────────────────────── │ │ │ │ 2: ───Y^0.5───X────────T───Y^-0.5───@───Y^0.5───T────────Y^-0.5───────────@───Y^0.5────T^-1───Y^-0.5───@───Y^0.5────T^-1───Y^-0.5───@───Y^0.5───Y^0.5───X─── |
Optimizers
MergeSingleQubitGatesオプティマイザは, 連続する単一量子ビット操作を実行し, それらを単一の PhasedXZ操作に, マージするとのこと
- Optimizers の サンプル
- Optimizers の サンプル
- Optimizers の サンプル
- Optimizers の サンプル
- Optimizers の サンプル
1 2 3 4 5 6 7 8 9 |
[編集内容(Optimizers)] import cirq q=cirq.GridQubit(1, 1) optimizer=cirq.MergeSingleQubitGates() c=cirq.Circuit(cirq.X(q) ** 0.25, cirq.Y(q) ** 0.25, cirq.Z(q) ** 0.25) print(c) optimizer.optimize_circuit(c) print(c) |
1 2 3 4 5 6 |
[出力結果] (1, 1): ───X^0.25───Y^0.25───T─── ┌ ┐ (1, 1): ───│ 0.5 +0.707j -0. -0.5j │─────────── │ 0.354+0.354j 0.146+0.854j│ └ ┘ |
1 2 3 4 5 6 7 8 9 |
[編集内容(Optimizers)] import cirq q = cirq.LineQubit(0) optimizer=cirq.MergeSingleQubitGates() c=cirq.Circuit(cirq.X(q), cirq.Y(q), cirq.Z(q)) print(c) optimizer.optimize_circuit(c) print(c) |
1 2 3 4 5 6 |
[出力結果] 0: ───X───Y───Z─── ┌ ┐ 0: ───│0.-1.j 0.+0.j│─────────── │0.+0.j 0.-1.j│ └ ┘ |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
[編集内容(Optimizers)] import cirq q = cirq.LineQubit(0) optimizer=cirq.MergeSingleQubitGates() c0 = cirq.Circuit(cirq.X(q), cirq.X(q)) print(c0) optimizer.optimize_circuit(c0) print(c0) c1 = cirq.Circuit(cirq.Y(q), cirq.Y(q)) print(c1) optimizer.optimize_circuit(c1) print(c1) c2 = cirq.Circuit(cirq.Z(q), cirq.Z(q)) print(c2) optimizer.optimize_circuit(c2) print(c2) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
[出力結果] 0: ───X───X─── ┌ ┐ 0: ───│1.+0.j 0.+0.j│─────── │0.+0.j 1.+0.j│ └ ┘ 0: ───Y───Y─── ┌ ┐ 0: ───│1.+0.j 0.+0.j│─────── │0.+0.j 1.+0.j│ └ ┘ 0: ───Z───Z─── ┌ ┐ 0: ───│1.+0.j 0.+0.j│─────── │0.+0.j 1.+0.j│ └ ┘ |
1 2 3 4 5 6 7 8 9 |
[編集内容(Optimizers)] import cirq q = cirq.LineQubit(0) optimizer=cirq.MergeSingleQubitGates() c=cirq.Circuit(cirq.X(q), cirq.Z(q), cirq.Y(q)) print(c) optimizer.optimize_circuit(c) print(c) |
1 2 3 4 5 |
[出力結果] 0: ───X───Z───Y─── ┌ ┐ 0: ───│0.+1.j 0.+0.j│─────────── │0.+0.j 0.+1.j│ |
1 2 3 4 5 6 7 8 9 10 |
[編集内容(Optimizers)] [編集内容(Optimizers)] import cirq q = cirq.LineQubit(0) optimizer=cirq.MergeSingleQubitGates() c=cirq.Circuit(cirq.H(q), cirq.H(q)) print(c) optimizer.optimize_circuit(c) print(c) |
1 2 3 4 5 6 |
[出力結果] 0: ───H───H─── ┌ ┐ 0: ───│ 1.+0.j -0.+0.j│─────── │-0.+0.j 1.+0.j│ └ ┘ |