Qulacsで量子回路のゲート一覧を取ってくる
Feb. 4, 2024, 7:32 a.m.Qulacs で適当な量子回路を作って、それを最適化したとき、以下のようにすると
from qulacs import QuantumCircuit
from qulacs.circuit import QuantumCircuitOptimizer
from qulacs.gate import TOFFOLI
circuit = QuantumCircuit(3)
circuit.add_H_gate(0)
circuit.add_H_gate(1)
circuit.add_gate(TOFFOLI(0, 1, 2))
print(circuit)
optimizer = QuantumCircuitOptimizer()
optimizer.optimize(circuit, 2)
print(circuit)
出力は
*** Quantum Circuit Info ***
# of qubit: 3
# of step : 2
# of gate : 3
# of 1 qubit gate: 2
# of 2 qubit gate: 0
# of 3 qubit gate: 1
Clifford : no
Gaussian : no
*** Quantum Circuit Info ***
# of qubit: 3
# of step : 2
# of gate : 2
# of 1 qubit gate: 0
# of 2 qubit gate: 1
# of 3 qubit gate: 1
Clifford : no
Gaussian : no
のように、最適化前後それぞれの回路の統計情報が得られる。ここには、量子ビットの数・ステップ数(回路深さ)・量子ゲート数・クリフォードゲートのみで構成されているか、などの情報が記載されている。
しかし、現在の量子回路が具体的にどのようなゲートで構成されているかまでは把握することができない。そこで、プログラムの末尾に
for i in range(circuit.get_gate_count()):
print(circuit.get_gate(i))
を追加して実行してやると
*** gate info ***
* gate name : DenseMatrix
* target :
0 : commute
1 : commute
* control :
* Pauli : no
* Clifford : yes
* Gaussian : no
* Parametric: no
* Diagonal : no
* Matrix
(0.5,0) (0.5,0) (0.5,0) (0.5,0)
(0.5,0) (-0.5,0) (0.5,0) (-0.5,0)
(0.5,0) (0.5,0) (-0.5,0) (-0.5,0)
(0.5,0) (-0.5,0) (-0.5,0) (0.5,0)
*** gate info ***
* gate name : DenseMatrix
* target :
2 : commute X
* control :
0 : value 1
1 : value 1
* Pauli : no
* Clifford : no
* Gaussian : no
* Parametric: no
* Diagonal : no
* Matrix
(0,0) (1,0)
(1,0) (0,0)
のように構成するゲート一覧の情報も得ることができる。
Tags
- #Python (26)
- #量子力学 (23)
- #量子情報 (21)
- #Unity (11)
- #Outer Wilds (11)
- #Mac (9)
- #数学 (8)
- #AoE2 (8)
- #Linux (6)
- #Quantum Zoo (6)
- #意識 (5)
- #シミュレーション (5)
- #NumPy (5)
- #Bash (5)
- #相対論 (4)
- #Docker (4)
- #Android (4)
- #Qiskit (4)
- #Rust (3)
- #PyO3 (3)
- #GitHub (3)
- #Django (2)
- #情報理論 (2)
- #LaTeX (2)
- #AR (2)
- #Git (2)
- #iOS (2)
- #C++ (2)
- #正規表現 (2)
- #電磁気学 (1)
- #Google Drive (1)
- #Overleaf (1)
- #Let's Encrypt (1)
- #ポケモン (1)
- #AdMob (1)
- #Autoya (1)
- #docopt (1)
- #SymPy (1)
- #AWS (1)
- #Twitter (1)
- #URP (1)
- #iMovie (1)
- #論文 (1)
- #PyTorch (1)
- #C# (1)
- #Vim (1)