概要
- Qiskit について, サンプルプログラムを動かしてみた.
- 動作環境は, Google Colaboratory で行った
- 実行プログラム, 解説は, 下記の参照サイトをご覧ください
感想
- 本家のサイトが詳しいので, 今後も, どのような機能が利用できるかを, 時間を見つけて, 進めていこうと思う.
PrimitiveOps
- operators etc
- Bell-State
- 3-Qubit GHZ-State
- 5-Qubit GHZ-State
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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
[編集内容(operators etc)] from qiskit.aqua.operators import (X, Y, Z, I, CX, T, H, S, Zero, One, Plus, Minus, PrimitiveOp) # X print(X) print(X.to_matrix().real) # Y print(Y) print(Y.to_matrix().real) # Z print(Z) print(Z.to_matrix().real) # I print(I) print(I.to_matrix().real) # CX print(CX) print(CX.to_matrix().real) # T print(T) print(T.to_matrix().real) # H print(H) print(H.to_matrix().real) # S print(S) print(S.to_matrix().real) # Zero print(Zero) print(Zero.to_matrix().real) # One print(One) print(One.to_matrix().real) # Plus print(Plus) print(Plus.to_matrix().real) # Minus print(Minus) print(Minus.to_matrix().real) |
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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
[出力結果] X [[0. 1.] [1. 0.]] Y [[0. 0.] [0. 0.]] Z [[ 1. 0.] [ 0. -1.]] I [[1. 0.] [0. 1.]] q_0: ──■── ┌─┴─┐ q_1: ┤ X ├ └───┘ [[1. 0. 0. 0.] [0. 0. 0. 1.] [0. 0. 1. 0.] [0. 1. 0. 0.]] ┌───┐ q_0: ┤ T ├ └───┘ [[1. 0. ] [0. 0.70710678]] ┌───┐ q_0: ┤ H ├ └───┘ [[ 0.70710678 0.70710678] [ 0.70710678 -0.70710678]] ┌───┐ q_0: ┤ S ├ └───┘ [[1. 0.] [0. 0.]] DictStateFn({'0': 1}) [1. 0.] DictStateFn({'1': 1}) [0. 1.] CircuitStateFn( ┌───┐ q_0: ┤ H ├ └───┘ ) [0.70710678 0.70710678] CircuitStateFn( ┌───┐┌───┐ q_0: ┤ X ├┤ H ├ └───┘└───┘ ) [ 0.70710678 -0.70710678] |
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 |
[編集内容(Bell-State)] import numpy as np # Import Qiskit from qiskit import QuantumCircuit from qiskit import Aer, transpile from qiskit.tools.visualization import plot_histogram, plot_state_city import qiskit.quantum_info as qi #Aer.backends() simulator = Aer.get_backend('aer_simulator') # Create circuit circ = QuantumCircuit(2) circ.h(0) circ.cx(0, 1) circ.measure_all() # Transpile for simulator simulator = Aer.get_backend('aer_simulator') circ = transpile(circ, simulator) # Run and get counts result = simulator.run(circ, shots=10000, memory=True).result() counts = result.get_counts(circ) plot_histogram(counts, title='Bell-State counts') |
1 2 |
[出力結果] グラフが表示された. |
1 2 3 |
[編集内容(Bell-State)] # Run and get memory print(counts) |
1 2 |
[出力結果] {'11': 4999, '00': 5001} |
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 27 |
[編集内容(3-Qubit GHZ-State)] import numpy as np # Import Qiskit from qiskit import QuantumCircuit from qiskit import Aer, transpile from qiskit.tools.visualization import plot_histogram, plot_state_city import qiskit.quantum_info as qi #Aer.backends() simulator = Aer.get_backend('aer_simulator') # Create circuit circ = QuantumCircuit(3) circ.h(0) circ.cx(0, 1) circ.cx(1, 2) circ.measure_all() # Transpile for simulator simulator = Aer.get_backend('aer_simulator') circ = transpile(circ, simulator) # Run and get counts result = simulator.run(circ, shots=10000, memory=True).result() counts = result.get_counts(circ) plot_histogram(counts, title='3-Qubit GHZ-State counts') |
1 2 |
[出力結果] グラフが表示された. |
1 2 3 |
[編集内容(3-Qubit GHZ-State)] # Run and get memory print(counts) |
1 2 |
[出力結果] {'111': 4930, '000': 5070} |
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 27 28 29 |
[編集内容(5-Qubit GHZ-State)] import numpy as np # Import Qiskit from qiskit import QuantumCircuit from qiskit import Aer, transpile from qiskit.tools.visualization import plot_histogram, plot_state_city import qiskit.quantum_info as qi #Aer.backends() simulator = Aer.get_backend('aer_simulator') # Create circuit circ = QuantumCircuit(5) circ.h(0) circ.cx(0, 1) circ.cx(1, 2) circ.cx(2, 3) circ.cx(3, 4) circ.measure_all() # Transpile for simulator simulator = Aer.get_backend('aer_simulator') circ = transpile(circ, simulator) # Run and get counts result = simulator.run(circ, shots=10000, memory=True).result() counts = result.get_counts(circ) plot_histogram(counts, title='5-Qubit GHZ-State counts') |
1 2 |
[出力結果] グラフが表示された. |
1 2 3 |
[編集内容(5-Qubit GHZ-State)] # Run and get memory print(counts) |
1 2 |
[出力結果] {'11111': 4938, '00000': 5062} |