This document contains the decomposition diagrams and explanations for various quantum gates implemented in pyqasm.
The U3 gate is implemented as a decomposition of other gates using the following qiskit decomposition:
In [10]: q = QuantumCircuit(1)
In [11]: q.u(theta, phi, lam, 0)
In [12]: qc = transpile(q, basis_gates['rz','rx'])
In [13]: print(qc)
Out[14]:
┌────────────┐┌─────────┐┌───────────────┐┌─────────┐┌──────────────┐
q: ┤ Rz(lambda) ├┤ Rx(π/2) ├┤ Rz(theta + π) ├┤ Rx(π/2) ├┤ Rz(phi + 3π) ├
└────────────┘└─────────┘└───────────────┘└─────────┘└──────────────┘The CY (controlled-Y) gate is implemented as a decomposition of other gates using the following qiskit decomposition:
In [10]: q = QuantumCircuit(2)
In [11]: q.cy(0,1)
In [12]: q.decompose().draw()
Out[13]:
q_0: ─────────■───────
┌─────┐┌─┴─┐┌───┐
q_1: ┤ Sdg ├┤ X ├┤ S ├
└─────┘└───┘└───┘The CH (Controlled-Hadamard) gate is implemented as a decomposition of other gates using the following qiskit decomposition:
In [10]: q = QuantumCircuit(2)
In [11]: q.ch(0, 1)
Out[11]: <qiskit.circuit.instructionset.InstructionSet at 0x127e00a90>
In [12]: q.decompose().draw()
Out[12]:
q_0: ─────────────────■─────────────────────
┌───┐┌───┐┌───┐┌─┴─┐┌─────┐┌───┐┌─────┐
q_1: ┤ S ├┤ H ├┤ T ├┤ X ├┤ Tdg ├┤ H ├┤ Sdg ├
└───┘└───┘└───┘└───┘└─────┘└───┘└─────┘The XX+YY gate is implemented using the following qiskit decomposition:
In [7]: qc.draw()
Out[7]:
┌─────────────────────┐
q_0: ┤0 ├
│ (XX+YY)(theta,phi) │
q_1: ┤1 ├
└─────────────────────┘
In [8]: qc.decompose().draw()
Out[8]:
┌─────────┐ ┌───┐ ┌───┐┌──────────────┐┌───┐ ┌─────┐ ┌──────────┐
q_0: ┤ Rz(phi) ├─┤ S ├────────────┤ X ├┤ Ry(-theta/2) ├┤ X ├──┤ Sdg ├───┤ Rz(-phi) ├───────────
├─────────┴┐├───┴┐┌─────────┐└─┬─┘├──────────────┤└─┬─┘┌─┴─────┴──┐└─┬──────┬─┘┌─────────┐
q_1: ┤ Rz(-π/2) ├┤ √X ├┤ Rz(π/2) ├──■──┤ Ry(-theta/2) ├──■──┤ Rz(-π/2) ├──┤ √Xdg ├──┤ Rz(π/2) ├
└──────────┘└────┘└─────────┘ └──────────────┘ └──────────┘ └──────┘ └─────────┘The RYY gate is implemented using the following qiskit decomposition:
In [9]: qc.draw()
Out[9]:
┌─────────────┐
q_0: ┤0 ├
│ Ryy(theta) │
q_1: ┤1 ├
└─────────────┘
In [10]: qc.decompose().draw()
Out[10]:
┌─────────┐ ┌──────────┐
q_0: ┤ Rx(π/2) ├──■─────────────────■──┤ Rx(-π/2) ├
├─────────┤┌─┴─┐┌───────────┐┌─┴─┐├──────────┤
q_1: ┤ Rx(π/2) ├┤ X ├┤ Rz(theta) ├┤ X ├┤ Rx(-π/2) ├
└─────────┘└───┘└───────────┘└───┘└──────────┘The rotation about ZZ axis is implemented as a decomposition of other gates using the following qiskit decomposition:
In [10]: q = QuantumCircuit(2)
In [11]: q.rzz(np.pi,0,1)
In [12]: qc.decompose().draw()
Out[12]:
q_0: ──■─────────────■──
┌─┴─┐┌───────┐┌─┴─┐
q_1: ┤ X ├┤ Rz(π) ├┤ X ├
└───┘└───────┘└───┘The phaseshift gate is implemented as a decomposition of other gates using the following qiskit decomposition:
In [10]: q = QuantumCircuit(1)
In [11]: q.p(theta,0)
In [12]: new_qc = transpile(q, basis_gates=['rx','h'])
In [13]: print(new_qc)
Out[13]:
┌───┐┌───────────┐┌───┐
q: ┤ H ├┤ Rx(theta) ├┤ H ├
└───┘└───────────┘└───┘The CSWAP (Controlled-SWAP) gate is implemented as a decomposition of other gates using the following qiskit decomposition:
In [10]: q = QuantumCircuit(3)
In [11]: q.cswap(0,1,2)
In [12]: q.decompose().draw()
Out[12]:
┌───┐
q_0: ────────────────────────■─────────────────────■────■───┤ T ├───■───────
┌───┐ │ ┌───┐ │ ┌─┴─┐┌┴───┴┐┌─┴─┐┌───┐
q_1: ┤ X ├───────■───────────┼─────────■───┤ T ├───┼──┤ X ├┤ Tdg ├┤ X ├┤ X ├
└─┬─┘┌───┐┌─┴─┐┌─────┐┌─┴─┐┌───┐┌─┴─┐┌┴───┴┐┌─┴─┐├───┤└┬───┬┘└───┘└─┬─┘
q_2: ──■──┤ H ├┤ X ├┤ Tdg ├┤ X ├┤ T ├┤ X ├┤ Tdg ├┤ X ├┤ T ├─┤ H ├────────■──
└───┘└───┘└─────┘└───┘└───┘└───┘└─────┘└───┘└───┘ └───┘ The PSWAP (Phase-SWAP) gate is implemented as a decomposition of other gates using the following qiskit decomposition:
In [10]: pswap_matrix = np.array([[1, 0, 0, 0],
[0, 0, np.exp(1j * phi), 0],
[0, np.exp(1j * phi), 0, 0],
[0, 0, 0, 1]])
In [11]: op = Operator(pswap_matrix)
In [12]: qc = QuantumCircuit(op.num_qubits)
In [13]: qc.append(op.to_instruction(), qc.qubits)
In [14]: qc.decompose().draw()
Out[14]:
┌───────────────┐ ┌──────────────────┐ »
q_0: ┤ U(π/2,-π/2,ϕ) ├──■──────┤ U(π/2,-π/2,-π/2) ├─────■──»
└──┬──────────┬─┘┌─┴─┐┌───┴──────────────────┴──┐┌─┴─┐»
q_1: ───┤ U(ϕ,ϕ,ϕ) ├──┤ X ├┤ U(1.8581,2.6524,0.4892) ├┤ X ├»
└──────────┘ └───┘└─────────────────────────┘└───┘»
« ┌──────────┐ ┌────────────┐
«q_0: ─────────┤ U(ϕ,ϕ,ϕ) ├──────────■──┤ U(π/2,0,ϕ) ├
« ┌────────┴──────────┴───────┐┌─┴─┐├────────────┤
«q_1: ┤ U(1.1033,0.32306,-2.2097) ├┤ X ├┤ U(π/2,ϕ,0) ├
« └───────────────────────────┘└───┘└────────────┘The iSWAP gate is implemented as a decomposition of other gates using the following qiskit decomposition:
In [10]: q = QuantumCircuit(2)
In [11]: q.iswap(0,1)
In [12]: q.decompose().draw()
Out[12]:
┌───┐┌───┐ ┌───┐
q_0: ┤ S ├┤ H ├──■──┤ X ├─────
├───┤└───┘┌─┴─┐└─┬─┘┌───┐
q_1: ┤ S ├─────┤ X ├──■──┤ H ├
└───┘ └───┘ └───┘The CRX (Controlled-RX) gate is implemented using the following qiskit decomposition:
In [26]: q.draw()
Out[26]:
q_0: ──────■──────
┌─────┴─────┐
q_1: ┤ Rx(theta) ├
└───────────┘
In [27]: q.decompose().decompose().decompose().draw()
Out[27]:
q_0: ────────────────■───────────────────────■───────────────────────
┌────────────┐┌─┴─┐┌─────────────────┐┌─┴─┐┌───────────────────┐
q_1: ┤ U(0,0,π/2) ├┤ X ├┤ U(-theta/2,0,0) ├┤ X ├┤ U(theta/2,-π/2,0) ├
└────────────┘└───┘└─────────────────┘└───┘└───────────────────┘The CRY (Controlled-RY) gate is implemented using the following qiskit decomposition:
In [4]: q.draw()
Out[4]:
q_0: ──────■──────
┌─────┴─────┐
q_1: ┤ Ry(theta) ├
└───────────┘
In [5]: q.decompose().decompose().decompose().draw()
Out[5]:
q_0: ─────────────────────■────────────────────────■──
┌─────────────────┐┌─┴─┐┌──────────────────┐┌─┴─┐
q_1: ┤ U3(theta/2,0,0) ├┤ X ├┤ U3(-theta/2,0,0) ├┤ X ├
└─────────────────┘└───┘└──────────────────┘└───┘The CRZ (Controlled-RZ) gate is implemented using the following qiskit decomposition:
In [4]: q.draw()
Out[4]:
q_0: ──────■──────
┌─────┴─────┐
q_1: ┤ Rz(theta) ├
└───────────┘
In [5]: q.decompose().decompose().decompose().draw()
Out[5]:
global phase: 0
q_0: ─────────────────────■────────────────────────■──
┌─────────────────┐┌─┴─┐┌──────────────────┐┌─┴─┐
q_1: ┤ U3(0,0,theta/2) ├┤ X ├┤ U3(0,0,-theta/2) ├┤ X ├
└─────────────────┘└───┘└──────────────────┘└───┘The CU (Controlled-U) gate is implemented using the following qiskit decomposition:
In [7]: qc.draw()
Out[7]:
q_0: ────────────■─────────────
┌───────────┴────────────┐
q_1: ┤ U(theta,phi,lam,gamma) ├
└────────────────────────┘
In [8]: qc.decompose().decompose().decompose().draw()
Out[8]:
┌──────────────┐ ┌──────────────────────┐ »
q_0: ────┤ U(0,0,gamma) ├────┤ U(0,0,lam/2 + phi/2) ├──■──────────────────────────────────»
┌───┴──────────────┴───┐└──────────────────────┘┌─┴─┐┌──────────────────────────────┐»
q_1: ┤ U(0,0,lam/2 - phi/2) ├────────────────────────┤ X ├┤ U(-theta/2,0,-lam/2 - phi/2) ├»
└──────────────────────┘ └───┘└──────────────────────────────┘»
«
«q_0: ──■──────────────────────
« ┌─┴─┐┌──────────────────┐
«q_1: ┤ X ├┤ U(theta/2,phi,0) ├
« └───┘└──────────────────┘The CU3 (Controlled-U3) gate is implemented using the following qiskit decomposition:
In [7]: qc.draw()
Out[7]:
q_0: ──────────■──────────
┌─────────┴─────────┐
q_1: ┤ U3(theta,phi,lam) ├
└───────────────────┘
In [8]: qc.decompose().decompose().decompose().draw()
Out[8]:
┌──────────────────────┐
q_0: ┤ U(0,0,lam/2 + phi/2) ├──■────────────────────────────────────■──────────────────────
├──────────────────────┤┌─┴─┐┌──────────────────────────────┐┌─┴─┐┌──────────────────┐
q_1: ┤ U(0,0,lam/2 - phi/2) ├┤ X ├┤ U(-theta/2,0,-lam/2 - phi/2) ├┤ X ├┤ U(theta/2,phi,0) ├
└──────────────────────┘└───┘└──────────────────────────────┘└───┘└──────────────────┘The CU1 (Controlled-U1) gate is implemented using the following qiskit decomposition:
In [11]: qc.draw()
Out[11]:
q_0: ─■──────────
│U1(theta)
q_1: ─■──────────
In [12]: qc.decompose().decompose().decompose().draw()
Out[12]:
┌────────────────┐
q_0: ┤ U(0,0,theta/2) ├──■───────────────────────■────────────────────
└────────────────┘┌─┴─┐┌─────────────────┐┌─┴─┐┌────────────────┐
q_1: ──────────────────┤ X ├┤ U(0,0,-theta/2) ├┤ X ├┤ U(0,0,theta/2) ├
└───┘└─────────────────┘└───┘└────────────────┘The CSX (Controlled-SX) gate is implemented using the following qiskit decomposition:
In [19]: q = QuantumCircuit(2)
In [20]: q.csx(0,1)
Out[20]: <qiskit.circuit.instructionset.InstructionSet at 0x127e022f0>
In [21]: q.draw()
Out[21]:
q_0: ──■───
┌─┴──┐
q_1: ┤ Sx ├
└────┘
In [22]: q.decompose().decompose().draw()
Out[22]:
┌─────────┐
q_0: ┤ U1(π/4) ├──■────────────────■────────────────────────
├─────────┤┌─┴─┐┌──────────┐┌─┴─┐┌─────────┐┌─────────┐
q_1: ┤ U2(0,π) ├┤ X ├┤ U1(-π/4) ├┤ X ├┤ U1(π/4) ├┤ U2(0,π) ├
└─────────┘└───┘└──────────┘└───┘└─────────┘└─────────┘The RXX gate is implemented using the following qiskit decomposition:
In [10]: q = QuantumCircuit(2)
In [11]: q.rxx(theta,0,1)
In [12]: q.decompose().draw()
Out[12]:
┌───┐ ┌───┐
q_0: ┤ H ├──■─────────────────■──┤ H ├
├───┤┌─┴─┐┌───────────┐┌─┴─┐├───┤
q_1: ┤ H ├┤ X ├┤ Rz(theta) ├┤ X ├┤ H ├
└───┘└───┘└───────────┘└───┘└───┘
In [13]: q.decompose().decompose().draw()
Out[13]:
global phase: -theta/2
┌─────────┐ ┌─────────┐
q_0: ┤ U2(0,π) ├──■─────────────────■──┤ U2(0,π) ├
├─────────┤┌─┴─┐┌───────────┐┌─┴─┐├─────────┤
q_1: ┤ U2(0,π) ├┤ X ├┤ U1(theta) ├┤ X ├┤ U2(0,π) ├
└─────────┘└───┘└───────────┘└───┘└─────────┘The RCCX gate is implemented using the following qiskit decomposition:
In [10]: q = QuantumCircuit(3)
In [11]: q.rccx(0,1,2)
In [12]: q.decompose().draw()
Out[12]:
»
q_0: ─────────────────────────────────────────■──────────────────────────────»
│ »
q_1: ────────────────────────■────────────────┼───────────────■──────────────»
┌─────────┐┌─────────┐┌─┴─┐┌──────────┐┌─┴─┐┌─────────┐┌─┴─┐┌──────────┐»
q_2: ┤ U2(0,π) ├┤ U1(π/4) ├┤ X ├┤ U1(-π/4) ├┤ X ├┤ U1(π/4) ├┤ X ├┤ U1(-π/4) ├»
└─────────┘└─────────┘└───┘└──────────┘└───┘└─────────┘└───┘└──────────┘»
«
«q_0: ───────────
«
«q_1: ───────────
« ┌─────────┐
«q_2: ┤ U2(0,π) ├
« └─────────┘The RZZ gate is implemented using the following qiskit decomposition:
In [32]: q.draw()
Out[32]:
q_0: ─■──────────
│ZZ(theta)
q_1: ─■──────────
In [33]: q.decompose().decompose().decompose().draw()
Out[33]:
global phase: -theta/2
q_0: ──■─────────────────────■──
┌─┴─┐┌───────────────┐┌─┴─┐
q_1: ┤ X ├┤ U3(0,0,theta) ├┤ X ├
└───┘└───────────────┘└───┘The controlled phase shift gate is implemented using the following qiskit decomposition:
In [11]: qc.draw()
Out[11]:
q_0: ─■─────────
│P(theta)
q_1: ─■─────────
In [12]: qc.decompose().decompose().decompose().draw()
Out[12]:
┌────────────────┐
q_0: ┤ U(0,0,theta/2) ├──■───────────────────────■────────────────────
└────────────────┘┌─┴─┐┌─────────────────┐┌─┴─┐┌────────────────┐
q_1: ──────────────────┤ X ├┤ U(0,0,-theta/2) ├┤ X ├┤ U(0,0,theta/2) ├
└───┘└─────────────────┘└───┘└────────────────┘The controlled phase shift-00 gate is implemented using the following qiskit decomposition:
In [6]: from qiskit import QuantumCircuit
...:
...: qc = QuantumCircuit(2)
...: theta = Parameter('θ')
...: # X gate on qubits
...: qc.x(0)
...: qc.x(1)
...: qc.barrier()
...:
...: # Decomposition of CPhaseShift (controlled phase shift gate)
...: qc.u(0, 0, theta/2, 0)
...: qc.cx(0, 1)
...: qc.u(0, 0, -theta/2, 1)
...: qc.cx(0, 1)
...: qc.u(0, 0, theta/2, 1)
...:
...: qc.barrier()
...: # X gate on qubits
...: qc.x(0)
...: qc.x(1)
...:
...: qc.decompose().decompose().draw()
Out[6]:
┌──────────┐ ░ ┌────────────┐ ░ ┌──────────┐
q_0: ┤ U(π,0,π) ├─░─┤ U(0,0,θ/2) ├──■───────────────────■─────────────────░─┤ U(π,0,π) ├
├──────────┤ ░ └────────────┘┌─┴─┐┌─────────────┐┌─┴─┐┌────────────┐ ░ ├──────────┤
q_1: ┤ U(π,0,π) ├─░───────────────┤ X ├┤ U(0,0,-θ/2) ├┤ X ├┤ U(0,0,θ/2) ├─░─┤ U(π,0,π) ├
└──────────┘ ░ └───┘└─────────────┘└───┘└────────────┘ ░ └──────────┘The controlled phase shift-01 gate is implemented using the following qiskit decomposition:
In [7]: from qiskit import QuantumCircuit
...:
...: qc = QuantumCircuit(2)
...: theta = Parameter('θ')
...: # X gate on qubit 0
...: qc.x(0)
...: qc.barrier()
...:
...: # Decomposition of CPhaseShift (controlled phase shift gate)
...: qc.u(0, 0, theta/2, 0)
...: qc.cx(0, 1)
...: qc.u(0, 0, -theta/2, 1)
...: qc.cx(0, 1)
...: qc.u(0, 0, theta/2, 1)
...:
...: qc.barrier()
...: # X gate on qubit 0
...: qc.x(0)
...:
...: qc.decompose().decompose().draw()
Out[7]:
┌──────────┐ ░ ┌────────────┐ ░ ┌──────────┐
q_0: ┤ U(π,0,π) ├─░─┤ U(0,0,θ/2) ├──■───────────────────■─────────────────░─┤ U(π,0,π) ├
└──────────┘ ░ └────────────┘┌─┴─┐┌─────────────┐┌─┴─┐┌────────────┐ ░ └──────────┘
q_1: ─────────────░───────────────┤ X ├┤ U(0,0,-θ/2) ├┤ X ├┤ U(0,0,θ/2) ├─░─────────────
░ └───┘└─────────────┘└───┘└────────────┘ ░ The controlled phase shift-10 gate is implemented using the following qiskit decomposition:
In [8]: from qiskit import QuantumCircuit
...:
...: qc = QuantumCircuit(2)
...: theta = Parameter('θ')
...: # X gate on qubit 1
...: qc.x(1)
...: qc.barrier()
...:
...: # Decomposition of CPhaseShift (controlled phase shift gate)
...: qc.u(0, 0, theta/2, 0)
...: qc.cx(0, 1)
...: qc.u(0, 0, -theta/2, 1)
...: qc.cx(0, 1)
...: qc.u(0, 0, theta/2, 1)
...:
...: qc.barrier()
...: # X gate on qubit 1
...: qc.x(1)
...:
...: qc.decompose().decompose().draw()
Out[8]:
░ ┌────────────┐ ░
q_0: ─────────────░─┤ U(0,0,θ/2) ├──■───────────────────■─────────────────░─────────────
┌──────────┐ ░ └────────────┘┌─┴─┐┌─────────────┐┌─┴─┐┌────────────┐ ░ ┌──────────┐
q_1: ┤ U(π,0,π) ├─░───────────────┤ X ├┤ U(0,0,-θ/2) ├┤ X ├┤ U(0,0,θ/2) ├─░─┤ U(π,0,π) ├
└──────────┘ ░ └───┘└─────────────┘└───┘└────────────┘ ░ └──────────┘The ECR (Echoed Cross-Resonance) gate is implemented using the following qiskit decomposition:
In [10]: q = QuantumCircuit(2)
In [11]: q.ecr(0,1)
In [12]: q.draw()
Out[12]:
┌──────┐
q_0: ┤0 ├
│ Ecr │
q_1: ┤1 ├
└──────┘
In [13]: new_qc = transpile(q, basis_gates=['x','cx','rx','s'])
In [14]: new_qc.draw()
Out[14]:
┌───┐ ┌───┐
q_0: ───┤ S ├─────■──┤ X ├
┌──┴───┴──┐┌─┴─┐└───┘
q_1: ┤ Rx(π/2) ├┤ X ├─────
└─────────┘└───┘ The C3SX (3-Controlled-SX) gate is implemented using the following qiskit decomposition:
In [15]: qc.draw()
Out[15]:
q_0: ──■───
│
q_1: ──■───
│
q_2: ──■───
┌─┴──┐
q_3: ┤ Sx ├
└────┘
In [16]: qc.decompose().draw()
Out[16]:
q_0: ──────■──────────■────────────────────■────────────────────────────────────────■────────
│ ┌─┴─┐ ┌─┴─┐ │
q_1: ──────┼────────┤ X ├──────■─────────┤ X ├──────■──────────■────────────────────┼────────
│ └───┘ │ └───┘ │ ┌─┴─┐ ┌─┴─┐
q_2: ──────┼───────────────────┼────────────────────┼────────┤ X ├──────■─────────┤ X ├──────
┌───┐ │U1(π/8) ┌───┐┌───┐ │U1(-π/8) ┌───┐┌───┐ │U1(π/8) ├───┤┌───┐ │U1(-π/8) ├───┤┌───┐
q_3: ┤ H ├─■────────┤ H ├┤ H ├─■─────────┤ H ├┤ H ├─■────────┤ H ├┤ H ├─■─────────┤ H ├┤ H ├─
└───┘ └───┘└───┘ └───┘└───┘ └───┘└───┘ └───┘└───┘
«
«q_0:─────────────────────────────────■──────────────────────
« │
«q_1:────────────■────────────────────┼──────────────────────
« ┌─┴─┐ ┌─┴─┐
«q_2:─■────────┤ X ├──────■─────────┤ X ├──────■─────────────
« │U1(π/8) ├───┤┌───┐ │U1(-π/8) ├───┤┌───┐ │U1(π/8) ┌───┐
«q_3:─■────────┤ H ├┤ H ├─■─────────┤ H ├┤ H ├─■────────┤ H ├
« └───┘└───┘ └───┘└───┘ └───┘