diff --git a/.github/workflows/logo-check.yml b/.github/workflows/logo-check.yml index 02e2f9a..e361bc5 100644 --- a/.github/workflows/logo-check.yml +++ b/.github/workflows/logo-check.yml @@ -16,6 +16,10 @@ jobs: with: fetch-depth: 0 + - name: Fetch main changes for diff + run: | + git fetch origin main + - name: Check for logo.png changes id : logo_check run: | diff --git a/CHANGELOG.md b/CHANGELOG.md index 2824475..2049a57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ Types of changes: ## Unreleased ### Added + - Added support to `OPENPULSE` code in pyqasm. ([#246](https://github.com/qBraid/pyqasm/pull/246)) ###### Example: ```qasm @@ -48,6 +49,8 @@ Types of changes: } ``` - Added a workflow to track changes in the `docs/_static/logo.png` file to prevent unnecessary modifications. ([#257](https://github.com/qBraid/pyqasm/pull/257)) +- Added decomposition details for all gates in the `docs/gate_decompositions.md` file. ([#237](https://github.com/qBraid/pyqasm/pull/237)) + ### Improved / Modified - Modified if statement validation to now include empty blocks as well. See [Issue #246](https://github.com/qBraid/pyqasm/issues/246) for details. ([#251](https://github.com/qBraid/pyqasm/pull/251)) diff --git a/README.md b/README.md index dd3215d..9ea5235 100644 --- a/README.md +++ b/README.md @@ -150,6 +150,7 @@ PyQASM ensures your OpenQASM programs are **semantically correct** and **hardwar - [API Reference](https://qbraid.github.io/pyqasm/api/pyqasm.html): Developer documentation. - [Usage Examples](examples): Scripts and Markdown examples demonstrating core functionality. - [Supported Operations](pyqasm/README.md#supported-operations): OpenQASM language features supported, in progress, and planned for future support. +- [Gate Decompositions](docs/gate_decompositions.md): Detailed decomposition diagrams and explanations for quantum gates. ## Contributing diff --git a/docs/gate_decompositions.md b/docs/gate_decompositions.md new file mode 100644 index 0000000..9215827 --- /dev/null +++ b/docs/gate_decompositions.md @@ -0,0 +1,619 @@ +# Gate Decompositions + +This document contains the decomposition diagrams and explanations for various quantum gates implemented in [pyqasm](../src/pyqasm/maps/gates.py). + +## [U3 Gate](../src/pyqasm/maps/gates.py#L34) + +The U3 gate is implemented as a decomposition of other gates using the following qiskit decomposition: + +```python +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π) ├ + └────────────┘└─────────┘└───────────────┘└─────────┘└──────────────┘ +``` + +## [CY Gate](../src/pyqasm/maps/gates.py#L129) + +The CY (controlled-Y) gate is implemented as a decomposition of other gates using the following qiskit decomposition: + +```python +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 ├ + └─────┘└───┘└───┘ +``` + +## [CH Gate](../src/pyqasm/maps/gates.py#L144) + +The CH (Controlled-Hadamard) gate is implemented as a decomposition of other gates using the following qiskit decomposition: + +```python +In [10]: q = QuantumCircuit(2) + +In [11]: q.ch(0, 1) +Out[11]: + +In [12]: q.decompose().draw() +Out[12]: + +q_0: ─────────────────■───────────────────── + ┌───┐┌───┐┌───┐┌─┴─┐┌─────┐┌───┐┌─────┐ +q_1: ┤ S ├┤ H ├┤ T ├┤ X ├┤ Tdg ├┤ H ├┤ Sdg ├ + └───┘└───┘└───┘└───┘└─────┘└───┘└─────┘ +``` + +## [XX+YY Gate](../src/pyqasm/maps/gates.py#L176) + +The XX+YY gate is implemented using the following qiskit decomposition: + +```python +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) ├ + └──────────┘└────┘└─────────┘ └──────────────┘ └──────────┘ └──────┘ └─────────┘ +``` + +## [RYY Gate](../src/pyqasm/maps/gates.py#L209) + +The RYY gate is implemented using the following qiskit decomposition: + +```python +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) ├ + └─────────┘└───┘└───────────┘└───┘└──────────┘ +``` + +## [ZZ Gate](../src/pyqasm/maps/gates.py#L230) + +The rotation about ZZ axis is implemented as a decomposition of other gates using the following qiskit decomposition: + +```python +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 ├ + └───┘└───────┘└───┘ +``` + +## [Phaseshift Gate](../src/pyqasm/maps/gates.py#L249) + +The phaseshift gate is implemented as a decomposition of other gates using the following qiskit decomposition: + +```python +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 ├ + └───┘└───────────┘└───┘ +``` + +## [CSWAP Gate](../src/pyqasm/maps/gates.py#L264) + +The CSWAP (Controlled-SWAP) gate is implemented as a decomposition of other gates using the following qiskit decomposition: + +```python +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 ├────────■── + └───┘└───┘└─────┘└───┘└───┘└───┘└─────┘└───┘└───┘ └───┘ +``` + +## [PSWAP Gate](../src/pyqasm/maps/gates.py#L295) + +The PSWAP (Phase-SWAP) gate is implemented as a decomposition of other gates using the following qiskit decomposition: + +```python +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) ├ +« └───────────────────────────┘└───┘└────────────┘ +``` + +## [iSWAP Gate](../src/pyqasm/maps/gates.py#L313) + +The iSWAP gate is implemented as a decomposition of other gates using the following qiskit decomposition: + +```python +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 ├ + └───┘ └───┘ └───┘ +``` + +## [CRX Gate](../src/pyqasm/maps/gates.py#L334) + +The CRX (Controlled-RX) gate is implemented using the following qiskit decomposition: + +```python +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) ├ + └────────────┘└───┘└─────────────────┘└───┘└───────────────────┘ +``` + +## [CRY Gate](../src/pyqasm/maps/gates.py#L353) + +The CRY (Controlled-RY) gate is implemented using the following qiskit decomposition: + +```python +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 ├ + └─────────────────┘└───┘└──────────────────┘└───┘ +``` + +## [CRZ Gate](../src/pyqasm/maps/gates.py#L371) + +The CRZ (Controlled-RZ) gate is implemented using the following qiskit decomposition: + +```python +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 ├ + └─────────────────┘└───┘└──────────────────┘└───┘ +``` + +## [CU Gate](../src/pyqasm/maps/gates.py#L389) + +The CU (Controlled-U) gate is implemented using the following qiskit decomposition: + +```python +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) ├ +« └───┘└──────────────────┘ +``` + +## [CU3 Gate](../src/pyqasm/maps/gates.py#L416) + +The CU3 (Controlled-U3) gate is implemented using the following qiskit decomposition: + +```python +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) ├ + └──────────────────────┘└───┘└──────────────────────────────┘└───┘└──────────────────┘ +``` + +## [CU1 Gate](../src/pyqasm/maps/gates.py#L441) + +The CU1 (Controlled-U1) gate is implemented using the following qiskit decomposition: + +```python +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) ├ + └───┘└─────────────────┘└───┘└────────────────┘ +``` + +## [CSX Gate](../src/pyqasm/maps/gates.py#L461) + +The CSX (Controlled-SX) gate is implemented using the following qiskit decomposition: + +```python +In [19]: q = QuantumCircuit(2) + +In [20]: q.csx(0,1) +Out[20]: + +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,π) ├ + └─────────┘└───┘└──────────┘└───┘└─────────┘└─────────┘ +``` + +## [RXX Gate](../src/pyqasm/maps/gates.py#L480) + +The RXX gate is implemented using the following qiskit decomposition: + +```python +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,π) ├ + └─────────┘└───┘└───────────┘└───┘└─────────┘ +``` + +## [RCCX Gate](../src/pyqasm/maps/gates.py#L504) + +The RCCX gate is implemented using the following qiskit decomposition: + +```python +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,π) ├ +« └─────────┘ +``` + +## [RZZ Gate](../src/pyqasm/maps/gates.py#L528) + +The RZZ gate is implemented using the following qiskit decomposition: + +```python +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 ├ + └───┘└───────────────┘└───┘ +``` + +## [CPhaseShift Gate](../src/pyqasm/maps/gates.py#L548) + +The controlled phase shift gate is implemented using the following qiskit decomposition: + +```python +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) ├ + └───┘└─────────────────┘└───┘└────────────────┘ +``` + +## [CPhaseShift00 Gate](../src/pyqasm/maps/gates.py#L568) + +The controlled phase shift-00 gate is implemented using the following qiskit decomposition: + +```python +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,π) ├ + └──────────┘ ░ └───┘└─────────────┘└───┘└────────────┘ ░ └──────────┘ +``` + +## [CPhaseShift01 Gate](../src/pyqasm/maps/gates.py#L591) + +The controlled phase shift-01 gate is implemented using the following qiskit decomposition: + +```python +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) ├─░───────────── + ░ └───┘└─────────────┘└───┘└────────────┘ ░ +``` + +## [CPhaseShift10 Gate](../src/pyqasm/maps/gates.py#L612) + +The controlled phase shift-10 gate is implemented using the following qiskit decomposition: + +```python +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,π) ├ + └──────────┘ ░ └───┘└─────────────┘└───┘└────────────┘ ░ └──────────┘ +``` + +## [ECR Gate](../src/pyqasm/maps/gates.py#L723) + +The ECR (Echoed Cross-Resonance) gate is implemented using the following qiskit decomposition: + +```python +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 ├───── + └─────────┘└───┘ +``` + +## [C3SX Gate](../src/pyqasm/maps/gates.py#L739) + +The C3SX (3-Controlled-SX) gate is implemented using the following qiskit decomposition: + +```python +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 ├ +« └───┘└───┘ └───┘└───┘ └───┘ +``` \ No newline at end of file diff --git a/docs/index.rst b/docs/index.rst index c3cba43..68f47a1 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -46,7 +46,7 @@

- qbraid logo + pyqasm logo PyQASM

diff --git a/src/pyqasm/maps/gates.py b/src/pyqasm/maps/gates.py index dcd6977..a1accc9 100644 --- a/src/pyqasm/maps/gates.py +++ b/src/pyqasm/maps/gates.py @@ -51,6 +51,10 @@ def u3_gate( Returns: list: A list of QuantumGate objects representing the decomposition of the U3 gate. + + Reference : + See https://github.com/qBraid/pyqasm/tree/main/docs/gate_decompositions.md#u3-gate + for decomposition details """ result: list[QuantumGate] = [] result.extend(one_qubit_rotation_op("rz", lam, qubit_id)) @@ -125,6 +129,10 @@ def sxdg_gate_op(qubit_id) -> list[QuantumGate]: def cy_gate(qubit0: IndexedIdentifier, qubit1: IndexedIdentifier) -> list[QuantumGate]: """ Implements the CY gate as a decomposition of other gates. + + Reference : + See https://github.com/qBraid/pyqasm/tree/main/docs/gate_decompositions.md#cy-gate + for decomposition details """ result: list[QuantumGate] = [] result.extend(one_qubit_gate_op("sdg", qubit1)) @@ -137,20 +145,9 @@ def ch_gate(qubit0: IndexedIdentifier, qubit1: IndexedIdentifier) -> list[Quantu """ Implements the CH gate as a decomposition of other gates. - Used the following qiskit decomposition - - - In [10]: q = QuantumCircuit(2) - - In [11]: q.ch(0, 1) - Out[11]: - - In [12]: q.decompose().draw() - Out[12]: - - q_0: ─────────────────■───────────────────── - ┌───┐┌───┐┌───┐┌─┴─┐┌─────┐┌───┐┌─────┐ - q_1: ┤ S ├┤ H ├┤ T ├┤ X ├┤ Tdg ├┤ H ├┤ Sdg ├ - └───┘└───┘└───┘└───┘└─────┘└───┘└─────┘ + Reference : + See https://github.com/qBraid/pyqasm/tree/main/docs/gate_decompositions.md#ch-gate) + for decomposition details """ result: list[QuantumGate] = [] result.extend(one_qubit_gate_op("s", qubit1)) @@ -185,23 +182,9 @@ def xx_plus_yy_gate( """ Implements the XXPlusYY gate as a decomposition of other gates. - Uses 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) ├ - └──────────┘└────┘└─────────┘ └──────────────┘ └──────────┘ └──────┘ └─────────┘ + Reference : + See https://github.com/qBraid/pyqasm/tree/main/docs/gate_decompositions.md#xxyy-gate + for decomposition details """ result: list[QuantumGate] = [] @@ -229,24 +212,9 @@ def ryy_gate( """ Implements the YY gate as a decomposition of other gates. - Uses 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) ├ - └─────────┘└───┘└───────────┘└───┘└──────────┘ - + Reference : + See https://github.com/qBraid/pyqasm/tree/main/docs/gate_decompositions.md#ryy-gate + for decomposition details """ result: list[QuantumGate] = [] result.extend(one_qubit_rotation_op("rx", CONSTANTS_MAP["pi"] / 2, qubit0)) @@ -264,6 +232,10 @@ def zz_gate( ) -> list[QuantumGate]: """ Implements the ZZ gate as a decomposition of other gates. + + Reference : + See https://github.com/qBraid/pyqasm/tree/main/docs/gate_decompositions.md#zz-gate + for decomposition details """ result: list[QuantumGate] = [] result.extend(two_qubit_gate_op("cz", qubit0, qubit1)) @@ -277,6 +249,10 @@ def zz_gate( def phaseshift_gate(theta: int | float, qubit: IndexedIdentifier) -> list[QuantumGate]: """ Implements the phase shift gate as a decomposition of other gates. + + Reference : + See https://github.com/qBraid/pyqasm/tree/main/docs/gate_decompositions.md#phaseshift-gate + for decomposition details """ result: list[QuantumGate] = [] result.extend(one_qubit_gate_op("h", qubit)) @@ -290,6 +266,10 @@ def cswap_gate( ) -> list[QuantumGate]: """ Implements the CSWAP gate as a decomposition of other gates. + + Reference : + See https://github.com/qBraid/pyqasm/tree/main/docs/gate_decompositions.md#cswap-gate + for decomposition details """ result: list[QuantumGate] = [] result.extend(two_qubit_gate_op("cx", qubit2, qubit1)) @@ -317,6 +297,10 @@ def pswap_gate( ) -> list[QuantumGate]: """ Implements the PSWAP gate as a decomposition of other gates. + + Reference : + See https://github.com/qBraid/pyqasm/tree/main/docs/gate_decompositions.md#pswap-gate + for decomposition details """ result: list[QuantumGate] = [] result.extend(two_qubit_gate_op("swap", qubit0, qubit1)) @@ -330,6 +314,9 @@ def iswap_gate(qubit0: IndexedIdentifier, qubit1: IndexedIdentifier) -> list[Qua """Implements the iSwap gate as a decomposition of other gates. Reference: https://docs.quantum.ibm.com/api/qiskit/qiskit.circuit.library.iSwapGate + + See https://github.com/qBraid/pyqasm/tree/main/docs/gate_decompositions.md#iswap-gate + for decomposition details """ result: list[QuantumGate] = [] @@ -350,23 +337,9 @@ def crx_gate( """ Implements the CRX gate as a decomposition of other gates. - Used 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) ├ - └────────────┘└───┘└─────────────────┘└───┘└───────────────────┘ + Reference : + See https://github.com/qBraid/pyqasm/tree/main/docs/gate_decompositions.md#crx-gate + for decomposition details """ result: list[QuantumGate] = [] result.extend(u3_gate(0, 0, CONSTANTS_MAP["pi"] / 2, qubit1)) @@ -383,23 +356,9 @@ def cry_gate( """ Implements the CRY gate as a decomposition of other gates. - Used 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 ├ - └─────────────────┘└───┘└──────────────────┘└───┘ + Reference : + See https://github.com/qBraid/pyqasm/tree/main/docs/gate_decompositions.md#cry-gate + for decomposition details """ result: list[QuantumGate] = [] result.extend(u3_gate(theta / 2, 0, 0, qubit1)) @@ -415,24 +374,9 @@ def crz_gate( """ Implements the CRZ gate as a decomposition of other gates. - Used 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 ├ - └─────────────────┘└───┘└──────────────────┘└───┘ + Reference : + See https://github.com/qBraid/pyqasm/tree/main/docs/gate_decompositions.md#crz-gate + for decomposition details """ result: list[QuantumGate] = [] result.extend(u3_gate(0, 0, theta / 2, qubit1)) @@ -453,28 +397,9 @@ def cu_gate( # pylint: disable=too-many-arguments """ Implements the CU gate as a decomposition of other gates. - Uses 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) ├ - « └───┘└──────────────────┘ + Reference : + See https://github.com/qBraid/pyqasm/tree/main/docs/gate_decompositions.md#cu-gate + for decomposition details """ result: list[QuantumGate] = [] result.extend(u3_gate(0, 0, gamma, qubit0)) @@ -498,23 +423,9 @@ def cu3_gate( # pylint: disable=too-many-arguments """ Implements the CU3 gate as a decomposition of other gates. - Uses 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) ├ - └──────────────────────┘└───┘└──────────────────────────────┘└───┘└──────────────────┘ + Reference : + See https://github.com/qBraid/pyqasm/tree/main/docs/gate_decompositions.md#cu3-gate + for decomposition details """ result: list[QuantumGate] = [] result.extend(u3_gate(0, 0, lam / 2 + phi / 2, qubit0)) @@ -533,23 +444,9 @@ def cu1_gate( """ Implements the CU1 gate as a decomposition of other gates. - Uses 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) ├ - └───┘└─────────────────┘└───┘└────────────────┘ + Reference : + See https://github.com/qBraid/pyqasm/tree/main/docs/gate_decompositions.md#cu1-gate + for decomposition details """ result: list[QuantumGate] = [] result.extend(u3_gate(0, 0, theta / 2, qubit0)) @@ -564,28 +461,9 @@ def cu1_gate( def csx_gate(qubit0: IndexedIdentifier, qubit1: IndexedIdentifier) -> list[QuantumGate]: """Implement the CSX gate as a decomposition of other gates. - Used the following qiskit decomposition - - - In [19]: q = QuantumCircuit(2) - - In [20]: q.csx(0,1) - Out[20]: - - 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,π) ├ - └─────────┘└───┘└──────────┘└───┘└─────────┘└─────────┘ + Reference : + See https://github.com/qBraid/pyqasm/tree/main/docs/gate_decompositions.md#csx-gate + for decomposition details """ result: list[QuantumGate] = [] result.extend(phaseshift_gate(CONSTANTS_MAP["pi"] / 4, qubit0)) @@ -604,6 +482,10 @@ def rxx_gate( ) -> list[QuantumGate | QuantumPhase]: """ Implements the RXX gate as a decomposition of other gates. + + Reference : + See https://github.com/qBraid/pyqasm/tree/main/docs/gate_decompositions.md#rxx-gate + for decomposition details """ result: list[QuantumGate | QuantumPhase] = [] @@ -622,6 +504,13 @@ def rxx_gate( def rccx_gate( qubit0: IndexedIdentifier, qubit1: IndexedIdentifier, qubit2: IndexedIdentifier ) -> list[QuantumGate]: + """ + Implements the RCCX gate as a decomposition of other gates. + + Reference : + See https://github.com/qBraid/pyqasm/tree/main/docs/gate_decompositions.md#rccx-gate + for decomposition details + """ result: list[QuantumGate] = [] result.extend(u2_gate(0, CONSTANTS_MAP["pi"], qubit2)) result.extend(phaseshift_gate(CONSTANTS_MAP["pi"] / 4, qubit2)) @@ -642,24 +531,9 @@ def rzz_gate( """ Implements the RZZ gate as a decomposition of other gates. - Used 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 ├ - └───┘└───────────────┘└───┘ + Reference : + See https://github.com/qBraid/pyqasm/tree/main/docs/gate_decompositions.md#rzz-gate + for decomposition details """ result: list[QuantumGate | QuantumPhase] = [] @@ -677,23 +551,9 @@ def cphaseshift_gate( """ Implements the controlled phase shift gate as a decomposition of other gates. - Uses 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) ├ - └───┘└─────────────────┘└───┘└────────────────┘ + Reference : + See https://github.com/qBraid/pyqasm/tree/main/docs/gate_decompositions.md#cphaseshift-gate + for decomposition details """ result: list[QuantumGate] = [] result.extend(u3_gate(0, 0, theta / 2, qubit0)) @@ -710,15 +570,15 @@ def cphaseshift00_gate( ) -> list[QuantumGate]: """ Implements the controlled phase shift 00 gate as a decomposition of other gates. + + Reference : + See https://github.com/qBraid/pyqasm/tree/main/docs/gate_decompositions.md#cphaseshift00-gate + for decomposition details """ result: list[QuantumGate] = [] result.extend(one_qubit_gate_op("x", qubit0)) result.extend(one_qubit_gate_op("x", qubit1)) - result.extend(u3_gate(0, 0, theta / 2, qubit0)) - result.extend(u3_gate(0, 0, theta / 2, qubit1)) - result.extend(two_qubit_gate_op("cx", qubit0, qubit1)) - result.extend(u3_gate(0, 0, -theta / 2, qubit1)) - result.extend(two_qubit_gate_op("cx", qubit0, qubit1)) + result.extend(cphaseshift_gate(theta, qubit0, qubit1)) result.extend(one_qubit_gate_op("x", qubit0)) result.extend(one_qubit_gate_op("x", qubit1)) return result @@ -729,14 +589,14 @@ def cphaseshift01_gate( ) -> list[QuantumGate]: """ Implements the controlled phase shift 01 gate as a decomposition of other gates. + + Reference : + See https://github.com/qBraid/pyqasm/tree/main/docs/gate_decompositions.md#cphaseshift01-gate + for decomposition details """ result: list[QuantumGate] = [] result.extend(one_qubit_gate_op("x", qubit0)) - result.extend(u3_gate(0, 0, theta / 2, qubit1)) - result.extend(u3_gate(0, 0, theta / 2, qubit0)) - result.extend(two_qubit_gate_op("cx", qubit0, qubit1)) - result.extend(u3_gate(0, 0, -theta / 2, qubit1)) - result.extend(two_qubit_gate_op("cx", qubit0, qubit1)) + result.extend(cphaseshift_gate(theta, qubit0, qubit1)) result.extend(one_qubit_gate_op("x", qubit0)) return result @@ -746,14 +606,14 @@ def cphaseshift10_gate( ) -> list[QuantumGate]: """ Implements the controlled phase shift 10 gate as a decomposition of other gates. + + Reference : + See https://github.com/qBraid/pyqasm/tree/main/docs/gate_decompositions.md#cphaseshift10-gate + for decomposition details """ result: list[QuantumGate] = [] - result.extend(u3_gate(0, 0, theta / 2, qubit0)) result.extend(one_qubit_gate_op("x", qubit1)) - result.extend(u3_gate(0, 0, theta / 2, qubit1)) - result.extend(two_qubit_gate_op("cx", qubit0, qubit1)) - result.extend(u3_gate(0, 0, -theta / 2, qubit1)) - result.extend(two_qubit_gate_op("cx", qubit0, qubit1)) + result.extend(cphaseshift_gate(theta, qubit0, qubit1)) result.extend(one_qubit_gate_op("x", qubit1)) return result @@ -851,6 +711,10 @@ def ccx_gate_op( def ecr_gate(qubit0: IndexedIdentifier, qubit1: IndexedIdentifier) -> list[QuantumGate]: """ Implements the ECR gate as a decomposition of other gates. + + Reference : + See https://github.com/qBraid/pyqasm/tree/main/docs/gate_decompositions.md#ecr-gate + for decomposition details """ result: list[QuantumGate] = [] result.extend(one_qubit_gate_op("s", qubit0)) @@ -869,40 +733,9 @@ def c3sx_gate( """ Implements the c3sx gate as a decomposition of other gates. - Uses 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 ├ - « └───┘└───┘ └───┘└───┘ └───┘ + Reference : + See https://github.com/qBraid/pyqasm/tree/main/docs/gate_decompositions.md#c3sx-gate + for decomposition details """ result: list[QuantumGate] = []