From fc47935ede0e381638fce702049475b118f89375 Mon Sep 17 00:00:00 2001 From: Jintaoyu Date: Wed, 24 Nov 2021 14:48:11 +0800 Subject: [PATCH 01/18] Add circuit diagrams to test_hoare_opt.py --- .../standard_gates/equivalence_library.py | 32 +- test/python/transpiler/test_hoare_opt.py | 327 +++++++++++++++++- 2 files changed, 354 insertions(+), 5 deletions(-) diff --git a/qiskit/circuit/library/standard_gates/equivalence_library.py b/qiskit/circuit/library/standard_gates/equivalence_library.py index 4de5edd172fe..7b0a8125be60 100644 --- a/qiskit/circuit/library/standard_gates/equivalence_library.py +++ b/qiskit/circuit/library/standard_gates/equivalence_library.py @@ -71,14 +71,26 @@ # Import existing gate definitions -# HGate +""" +HGate + ┌───┐ ┌─────────┐ +q_0: ┤ H ├ ≡ q_0: ┤ U2(0,π) ├ + └───┘ └─────────┘ +""" q = QuantumRegister(1, "q") def_h = QuantumCircuit(q) def_h.append(U2Gate(0, pi), [q[0]], []) _sel.add_equivalence(HGate(), def_h) -# CHGate +""" +CHGate + +q_0: ──■── q_0: ─────────────────■───────────────────── + ┌─┴─┐ ≡ ┌───┐┌───┐┌───┐┌─┴─┐┌─────┐┌───┐┌─────┐ +q_1: ┤ H ├ q_1: ┤ S ├┤ H ├┤ T ├┤ X ├┤ Tdg ├┤ H ├┤ Sdg ├ + └───┘ └───┘└───┘└───┘└───┘└─────┘└───┘└─────┘ +""" q = QuantumRegister(2, "q") def_ch = QuantumCircuit(q) @@ -107,8 +119,13 @@ warnings.filterwarnings("ignore", category=DeprecationWarning) _sel.add_equivalence(MSGate(num_qubits, theta), def_ms) -# PhaseGate +""" +PhaseGate + ┌──────┐ ┌───────┐ +q_0: ┤ P(ϴ) ├ ≡ q_0: ┤ U1(ϴ) ├ + └──────┘ └───────┘ +""" q = QuantumRegister(1, "q") theta = Parameter("theta") phase_to_u1 = QuantumCircuit(q) @@ -121,8 +138,15 @@ phase_to_u.u(0, 0, theta, 0) _sel.add_equivalence(PhaseGate(theta), phase_to_u) -# CPhaseGate +""" +CPhaseGate + ┌────────┐ +q_0: ─■──── q_0: ┤ P(ϴ/2) ├──■─────────────────■──────────── + │P(ϴ) ≡ └────────┘┌─┴─┐┌───────────┐┌─┴─┐┌────────┐ +q_1: ─■──── q_1: ──────────┤ X ├┤ P(-0.5*ϴ) ├┤ X ├┤ P(ϴ/2) ├ + └───┘└───────────┘└───┘└────────┘ +""" q = QuantumRegister(2, "q") theta = Parameter("theta") def_cphase = QuantumCircuit(q) diff --git a/test/python/transpiler/test_hoare_opt.py b/test/python/transpiler/test_hoare_opt.py index 926879bb37b0..b4ae54c5d08f 100644 --- a/test/python/transpiler/test_hoare_opt.py +++ b/test/python/transpiler/test_hoare_opt.py @@ -31,6 +31,24 @@ class TestHoareOptimizer(QiskitTestCase): def test_phasegate_removal(self): """Should remove the phase on a classical state, but not on a superposition state. + + (circuit) + + ┌───┐ + q_0: ┤ Z ├────── + ├───┤┌───┐ + q_1:─┤ H ├┤ Z ├─ + └───┘└───┘ + q_2: ─────────── + + (expected) + + q_0: ─────────── + ┌───┐┌───┐ + q_1:─┤ H ├┤ Z ├─ + └───┘└───┘ + q_2: ─────────── + """ circuit = QuantumCircuit(3) circuit.z(0) @@ -52,6 +70,54 @@ def test_phasegate_removal(self): def test_cswap_removal(self): """Should remove Fredkin gates because the optimizer can deduce the targets are in the same state + + (circuit) + + ┌───┐┌───┐ ┌───┐ ┌───┐ ┌───┐ + q_0: ┤ X ├┤ X ├──■──┤ X ├──■──┤ X ├──■────■──┤ X ├───────────────────────────────── + └───┘└─┬─┘┌─┴─┐└─┬─┘ │ └─┬─┘┌─┴─┐ │ └─┬─┘ + q_1: ───────┼──┤ X ├──■────┼────┼──┤ X ├──┼────■───■──■──■──■─────■─────■────────── + │ └─┬─┘ ┌─┴─┐ │ └─┬─┘┌─┴─┐ │ │ │ │ │ │ │ + q_2: ───────┼────┼───────┤ X ├──■────┼──┤ X ├──■───┼──┼──┼──┼──■──┼──■──┼──■──■──■─ + ┌───┐ │ │ └─┬─┘ │ └─┬─┘ │ │ │ │ │ │ │ │ │ │ │ + q_3: ┤ H ├──■────┼─────────┼─────────┼────┼────────┼──┼──X──X──┼──┼──X──┼──┼──X──┼─ + ├───┤ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ + q_4: ┤ H ├───────■─────────┼─────────┼────┼────────┼──┼──┼──X──┼──X──┼──┼──X──┼──X─ + ├───┤ │ │ │ │ │ │ │ │ │ │ │ │ │ + q_5: ┤ H ├─────────────────■─────────┼────┼────────┼──┼──┼─────┼──X──┼──X──┼──X──┼─ + ├───┤ │ │ │ │ │ │ │ │ │ │ + q_6: ┤ H ├───────────────────────────■────■────────┼──┼──┼─────┼─────┼──X──┼─────X─ + └───┘ │ │ │ │ │ │ + q_7: ──────────────────────────────────────────────X──┼──┼─────X─────┼─────┼─────── + │ │ │ │ │ │ + q_8: ──────────────────────────────────────────────X──X──┼─────┼─────X─────┼─────── + │ │ │ │ + q_9: ─────────────────────────────────────────────────X──X─────X───────────X─────── + + + (expected) + + ┌───┐┌───┐ ┌───┐ ┌───┐ ┌───┐ + q_0: ┤ X ├┤ X ├──■──┤ X ├──■──┤ X ├──■────■──┤ X ├─────────────── + └───┘└─┬─┘┌─┴─┐└─┬─┘ │ └─┬─┘┌─┴─┐ │ └─┬─┘ + q_1: ───────┼──┤ X ├──■────┼────┼──┤ X ├──┼────■───■──■──■─────── + │ └─┬─┘ ┌─┴─┐ │ └─┬─┘┌─┴─┐ │ │ │ │ + q_2: ───────┼────┼───────┤ X ├──■────┼──┤ X ├──■───┼──┼──┼──■──■─ + ┌───┐ │ │ └─┬─┘ │ └─┬─┘ │ │ │ │ │ + q_3: ┤ H ├──■────┼─────────┼─────────┼────┼────────X──┼──┼──X──┼─ + ├───┤ │ │ │ │ │ │ │ │ │ + q_4: ┤ H ├───────■─────────┼─────────┼────┼────────X──X──┼──┼──X─ + ├───┤ │ │ │ │ │ │ │ + q_5: ┤ H ├─────────────────■─────────┼────┼───────────X──X──X──┼─ + ├───┤ │ │ │ │ + q_6: ┤ H ├───────────────────────────■────■──────────────X─────X─ + └───┘ + q_7: ──────────────────────────────────────────────────────────── + + q_8: ──────────────────────────────────────────────────────────── + + q_9: ──────────────────────────────────────────────────────────── + """ circuit = QuantumCircuit(10) # prep @@ -117,6 +183,45 @@ def test_lnn_cnot_removal(self): """Should remove some cnots from swaps introduced because of linear nearest architecture. Only uses single-gate optimization techniques. + + (circuit) + + ┌───┐ ┌───┐ » + q_0: ┤ H ├──■──┤ X ├──■────────────────────────────────────────────────────» + └───┘┌─┴─┐└─┬─┘┌─┴─┐ ┌───┐ » + q_1: ─────┤ X ├──■──┤ X ├──■──┤ X ├──■──────────────────────────────────■──» + └───┘ └───┘┌─┴─┐└─┬─┘┌─┴─┐ ┌───┐ ┌───┐┌─┴─┐» + q_2: ────────────────────┤ X ├──■──┤ X ├──■──┤ X ├──■─────────■──┤ X ├┤ X ├» + └───┘ └───┘┌─┴─┐└─┬─┘┌─┴─┐ ┌─┴─┐└─┬─┘└───┘» + q_3: ───────────────────────────────────┤ X ├──■──┤ X ├──■──┤ X ├──■───────» + └───┘ └───┘┌─┴─┐└───┘ » + q_4: ──────────────────────────────────────────────────┤ X ├───────────────» + └───┘ » + « ┌───┐ + «q_0: ───────■──┤ X ├ + « ┌───┐┌─┴─┐└─┬─┘ + «q_1: ┤ X ├┤ X ├──■── + « └─┬─┘└───┘ + «q_2: ──■──────────── + « + «q_3: ─────────────── + « + «q_4: ─────────────── + « + + (expected) + + ┌───┐ ┌───┐ ┌───┐ + q_0: ┤ H ├──■──┤ X ├───────────────────────────────────┤ X ├ + └───┘┌─┴─┐└─┬─┘ ┌───┐ ┌───┐└─┬─┘ + q_1: ─────┤ X ├──■────■──┤ X ├────────────────────┤ X ├──■── + └───┘ ┌─┴─┐└─┬─┘ ┌───┐ ┌───┐└─┬─┘ + q_2: ───────────────┤ X ├──■────■──┤ X ├─────┤ X ├──■─────── + └───┘ ┌─┴─┐└─┬─┘ └─┬─┘ + q_3: ─────────────────────────┤ X ├──■────■────■──────────── + └───┘ ┌─┴─┐ + q_4: ───────────────────────────────────┤ X ├─────────────── + └───┘ """ circuit = QuantumCircuit(5) circuit.h(0) @@ -150,6 +255,45 @@ def test_lnncnot_advanced_removal(self): """Should remove all cnots from swaps introduced because of linear nearest architecture. This time using multi-gate optimization techniques. + + (circuit) + + ┌───┐ ┌───┐ » + q_0: ┤ H ├──■──┤ X ├──■────────────────────────────────────────────────────» + └───┘┌─┴─┐└─┬─┘┌─┴─┐ ┌───┐ » + q_1: ─────┤ X ├──■──┤ X ├──■──┤ X ├──■──────────────────────────────────■──» + └───┘ └───┘┌─┴─┐└─┬─┘┌─┴─┐ ┌───┐ ┌───┐┌─┴─┐» + q_2: ────────────────────┤ X ├──■──┤ X ├──■──┤ X ├──■─────────■──┤ X ├┤ X ├» + └───┘ └───┘┌─┴─┐└─┬─┘┌─┴─┐ ┌─┴─┐└─┬─┘└───┘» + q_3: ───────────────────────────────────┤ X ├──■──┤ X ├──■──┤ X ├──■───────» + └───┘ └───┘┌─┴─┐└───┘ » + q_4: ──────────────────────────────────────────────────┤ X ├───────────────» + └───┘ » + « ┌───┐ + «q_0: ───────■──┤ X ├ + « ┌───┐┌─┴─┐└─┬─┘ + «q_1: ┤ X ├┤ X ├──■── + « └─┬─┘└───┘ + «q_2: ──■──────────── + « + «q_3: ─────────────── + « + «q_4: ─────────────── + « + + (expected) + + ┌───┐ + q_0: ┤ H ├──■───────────────── + └───┘┌─┴─┐ + q_1: ─────┤ X ├──■──────────── + └───┘┌─┴─┐ + q_2: ──────────┤ X ├──■─────── + └───┘┌─┴─┐ + q_3: ───────────────┤ X ├──■── + └───┘┌─┴─┐ + q_4: ────────────────────┤ X ├ + └───┘ """ circuit = QuantumCircuit(5) circuit.h(0) @@ -179,6 +323,26 @@ def test_targetsuccessive_identity_removal(self): """Should remove pair of controlled target successive which are the inverse of each other, if they can be identified to be executed as a unit (either both or none). + + (circuit) + + ┌───┐ ┌───┐┌───┐ + q_0: ┤ H ├──■──┤ X ├┤ X ├──■── + ├───┤ │ └─┬─┘└───┘ │ + q_1: ┤ H ├──■────■─────────■── + ├───┤┌─┴─┐ ┌─┴─┐ + q_2: ┤ H ├┤ X ├──────────┤ X ├ + └───┘└───┘ └───┘ + + (expected) + + ┌───┐┌───┐┌───┐ + q_0: ┤ H ├┤ X ├┤ X ├ + ├───┤└─┬─┘└───┘ + q_1: ┤ H ├──■─────── + ├───┤ + q_2: ┤ H ├────────── + └───┘ """ circuit = QuantumCircuit(3) circuit.h(0) @@ -208,6 +372,114 @@ def test_targetsuccessive_identity_advanced_removal(self): """Should remove target successive identity gates with DIFFERENT sets of control qubits. In this case CCCX(4,5,6,7) & CCX(5,6,7). + + (circuit) + + ┌───┐┌───┐ » + q_0: ┤ H ├┤ X ├───────■─────────────────────────────■───────────────────■──» + ├───┤└─┬─┘ │ │ │ » + q_1: ┤ H ├──■─────────■─────────────────────────────■───────────────────■──» + ├───┤┌───┐ │ ┌───┐ │ │ » + q_2: ┤ H ├┤ X ├───────┼──┤ X ├──■──────────────■────┼───────────────────┼──» + ├───┤└─┬─┘ ┌─┴─┐└─┬─┘ │ │ ┌─┴─┐ ┌─┴─┐» + q_3: ┤ H ├──■────■──┤ X ├──■────■──────────────■──┤ X ├──■─────────■──┤ X ├» + ├───┤┌───┐ │ └───┘ │ ┌───┐ │ └───┘ │ │ └───┘» + q_4: ┤ H ├┤ X ├──┼──────────────┼──┤ X ├──■────┼─────────┼─────────┼───────» + ├───┤└─┬─┘┌─┴─┐ ┌─┴─┐└─┬─┘ │ ┌─┴─┐ ┌─┴─┐ ┌─┴─┐ » + q_5: ┤ H ├──■──┤ X ├──────────┤ X ├──■────■──┤ X ├─────┤ X ├──■──┤ X ├─────» + └───┘ └───┘ └───┘ ┌─┴─┐└───┘ └───┘┌─┴─┐├───┤ » + q_6: ───────────────────────────────────┤ X ├───────────────┤ X ├┤ X ├─────» + └───┘ └───┘└───┘ » + q_7: ──────────────────────────────────────────────────────────────────────» + » + « ┌───┐┌───┐ » + «q_0: ──────────────────────■──┤ X ├┤ X ├──■─────────────────────────────■──» + « │ └─┬─┘└─┬─┘ │ │ » + «q_1: ──────────────────────■────■────■────■─────────────────────────────■──» + « ┌───┐ │ │ │ ┌───┐ │ » + «q_2: ──■─────────■──┤ X ├──┼─────────┼────┼──┤ X ├──■──────────────■────┼──» + « │ │ └─┬─┘┌─┴─┐ │ ┌─┴─┐└─┬─┘ │ │ ┌─┴─┐» + «q_3: ──■─────────■────■──┤ X ├───────┼──┤ X ├──■────■──────────────■──┤ X ├» + « │ ┌───┐ │ └───┘ │ └───┘ │ │ ┌───┐ │ └───┘» + «q_4: ──┼──┤ X ├──┼───────────────────┼─────────┼────┼──┤ X ├──■────┼───────» + « ┌─┴─┐└─┬─┘┌─┴─┐ │ │ ┌─┴─┐└─┬─┘ │ ┌─┴─┐ » + «q_5: ┤ X ├──■──┤ X ├─────────────────┼─────────┼──┤ X ├──■────■──┤ X ├─────» + « └───┘ └───┘ │ │ └───┘ │ │ └───┘ » + «q_6: ────────────────────────────────■─────────■─────────■────■────────────» + « ┌─┴─┐ » + «q_7: ───────────────────────────────────────────────────────┤ X ├──────────» + « └───┘ » + « + «q_0: ─────────────── + « + «q_1: ─────────────── + « ┌───┐ + «q_2: ─────┤ X ├───── + « └─┬─┘ + «q_3: ──■────■─────── + « │ ┌───┐ + «q_4: ──┼──┤ X ├───── + « ┌─┴─┐└─┬─┘ + «q_5: ┤ X ├──■────■── + « └───┘ │ + «q_6: ────────────■── + « ┌─┴─┐ + «q_7: ──────────┤ X ├ + « └───┘ + + (expected) + + ┌───┐┌───┐ » + q_0: ┤ H ├┤ X ├───────■─────────────────────────────■───────────────────■──» + ├───┤└─┬─┘ │ │ │ » + q_1: ┤ H ├──■─────────■─────────────────────────────■───────────────────■──» + ├───┤┌───┐ │ ┌───┐ │ │ » + q_2: ┤ H ├┤ X ├───────┼──┤ X ├──■──────────────■────┼───────────────────┼──» + ├───┤└─┬─┘ ┌─┴─┐└─┬─┘ │ │ ┌─┴─┐ ┌─┴─┐» + q_3: ┤ H ├──■────■──┤ X ├──■────■──────────────■──┤ X ├──■─────────■──┤ X ├» + ├───┤┌───┐ │ └───┘ │ ┌───┐ │ └───┘ │ │ └───┘» + q_4: ┤ H ├┤ X ├──┼──────────────┼──┤ X ├──■────┼─────────┼─────────┼───────» + ├───┤└─┬─┘┌─┴─┐ ┌─┴─┐└─┬─┘ │ ┌─┴─┐ ┌─┴─┐ ┌─┴─┐ » + q_5: ┤ H ├──■──┤ X ├──────────┤ X ├──■────■──┤ X ├─────┤ X ├──■──┤ X ├─────» + └───┘ └───┘ └───┘ ┌─┴─┐└───┘ └───┘┌─┴─┐├───┤ » + q_6: ───────────────────────────────────┤ X ├───────────────┤ X ├┤ X ├─────» + └───┘ └───┘└───┘ » + q_7: ──────────────────────────────────────────────────────────────────────» + » + « ┌───┐┌───┐ » + «q_0: ──────────────────────■──┤ X ├┤ X ├──■────────────────────────■───────» + « │ └─┬─┘└─┬─┘ │ │ » + «q_1: ──────────────────────■────■────■────■────────────────────────■───────» + « ┌───┐ │ │ │ ┌───┐ │ » + «q_2: ──■─────────■──┤ X ├──┼─────────┼────┼──┤ X ├──■─────────■────┼───────» + « │ │ └─┬─┘┌─┴─┐ │ ┌─┴─┐└─┬─┘ │ │ ┌─┴─┐ » + «q_3: ──■─────────■────■──┤ X ├───────┼──┤ X ├──■────■─────────■──┤ X ├──■──» + « │ ┌───┐ │ └───┘ │ └───┘ │ │ ┌───┐ │ └───┘ │ » + «q_4: ──┼──┤ X ├──┼───────────────────┼─────────┼────┼──┤ X ├──┼─────────┼──» + « ┌─┴─┐└─┬─┘┌─┴─┐ │ │ ┌─┴─┐└─┬─┘┌─┴─┐ ┌─┴─┐» + «q_5: ┤ X ├──■──┤ X ├─────────────────┼─────────┼──┤ X ├──■──┤ X ├─────┤ X ├» + « └───┘ └───┘ │ │ └───┘ │ └───┘ └───┘» + «q_6: ────────────────────────────────■─────────■─────────■─────────────────» + « » + «q_7: ──────────────────────────────────────────────────────────────────────» + « » + « + «q_0: ───── + « + «q_1: ───── + « ┌───┐ + «q_2: ┤ X ├ + « └─┬─┘ + «q_3: ──■── + « ┌───┐ + «q_4: ┤ X ├ + « └─┬─┘ + «q_5: ──■── + « + «q_6: ───── + « + «q_7: ───── + « """ circuit = QuantumCircuit(8) circuit.h(0) @@ -294,7 +566,24 @@ def test_targetsuccessive_identity_advanced_removal(self): self.assertEqual(result, circuit_to_dag(expected)) def test_control_removal(self): - """Should replace CX by X and CZ by Z.""" + """Should replace CX by X. + + (circuit) + + ┌───┐ + q_0: ┤ X ├──■── + └───┘┌─┴─┐ + q_1: ─────┤ X ├ + └───┘ + + (expected) + + ┌───┐ + q_0: ┤ X ├ + ├───┤ + q_1: ┤ X ├ + └───┘ + """ circuit = QuantumCircuit(2) circuit.x(0) circuit.cx(0, 1) @@ -311,6 +600,26 @@ def test_control_removal(self): self.assertEqual(result, circuit_to_dag(expected)) + """ + Should replace CZ by Z + + (circuit) + + ┌───┐ ┌───┐ + q_0: ┤ H ├─■─┤ H ├ + ├───┤ │ └───┘ + q_1: ┤ X ├─■────── + └───┘ + + (expected) + + ┌───┐┌───┐┌───┐ + q_0: ┤ H ├┤ Z ├┤ H ├ + ├───┤└───┘└───┘ + q_1: ┤ X ├────────── + └───┘ + """ + circuit = QuantumCircuit(2) circuit.h(0) circuit.x(1) @@ -350,6 +659,22 @@ def test_is_identity(self): def test_multiple_pass(self): """Verify that multiple pass can be run with the same Hoare instance. + + (circuit2) + + ┌───┐┌───┐ + q_0:─┤ H ├┤ Z ├─ + ├───┤└───┘ + q_1: ┤ Z ├────── + └───┘ + + (expected) + + ┌───┐┌───┐ + q_0:─┤ H ├┤ Z ├─ + └───┘└───┘ + q_1: ─────────── + """ circuit1 = QuantumCircuit(2) circuit1.z(0) From 80e8d57fe7d09ef46f423eea883bb941e0e6c111 Mon Sep 17 00:00:00 2001 From: Jintaoyu Date: Fri, 26 Nov 2021 17:49:17 +0800 Subject: [PATCH 02/18] Add circuit diagram to equivalence_library.py --- .../standard_gates/equivalence_library.py | 439 +++++++++++++++--- 1 file changed, 380 insertions(+), 59 deletions(-) diff --git a/qiskit/circuit/library/standard_gates/equivalence_library.py b/qiskit/circuit/library/standard_gates/equivalence_library.py index 7b0a8125be60..3d3837efc847 100644 --- a/qiskit/circuit/library/standard_gates/equivalence_library.py +++ b/qiskit/circuit/library/standard_gates/equivalence_library.py @@ -73,11 +73,11 @@ """ HGate - ┌───┐ ┌─────────┐ -q_0: ┤ H ├ ≡ q_0: ┤ U2(0,π) ├ - └───┘ └─────────┘ -""" + ┌───┐ ┌─────────┐ +q: ┤ H ├ ≡ q: ┤ U2(0,π) ├ + └───┘ └─────────┘ +""" q = QuantumRegister(1, "q") def_h = QuantumCircuit(q) def_h.append(U2Gate(0, pi), [q[0]], []) @@ -91,7 +91,6 @@ q_1: ┤ H ├ q_1: ┤ S ├┤ H ├┤ T ├┤ X ├┤ Tdg ├┤ H ├┤ Sdg ├ └───┘ └───┘└───┘└───┘└───┘└─────┘└───┘└─────┘ """ - q = QuantumRegister(2, "q") def_ch = QuantumCircuit(q) for inst, qargs, cargs in [ @@ -122,9 +121,9 @@ """ PhaseGate - ┌──────┐ ┌───────┐ -q_0: ┤ P(ϴ) ├ ≡ q_0: ┤ U1(ϴ) ├ - └──────┘ └───────┘ + ┌──────┐ ┌───────┐ +q: ┤ P(ϴ) ├ ≡ q: ┤ U1(ϴ) ├ + └──────┘ └───────┘ """ q = QuantumRegister(1, "q") theta = Parameter("theta") @@ -140,7 +139,6 @@ """ CPhaseGate - ┌────────┐ q_0: ─■──── q_0: ┤ P(ϴ/2) ├──■─────────────────■──────────── │P(ϴ) ≡ └────────┘┌─┴─┐┌───────────┐┌─┴─┐┌────────┐ @@ -157,14 +155,26 @@ def_cphase.p(theta / 2, 1) _sel.add_equivalence(CPhaseGate(theta), def_cphase) +""" +CPhaseGate + +q_0: ─■──── q_0: ─■──── + │P(ϴ) ≡ │U1(ϴ) +q_1: ─■──── q_1: ─■──── +""" q = QuantumRegister(2, "q") theta = Parameter("theta") cphase_to_cu1 = QuantumCircuit(q) cphase_to_cu1.append(CU1Gate(theta), [0, 1]) _sel.add_equivalence(CPhaseGate(theta), cphase_to_cu1) -# RGate +""" +RGate + ┌────────┐ ┌───────────────────────┐ +q: ┤ R(ϴ,φ) ├ ≡ q: ┤ U3(ϴ,φ - π/2,π/2 - φ) ├ + └────────┘ └───────────────────────┘ +""" q = QuantumRegister(1, "q") theta = Parameter("theta") phi = Parameter("phi") @@ -172,8 +182,17 @@ def_r.append(U3Gate(theta, phi - pi / 2, -phi + pi / 2), [q[0]]) _sel.add_equivalence(RGate(theta, phi), def_r) -# RCCXGate - +""" +RCCXGate + + ┌───────┐ +q_0: ┤0 ├ q_0: ────────────────────────■──────────────────────── + │ │ │ +q_1: ┤1 Rccx ├ ≡ q_1: ────────────■───────────┼─────────■────────────── + │ │ ┌───┐┌───┐┌─┴─┐┌─────┐┌─┴─┐┌───┐┌─┴─┐┌─────┐┌───┐ +q_2: ┤2 ├ q_2: ┤ H ├┤ T ├┤ X ├┤ Tdg ├┤ X ├┤ T ├┤ X ├┤ Tdg ├┤ H ├ + └───────┘ └───┘└───┘└───┘└─────┘└───┘└───┘└───┘└─────┘└───┘ +""" q = QuantumRegister(3, "q") def_rccx = QuantumCircuit(q) for inst, qargs, cargs in [ @@ -190,16 +209,27 @@ def_rccx.append(inst, qargs, cargs) _sel.add_equivalence(RCCXGate(), def_rccx) -# RXGate +""" +RXGate + ┌───────┐ ┌────────┐ +q: ┤ Rx(ϴ) ├ ≡ q: ┤ R(ϴ,0) ├ + └───────┘ └────────┘ +""" q = QuantumRegister(1, "q") theta = Parameter("theta") def_rx = QuantumCircuit(q) def_rx.append(RGate(theta, 0), [q[0]], []) _sel.add_equivalence(RXGate(theta), def_rx) -# CRXGate +""" +CRXGate +q_0: ────■──── q_0: ─────────────■──────────────────────■──────────────────── + ┌───┴───┐ ┌─────────┐┌─┴─┐┌────────────────┐┌─┴─┐┌────────────────┐ +q_1: ┤ Rx(ϴ) ├ ≡ q_1: ┤ U1(π/2) ├┤ X ├┤ U3(-0.5*ϴ,0,0) ├┤ X ├┤ U3(ϴ/2,-π/2,0) ├ + └───────┘ └─────────┘└───┘└────────────────┘└───┘└────────────────┘ +""" q = QuantumRegister(2, "q") theta = Parameter("theta") def_crx = QuantumCircuit(q) @@ -213,6 +243,14 @@ def_crx.append(inst, qargs, cargs) _sel.add_equivalence(CRXGate(theta), def_crx) +""" +CRXGate + +q_0: ────■──── q_0: ───────■──────────────────■──────────────────── + ┌───┴───┐ ┌───┐┌─┴─┐┌────────────┐┌─┴─┐┌─────────┐┌─────┐ +q_1: ┤ Rx(ϴ) ├ ≡ q_1: ┤ S ├┤ X ├┤ Ry(-0.5*ϴ) ├┤ X ├┤ Ry(ϴ/2) ├┤ Sdg ├ + └───────┘ └───┘└───┘└────────────┘└───┘└─────────┘└─────┘ +""" q = QuantumRegister(2, "q") theta = Parameter("theta") crx_to_srycx = QuantumCircuit(q) @@ -227,8 +265,15 @@ crx_to_srycx.append(inst, qargs, cargs) _sel.add_equivalence(CRXGate(theta), crx_to_srycx) -# RXXGate +""" +RXXGate + ┌─────────┐ ┌───┐ ┌───┐ +q_0: ┤0 ├ q_0: ┤ H ├──■─────────────■──┤ H ├ + │ Rxx(ϴ) │ ≡ ├───┤┌─┴─┐┌───────┐┌─┴─┐├───┤ +q_1: ┤1 ├ q_1: ┤ H ├┤ X ├┤ Rz(ϴ) ├┤ X ├┤ H ├ + └─────────┘ └───┘└───┘└───────┘└───┘└───┘ +""" q = QuantumRegister(2, "q") theta = Parameter("theta") def_rxx = QuantumCircuit(q) @@ -244,8 +289,15 @@ def_rxx.append(inst, qargs, cargs) _sel.add_equivalence(RXXGate(theta), def_rxx) -# RZXGate +""" +RZXGate + ┌─────────┐ +q_0: ┤0 ├ q_0: ───────■─────────────■─────── + │ Rzx(ϴ) │ ≡ ┌───┐┌─┴─┐┌───────┐┌─┴─┐┌───┐ +q_1: ┤1 ├ q_1: ┤ H ├┤ X ├┤ Rz(ϴ) ├┤ X ├┤ H ├ + └─────────┘ └───┘└───┘└───────┘└───┘└───┘ +""" q = QuantumRegister(2, "q") theta = Parameter("theta") def_rzx = QuantumCircuit(q) @@ -260,16 +312,27 @@ _sel.add_equivalence(RZXGate(theta), def_rzx) -# RYGate +""" +RYGate + ┌───────┐ ┌──────────┐ +q: ┤ Ry(ϴ) ├ ≡ q: ┤ R(ϴ,π/2) ├ + └───────┘ └──────────┘ +""" q = QuantumRegister(1, "q") theta = Parameter("theta") def_ry = QuantumCircuit(q) def_ry.append(RGate(theta, pi / 2), [q[0]], []) _sel.add_equivalence(RYGate(theta), def_ry) -# CRYGate +""" +CRYGate +q_0: ────■──── q_0: ─────────────■──────────────────■── + ┌───┴───┐ ≡ ┌─────────┐┌─┴─┐┌────────────┐┌─┴─┐ +q_1: ┤ Ry(ϴ) ├ q_1: ┤ Ry(ϴ/2) ├┤ X ├┤ Ry(-0.5*ϴ) ├┤ X ├ + └───────┘ └─────────┘└───┘└────────────┘└───┘ +""" q = QuantumRegister(2, "q") theta = Parameter("theta") def_cry = QuantumCircuit(q) @@ -282,8 +345,15 @@ def_cry.append(inst, qargs, cargs) _sel.add_equivalence(CRYGate(theta), def_cry) -# RYYGate +""" +RYYGate + ┌─────────┐ ┌─────────┐ ┌──────────┐ +q_0: ┤0 ├ q_0: ┤ Rx(π/2) ├──■─────────────■──┤ Rx(-π/2) ├ + │ Ryy(ϴ) │ ≡ ├─────────┤┌─┴─┐┌───────┐┌─┴─┐├──────────┤ +q_1: ┤1 ├ q_1: ┤ Rx(π/2) ├┤ X ├┤ Rz(ϴ) ├┤ X ├┤ Rx(-π/2) ├ + └─────────┘ └─────────┘└───┘└───────┘└───┘└──────────┘ +""" q = QuantumRegister(2, "q") theta = Parameter("theta") def_ryy = QuantumCircuit(q) @@ -299,14 +369,26 @@ def_ryy.append(inst, qargs, cargs) _sel.add_equivalence(RYYGate(theta), def_ryy) -# RZGate - +""" +RZGate + global phase: -0.5*ϴ + ┌───────┐ ┌───────┐ +q: ┤ Rz(ϴ) ├ ≡ q: ┤ U1(ϴ) ├ + └───────┘ └───────┘ +""" q = QuantumRegister(1, "q") theta = Parameter("theta") def_rz = QuantumCircuit(q, global_phase=-theta / 2) def_rz.append(U1Gate(theta), [q[0]], []) _sel.add_equivalence(RZGate(theta), def_rz) +""" +RZGate + + ┌───────┐ ┌────┐┌────────────┐┌──────┐ +q: ┤ Rz(ϴ) ├ ≡ q: ┤ √X ├┤ Ry(-1.0*ϴ) ├┤ √Xdg ├ + └───────┘ └────┘└────────────┘└──────┘ +""" q = QuantumRegister(1, "q") rz_to_sxry = QuantumCircuit(q) rz_to_sxry.sx(0) @@ -314,8 +396,14 @@ rz_to_sxry.sxdg(0) _sel.add_equivalence(RZGate(theta), rz_to_sxry) -# CRZGate +""" +CRZGate +q_0: ────■──── q_0: ─────────────■──────────────────■── + ┌───┴───┐ ┌─────────┐┌─┴─┐┌────────────┐┌─┴─┐ +q_1: ┤ Rz(ϴ) ├ ≡ q_1: ┤ Rz(ϴ/2) ├┤ X ├┤ Rz(-0.5*ϴ) ├┤ X ├ + └───────┘ └─────────┘└───┘└────────────┘└───┘ +""" q = QuantumRegister(2, "q") theta = Parameter("theta") def_crz = QuantumCircuit(q) @@ -328,8 +416,14 @@ def_crz.append(inst, qargs, cargs) _sel.add_equivalence(CRZGate(theta), def_crz) -# RZZGate +""" +RZZGate +q_0: ─■───── q_0: ──■─────────────■── + │ZZ(ϴ) ≡ ┌─┴─┐┌───────┐┌─┴─┐ +q_1: ─■───── q_1: ┤ X ├┤ Rz(ϴ) ├┤ X ├ + └───┘└───────┘└───┘ +""" q = QuantumRegister(2, "q") theta = Parameter("theta") def_rzz = QuantumCircuit(q) @@ -341,8 +435,15 @@ def_rzz.append(inst, qargs, cargs) _sel.add_equivalence(RZZGate(theta), def_rzz) -# RZXGate +""" +RZXGate + ┌─────────┐ +q_0: ┤0 ├ q_0: ───────■─────────────■─────── + │ Rzx(ϴ) │ ≡ ┌───┐┌─┴─┐┌───────┐┌─┴─┐┌───┐ +q_1: ┤1 ├ q_1: ┤ H ├┤ X ├┤ Rz(ϴ) ├┤ X ├┤ H ├ + └─────────┘ └───┘└───┘└───────┘└───┘└───┘ +""" q = QuantumRegister(2, "q") theta = Parameter("theta") def_rzx = QuantumCircuit(q) @@ -356,8 +457,15 @@ def_rzx.append(inst, qargs, cargs) _sel.add_equivalence(RZXGate(theta), def_rzx) -# ECRGate +""" +ECRGate + ┌──────┐ ┌───────────┐┌───┐┌────────────┐ +q_0: ┤0 ├ q_0: ┤0 ├┤ X ├┤0 ├ + │ Ecr │ ≡ │ Rzx(π/4) │└───┘│ Rzx(-π/4) │ +q_1: ┤1 ├ q_1: ┤1 ├─────┤1 ├ + └──────┘ └───────────┘ └────────────┘ +""" q = QuantumRegister(2, "q") def_ecr = QuantumCircuit(q) for inst, qargs, cargs in [ @@ -368,20 +476,37 @@ def_ecr.append(inst, qargs, cargs) _sel.add_equivalence(ECRGate(), def_ecr) -# SGate +""" +SGate + ┌───┐ ┌─────────┐ +q: ┤ S ├ ≡ q: ┤ U1(π/2) ├ + └───┘ └─────────┘ +""" q = QuantumRegister(1, "q") def_s = QuantumCircuit(q) def_s.append(U1Gate(pi / 2), [q[0]], []) _sel.add_equivalence(SGate(), def_s) -# SdgGate +""" +SdgGate + ┌─────┐ ┌──────────┐ +q: ┤ Sdg ├ ≡ q: ┤ U1(-π/2) ├ + └─────┘ └──────────┘ +""" q = QuantumRegister(1, "q") def_sdg = QuantumCircuit(q) def_sdg.append(U1Gate(-pi / 2), [q[0]], []) _sel.add_equivalence(SdgGate(), def_sdg) +""" +SdgGate + + ┌─────┐ ┌───┐┌───┐ +q: ┤ Sdg ├ ≡ q: ┤ S ├┤ Z ├ + └─────┘ └───┘└───┘ +""" q = QuantumRegister(1, "q") def_sdg = QuantumCircuit(q) for inst, qargs, cargs in [ @@ -391,6 +516,13 @@ def_sdg.append(inst, qargs, cargs) _sel.add_equivalence(SdgGate(), def_sdg) +""" +SdgGate + + ┌─────┐ ┌───┐┌───┐ +q: ┤ Sdg ├ ≡ q: ┤ Z ├┤ S ├ + └─────┘ └───┘└───┘ +""" q = QuantumRegister(1, "q") def_sdg = QuantumCircuit(q) for inst, qargs, cargs in [ @@ -400,6 +532,13 @@ def_sdg.append(inst, qargs, cargs) _sel.add_equivalence(SdgGate(), def_sdg) +""" +SdgGate + + ┌─────┐ ┌───┐┌───┐┌───┐ +q: ┤ Sdg ├ ≡ q: ┤ S ├┤ S ├┤ S ├ + └─────┘ └───┘└───┘└───┘ +""" q = QuantumRegister(1, "q") def_sdg = QuantumCircuit(q) for inst, qargs, cargs in [ @@ -410,8 +549,14 @@ def_sdg.append(inst, qargs, cargs) _sel.add_equivalence(SdgGate(), def_sdg) -# SwapGate - +""" +SwapGate + ┌───┐ +q_0: ─X─ q_0: ──■──┤ X ├──■── + │ ≡ ┌─┴─┐└─┬─┘┌─┴─┐ +q_1: ─X─ q_1: ┤ X ├──■──┤ X ├ + └───┘ └───┘ +""" q = QuantumRegister(2, "q") def_swap = QuantumCircuit(q) for inst, qargs, cargs in [ @@ -422,8 +567,15 @@ def_swap.append(inst, qargs, cargs) _sel.add_equivalence(SwapGate(), def_swap) -# iSwapGate +""" +iSwapGate + ┌────────┐ ┌───┐┌───┐ ┌───┐ +q_0: ┤0 ├ q_0: ┤ S ├┤ H ├──■──┤ X ├───── + │ Iswap │ ≡ ├───┤└───┘┌─┴─┐└─┬─┘┌───┐ +q_1: ┤1 ├ q_1: ┤ S ├─────┤ X ├──■──┤ H ├ + └────────┘ └───┘ └───┘ └───┘ +""" q = QuantumRegister(2, "q") def_iswap = QuantumCircuit(q) for inst, qargs, cargs in [ @@ -437,34 +589,72 @@ def_iswap.append(inst, qargs, cargs) _sel.add_equivalence(iSwapGate(), def_iswap) -# SXGate - +""" +SXGate + global phase: π/4 + ┌────┐ ┌─────┐┌───┐┌─────┐ +q: ┤ √X ├ ≡ q: ┤ Sdg ├┤ H ├┤ Sdg ├ + └────┘ └─────┘└───┘└─────┘ +""" q = QuantumRegister(1, "q") def_sx = QuantumCircuit(q, global_phase=pi / 4) -for inst, qargs, cargs in [(SdgGate(), [q[0]], []), (HGate(), [q[0]], []), (SdgGate(), [q[0]], [])]: +for inst, qargs, cargs in [ + (SdgGate(), [q[0]], []), + (HGate(), [q[0]], []), + (SdgGate(), [q[0]], []) +]: def_sx.append(inst, qargs, cargs) _sel.add_equivalence(SXGate(), def_sx) +""" +SXGate + global phase: π/4 + ┌────┐ ┌─────────┐ +q: ┤ √X ├ ≡ q: ┤ Rx(π/2) ├ + └────┘ └─────────┘ +""" q = QuantumRegister(1, "q") sx_to_rx = QuantumCircuit(q, global_phase=pi / 4) sx_to_rx.rx(pi / 2, 0) _sel.add_equivalence(SXGate(), sx_to_rx) -# SXdgGate - +""" +SXdgGate + global phase: 7π/4 + ┌──────┐ ┌───┐┌───┐┌───┐ +q: ┤ √Xdg ├ ≡ q: ┤ S ├┤ H ├┤ S ├ + └──────┘ └───┘└───┘└───┘ +""" q = QuantumRegister(1, "q") def_sxdg = QuantumCircuit(q, global_phase=-pi / 4) -for inst, qargs, cargs in [(SGate(), [q[0]], []), (HGate(), [q[0]], []), (SGate(), [q[0]], [])]: +for inst, qargs, cargs in [ + (SGate(), [q[0]], []), + (HGate(), [q[0]], []), + (SGate(), [q[0]], []) +]: def_sxdg.append(inst, qargs, cargs) _sel.add_equivalence(SXdgGate(), def_sxdg) +""" +SXdgGate + global phase: 7π/4 + ┌──────┐ ┌──────────┐ +q: ┤ √Xdg ├ ≡ q: ┤ Rx(-π/2) ├ + └──────┘ └──────────┘ +""" q = QuantumRegister(1, "q") sxdg_to_rx = QuantumCircuit(q, global_phase=-pi / 4) sxdg_to_rx.rx(-pi / 2, 0) _sel.add_equivalence(SXdgGate(), sxdg_to_rx) -# CSXGate +""" +CSXGate +q_0: ──■─── q_0: ──────■───────────── + ┌─┴──┐ ≡ ┌───┐ │U1(π/2) ┌───┐ +q_1: ┤ Sx ├ q_1: ┤ H ├─■────────┤ H ├ + └────┘ └───┘ └───┘ +""" q = QuantumRegister(2, "q") def_csx = QuantumCircuit(q) for inst, qargs, cargs in [ @@ -475,6 +665,15 @@ def_csx.append(inst, qargs, cargs) _sel.add_equivalence(CSXGate(), def_csx) +""" +CSXGate + global phase: π/8 + ┌───┐┌───────────┐ ┌─────┐ ┌───┐ +q_0: ──■─── q_0: ┤ X ├┤0 ├─┤ Tdg ├──┤ X ├ + ┌─┴──┐ ≡ └───┘│ Rzx(π/4) │┌┴─────┴─┐└───┘ +q_1: ┤ Sx ├ q_1: ─────┤1 ├┤ sx^0.5 ├───── + └────┘ └───────────┘└────────┘ +""" q = QuantumRegister(2, "q") csx_to_zx45 = QuantumCircuit(q, global_phase=pi / 8) for inst, qargs, cargs in [ @@ -488,14 +687,33 @@ _sel.add_equivalence(CSXGate(), csx_to_zx45) -# DCXGate +""" +DCXGate + ┌──────┐ ┌───┐ +q_0: ┤0 ├ q_0: ──■──┤ X ├ + │ Dcx │ ≡ ┌─┴─┐└─┬─┘ +q_1: ┤1 ├ q_1: ┤ X ├──■── + └──────┘ └───┘ +""" q = QuantumRegister(2, "q") def_dcx = QuantumCircuit(q) -for inst, qargs, cargs in [(CXGate(), [q[0], q[1]], []), (CXGate(), [q[1], q[0]], [])]: +for inst, qargs, cargs in [ + (CXGate(), [q[0], q[1]], []), + (CXGate(), [q[1], q[0]], []) +]: def_dcx.append(inst, qargs, cargs) _sel.add_equivalence(DCXGate(), def_dcx) +""" +DCXGate + + ┌──────┐ ┌───┐ ┌─────┐┌────────┐ +q_0: ┤0 ├ q_0: ─┤ H ├─┤ Sdg ├┤0 ├───── + │ Dcx │ ≡ ┌┴───┴┐└─────┘│ Iswap │┌───┐ +q_1: ┤1 ├ q_1: ┤ Sdg ├───────┤1 ├┤ H ├ + └──────┘ └─────┘ └────────┘└───┘ +""" q = QuantumRegister(2, "q") dcx_to_iswap = QuantumCircuit(q) for inst, qargs, cargs in [ @@ -508,8 +726,16 @@ dcx_to_iswap.append(inst, qargs, cargs) _sel.add_equivalence(DCXGate(), dcx_to_iswap) -# CSwapGate - +""" +CSwapGate + +q_0: ─■─ q_0: ───────■─────── + │ ┌───┐ │ ┌───┐ +q_1: ─X─ ≡ q_1: ┤ X ├──■──┤ X ├ + │ └─┬─┘┌─┴─┐└─┬─┘ +q_2: ─X─ q_2: ──■──┤ X ├──■── + └───┘ +""" q = QuantumRegister(3, "q") def_cswap = QuantumCircuit(q) for inst, qargs, cargs in [ @@ -520,22 +746,37 @@ def_cswap.append(inst, qargs, cargs) _sel.add_equivalence(CSwapGate(), def_cswap) -# TGate +""" +TGate + ┌───┐ ┌─────────┐ +q: ┤ T ├ ≡ q: ┤ U1(π/4) ├ + └───┘ └─────────┘ +""" q = QuantumRegister(1, "q") def_t = QuantumCircuit(q) def_t.append(U1Gate(pi / 4), [q[0]], []) _sel.add_equivalence(TGate(), def_t) -# TdgGate +""" +TdgGate + ┌─────┐ ┌──────────┐ +q: ┤ Tdg ├ ≡ q: ┤ U1(-π/4) ├ + └─────┘ └──────────┘ +""" q = QuantumRegister(1, "q") def_tdg = QuantumCircuit(q) def_tdg.append(U1Gate(-pi / 4), [q[0]], []) _sel.add_equivalence(TdgGate(), def_tdg) -# UGate +""" +UGate + ┌──────────┐ ┌───────────┐ +q: ┤ U(θ,ϕ,λ) ├ ≡ q: ┤ U3(θ,ϕ,λ) ├ + └──────────┘ └───────────┘ +""" q = QuantumRegister(1, "q") theta = Parameter("theta") phi = Parameter("phi") @@ -544,8 +785,19 @@ u_to_u3.append(U3Gate(theta, phi, lam), [0]) _sel.add_equivalence(UGate(theta, phi, lam), u_to_u3) -# CUGate - +""" +CUGate + ┌──────┐ ┌──────────────┐ » +q_0: ──────■─────── q_0: ────┤ P(γ) ├────┤ P(λ/2 + ϕ/2) ├──■──» + ┌─────┴──────┐ ≡ ┌───┴──────┴───┐└──────────────┘┌─┴─┐» +q_1: ┤ U(θ,ϕ,λ,γ) ├ q_1: ┤ P(λ/2 - ϕ/2) ├────────────────┤ X ├» + └────────────┘ └──────────────┘ └───┘» +« +«q_0: ────────────────────────────────■──────────────── +« ┌────────────────────────────┐┌─┴─┐┌────────────┐ +«q_1: ┤ U(-0.5*θ,ϕ,-0.5*λ - 0.5*ϕ) ├┤ X ├┤ U(θ/2,ϕ,0) ├ +« └────────────────────────────┘└───┘└────────────┘ +""" q = QuantumRegister(2, "q") theta = Parameter("theta") phi = Parameter("phi") @@ -561,6 +813,14 @@ def_cu.u(theta / 2, phi, 0, 1) _sel.add_equivalence(CUGate(theta, phi, lam, gamma), def_cu) +""" +CUGate + ┌──────┐ +q_0: ──────■─────── q_0: ┤ P(γ) ├──────■────── + ┌─────┴──────┐ ≡ └──────┘┌─────┴─────┐ +q_1: ┤ U(θ,ϕ,λ,γ) ├ q_1: ────────┤ U3(θ,ϕ,λ) ├ + └────────────┘ └───────────┘ +""" q = QuantumRegister(2, "q") theta = Parameter("theta") phi = Parameter("phi") @@ -571,30 +831,53 @@ cu_to_cu3.append(CU3Gate(theta, phi, lam), [0, 1]) _sel.add_equivalence(CUGate(theta, phi, lam, gamma), cu_to_cu3) -# U1Gate +""" +U1Gate + ┌───────┐ ┌───────────┐ +q: ┤ U1(θ) ├ ≡ q: ┤ U3(0,0,θ) ├ + └───────┘ └───────────┘ +""" q = QuantumRegister(1, "q") theta = Parameter("theta") def_u1 = QuantumCircuit(q) def_u1.append(U3Gate(0, 0, theta), [q[0]], []) _sel.add_equivalence(U1Gate(theta), def_u1) +""" +U1Gate + + ┌───────┐ ┌──────┐ +q: ┤ U1(θ) ├ ≡ q: ┤ P(0) ├ + └───────┘ └──────┘ +""" q = QuantumRegister(1, "q") theta = Parameter("theta") u1_to_phase = QuantumCircuit(q) u1_to_phase.p(theta, 0) _sel.add_equivalence(U1Gate(theta), u1_to_phase) -# U1Gate - +""" +U1Gate + global phase: θ/2 + ┌───────┐ ┌───────┐ +q: ┤ U1(θ) ├ ≡ q: ┤ Rz(θ) ├ + └───────┘ └───────┘ +""" q = QuantumRegister(1, "q") theta = Parameter("theta") u1_to_rz = QuantumCircuit(q, global_phase=theta / 2) u1_to_rz.append(RZGate(theta), [q[0]], []) _sel.add_equivalence(U1Gate(theta), u1_to_rz) -# CU1Gate - +""" +CU1Gate + ┌─────────┐ +q_0: ─■───── q_0: ┤ U1(θ/2) ├──■──────────────────■───────────── + │U1(θ) ≡ └─────────┘┌─┴─┐┌────────────┐┌─┴─┐┌─────────┐ +q_1: ─■───── q_1: ───────────┤ X ├┤ U1(-0.5*θ) ├┤ X ├┤ U1(θ/2) ├ + └───┘└────────────┘└───┘└─────────┘ +""" q = QuantumRegister(2, "q") theta = Parameter("theta") def_cu1 = QuantumCircuit(q) @@ -608,8 +891,13 @@ def_cu1.append(inst, qargs, cargs) _sel.add_equivalence(CU1Gate(theta), def_cu1) -# U2Gate +""" +U2Gate + ┌─────────┐ ┌─────────────┐ +q: ┤ U2(ϕ,λ) ├ ≡ q: ┤ U3(π/2,ϕ,λ) ├ + └─────────┘ └─────────────┘ +""" q = QuantumRegister(1, "q") phi = Parameter("phi") lam = Parameter("lam") @@ -617,8 +905,13 @@ def_u2.append(U3Gate(pi / 2, phi, lam), [q[0]], []) _sel.add_equivalence(U2Gate(phi, lam), def_u2) -# U2Gate - +""" +U2Gate + global phase: 7π/4 + ┌─────────┐ ┌─────────────┐┌────┐┌─────────────┐ +q: ┤ U2(ϕ,λ) ├ ≡ q: ┤ U1(λ - π/2) ├┤ √X ├┤ U1(ϕ + π/2) ├ + └─────────┘ └─────────────┘└────┘└─────────────┘ +""" q = QuantumRegister(1, "q") phi = Parameter("phi") lam = Parameter("lam") @@ -628,8 +921,13 @@ u2_to_u1sx.append(U1Gate(phi + pi / 2), [0]) _sel.add_equivalence(U2Gate(phi, lam), u2_to_u1sx) -# U3Gate - +""" +U3Gate + global phase: λ/2 + ϕ/2 - π/2 + ┌───────────┐ ┌───────┐┌────┐┌───────────┐┌────┐┌────────────┐ +q: ┤ U3(θ,ϕ,λ) ├ ≡ q: ┤ Rz(λ) ├┤ √X ├┤ Rz(θ + π) ├┤ √X ├┤ Rz(ϕ + 3π) ├ + └───────────┘ └───────┘└────┘└───────────┘└────┘└────────────┘ +""" q = QuantumRegister(1, "q") theta = Parameter("theta") phi = Parameter("phi") @@ -642,6 +940,13 @@ u3_qasm_def.rz(phi + 3 * pi, 0) _sel.add_equivalence(U3Gate(theta, phi, lam), u3_qasm_def) +""" +U3Gate + + ┌───────────┐ ┌──────────┐ +q: ┤ U3(θ,ϕ,λ) ├ ≡ q: ┤ U(θ,ϕ,λ) ├ + └───────────┘ └──────────┘ +""" q = QuantumRegister(1, "q") theta = Parameter("theta") phi = Parameter("phi") @@ -650,8 +955,19 @@ u3_to_u.u(theta, phi, lam, 0) _sel.add_equivalence(U3Gate(theta, phi, lam), u3_to_u) -# CU3Gate - +""" +CU3Gate + ┌───────────────┐ » +q_0: ──────■────── q_0: ┤ U1(λ/2 + ϕ/2) ├──■───────────────────────────────────■──» + ┌─────┴─────┐ ≡ ├───────────────┤┌─┴─┐┌─────────────────────────────┐┌─┴─┐» +q_1: ┤ U3(θ,ϕ,λ) ├ q_1: ┤ U1(λ/2 - ϕ/2) ├┤ X ├┤ U3(-0.5*θ,0,-0.5*λ - 0.5*ϕ) ├┤ X ├» + └───────────┘ └───────────────┘└───┘└─────────────────────────────┘└───┘» +« +«q_0: ─────────────── +« ┌─────────────┐ +«q_1: ┤ U3(θ/2,ϕ,0) ├ +« └─────────────┘ +""" q = QuantumRegister(2, "q") theta = Parameter("theta") phi = Parameter("phi") @@ -675,8 +991,13 @@ cu3_to_cu = QuantumCircuit(q) cu3_to_cu.cu(theta, phi, lam, 0, 0, 1) -# XGate +""" +XGate + ┌───┐ ┌───────────┐ +q: ┤ X ├ ≡ q: ┤ U3(π,0,π) ├ + └───┘ └───────────┘ +""" q = QuantumRegister(1, "q") def_x = QuantumCircuit(q) def_x.append(U3Gate(pi, 0, pi), [q[0]], []) From 361fd9ff7c62458a03872f7fc0f7e143bcda5c52 Mon Sep 17 00:00:00 2001 From: Jintaoyu Date: Sun, 28 Nov 2021 15:23:48 +0800 Subject: [PATCH 03/18] Add a TODO in equivalence_library.py --- .../standard_gates/equivalence_library.py | 242 +++++++++++++----- 1 file changed, 183 insertions(+), 59 deletions(-) diff --git a/qiskit/circuit/library/standard_gates/equivalence_library.py b/qiskit/circuit/library/standard_gates/equivalence_library.py index 3d3837efc847..b5de48ac2b9f 100644 --- a/qiskit/circuit/library/standard_gates/equivalence_library.py +++ b/qiskit/circuit/library/standard_gates/equivalence_library.py @@ -140,10 +140,10 @@ """ CPhaseGate ┌────────┐ -q_0: ─■──── q_0: ┤ P(ϴ/2) ├──■─────────────────■──────────── - │P(ϴ) ≡ └────────┘┌─┴─┐┌───────────┐┌─┴─┐┌────────┐ -q_1: ─■──── q_1: ──────────┤ X ├┤ P(-0.5*ϴ) ├┤ X ├┤ P(ϴ/2) ├ - └───┘└───────────┘└───┘└────────┘ +q_0: ─■──── q_0: ┤ P(ϴ/2) ├──■───────────────■──────────── + │P(ϴ) ≡ └────────┘┌─┴─┐┌─────────┐┌─┴─┐┌────────┐ +q_1: ─■──── q_1: ──────────┤ X ├┤ P(-ϴ/2) ├┤ X ├┤ P(ϴ/2) ├ + └───┘└─────────┘└───┘└────────┘ """ q = QuantumRegister(2, "q") theta = Parameter("theta") @@ -225,10 +225,10 @@ """ CRXGate -q_0: ────■──── q_0: ─────────────■──────────────────────■──────────────────── - ┌───┴───┐ ┌─────────┐┌─┴─┐┌────────────────┐┌─┴─┐┌────────────────┐ -q_1: ┤ Rx(ϴ) ├ ≡ q_1: ┤ U1(π/2) ├┤ X ├┤ U3(-0.5*ϴ,0,0) ├┤ X ├┤ U3(ϴ/2,-π/2,0) ├ - └───────┘ └─────────┘└───┘└────────────────┘└───┘└────────────────┘ +q_0: ────■──── q_0: ─────────────■────────────────────■──────────────────── + ┌───┴───┐ ≡ ┌─────────┐┌─┴─┐┌──────────────┐┌─┴─┐┌────────────────┐ +q_1: ┤ Rx(ϴ) ├ q_1: ┤ U1(π/2) ├┤ X ├┤ U3(-ϴ/2,0,0) ├┤ X ├┤ U3(ϴ/2,-π/2,0) ├ + └───────┘ └─────────┘└───┘└──────────────┘└───┘└────────────────┘ """ q = QuantumRegister(2, "q") theta = Parameter("theta") @@ -246,10 +246,10 @@ """ CRXGate -q_0: ────■──── q_0: ───────■──────────────────■──────────────────── - ┌───┴───┐ ┌───┐┌─┴─┐┌────────────┐┌─┴─┐┌─────────┐┌─────┐ -q_1: ┤ Rx(ϴ) ├ ≡ q_1: ┤ S ├┤ X ├┤ Ry(-0.5*ϴ) ├┤ X ├┤ Ry(ϴ/2) ├┤ Sdg ├ - └───────┘ └───┘└───┘└────────────┘└───┘└─────────┘└─────┘ +q_0: ────■──── q_0: ───────■────────────────■──────────────────── + ┌───┴───┐ ≡ ┌───┐┌─┴─┐┌──────────┐┌─┴─┐┌─────────┐┌─────┐ +q_1: ┤ Rx(ϴ) ├ q_1: ┤ S ├┤ X ├┤ Ry(-ϴ/2) ├┤ X ├┤ Ry(ϴ/2) ├┤ Sdg ├ + └───────┘ └───┘└───┘└──────────┘└───┘└─────────┘└─────┘ """ q = QuantumRegister(2, "q") theta = Parameter("theta") @@ -328,10 +328,10 @@ """ CRYGate -q_0: ────■──── q_0: ─────────────■──────────────────■── - ┌───┴───┐ ≡ ┌─────────┐┌─┴─┐┌────────────┐┌─┴─┐ -q_1: ┤ Ry(ϴ) ├ q_1: ┤ Ry(ϴ/2) ├┤ X ├┤ Ry(-0.5*ϴ) ├┤ X ├ - └───────┘ └─────────┘└───┘└────────────┘└───┘ +q_0: ────■──── q_0: ─────────────■────────────────■── + ┌───┴───┐ ≡ ┌─────────┐┌─┴─┐┌──────────┐┌─┴─┐ +q_1: ┤ Ry(ϴ) ├ q_1: ┤ Ry(ϴ/2) ├┤ X ├┤ Ry(-ϴ/2) ├┤ X ├ + └───────┘ └─────────┘└───┘└──────────┘└───┘ """ q = QuantumRegister(2, "q") theta = Parameter("theta") @@ -371,7 +371,7 @@ """ RZGate - global phase: -0.5*ϴ + global phase: -ϴ/2 ┌───────┐ ┌───────┐ q: ┤ Rz(ϴ) ├ ≡ q: ┤ U1(ϴ) ├ └───────┘ └───────┘ @@ -385,9 +385,9 @@ """ RZGate - ┌───────┐ ┌────┐┌────────────┐┌──────┐ -q: ┤ Rz(ϴ) ├ ≡ q: ┤ √X ├┤ Ry(-1.0*ϴ) ├┤ √Xdg ├ - └───────┘ └────┘└────────────┘└──────┘ + ┌───────┐ ┌────┐┌────────┐┌──────┐ +q: ┤ Rz(ϴ) ├ ≡ q: ┤ √X ├┤ Ry(-ϴ) ├┤ √Xdg ├ + └───────┘ └────┘└────────┘└──────┘ """ q = QuantumRegister(1, "q") rz_to_sxry = QuantumCircuit(q) @@ -399,10 +399,10 @@ """ CRZGate -q_0: ────■──── q_0: ─────────────■──────────────────■── - ┌───┴───┐ ┌─────────┐┌─┴─┐┌────────────┐┌─┴─┐ -q_1: ┤ Rz(ϴ) ├ ≡ q_1: ┤ Rz(ϴ/2) ├┤ X ├┤ Rz(-0.5*ϴ) ├┤ X ├ - └───────┘ └─────────┘└───┘└────────────┘└───┘ +q_0: ────■──── q_0: ─────────────■────────────────■── + ┌───┴───┐ ≡ ┌─────────┐┌─┴─┐┌──────────┐┌─┴─┐ +q_1: ┤ Rz(ϴ) ├ q_1: ┤ Rz(ϴ/2) ├┤ X ├┤ Rz(-ϴ/2) ├┤ X ├ + └───────┘ └─────────┘└───┘└──────────┘└───┘ """ q = QuantumRegister(2, "q") theta = Parameter("theta") @@ -591,7 +591,7 @@ """ SXGate - global phase: π/4 + global phase: π/4 ┌────┐ ┌─────┐┌───┐┌─────┐ q: ┤ √X ├ ≡ q: ┤ Sdg ├┤ H ├┤ Sdg ├ └────┘ └─────┘└───┘└─────┘ @@ -608,7 +608,7 @@ """ SXGate - global phase: π/4 + global phase: π/4 ┌────┐ ┌─────────┐ q: ┤ √X ├ ≡ q: ┤ Rx(π/2) ├ └────┘ └─────────┘ @@ -620,7 +620,7 @@ """ SXdgGate - global phase: 7π/4 + global phase: 7π/4 ┌──────┐ ┌───┐┌───┐┌───┐ q: ┤ √Xdg ├ ≡ q: ┤ S ├┤ H ├┤ S ├ └──────┘ └───┘└───┘└───┘ @@ -637,7 +637,7 @@ """ SXdgGate - global phase: 7π/4 + global phase: 7π/4 ┌──────┐ ┌──────────┐ q: ┤ √Xdg ├ ≡ q: ┤ Rx(-π/2) ├ └──────┘ └──────────┘ @@ -667,7 +667,7 @@ """ CSXGate - global phase: π/8 + global phase: π/8 ┌───┐┌───────────┐ ┌─────┐ ┌───┐ q_0: ──■─── q_0: ┤ X ├┤0 ├─┤ Tdg ├──┤ X ├ ┌─┴──┐ ≡ └───┘│ Rzx(π/4) │┌┴─────┴─┐└───┘ @@ -793,10 +793,10 @@ q_1: ┤ U(θ,ϕ,λ,γ) ├ q_1: ┤ P(λ/2 - ϕ/2) ├────────────────┤ X ├» └────────────┘ └──────────────┘ └───┘» « -«q_0: ────────────────────────────────■──────────────── -« ┌────────────────────────────┐┌─┴─┐┌────────────┐ -«q_1: ┤ U(-0.5*θ,ϕ,-0.5*λ - 0.5*ϕ) ├┤ X ├┤ U(θ/2,ϕ,0) ├ -« └────────────────────────────┘└───┘└────────────┘ +«q_0: ──────────────────────────■──────────────── +« ┌──────────────────────┐┌─┴─┐┌────────────┐ +«q_1: ┤ U(-θ/2,ϕ,-λ/2 - ϕ/2) ├┤ X ├┤ U(θ/2,ϕ,0) ├ +« └──────────────────────┘└───┘└────────────┘ """ q = QuantumRegister(2, "q") theta = Parameter("theta") @@ -859,7 +859,7 @@ """ U1Gate - global phase: θ/2 + global phase: θ/2 ┌───────┐ ┌───────┐ q: ┤ U1(θ) ├ ≡ q: ┤ Rz(θ) ├ └───────┘ └───────┘ @@ -873,10 +873,10 @@ """ CU1Gate ┌─────────┐ -q_0: ─■───── q_0: ┤ U1(θ/2) ├──■──────────────────■───────────── - │U1(θ) ≡ └─────────┘┌─┴─┐┌────────────┐┌─┴─┐┌─────────┐ -q_1: ─■───── q_1: ───────────┤ X ├┤ U1(-0.5*θ) ├┤ X ├┤ U1(θ/2) ├ - └───┘└────────────┘└───┘└─────────┘ +q_0: ─■───── q_0: ┤ U1(θ/2) ├──■────────────────■───────────── + │U1(θ) ≡ └─────────┘┌─┴─┐┌──────────┐┌─┴─┐┌─────────┐ +q_1: ─■───── q_1: ───────────┤ X ├┤ U1(-θ/2) ├┤ X ├┤ U1(θ/2) ├ + └───┘└──────────┘└───┘└─────────┘ """ q = QuantumRegister(2, "q") theta = Parameter("theta") @@ -907,7 +907,7 @@ """ U2Gate - global phase: 7π/4 + global phase: 7π/4 ┌─────────┐ ┌─────────────┐┌────┐┌─────────────┐ q: ┤ U2(ϕ,λ) ├ ≡ q: ┤ U1(λ - π/2) ├┤ √X ├┤ U1(ϕ + π/2) ├ └─────────┘ └─────────────┘└────┘└─────────────┘ @@ -957,11 +957,11 @@ """ CU3Gate - ┌───────────────┐ » -q_0: ──────■────── q_0: ┤ U1(λ/2 + ϕ/2) ├──■───────────────────────────────────■──» - ┌─────┴─────┐ ≡ ├───────────────┤┌─┴─┐┌─────────────────────────────┐┌─┴─┐» -q_1: ┤ U3(θ,ϕ,λ) ├ q_1: ┤ U1(λ/2 - ϕ/2) ├┤ X ├┤ U3(-0.5*θ,0,-0.5*λ - 0.5*ϕ) ├┤ X ├» - └───────────┘ └───────────────┘└───┘└─────────────────────────────┘└───┘» + ┌───────────────┐ » +q_0: ──────■────── q_0: ┤ U1(λ/2 + ϕ/2) ├──■─────────────────────────────■──» + ┌─────┴─────┐ ≡ ├───────────────┤┌─┴─┐┌───────────────────────┐┌─┴─┐» +q_1: ┤ U3(θ,ϕ,λ) ├ q_1: ┤ U1(λ/2 - ϕ/2) ├┤ X ├┤ U3(-θ/2,0,-λ/2 - ϕ/2) ├┤ X ├» + └───────────┘ └───────────────┘└───┘└───────────────────────┘└───┘» « «q_0: ─────────────── « ┌─────────────┐ @@ -990,6 +990,8 @@ lam = Parameter("lam") cu3_to_cu = QuantumCircuit(q) cu3_to_cu.cu(theta, phi, lam, 0, 0, 1) +# TODO the following line causes a TypeError during test +# _sel.add_equivalence(CU3Gate(theta, phi, lam), cu3_to_cu) """ XGate @@ -1003,6 +1005,13 @@ def_x.append(U3Gate(pi, 0, pi), [q[0]], []) _sel.add_equivalence(XGate(), def_x) +""" +XGate + + ┌───┐ ┌───┐┌───┐┌───┐┌───┐ +q: ┤ X ├ ≡ q: ┤ H ├┤ S ├┤ S ├┤ H ├ + └───┘ └───┘└───┘└───┘└───┘ +""" q = QuantumRegister(1, "q") def_x = QuantumCircuit(q) for inst, qargs, cargs in [ @@ -1022,6 +1031,14 @@ cx_to_rxx = cnot_rxx_decompose(plus_ry, plus_rxx) _sel.add_equivalence(CXGate(), cx_to_rxx) +""" +CXGate + +q_0: ──■── q_0: ──────■────── + ┌─┴─┐ ≡ ┌───┐ │ ┌───┐ +q_1: ┤ X ├ q_1: ┤ H ├─■─┤ H ├ + └───┘ └───┘ └───┘ +""" q = QuantumRegister(2, "q") cx_to_cz = QuantumCircuit(q) for inst, qargs, cargs in [ @@ -1032,6 +1049,15 @@ cx_to_cz.append(inst, qargs, cargs) _sel.add_equivalence(CXGate(), cx_to_cz) +""" +CXGate + global phase: 3π/4 + ┌───┐ ┌────────┐┌───┐ ┌────────┐┌───┐┌───┐ +q_0: ──■── q_0: ┤ H ├─────┤0 ├┤ X ├─────┤0 ├┤ H ├┤ S ├───── + ┌─┴─┐ ≡ ├───┤┌───┐│ Iswap │├───┤┌───┐│ Iswap │├───┤├───┤┌───┐ +q_1: ┤ X ├ q_1: ┤ X ├┤ H ├┤1 ├┤ X ├┤ H ├┤1 ├┤ S ├┤ X ├┤ H ├ + └───┘ └───┘└───┘└────────┘└───┘└───┘└────────┘└───┘└───┘└───┘ +""" q = QuantumRegister(2, "q") cx_to_iswap = QuantumCircuit(q, global_phase=3 * pi / 4) for inst, qargs, cargs in [ @@ -1052,6 +1078,15 @@ cx_to_iswap.append(inst, qargs, cargs) _sel.add_equivalence(CXGate(), cx_to_iswap) +""" +CXGate + global phase: 7π/4 + ┌──────────┐┌───────┐┌──────┐ +q_0: ──■── q_0: ┤ Rz(-π/2) ├┤ Ry(π) ├┤0 ├ + ┌─┴─┐ ≡ ├─────────┬┘└───────┘│ Ecr │ +q_1: ┤ X ├ q_1: ┤ Rx(π/2) ├──────────┤1 ├ + └───┘ └─────────┘ └──────┘ +""" q = QuantumRegister(2, "q") cx_to_ecr = QuantumCircuit(q, global_phase=-pi / 4) for inst, qargs, cargs in [ @@ -1063,6 +1098,15 @@ cx_to_ecr.append(inst, qargs, cargs) _sel.add_equivalence(CXGate(), cx_to_ecr) +""" +CXGate + global phase: π/4 + ┌───────────┐┌─────┐ +q_0: ──■── q_0: ┤0 ├┤ Sdg ├─ + ┌─┴─┐ ≡ │ Rzx(π/2) │├─────┴┐ +q_1: ┤ X ├ q_1: ┤1 ├┤ √Xdg ├ + └───┘ └───────────┘└──────┘ +""" q = QuantumRegister(2, "q") cx_to_zx90 = QuantumCircuit(q, global_phase=pi / 4) for inst, qargs, cargs in [ @@ -1073,8 +1117,16 @@ cx_to_zx90.append(inst, qargs, cargs) _sel.add_equivalence(CXGate(), cx_to_zx90) -# CCXGate - +""" +CCXGate + ┌───┐ +q_0: ──■── q_0: ───────────────────■─────────────────────■────■───┤ T ├───■── + │ │ ┌───┐ │ ┌─┴─┐┌┴───┴┐┌─┴─┐ +q_1: ──■── ≡ q_1: ───────■───────────┼─────────■───┤ T ├───┼──┤ X ├┤ Tdg ├┤ X ├ + ┌─┴─┐ ┌───┐┌─┴─┐┌─────┐┌─┴─┐┌───┐┌─┴─┐┌┴───┴┐┌─┴─┐├───┤└┬───┬┘└───┘ +q_2: ┤ X ├ q_2: ┤ H ├┤ X ├┤ Tdg ├┤ X ├┤ T ├┤ X ├┤ Tdg ├┤ X ├┤ T ├─┤ H ├────── + └───┘ └───┘└───┘└─────┘└───┘└───┘└───┘└─────┘└───┘└───┘ └───┘ +""" q = QuantumRegister(3, "q") def_ccx = QuantumCircuit(q) for inst, qargs, cargs in [ @@ -1097,6 +1149,16 @@ def_ccx.append(inst, qargs, cargs) _sel.add_equivalence(CCXGate(), def_ccx) +""" +CCXGate + +q_0: ──■── q_0: ────────■─────────────────■────■─── + │ ┌─┴─┐┌─────┐ ┌─┴─┐ │ +q_1: ──■── ≡ q_1: ──■───┤ X ├┤ Sdg ├──■───┤ X ├──┼─── + ┌─┴─┐ ┌─┴──┐├───┤└─────┘┌─┴──┐├───┤┌─┴──┐ +q_2: ┤ X ├ q_2: ┤ Sx ├┤ Z ├───────┤ Sx ├┤ Z ├┤ Sx ├ + └───┘ └────┘└───┘ └────┘└───┘└────┘ +""" q = QuantumRegister(3, "q") ccx_to_cx_csx = QuantumCircuit(q) for inst, qargs, cargs in [ @@ -1112,13 +1174,25 @@ ccx_to_cx_csx.append(inst, qargs, cargs) _sel.add_equivalence(CCXGate(), ccx_to_cx_csx) -# YGate +""" +YGate + ┌───┐ ┌───────────────┐ +q: ┤ Y ├ ≡ q: ┤ U3(π,π/2,π/2) ├ + └───┘ └───────────────┘ +""" q = QuantumRegister(1, "q") def_y = QuantumCircuit(q) def_y.append(U3Gate(pi, pi / 2, pi / 2), [q[0]], []) _sel.add_equivalence(YGate(), def_y) +""" +YGate + global phase: 3π/2 + ┌───┐ ┌───┐┌───┐┌───┐┌───┐┌───┐┌───┐ +q: ┤ Y ├ ≡ q: ┤ H ├┤ S ├┤ S ├┤ H ├┤ S ├┤ S ├ + └───┘ └───┘└───┘└───┘└───┘└───┘└───┘ +""" q = QuantumRegister(1, "q") def_y = QuantumCircuit(q) def_y.global_phase = 3 * pi / 2 @@ -1133,6 +1207,13 @@ def_y.append(inst, qargs, cargs) _sel.add_equivalence(YGate(), def_y) +""" +YGate + global phase: π/2 + ┌───┐ ┌───┐┌───┐┌───┐┌───┐┌───┐┌───┐ +q: ┤ Y ├ ≡ q: ┤ S ├┤ S ├┤ H ├┤ S ├┤ S ├┤ H ├ + └───┘ └───┘└───┘└───┘└───┘└───┘└───┘ +""" q = QuantumRegister(1, "q") def_y = QuantumCircuit(q) def_y.global_phase = pi / 2 @@ -1147,8 +1228,14 @@ def_y.append(inst, qargs, cargs) _sel.add_equivalence(YGate(), def_y) -# CYGate +""" +CYGate +q_0: ──■── q_0: ─────────■─────── + ┌─┴─┐ ≡ ┌─────┐┌─┴─┐┌───┐ +q_1: ┤ Y ├ q_1: ┤ Sdg ├┤ X ├┤ S ├ + └───┘ └─────┘└───┘└───┘ +""" q = QuantumRegister(2, "q") def_cy = QuantumCircuit(q) for inst, qargs, cargs in [ @@ -1159,13 +1246,25 @@ def_cy.append(inst, qargs, cargs) _sel.add_equivalence(CYGate(), def_cy) -# ZGate +""" +ZGate + ┌───┐ ┌───────┐ +q: ┤ Z ├ ≡ q: ┤ U1(π) ├ + └───┘ └───────┘ +""" q = QuantumRegister(1, "q") def_z = QuantumCircuit(q) def_z.append(U1Gate(pi), [q[0]], []) _sel.add_equivalence(ZGate(), def_z) +""" +ZGate + + ┌───┐ ┌───┐┌───┐ +q: ┤ Z ├ ≡ q: ┤ S ├┤ S ├ + └───┘ └───┘└───┘ +""" q = QuantumRegister(1, "q") def_z = QuantumCircuit(q) for inst, qargs, cargs in [ @@ -1175,8 +1274,14 @@ def_z.append(inst, qargs, cargs) _sel.add_equivalence(ZGate(), def_z) -# CZGate +""" +CZGate +q_0: ─■─ q_0: ───────■─────── + │ ≡ ┌───┐┌─┴─┐┌───┐ +q_1: ─■─ q_1: ┤ H ├┤ X ├┤ H ├ + └───┘└───┘└───┘ +""" q = QuantumRegister(2, "q") def_cz = QuantumCircuit(q) for inst, qargs, cargs in [ @@ -1187,25 +1292,39 @@ def_cz.append(inst, qargs, cargs) _sel.add_equivalence(CZGate(), def_cz) -# RXGate, XGate equivalence - +""" +XGate + global phase: π/2 + ┌───┐ ┌───────┐ +q: ┤ X ├ ≡ q: ┤ Rx(π) ├ + └───┘ └───────┘ +""" q = QuantumRegister(1, "q") x_to_rx = QuantumCircuit(q) x_to_rx.append(RXGate(theta=pi), [q[0]]) x_to_rx.global_phase = pi / 2 _sel.add_equivalence(XGate(), x_to_rx) -# RYGate, YGate equivalence - +""" +YGate + global phase: π/2 + ┌───┐ ┌───────┐ +q: ┤ Y ├ ≡ q: ┤ Ry(π) ├ + └───┘ └───────┘ +""" q = QuantumRegister(1, "q") y_to_ry = QuantumCircuit(q) y_to_ry.append(RYGate(theta=pi), [q[0]]) y_to_ry.global_phase = pi / 2 _sel.add_equivalence(YGate(), y_to_ry) - -# HGate, RXGate(pi).RYGate(pi/2) equivalence - +""" +HGate + global phase: π/2 + ┌───┐ ┌─────────┐┌───────┐ +q: ┤ H ├ ≡ q: ┤ Ry(π/2) ├┤ Rx(π) ├ + └───┘ └─────────┘└───────┘ +""" q = QuantumRegister(1, "q") h_to_rxry = QuantumCircuit(q) h_to_rxry.append(RYGate(theta=pi / 2), [q[0]]) @@ -1213,8 +1332,13 @@ h_to_rxry.global_phase = pi / 2 _sel.add_equivalence(HGate(), h_to_rxry) -# HGate, RGate(pi, 0).RGate(pi/2, pi/2) equivalence - +""" +HGate + global phase: π/2 + ┌───┐ ┌────────────┐┌────────┐ +q: ┤ H ├ ≡ q: ┤ R(π/2,π/2) ├┤ R(π,0) ├ + └───┘ └────────────┘└────────┘ +""" q = QuantumRegister(1, "q") h_to_rr = QuantumCircuit(q) h_to_rr.append(RGate(theta=pi / 2, phi=pi / 2), [q[0]]) From 5ec4e5146ccc7c5cdbefc484d4c9675b2242879d Mon Sep 17 00:00:00 2001 From: Jintaoyu Date: Wed, 1 Dec 2021 11:35:55 +0800 Subject: [PATCH 04/18] Add circuit diagram to echo_rzx_weyl_decomposition --- .../standard_gates/equivalence_library.py | 2 -- .../optimization/echo_rzx_weyl_decomposition.py | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/qiskit/circuit/library/standard_gates/equivalence_library.py b/qiskit/circuit/library/standard_gates/equivalence_library.py index b5de48ac2b9f..b04398af24b1 100644 --- a/qiskit/circuit/library/standard_gates/equivalence_library.py +++ b/qiskit/circuit/library/standard_gates/equivalence_library.py @@ -990,8 +990,6 @@ lam = Parameter("lam") cu3_to_cu = QuantumCircuit(q) cu3_to_cu.cu(theta, phi, lam, 0, 0, 1) -# TODO the following line causes a TypeError during test -# _sel.add_equivalence(CU3Gate(theta, phi, lam), cu3_to_cu) """ XGate diff --git a/qiskit/transpiler/passes/optimization/echo_rzx_weyl_decomposition.py b/qiskit/transpiler/passes/optimization/echo_rzx_weyl_decomposition.py index 76e0ecc13ac9..5f62747f50d0 100644 --- a/qiskit/transpiler/passes/optimization/echo_rzx_weyl_decomposition.py +++ b/qiskit/transpiler/passes/optimization/echo_rzx_weyl_decomposition.py @@ -51,6 +51,14 @@ def _is_native(self, qubit_pair: Tuple) -> bool: @staticmethod def _echo_rzx_dag(theta): + """Return the following circuit: + + ┌───────────────┐┌───┐┌────────────────┐┌───┐ + q_0: ┤0 ├┤ X ├┤0 ├┤ X ├ + │ Rzx(theta/2) │└───┘│ Rzx(-theta/2) │└───┘ + q_1: ┤1 ├─────┤1 ├───── + └───────────────┘ └────────────────┘ + """ rzx_dag = DAGCircuit() qr = QuantumRegister(2) rzx_dag.add_qreg(qr) @@ -62,6 +70,14 @@ def _echo_rzx_dag(theta): @staticmethod def _reverse_echo_rzx_dag(theta): + """Return the following circuit: + + ┌───┐┌───────────────┐ ┌────────────────┐┌───┐ + q_0: ┤ H ├┤1 ├─────┤1 ├┤ H ├───── + ├───┤│ Rzx(theta/2) │┌───┐│ Rzx(-theta/2) │├───┤┌───┐ + q_1: ┤ H ├┤0 ├┤ X ├┤0 ├┤ X ├┤ H ├ + └───┘└───────────────┘└───┘└────────────────┘└───┘└───┘ + """ reverse_rzx_dag = DAGCircuit() qr = QuantumRegister(2) reverse_rzx_dag.add_qreg(qr) From e55d0f85c34751694bb56b4da499bbc994199e43 Mon Sep 17 00:00:00 2001 From: Jintaoyu Date: Wed, 1 Dec 2021 11:56:51 +0800 Subject: [PATCH 05/18] Add circuit diagram to merge_adjacent_barriers.py --- .../passes/optimization/echo_rzx_weyl_decomposition.py | 4 ++-- .../transpiler/passes/utils/merge_adjacent_barriers.py | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/qiskit/transpiler/passes/optimization/echo_rzx_weyl_decomposition.py b/qiskit/transpiler/passes/optimization/echo_rzx_weyl_decomposition.py index 5f62747f50d0..e1f81f36d3a1 100644 --- a/qiskit/transpiler/passes/optimization/echo_rzx_weyl_decomposition.py +++ b/qiskit/transpiler/passes/optimization/echo_rzx_weyl_decomposition.py @@ -51,7 +51,7 @@ def _is_native(self, qubit_pair: Tuple) -> bool: @staticmethod def _echo_rzx_dag(theta): - """Return the following circuit: + """Return the following circuit:: ┌───────────────┐┌───┐┌────────────────┐┌───┐ q_0: ┤0 ├┤ X ├┤0 ├┤ X ├ @@ -70,7 +70,7 @@ def _echo_rzx_dag(theta): @staticmethod def _reverse_echo_rzx_dag(theta): - """Return the following circuit: + """Return the following circuit:: ┌───┐┌───────────────┐ ┌────────────────┐┌───┐ q_0: ┤ H ├┤1 ├─────┤1 ├┤ H ├───── diff --git a/qiskit/transpiler/passes/utils/merge_adjacent_barriers.py b/qiskit/transpiler/passes/utils/merge_adjacent_barriers.py index 0614eeb0ac09..d939271f1125 100644 --- a/qiskit/transpiler/passes/utils/merge_adjacent_barriers.py +++ b/qiskit/transpiler/passes/utils/merge_adjacent_barriers.py @@ -38,6 +38,16 @@ class MergeAdjacentBarriers(TransformationPass): circuit.barrier(qr[0]) circuit.barrier(qr) + i.e, + + ░ ░ ░ ░ + q_0: ─░──░─ q_0: ─░──░─ + ░ ░ ░ ░ + q_1: ─░──░─ => q_1: ────░─ + ░ ░ ░ + q_2: ────░─ q_2: ────░─ + ░ + after one iteration of the pass. These two barriers were not merged by the first pass as they are not adjacent in the initial circuit. From a8fd4f3d23cf0ce3061eb200cf53dffb64d5b6db Mon Sep 17 00:00:00 2001 From: Jintaoyu Date: Wed, 1 Dec 2021 19:51:26 +0800 Subject: [PATCH 06/18] Add circuit diagram to test/python/circuit/library --- .../algorithms/test_skip_qobj_validation.py | 11 ++ test/python/basicaer/test_qasm_simulator.py | 100 +++++++++++++++++- .../circuit/library/test_evolution_gate.py | 7 ++ .../circuit/library/test_grover_operator.py | 20 +++- test/python/circuit/library/test_iqp.py | 12 +++ test/python/circuit/library/test_nlocal.py | 98 ++++++++++++++++- .../circuit/library/test_pauli_feature_map.py | 42 ++++++++ .../circuit/library/test_phase_estimation.py | 18 ++++ .../circuit/library/test_random_pauli.py | 14 ++- 9 files changed, 315 insertions(+), 7 deletions(-) diff --git a/test/python/algorithms/test_skip_qobj_validation.py b/test/python/algorithms/test_skip_qobj_validation.py index 7c3195e97e9f..1c76140db78d 100644 --- a/test/python/algorithms/test_skip_qobj_validation.py +++ b/test/python/algorithms/test_skip_qobj_validation.py @@ -40,6 +40,17 @@ def setUp(self): super().setUp() self.random_seed = 10598 + """ + (qc) + + ┌───┐ ░ ┌─┐ ░ + q0_0: ┤ H ├──■───░─┤M├─░──── + └───┘┌─┴─┐ ░ └╥┘ ░ ┌─┐ + q0_1: ─────┤ X ├─░──╫──░─┤M├ + └───┘ ░ ║ ░ └╥┘ + c0: 2/══════════════╩═════╩═ + 0 1 + """ qr = QuantumRegister(2) cr = ClassicalRegister(2) qc = QuantumCircuit(qr, cr) diff --git a/test/python/basicaer/test_qasm_simulator.py b/test/python/basicaer/test_qasm_simulator.py index 0657be218d70..2ae9f09c5751 100644 --- a/test/python/basicaer/test_qasm_simulator.py +++ b/test/python/basicaer/test_qasm_simulator.py @@ -114,7 +114,24 @@ def test_measure_sampler_single_qubit(self): self.assertEqual(counts, target) def test_measure_sampler_partial_qubit(self): - """Test measure sampler if single-qubit is measured.""" + """Test measure sampler if single-qubit is measured. + + (circuit) + + ░ ░ ░ ┌─┐ ░ + qr_0: ──────░─────░─────░─┤M├─░──── + ┌───┐ ░ ░ ┌─┐ ░ └╥┘ ░ + qr_1: ┤ X ├─░─────░─┤M├─░──╫──░──── + └───┘ ░ ░ └╥┘ ░ ║ ░ + qr_2: ──────░─────░──╫──░──╫──░──── + ┌───┐ ░ ┌─┐ ░ ║ ░ ║ ░ ┌─┐ + qr_3: ┤ X ├─░─┤M├─░──╫──░──╫──░─┤M├ + └───┘ ░ └╥┘ ░ ║ ░ ║ ░ └╥┘ + qr_4: ──────░──╫──░──╫──░──╫──░──╫─ + ░ ║ ░ ║ ░ ║ ░ ║ + cr: 4/═════════╩═════╩═════╩═════╩═ + 1 0 2 3 + """ shots = 100 num_qubits = 5 qr = QuantumRegister(num_qubits, "qr") @@ -161,6 +178,18 @@ def test_if_statement(self): qr = QuantumRegister(3, "qr") cr = ClassicalRegister(3, "cr") + """ + ┌───┐┌─┐ ┌─┐ + qr_0: ┤ X ├┤M├──────────┤M├────── + ├───┤└╥┘┌─┐ └╥┘┌─┐ + qr_1: ┤ X ├─╫─┤M├────────╫─┤M├─── + └───┘ ║ └╥┘ ┌───┐ ║ └╥┘┌─┐ + qr_2: ──────╫──╫──┤ X ├──╫──╫─┤M├ + ║ ║ └─╥─┘ ║ ║ └╥┘ + ║ ║ ┌──╨──┐ ║ ║ ║ + cr: 3/══════╩══╩═╡ 0x3 ╞═╩══╩══╩═ + 0 1 └─────┘ 0 1 2 + """ circuit_if_true = QuantumCircuit(qr, cr) circuit_if_true.x(qr[0]) circuit_if_true.x(qr[1]) @@ -171,6 +200,18 @@ def test_if_statement(self): circuit_if_true.measure(qr[1], cr[1]) circuit_if_true.measure(qr[2], cr[2]) + """ + ┌───┐┌─┐ ┌─┐ + qr_0: ┤ X ├┤M├───────┤M├────── + └┬─┬┘└╥┘ └╥┘┌─┐ + qr_1: ─┤M├──╫─────────╫─┤M├─── + └╥┘ ║ ┌───┐ ║ └╥┘┌─┐ + qr_2: ──╫───╫──┤ X ├──╫──╫─┤M├ + ║ ║ └─╥─┘ ║ ║ └╥┘ + ║ ║ ┌──╨──┐ ║ ║ ║ + cr: 3/══╩═══╩═╡ 0x3 ╞═╩══╩══╩═ + 1 0 └─────┘ 0 1 2 + """ circuit_if_false = QuantumCircuit(qr, cr) circuit_if_false.x(qr[0]) circuit_if_false.measure(qr[0], cr[0]) @@ -194,7 +235,22 @@ def test_if_statement(self): def test_bit_cif_crossaffect(self): """Test if bits in a classical register other than - the single conditional bit affect the conditioned operation.""" + the single conditional bit affect the conditioned operation. + + (circuit) + + ┌───┐ ┌─┐ + q0_0: ────────┤ H ├──────────┤M├ + ┌───┐ └─╥─┘ ┌─┐ └╥┘ + q0_1: ┤ X ├─────╫──────┤M├────╫─ + ├───┤ ║ └╥┘┌─┐ ║ + q0_2: ┤ X ├─────╫───────╫─┤M├─╫─ + └───┘┌────╨─────┐ ║ └╥┘ ║ + c0: 3/═════╡ c0_0=0x1 ╞═╩══╩══╬═ + └──────────┘ 1 2 ║ + c1: 1/════════════════════════╩═ + 0 + """ shots = 100 qr = QuantumRegister(3) cr = ClassicalRegister(3) @@ -211,7 +267,25 @@ def test_bit_cif_crossaffect(self): self.assertEqual(result, target) def test_teleport(self): - """Test teleportation as in tutorials""" + """Test teleportation as in tutorials + + (circuit) + + ┌─────────┐ ┌───┐ ░ ┌─┐ + qr_0: ┤ Ry(π/4) ├───────■──┤ H ├─░─┤M├──────────────────── + └──┬───┬──┘ ┌─┴─┐└───┘ ░ └╥┘┌─┐ + qr_1: ───┤ H ├─────■──┤ X ├──────░──╫─┤M├───────────────── + └───┘ ┌─┴─┐└───┘ ░ ║ └╥┘ ┌───┐ ┌───┐ ┌─┐ + qr_2: ───────────┤ X ├───────────░──╫──╫──┤ Z ├──┤ X ├─┤M├ + └───┘ ░ ║ ║ └─╥─┘ └─╥─┘ └╥┘ + ║ ║ ┌──╨──┐ ║ ║ + cr0: 1/═════════════════════════════╩══╬═╡ 0x1 ╞═══╬════╬═ + 0 ║ └─────┘┌──╨──┐ ║ + cr1: 1/════════════════════════════════╩════════╡ 0x1 ╞═╬═ + 0 └─────┘ ║ + cr2: 1/═════════════════════════════════════════════════╩═ + 0 + """ self.log.info("test_teleport") pi = np.pi shots = 2000 @@ -256,7 +330,25 @@ def test_teleport(self): self.assertLess(error, 0.05) def test_memory(self): - """Test memory.""" + """Test memory. + + (circ) + + ┌───┐ ┌─┐ + qr_0: ┤ H ├──■─────┤M├─── + └───┘┌─┴─┐ └╥┘┌─┐ + qr_1: ─────┤ X ├────╫─┤M├ + └┬─┬┘ ║ └╥┘ + qr_2: ──────┤M├─────╫──╫─ + ┌───┐ └╥┘ ┌─┐ ║ ║ + qr_3: ┤ X ├──╫──┤M├─╫──╫─ + └───┘ ║ └╥┘ ║ ║ + cr0: 2/══════╬═══╬══╩══╩═ + ║ ║ 0 1 + ║ ║ + cr1: 2/══════╩═══╩═══════ + 0 1 + """ qr = QuantumRegister(4, "qr") cr0 = ClassicalRegister(2, "cr0") cr1 = ClassicalRegister(2, "cr1") diff --git a/test/python/circuit/library/test_evolution_gate.py b/test/python/circuit/library/test_evolution_gate.py index 5060ddcfe05f..f786f1f09d4f 100644 --- a/test/python/circuit/library/test_evolution_gate.py +++ b/test/python/circuit/library/test_evolution_gate.py @@ -61,6 +61,13 @@ def test_rzx_order(self): evo_gate = PauliEvolutionGate(X ^ Z) decomposed = evo_gate.definition.decompose() + """ + ┌───┐┌───────┐┌───┐ + q_0: ─────┤ X ├┤ Rz(2) ├┤ X ├───── + ┌───┐└─┬─┘└───────┘└─┬─┘┌───┐ + q_1: ┤ H ├──■─────────────■──┤ H ├ + └───┘ └───┘ + """ ref = QuantumCircuit(2) ref.h(1) ref.cx(1, 0) diff --git a/test/python/circuit/library/test_grover_operator.py b/test/python/circuit/library/test_grover_operator.py index 3fd27c02d212..e11398fe02c8 100644 --- a/test/python/circuit/library/test_grover_operator.py +++ b/test/python/circuit/library/test_grover_operator.py @@ -128,7 +128,25 @@ def test_custom_zero_reflection(self): self.assertEqual(expected, grover_op.decompose()) def test_num_mcx_ancillas(self): - """Test the number of ancilla bits for the mcx gate in zero_reflection.""" + """Test the number of ancilla bits for the mcx gate in zero_reflection. + + (oracle) + + q_0: ──■────────────────────── + │ + q_1: ──■────────────────────── + │ + q_2: ──┼────■───────────────── + │ │ + q_3: ──┼────■───────────────── + ┌─┴─┐ │ + q_4: ┤ X ├──┼────■──────────── + └───┘┌─┴─┐ │ + q_5: ─────┤ X ├──■──────────── + ┌───┐├───┤┌─┴─┐┌───┐┌───┐ + q_6: ┤ X ├┤ H ├┤ X ├┤ H ├┤ X ├ + └───┘└───┘└───┘└───┘└───┘ + """ oracle = QuantumCircuit(7) oracle.x(6) oracle.h(6) diff --git a/test/python/circuit/library/test_iqp.py b/test/python/circuit/library/test_iqp.py index 639a5eca5d58..41d4cd9551bd 100644 --- a/test/python/circuit/library/test_iqp.py +++ b/test/python/circuit/library/test_iqp.py @@ -28,6 +28,18 @@ class TestIQPLibrary(QiskitTestCase): def test_iqp(self): """Test iqp circuit.""" circuit = IQP(interactions=np.array([[6, 5, 1], [5, 4, 3], [1, 3, 2]])) + + """ + (expected) + + ┌───┐ ┌─────────┐┌───┐ + q_0: ┤ H ├─■───────────────────■───────┤ P(3π/4) ├┤ H ├ + ├───┤ │P(5π/2) │ └┬────────┤├───┤ + q_1: ┤ H ├─■─────────■─────────┼────────┤ P(π/2) ├┤ H ├ + ├───┤ │P(3π/2) │P(π/2) ├────────┤├───┤ + q_2: ┤ H ├───────────■─────────■────────┤ P(π/4) ├┤ H ├ + └───┘ └────────┘└───┘ + """ expected = QuantumCircuit(3) expected.h([0, 1, 2]) expected.cp(5 * np.pi / 2, 0, 1) diff --git a/test/python/circuit/library/test_nlocal.py b/test/python/circuit/library/test_nlocal.py index 18ef0209401b..c5acb93660b2 100644 --- a/test/python/circuit/library/test_nlocal.py +++ b/test/python/circuit/library/test_nlocal.py @@ -422,7 +422,16 @@ def test_entanglement_by_list(self): self.assertCircuitEqual(nlocal, circuit) def test_initial_state_as_circuit_object(self): - """Test setting `initial_state` to `QuantumCircuit` object""" + """Test setting `initial_state` to `QuantumCircuit` object + + (ref) + + ┌───┐ ┌───┐ + q_0: ──■──┤ X ├───────■──┤ X ├ + ┌─┴─┐├───┤┌───┐┌─┴─┐├───┤ + q_1: ┤ X ├┤ H ├┤ X ├┤ X ├┤ X ├ + └───┘└───┘└───┘└───┘└───┘ + """ ref = QuantumCircuit(2) ref.cx(0, 1) ref.x(0) @@ -565,6 +574,15 @@ def test_compose_inplace_to_circuit(self): circuit = QuantumCircuit(3) circuit.compose(two, inplace=True) + """ + ┌──────────┐┌──────────┐ ░ ░ ┌──────────┐ ┌──────────┐ + q_0: ┤ Ry(θ[0]) ├┤ Rz(θ[3]) ├─░──■──■─────░─┤ Ry(θ[6]) ├─┤ Rz(θ[9]) ├ + ├──────────┤├──────────┤ ░ │ │ ░ ├──────────┤┌┴──────────┤ + q_1: ┤ Ry(θ[1]) ├┤ Rz(θ[4]) ├─░──■──┼──■──░─┤ Ry(θ[7]) ├┤ Rz(θ[10]) ├ + ├──────────┤├──────────┤ ░ │ │ ░ ├──────────┤├───────────┤ + q_2: ┤ Ry(θ[2]) ├┤ Rz(θ[5]) ├─░─────■──■──░─┤ Ry(θ[8]) ├┤ Rz(θ[11]) ├ + └──────────┘└──────────┘ ░ ░ └──────────┘└───────────┘ + """ reference = QuantumCircuit(3) param_iter = iter(two.ordered_parameters) for i in range(3): @@ -616,6 +634,15 @@ def test_ry_circuit(self): parameters = ParameterVector("theta", num_qubits * (reps + 1)) param_iter = iter(parameters) + """ + ┌──────────┐ ┌──────────┐ ┌──────────┐ + q_0: ┤ Ry(θ[0]) ├──■────■──┤ Ry(θ[3]) ├──────────────■────■──┤ Ry(θ[6]) ├──────────── + ├──────────┤┌─┴─┐ │ └──────────┘┌──────────┐┌─┴─┐ │ └──────────┘┌──────────┐ + q_1: ┤ Ry(θ[1]) ├┤ X ├──┼─────────■────┤ Ry(θ[4]) ├┤ X ├──┼─────────■────┤ Ry(θ[7]) ├ + ├──────────┤└───┘┌─┴─┐ ┌─┴─┐ ├──────────┤└───┘┌─┴─┐ ┌─┴─┐ ├──────────┤ + q_2: ┤ Ry(θ[2]) ├─────┤ X ├─────┤ X ├──┤ Ry(θ[5]) ├─────┤ X ├─────┤ X ├──┤ Ry(θ[8]) ├ + └──────────┘ └───┘ └───┘ └──────────┘ └───┘ └───┘ └──────────┘ + """ expected = QuantumCircuit(3) for _ in range(reps): for i in range(num_qubits): @@ -652,6 +679,22 @@ def test_ryrz_circuit(self): parameters = ParameterVector("theta", 2 * num_qubits * (reps + 1)) param_iter = iter(parameters) + """ + ┌──────────┐┌──────────┐┌───┐ ┌──────────┐┌──────────┐ » + q_0: ┤ Ry(θ[0]) ├┤ Rz(θ[3]) ├┤ X ├──■──┤ Ry(θ[6]) ├┤ Rz(θ[9]) ├─────────────» + ├──────────┤├──────────┤└─┬─┘┌─┴─┐└──────────┘├──────────┤┌───────────┐» + q_1: ┤ Ry(θ[1]) ├┤ Rz(θ[4]) ├──┼──┤ X ├─────■──────┤ Ry(θ[7]) ├┤ Rz(θ[10]) ├» + ├──────────┤├──────────┤ │ └───┘ ┌─┴─┐ ├──────────┤├───────────┤» + q_2: ┤ Ry(θ[2]) ├┤ Rz(θ[5]) ├──■──────────┤ X ├────┤ Ry(θ[8]) ├┤ Rz(θ[11]) ├» + └──────────┘└──────────┘ └───┘ └──────────┘└───────────┘» + « ┌───┐ ┌───────────┐┌───────────┐ + «q_0: ┤ X ├──■──┤ Ry(θ[12]) ├┤ Rz(θ[15]) ├───────────── + « └─┬─┘┌─┴─┐└───────────┘├───────────┤┌───────────┐ + «q_1: ──┼──┤ X ├──────■──────┤ Ry(θ[13]) ├┤ Rz(θ[16]) ├ + « │ └───┘ ┌─┴─┐ ├───────────┤├───────────┤ + «q_2: ──■───────────┤ X ├────┤ Ry(θ[14]) ├┤ Rz(θ[17]) ├ + « └───┘ └───────────┘└───────────┘ + """ expected = QuantumCircuit(3) for _ in range(reps): for i in range(num_qubits): @@ -698,6 +741,29 @@ def test_swaprz_circuit(self): parameters = ParameterVector("theta", num_qubits * (reps + 1) + reps * (num_qubits - 1)) param_iter = iter(parameters) + """ + ┌──────────┐┌────────────┐┌────────────┐ ┌──────────┐ » + q_0: ┤ Rz(θ[0]) ├┤0 ├┤0 ├─┤ Rz(θ[5]) ├───────────────» + ├──────────┤│ Rxx(θ[3]) ││ Ryy(θ[3]) │┌┴──────────┴┐┌────────────┐» + q_1: ┤ Rz(θ[1]) ├┤1 ├┤1 ├┤0 ├┤0 ├» + ├──────────┤└────────────┘└────────────┘│ Rxx(θ[4]) ││ Ryy(θ[4]) │» + q_2: ┤ Rz(θ[2]) ├────────────────────────────┤1 ├┤1 ├» + └──────────┘ └────────────┘└────────────┘» + « ┌────────────┐┌────────────┐┌───────────┐ » + «q_0: ────────────┤0 ├┤0 ├┤ Rz(θ[10]) ├───────────────» + « ┌──────────┐│ Rxx(θ[8]) ││ Ryy(θ[8]) │├───────────┴┐┌────────────┐» + «q_1: ┤ Rz(θ[6]) ├┤1 ├┤1 ├┤0 ├┤0 ├» + « ├──────────┤└────────────┘└────────────┘│ Rxx(θ[9]) ││ Ryy(θ[9]) │» + «q_2: ┤ Rz(θ[7]) ├────────────────────────────┤1 ├┤1 ├» + « └──────────┘ └────────────┘└────────────┘» + « + «q_0: ───────────── + « ┌───────────┐ + «q_1: ┤ Rz(θ[11]) ├ + « ├───────────┤ + «q_2: ┤ Rz(θ[12]) ├ + « └───────────┘ + """ expected = QuantumCircuit(3) for _ in range(reps): for i in range(num_qubits): @@ -727,6 +793,29 @@ def test_fsim_circuit(self): parameters = [1] * (num_qubits * (reps + 1) + reps * (1 + num_qubits)) param_iter = iter(parameters) + """ + ┌───────┐┌─────────┐┌─────────┐ ┌───────┐ » + q_0: ┤ Rz(1) ├┤0 ├┤0 ├─■──────┤ Rz(1) ├───────────────────» + ├───────┤│ Rxx(1) ││ Ryy(1) │ │P(1) ┌┴───────┴┐┌─────────┐ » + q_1: ┤ Rz(1) ├┤1 ├┤1 ├─■─────┤0 ├┤0 ├─■─────» + ├───────┤└─────────┘└─────────┘ │ Rxx(1) ││ Ryy(1) │ │P(1) » + q_2: ┤ Rz(1) ├─────────────────────────────┤1 ├┤1 ├─■─────» + └───────┘ └─────────┘└─────────┘ » + « ┌─────────┐┌─────────┐ ┌───────┐ » + «q_0: ─────────┤0 ├┤0 ├─■──────┤ Rz(1) ├───────────────────» + « ┌───────┐│ Rxx(1) ││ Ryy(1) │ │P(1) ┌┴───────┴┐┌─────────┐ » + «q_1: ┤ Rz(1) ├┤1 ├┤1 ├─■─────┤0 ├┤0 ├─■─────» + « ├───────┤└─────────┘└─────────┘ │ Rxx(1) ││ Ryy(1) │ │P(1) » + «q_2: ┤ Rz(1) ├─────────────────────────────┤1 ├┤1 ├─■─────» + « └───────┘ └─────────┘└─────────┘ » + « + «q_0: ───────── + « ┌───────┐ + «q_1: ┤ Rz(1) ├ + « ├───────┤ + «q_2: ┤ Rz(1) ├ + « └───────┘ + """ expected = QuantumCircuit(3) for _ in range(reps): for i in range(num_qubits): @@ -754,6 +843,13 @@ def test_circular_on_same_block_and_circuit_size(self): two = TwoLocal(2, "ry", "cx", entanglement="circular", reps=1) parameters = np.arange(two.num_parameters) + """ + ┌───────┐ ┌───────┐ + q_0: ┤ Ry(0) ├──■──┤ Ry(2) ├ + ├───────┤┌─┴─┐├───────┤ + q_1: ┤ Ry(1) ├┤ X ├┤ Ry(3) ├ + └───────┘└───┘└───────┘ + """ ref = QuantumCircuit(2) ref.ry(parameters[0], 0) ref.ry(parameters[1], 1) diff --git a/test/python/circuit/library/test_pauli_feature_map.py b/test/python/circuit/library/test_pauli_feature_map.py index b7dc172c3bc4..f222cf3507b2 100644 --- a/test/python/circuit/library/test_pauli_feature_map.py +++ b/test/python/circuit/library/test_pauli_feature_map.py @@ -61,6 +61,14 @@ def test_pauli_evolution(self): self.assertTrue(Operator(pauli).equiv(evo)) with self.subTest(pauli_string="XYZ"): + """ + q_0: ─────────────■────────────────────────■────────────── + ┌─────────┐┌─┴─┐ ┌─┴─┐┌──────────┐ + q_1: ┤ Rx(π/2) ├┤ X ├──■──────────────■──┤ X ├┤ Rx(-π/2) ├ + └──┬───┬──┘└───┘┌─┴─┐┌────────┐┌─┴─┐├───┤└──────────┘ + q_2: ───┤ H ├────────┤ X ├┤ P(2.8) ├┤ X ├┤ H ├──────────── + └───┘ └───┘└────────┘└───┘└───┘ + """ evo = QuantumCircuit(3) # X on the most-significant, bottom qubit, Z on the top evo.h(2) @@ -86,6 +94,17 @@ def test_first_order_circuit(self): times = [0.2, 1, np.pi, -1.2] encoding = ZFeatureMap(4, reps=3).assign_parameters(times) + """ + ┌───┐ ┌────────┐┌───┐ ┌────────┐┌───┐ ┌────────┐ + q_0: ┤ H ├─┤ P(0.4) ├┤ H ├─┤ P(0.4) ├┤ H ├─┤ P(0.4) ├ + ├───┤ └┬──────┬┘├───┤ └┬──────┬┘├───┤ └┬──────┬┘ + q_1: ┤ H ├──┤ P(2) ├─┤ H ├──┤ P(2) ├─┤ H ├──┤ P(2) ├─ + ├───┤ ┌┴──────┤ ├───┤ ┌┴──────┤ ├───┤ ┌┴──────┤ + q_2: ┤ H ├─┤ P(2π) ├─┤ H ├─┤ P(2π) ├─┤ H ├─┤ P(2π) ├─ + ├───┤┌┴───────┴┐├───┤┌┴───────┴┐├───┤┌┴───────┴┐ + q_3: ┤ H ├┤ P(-2.4) ├┤ H ├┤ P(-2.4) ├┤ H ├┤ P(-2.4) ├ + └───┘└─────────┘└───┘└─────────┘└───┘└─────────┘ + """ ref = QuantumCircuit(4) for _ in range(3): ref.h([0, 1, 2, 3]) @@ -105,6 +124,29 @@ def zz_evolution(circuit, qubit1, qubit2): circuit.p(2 * time, qubit2) circuit.cx(qubit1, qubit2) + """ + ┌───┐┌────────┐ ┌───┐┌────────┐» + q_0: ┤ H ├┤ P(0.4) ├──■─────────────────■────■────────────■──┤ H ├┤ P(0.4) ├» + ├───┤└┬──────┬┘┌─┴─┐┌───────────┐┌─┴─┐ │ │ └───┘└────────┘» + q_1: ┤ H ├─┤ P(2) ├─┤ X ├┤ P(12.599) ├┤ X ├──┼────────────┼────■────────────» + ├───┤┌┴──────┤ └───┘└───────────┘└───┘┌─┴─┐┌──────┐┌─┴─┐┌─┴─┐ ┌──────┐ » + q_2: ┤ H ├┤ P(2π) ├────────────────────────┤ X ├┤ P(0) ├┤ X ├┤ X ├─┤ P(0) ├─» + └───┘└───────┘ └───┘└──────┘└───┘└───┘ └──────┘ » + « » + «q_0: ─────────────────────■─────────────────■────■────────────■───────────────» + « ┌───┐ ┌──────┐┌─┴─┐┌───────────┐┌─┴─┐ │ │ » + «q_1: ──■──┤ H ├─┤ P(2) ├┤ X ├┤ P(12.599) ├┤ X ├──┼────────────┼────■──────────» + « ┌─┴─┐├───┤┌┴──────┤└───┘└───────────┘└───┘┌─┴─┐┌──────┐┌─┴─┐┌─┴─┐┌──────┐» + «q_2: ┤ X ├┤ H ├┤ P(2π) ├───────────────────────┤ X ├┤ P(0) ├┤ X ├┤ X ├┤ P(0) ├» + « └───┘└───┘└───────┘ └───┘└──────┘└───┘└───┘└──────┘» + « + «q_0: ───── + « + «q_1: ──■── + « ┌─┴─┐ + «q_2: ┤ X ├ + « └───┘ + """ ref = QuantumCircuit(3) for _ in range(2): ref.h([0, 1, 2]) diff --git a/test/python/circuit/library/test_phase_estimation.py b/test/python/circuit/library/test_phase_estimation.py index eb990270da3d..dc4bea0c25cc 100644 --- a/test/python/circuit/library/test_phase_estimation.py +++ b/test/python/circuit/library/test_phase_estimation.py @@ -105,6 +105,15 @@ def test_phase_estimation(self): self.assertPhaseEstimationIsCorrect(pec, eigenstate, phase_as_binary) with self.subTest("a 3-q unitary"): + """ + ┌───┐ + q_0: ┤ X ├──■────■─────── + ├───┤ │ │ + q_1: ┤ X ├──■────■─────── + ├───┤┌───┐┌─┴─┐┌───┐ + q_2: ┤ X ├┤ H ├┤ X ├┤ H ├ + └───┘└───┘└───┘└───┘ + """ unitary = QuantumCircuit(3) unitary.x([0, 1, 2]) unitary.cz(0, 1) @@ -112,6 +121,15 @@ def test_phase_estimation(self): unitary.ccx(0, 1, 2) unitary.h(2) + """ + ┌───┐ + q_0: ┤ H ├──■────■── + └───┘┌─┴─┐ │ + q_1: ─────┤ X ├──┼── + └───┘┌─┴─┐ + q_2: ──────────┤ X ├ + └───┘ + """ eigenstate = QuantumCircuit(3) eigenstate.h(0) eigenstate.cx(0, 1) diff --git a/test/python/circuit/library/test_random_pauli.py b/test/python/circuit/library/test_random_pauli.py index 7d7d7fb8b92d..8d64950d271b 100644 --- a/test/python/circuit/library/test_random_pauli.py +++ b/test/python/circuit/library/test_random_pauli.py @@ -31,7 +31,19 @@ def test_random_pauli(self): qr = QuantumRegister(4, "q") params = circuit.ordered_parameters - # expected circuit for the random seed 12 + """ + expected circuit for the random seed 12 + + ┌─────────┐┌──────────┐ ┌──────────┐ + q_0: ┤ Ry(π/4) ├┤ Ry(θ[0]) ├─■─┤ Rx(θ[4]) ├──────────── + ├─────────┤├──────────┤ │ └──────────┘┌──────────┐ + q_1: ┤ Ry(π/4) ├┤ Rx(θ[1]) ├─■──────■──────┤ Rx(θ[5]) ├ + ├─────────┤├──────────┤ │ ├──────────┤ + q_2: ┤ Ry(π/4) ├┤ Rz(θ[2]) ├─■──────■──────┤ Rx(θ[6]) ├ + ├─────────┤├──────────┤ │ ┌──────────┐└──────────┘ + q_3: ┤ Ry(π/4) ├┤ Rz(θ[3]) ├─■─┤ Rx(θ[7]) ├──────────── + └─────────┘└──────────┘ └──────────┘ + """ expected = QuantumCircuit(qr) # initial RYs From b252a54af6e4560ca95876f5672a5e3d36ab633c Mon Sep 17 00:00:00 2001 From: Jintaoyu Date: Thu, 2 Dec 2021 10:52:22 +0800 Subject: [PATCH 07/18] Add circuit diagram to test/python/circuit --- .../python/circuit/test_circuit_properties.py | 516 ++++++++++++++++-- test/python/circuit/test_controlled_gate.py | 9 + test/python/circuit/test_tensor.py | 42 ++ 3 files changed, 535 insertions(+), 32 deletions(-) diff --git a/test/python/circuit/test_circuit_properties.py b/test/python/circuit/test_circuit_properties.py index 8410bb19fb9c..e9faa050adc1 100644 --- a/test/python/circuit/test_circuit_properties.py +++ b/test/python/circuit/test_circuit_properties.py @@ -79,7 +79,22 @@ def test_circuit_depth_meas_only(self): self.assertEqual(qc.depth(), 1) def test_circuit_depth_barrier(self): - """Make sure barriers do not add to depth""" + """Make sure barriers do not add to depth + + ┌───┐ ░ ┌─┐ + q_0: ┤ H ├──■──────────────────░─┤M├──────────── + ├───┤┌─┴─┐ ░ └╥┘┌─┐ + q_1: ┤ H ├┤ X ├──■─────────────░──╫─┤M├───────── + ├───┤└───┘ │ ┌───┐ ░ ║ └╥┘┌─┐ + q_2: ┤ H ├───────┼──┤ X ├──■───░──╫──╫─┤M├────── + ├───┤ │ └─┬─┘┌─┴─┐ ░ ║ ║ └╥┘┌─┐ + q_3: ┤ H ├───────┼────┼──┤ X ├─░──╫──╫──╫─┤M├─── + ├───┤ ┌─┴─┐ │ └───┘ ░ ║ ║ ║ └╥┘┌─┐ + q_4: ┤ H ├─────┤ X ├──■────────░──╫──╫──╫──╫─┤M├ + └───┘ └───┘ ░ ║ ║ ║ ║ └╥┘ + c: 5/═════════════════════════════╩══╩══╩══╩══╩═ + 0 1 2 3 4 + """ q = QuantumRegister(5, "q") c = ClassicalRegister(5, "c") qc = QuantumCircuit(q, c) @@ -97,7 +112,21 @@ def test_circuit_depth_barrier(self): self.assertEqual(qc.depth(), 6) def test_circuit_depth_simple(self): - """Test depth for simple circuit""" + """Test depth for simple circuit + ┌───┐ + q_0: ┤ H ├──■──────────────────── + └───┘ │ ┌───┐┌─┐ + q_1: ───────┼────────────┤ X ├┤M├ + ┌───┐ │ ┌───┐┌───┐└─┬─┘└╥┘ + q_2: ┤ X ├──┼──┤ X ├┤ X ├──┼───╫─ + └───┘ │ └───┘└───┘ │ ║ + q_3: ───────┼──────────────┼───╫─ + ┌─┴─┐┌───┐ │ ║ + q_4: ─────┤ X ├┤ X ├───────■───╫─ + └───┘└───┘ ║ + c: 1/══════════════════════════╩═ + 0 + """ q = QuantumRegister(5, "q") c = ClassicalRegister(1, "c") qc = QuantumCircuit(q, c) @@ -112,7 +141,21 @@ def test_circuit_depth_simple(self): self.assertEqual(qc.depth(), 5) def test_circuit_depth_multi_reg(self): - """Test depth for multiple registers""" + """Test depth for multiple registers + + ┌───┐ + q1_0: ┤ H ├──■───────────────── + ├───┤┌─┴─┐ + q1_1: ┤ H ├┤ X ├──■──────────── + ├───┤└───┘ │ ┌───┐ + q1_2: ┤ H ├───────┼──┤ X ├──■── + ├───┤ │ └─┬─┘┌─┴─┐ + q2_0: ┤ H ├───────┼────┼──┤ X ├ + ├───┤ ┌─┴─┐ │ └───┘ + q2_1: ┤ H ├─────┤ X ├──■─────── + └───┘ └───┘ + c: 5/═════════════════════════ + """ q1 = QuantumRegister(3, "q1") q2 = QuantumRegister(2, "q2") c = ClassicalRegister(5, "c") @@ -129,7 +172,21 @@ def test_circuit_depth_multi_reg(self): self.assertEqual(qc.depth(), 5) def test_circuit_depth_3q_gate(self): - """Test depth for 3q gate""" + """Test depth for 3q gate + + ┌───┐ + q1_0: ┤ H ├──■────■───────────────── + ├───┤ │ ┌─┴─┐ + q1_1: ┤ H ├──┼──┤ X ├──■──────────── + ├───┤ │ └───┘ │ ┌───┐ + q1_2: ┤ H ├──┼─────────┼──┤ X ├──■── + ├───┤┌─┴─┐ │ └─┬─┘┌─┴─┐ + q2_0: ┤ H ├┤ X ├───────┼────┼──┤ X ├ + ├───┤└─┬─┘ ┌─┴─┐ │ └───┘ + q2_1: ┤ H ├──■───────┤ X ├──■─────── + └───┘ └───┘ + c: 5/══════════════════════════════ + """ q1 = QuantumRegister(3, "q1") q2 = QuantumRegister(2, "q2") c = ClassicalRegister(5, "c") @@ -147,7 +204,21 @@ def test_circuit_depth_3q_gate(self): self.assertEqual(qc.depth(), 6) def test_circuit_depth_conditionals1(self): - """Test circuit depth for conditional gates #1.""" + """Test circuit depth for conditional gates #1. + + ┌───┐ ┌─┐ + q_0: ┤ H ├──■──┤M├───────────────── + ├───┤┌─┴─┐└╥┘┌─┐ + q_1: ┤ H ├┤ X ├─╫─┤M├────────────── + ├───┤└───┘ ║ └╥┘ ┌───┐ + q_2: ┤ H ├──■───╫──╫──┤ H ├──────── + ├───┤┌─┴─┐ ║ ║ └─╥─┘ ┌───┐ + q_3: ┤ H ├┤ X ├─╫──╫────╫────┤ H ├─ + └───┘└───┘ ║ ║ ║ └─╥─┘ + ║ ║ ┌──╨──┐┌──╨──┐ + c: 4/═══════════╩══╩═╡ 0x2 ╞╡ 0x4 ╞ + 0 1 └─────┘└─────┘ + """ size = 4 q = QuantumRegister(size, "q") c = ClassicalRegister(size, "c") @@ -166,7 +237,21 @@ def test_circuit_depth_conditionals1(self): self.assertEqual(qc.depth(), 5) def test_circuit_depth_conditionals2(self): - """Test circuit depth for conditional gates #2.""" + """Test circuit depth for conditional gates #2. + + ┌───┐ ┌─┐┌─┐ + q_0: ┤ H ├──■──┤M├┤M├────────────── + ├───┤┌─┴─┐└╥┘└╥┘ + q_1: ┤ H ├┤ X ├─╫──╫─────────────── + ├───┤└───┘ ║ ║ ┌───┐ + q_2: ┤ H ├──■───╫──╫──┤ H ├──────── + ├───┤┌─┴─┐ ║ ║ └─╥─┘ ┌───┐ + q_3: ┤ H ├┤ X ├─╫──╫────╫────┤ H ├─ + └───┘└───┘ ║ ║ ║ └─╥─┘ + ║ ║ ┌──╨──┐┌──╨──┐ + c: 4/═══════════╩══╩═╡ 0x2 ╞╡ 0x4 ╞ + 0 0 └─────┘└─────┘ + """ size = 4 q = QuantumRegister(size, "q") c = ClassicalRegister(size, "c") @@ -185,7 +270,21 @@ def test_circuit_depth_conditionals2(self): self.assertEqual(qc.depth(), 6) def test_circuit_depth_conditionals3(self): - """Test circuit depth for conditional gates #3.""" + """Test circuit depth for conditional gates #3. + + ┌───┐┌─┐ + q_0: ┤ H ├┤M├───■──────────── + ├───┤└╥┘ │ ┌─┐ + q_1: ┤ H ├─╫────┼───┤M├────── + ├───┤ ║ │ └╥┘┌─┐ + q_2: ┤ H ├─╫────┼────╫─┤M├─── + ├───┤ ║ ┌─┴─┐ ║ └╥┘┌─┐ + q_3: ┤ H ├─╫──┤ X ├──╫──╫─┤M├ + └───┘ ║ └─╥─┘ ║ ║ └╥┘ + ║ ┌──╨──┐ ║ ║ ║ + c: 4/══════╩═╡ 0x2 ╞═╩══╩══╩═ + 0 └─────┘ 1 2 3 + """ size = 4 q = QuantumRegister(size, "q") c = ClassicalRegister(size, "c") @@ -204,7 +303,21 @@ def test_circuit_depth_conditionals3(self): self.assertEqual(qc.depth(), 4) def test_circuit_depth_bit_conditionals1(self): - """Test circuit depth for single bit conditional gates #1.""" + """Test circuit depth for single bit conditional gates #1. + + ┌───┐┌─┐ + q_0: ┤ H ├┤M├───────────────────────── + ├───┤└╥┘ ┌───┐ + q_1: ┤ H ├─╫───────┤ H ├────────────── + ├───┤ ║ ┌─┐ └─╥─┘ + q_2: ┤ H ├─╫─┤M├─────╫──────────────── + ├───┤ ║ └╥┘ ║ ┌───┐ + q_3: ┤ H ├─╫──╫──────╫────────┤ H ├─── + └───┘ ║ ║ ║ └─╥─┘ + ║ ║ ┌────╨────┐┌────╨────┐ + c: 4/══════╩══╩═╡ c_0=0x1 ╞╡ c_2=0x0 ╞ + 0 2 └─────────┘└─────────┘ + """ size = 4 q = QuantumRegister(size, "q") c = ClassicalRegister(size, "c") @@ -221,7 +334,33 @@ def test_circuit_depth_bit_conditionals1(self): self.assertEqual(qc.depth(), 3) def test_circuit_depth_bit_conditionals2(self): - """Test circuit depth for single bit conditional gates #2.""" + """Test circuit depth for single bit conditional gates #2. + + ┌───┐┌─┐ » + q_0: ┤ H ├┤M├──────────────────────────────■─────────────────────■─────» + ├───┤└╥┘ ┌───┐ ┌─┴─┐ │ » + q_1: ┤ H ├─╫───────┤ H ├─────────────────┤ X ├───────────────────┼─────» + ├───┤ ║ ┌─┐ └─╥─┘ └─╥─┘ ┌─┴─┐ » + q_2: ┤ H ├─╫─┤M├─────╫─────────────────────╫──────────■────────┤ H ├───» + ├───┤ ║ └╥┘ ║ ┌───┐ ║ ┌─┴─┐ └─╥─┘ » + q_3: ┤ H ├─╫──╫──────╫────────┤ H ├────────╫────────┤ X ├────────╫─────» + └───┘ ║ ║ ║ └─╥─┘ ║ └─╥─┘ ║ » + ║ ║ ┌────╨────┐┌────╨────┐┌────╨────┐┌────╨────┐┌────╨────┐» + c: 4/══════╩══╩═╡ c_1=0x1 ╞╡ c_3=0x1 ╞╡ c_0=0x0 ╞╡ c_2=0x0 ╞╡ c_1=0x1 ╞» + 0 2 └─────────┘└─────────┘└─────────┘└─────────┘└─────────┘» + « + «q_0: ─────────── + « + «q_1: ─────■───── + « │ + «q_2: ─────┼───── + « ┌─┴─┐ + «q_3: ───┤ H ├─── + « └─╥─┘ + « ┌────╨────┐ + «c: 4/╡ c_3=0x1 ╞ + « └─────────┘ + """ size = 4 q = QuantumRegister(size, "q") c = ClassicalRegister(size, "c") @@ -242,7 +381,21 @@ def test_circuit_depth_bit_conditionals2(self): self.assertEqual(qc.depth(), 4) def test_circuit_depth_bit_conditionals3(self): - """Test circuit depth for single bit conditional gates #3.""" + """Test circuit depth for single bit conditional gates #3. + + ┌───┐┌─┐ + q_0: ┤ H ├┤M├────────────────────────────────────── + ├───┤└╥┘ ┌───┐ ┌─┐ + q_1: ┤ H ├─╫────┤ H ├─────────────────────┤M├────── + ├───┤ ║ └─╥─┘ ┌───┐ └╥┘┌─┐ + q_2: ┤ H ├─╫──────╫──────┤ H ├─────────────╫─┤M├─── + ├───┤ ║ ║ └─╥─┘ ┌───┐ ║ └╥┘┌─┐ + q_3: ┤ H ├─╫──────╫────────╫──────┤ H ├────╫──╫─┤M├ + └───┘ ║ ║ ║ └─╥─┘ ║ ║ └╥┘ + ║ ┌────╨────┐┌──╨──┐┌────╨────┐ ║ ║ ║ + c: 4/══════╩═╡ c_0=0x1 ╞╡ 0x2 ╞╡ c_3=0x1 ╞═╩══╩══╩═ + 0 └─────────┘└─────┘└─────────┘ 1 2 3 + """ size = 4 q = QuantumRegister(size, "q") c = ClassicalRegister(size, "c") @@ -262,7 +415,20 @@ def test_circuit_depth_bit_conditionals3(self): self.assertEqual(qc.depth(), 6) def test_circuit_depth_measurements1(self): - """Test circuit depth for measurements #1.""" + """Test circuit depth for measurements #1. + + ┌───┐┌─┐ + q_0: ┤ H ├┤M├───────── + ├───┤└╥┘┌─┐ + q_1: ┤ H ├─╫─┤M├────── + ├───┤ ║ └╥┘┌─┐ + q_2: ┤ H ├─╫──╫─┤M├─── + ├───┤ ║ ║ └╥┘┌─┐ + q_3: ┤ H ├─╫──╫──╫─┤M├ + └───┘ ║ ║ ║ └╥┘ + c: 4/══════╩══╩══╩══╩═ + 0 1 2 3 + """ size = 4 q = QuantumRegister(size, "q") c = ClassicalRegister(size, "c") @@ -279,7 +445,20 @@ def test_circuit_depth_measurements1(self): self.assertEqual(qc.depth(), 2) def test_circuit_depth_measurements2(self): - """Test circuit depth for measurements #2.""" + """Test circuit depth for measurements #2. + + ┌───┐┌─┐┌─┐┌─┐┌─┐ + q_0: ┤ H ├┤M├┤M├┤M├┤M├ + ├───┤└╥┘└╥┘└╥┘└╥┘ + q_1: ┤ H ├─╫──╫──╫──╫─ + ├───┤ ║ ║ ║ ║ + q_2: ┤ H ├─╫──╫──╫──╫─ + ├───┤ ║ ║ ║ ║ + q_3: ┤ H ├─╫──╫──╫──╫─ + └───┘ ║ ║ ║ ║ + c: 4/══════╩══╩══╩══╩═ + 0 1 2 3 + """ size = 4 q = QuantumRegister(size, "q") c = ClassicalRegister(size, "c") @@ -296,7 +475,20 @@ def test_circuit_depth_measurements2(self): self.assertEqual(qc.depth(), 5) def test_circuit_depth_measurements3(self): - """Test circuit depth for measurements #3.""" + """Test circuit depth for measurements #3. + + ┌───┐┌─┐ + q_0: ┤ H ├┤M├───────── + ├───┤└╥┘┌─┐ + q_1: ┤ H ├─╫─┤M├────── + ├───┤ ║ └╥┘┌─┐ + q_2: ┤ H ├─╫──╫─┤M├─── + ├───┤ ║ ║ └╥┘┌─┐ + q_3: ┤ H ├─╫──╫──╫─┤M├ + └───┘ ║ ║ ║ └╥┘ + c: 4/══════╩══╩══╩══╩═ + 0 0 0 0 + """ size = 4 q = QuantumRegister(size, "q") c = ClassicalRegister(size, "c") @@ -313,7 +505,19 @@ def test_circuit_depth_measurements3(self): self.assertEqual(qc.depth(), 5) def test_circuit_depth_barriers1(self): - """Test circuit depth for barriers #1.""" + """Test circuit depth for barriers #1. + + ┌───┐ ░ + q_0: ┤ H ├──■───░─────────── + └───┘┌─┴─┐ ░ + q_1: ─────┤ X ├─░─────────── + └───┘ ░ ┌───┐ + q_2: ───────────░─┤ H ├──■── + ░ └───┘┌─┴─┐ + q_3: ───────────░──────┤ X ├ + ░ └───┘ + c: 4/═══════════════════════ + """ q = QuantumRegister(4, "q") c = ClassicalRegister(4, "c") circ = QuantumCircuit(q, c) @@ -325,7 +529,19 @@ def test_circuit_depth_barriers1(self): self.assertEqual(circ.depth(), 4) def test_circuit_depth_barriers2(self): - """Test circuit depth for barriers #2.""" + """Test circuit depth for barriers #2. + + ┌───┐ ░ ░ ░ + q_0: ┤ H ├─░───■───░───────░────── + └───┘ ░ ┌─┴─┐ ░ ░ + q_1: ──────░─┤ X ├─░───────░────── + ░ └───┘ ░ ┌───┐ ░ + q_2: ──────░───────░─┤ H ├─░───■── + ░ ░ └───┘ ░ ┌─┴─┐ + q_3: ──────░───────░───────░─┤ X ├ + ░ ░ ░ └───┘ + c: 4/═════════════════════════════ + """ q = QuantumRegister(4, "q") c = ClassicalRegister(4, "c") circ = QuantumCircuit(q, c) @@ -339,7 +555,19 @@ def test_circuit_depth_barriers2(self): self.assertEqual(circ.depth(), 4) def test_circuit_depth_barriers3(self): - """Test circuit depth for barriers #3.""" + """Test circuit depth for barriers #3. + + ┌───┐ ░ ░ ░ ░ ░ + q_0: ┤ H ├─░───■───░──░──░───────░────── + └───┘ ░ ┌─┴─┐ ░ ░ ░ ░ + q_1: ──────░─┤ X ├─░──░──░───────░────── + ░ └───┘ ░ ░ ░ ┌───┐ ░ + q_2: ──────░───────░──░──░─┤ H ├─░───■── + ░ ░ ░ ░ └───┘ ░ ┌─┴─┐ + q_3: ──────░───────░──░──░───────░─┤ X ├ + ░ ░ ░ ░ ░ └───┘ + c: 4/═══════════════════════════════════ + """ q = QuantumRegister(4, "q") c = ClassicalRegister(4, "c") circ = QuantumCircuit(q, c) @@ -355,7 +583,19 @@ def test_circuit_depth_barriers3(self): self.assertEqual(circ.depth(), 4) def test_circuit_depth_snap1(self): - """Test circuit depth for snapshots #1.""" + """Test circuit depth for snapshots #1. + + ┌───┐ ░ + q_0: ┤ H ├──■───░─────────── + └───┘┌─┴─┐ ░ + q_1: ─────┤ X ├─░─────────── + └───┘ ░ ┌───┐ + q_2: ───────────░─┤ H ├──■── + ░ └───┘┌─┴─┐ + q_3: ───────────░──────┤ X ├ + ░ └───┘ + c: 4/═══════════════════════ + """ q = QuantumRegister(4, "q") c = ClassicalRegister(4, "c") circ = QuantumCircuit(q, c) @@ -367,7 +607,19 @@ def test_circuit_depth_snap1(self): self.assertEqual(circ.depth(), 4) def test_circuit_depth_snap2(self): - """Test circuit depth for snapshots #2.""" + """Test circuit depth for snapshots #2. + + ┌───┐ ░ ░ ░ + q_0: ┤ H ├─░───■───░───────░────── + └───┘ ░ ┌─┴─┐ ░ ░ + q_1: ──────░─┤ X ├─░───────░────── + ░ └───┘ ░ ┌───┐ ░ + q_2: ──────░───────░─┤ H ├─░───■── + ░ ░ └───┘ ░ ┌─┴─┐ + q_3: ──────░───────░───────░─┤ X ├ + ░ ░ ░ └───┘ + c: 4/═════════════════════════════ + """ q = QuantumRegister(4, "q") c = ClassicalRegister(4, "c") circ = QuantumCircuit(q, c) @@ -381,7 +633,19 @@ def test_circuit_depth_snap2(self): self.assertEqual(circ.depth(), 4) def test_circuit_depth_snap3(self): - """Test circuit depth for snapshots #3.""" + """Test circuit depth for snapshots #3. + + ┌───┐ ░ ░ + q_0: ┤ H ├──■───░──░─────────── + └───┘┌─┴─┐ ░ ░ + q_1: ─────┤ X ├─░──░─────────── + └───┘ ░ ░ ┌───┐ + q_2: ───────────░──░─┤ H ├──■── + ░ ░ └───┘┌─┴─┐ + q_3: ───────────░──░──────┤ X ├ + ░ ░ └───┘ + c: 4/══════════════════════════ + """ q = QuantumRegister(4, "q") c = ClassicalRegister(4, "c") circ = QuantumCircuit(q, c) @@ -535,7 +799,24 @@ def test_circuit_count_ops(self): self.assertEqual(expected, result) def test_circuit_nonlocal_gates(self): - """Test num_nonlocal_gates.""" + """Test num_nonlocal_gates. + + ┌───┐ ┌────────┐ + q_0: ┤ H ├───────────────────┤0 ├ + ├───┤ ┌───┐ │ │ + q_1: ┤ H ├───┤ X ├─────────■─┤ ├ + ├───┤ └───┘ │ │ │ + q_2: ┤ H ├─────■───────────X─┤ Iswap ├ + ├───┤ │ ┌───┐ │ │ │ + q_3: ┤ H ├─────┼─────┤ Z ├─X─┤ ├ + ├───┤┌────┴────┐├───┤ │ │ + q_4: ┤ H ├┤ Ry(0.1) ├┤ Z ├───┤1 ├ + ├───┤└──┬───┬──┘└───┘ └───╥────┘ + q_5: ┤ H ├───┤ Z ├───────────────╫───── + └───┘ └───┘ ┌──╨──┐ + c: 2/═════════════════════════╡ 0x2 ╞══ + └─────┘ + """ q = QuantumRegister(6, "q") c = ClassicalRegister(2, "c") qc = QuantumCircuit(q, c) @@ -567,7 +848,20 @@ def test_circuit_connected_components_empty(self): self.assertEqual(7, qc.num_connected_components()) def test_circuit_connected_components_multi_reg(self): - """Test tensor factors works over multi registers""" + """Test tensor factors works over multi registers + + ┌───┐ + q1_0: ┤ H ├──■───────────────── + ├───┤┌─┴─┐ + q1_1: ┤ H ├┤ X ├──■──────────── + ├───┤└───┘ │ ┌───┐ + q1_2: ┤ H ├───────┼──┤ X ├──■── + ├───┤ │ └─┬─┘┌─┴─┐ + q2_0: ┤ H ├───────┼────┼──┤ X ├ + ├───┤ ┌─┴─┐ │ └───┘ + q2_1: ┤ H ├─────┤ X ├──■─────── + └───┘ └───┘ + """ q1 = QuantumRegister(3, "q1") q2 = QuantumRegister(2, "q2") qc = QuantumCircuit(q1, q2) @@ -583,7 +877,19 @@ def test_circuit_connected_components_multi_reg(self): self.assertEqual(qc.num_connected_components(), 1) def test_circuit_connected_components_multi_reg2(self): - """Test tensor factors works over multi registers #2.""" + """Test tensor factors works over multi registers #2. + + q1_0: ──■──────────── + │ + q1_1: ──┼─────────■── + │ ┌───┐ │ + q1_2: ──┼──┤ X ├──┼── + │ └─┬─┘┌─┴─┐ + q2_0: ──┼────■──┤ X ├ + ┌─┴─┐ └───┘ + q2_1: ┤ X ├────────── + └───┘ + """ q1 = QuantumRegister(3, "q1") q2 = QuantumRegister(2, "q2") qc = QuantumCircuit(q1, q2) @@ -593,7 +899,29 @@ def test_circuit_connected_components_multi_reg2(self): self.assertEqual(qc.num_connected_components(), 2) def test_circuit_connected_components_disconnected(self): - """Test tensor factors works with 2q subspaces.""" + """Test tensor factors works with 2q subspaces. + + q1_0: ──■────────────────────── + │ + q1_1: ──┼────■───────────────── + │ │ + q1_2: ──┼────┼────■──────────── + │ │ │ + q1_3: ──┼────┼────┼────■─────── + │ │ │ │ + q1_4: ──┼────┼────┼────┼────■── + │ │ │ │ ┌─┴─┐ + q2_0: ──┼────┼────┼────┼──┤ X ├ + │ │ │ ┌─┴─┐└───┘ + q2_1: ──┼────┼────┼──┤ X ├───── + │ │ ┌─┴─┐└───┘ + q2_2: ──┼────┼──┤ X ├────────── + │ ┌─┴─┐└───┘ + q2_3: ──┼──┤ X ├─────────────── + ┌─┴─┐└───┘ + q2_4: ┤ X ├──────────────────── + └───┘ + """ q1 = QuantumRegister(5, "q1") q2 = QuantumRegister(5, "q2") qc = QuantumCircuit(q1, q2) @@ -605,7 +933,20 @@ def test_circuit_connected_components_disconnected(self): self.assertEqual(qc.num_connected_components(), 5) def test_circuit_connected_components_with_clbits(self): - """Test tensor components with classical register.""" + """Test tensor components with classical register. + + ┌───┐┌─┐ + q_0: ┤ H ├┤M├───────── + ├───┤└╥┘┌─┐ + q_1: ┤ H ├─╫─┤M├────── + ├───┤ ║ └╥┘┌─┐ + q_2: ┤ H ├─╫──╫─┤M├─── + ├───┤ ║ ║ └╥┘┌─┐ + q_3: ┤ H ├─╫──╫──╫─┤M├ + └───┘ ║ ║ ║ └╥┘ + c: 4/══════╩══╩══╩══╩═ + 0 1 2 3 + """ size = 4 q = QuantumRegister(size, "q") c = ClassicalRegister(size, "c") @@ -621,7 +962,21 @@ def test_circuit_connected_components_with_clbits(self): self.assertEqual(qc.num_connected_components(), 4) def test_circuit_connected_components_with_cond(self): - """Test tensor components with one conditional gate.""" + """Test tensor components with one conditional gate. + + ┌───┐┌─┐ + q_0: ┤ H ├┤M├───■──────────── + ├───┤└╥┘ │ ┌─┐ + q_1: ┤ H ├─╫────┼───┤M├────── + ├───┤ ║ │ └╥┘┌─┐ + q_2: ┤ H ├─╫────┼────╫─┤M├─── + ├───┤ ║ ┌─┴─┐ ║ └╥┘┌─┐ + q_3: ┤ H ├─╫──┤ X ├──╫──╫─┤M├ + └───┘ ║ └─╥─┘ ║ ║ └╥┘ + ║ ┌──╨──┐ ║ ║ ║ + c: 4/══════╩═╡ 0x2 ╞═╩══╩══╩═ + 0 └─────┘ 1 2 3 + """ size = 4 q = QuantumRegister(size, "q") c = ClassicalRegister(size, "c") @@ -638,7 +993,20 @@ def test_circuit_connected_components_with_cond(self): self.assertEqual(qc.num_connected_components(), 1) def test_circuit_connected_components_with_cond2(self): - """Test tensor components with two conditional gates.""" + """Test tensor components with two conditional gates. + + ┌───┐ ┌───┐ + q_0: ┤ H ├─┤ H ├──────── + ├───┤ └─╥─┘ + q_1: ┤ H ├───╫──────■─── + ├───┤ ║ ┌─┴─┐ + q_2: ┤ H ├───╫────┤ X ├─ + ├───┤ ║ └─╥─┘ + q_3: ┤ H ├───╫──────╫─── + └───┘┌──╨──┐┌──╨──┐ + c: 8/═════╡ 0x0 ╞╡ 0x4 ╞ + └─────┘└─────┘ + """ size = 4 q = QuantumRegister(size, "q") c = ClassicalRegister(2 * size, "c") @@ -652,7 +1020,21 @@ def test_circuit_connected_components_with_cond2(self): self.assertEqual(qc.num_connected_components(), 2) def test_circuit_connected_components_with_cond3(self): - """Test tensor components with three conditional gates and measurements.""" + """Test tensor components with three conditional gates and measurements. + + ┌───┐┌─┐ ┌───┐ + q0_0: ┤ H ├┤M├─┤ H ├────────────────── + ├───┤└╥┘ └─╥─┘ + q0_1: ┤ H ├─╫────╫──────■───────────── + ├───┤ ║ ║ ┌─┴─┐ ┌─┐ + q0_2: ┤ H ├─╫────╫────┤ X ├─┤M├─────── + ├───┤ ║ ║ └─╥─┘ └╥┘ ┌───┐ + q0_3: ┤ H ├─╫────╫──────╫────╫──┤ X ├─ + └───┘ ║ ║ ║ ║ └─╥─┘ + ║ ┌──╨──┐┌──╨──┐ ║ ┌──╨──┐ + c0: 4/══════╩═╡ 0x0 ╞╡ 0x1 ╞═╩═╡ 0x2 ╞ + 0 └─────┘└─────┘ 2 └─────┘ + """ size = 4 q = QuantumRegister(size) c = ClassicalRegister(size) @@ -669,7 +1051,21 @@ def test_circuit_connected_components_with_cond3(self): self.assertEqual(qc.num_connected_components(), 1) def test_circuit_connected_components_with_bit_cond(self): - """Test tensor components with one single bit conditional gate.""" + """Test tensor components with one single bit conditional gate. + + ┌───┐┌─┐ + q_0: ┤ H ├┤M├───────────■──────── + ├───┤└╥┘┌─┐ │ + q_1: ┤ H ├─╫─┤M├────────┼──────── + ├───┤ ║ └╥┘┌─┐ │ + q_2: ┤ H ├─╫──╫─┤M├─────┼──────── + ├───┤ ║ ║ └╥┘ ┌─┴─┐ ┌─┐ + q_3: ┤ H ├─╫──╫──╫────┤ X ├───┤M├ + └───┘ ║ ║ ║ └─╥─┘ └╥┘ + ║ ║ ║ ┌────╨────┐ ║ + c: 4/══════╩══╩══╩═╡ c_0=0x1 ╞═╩═ + 0 1 2 └─────────┘ 3 + """ size = 4 q = QuantumRegister(size, "q") c = ClassicalRegister(size, "c") @@ -686,7 +1082,20 @@ def test_circuit_connected_components_with_bit_cond(self): self.assertEqual(qc.num_connected_components(), 3) def test_circuit_connected_components_with_bit_cond2(self): - """Test tensor components with two bit conditional gates.""" + """Test tensor components with two bit conditional gates. + + ┌───┐ ┌───┐ ┌───┐ + q_0: ┤ H ├───┤ H ├─────────────────┤ X ├─── + ├───┤ └─╥─┘ └─┬─┘ + q_1: ┤ H ├─────╫─────────────────────■───── + ├───┤ ║ ║ + q_2: ┤ H ├─────╫──────────■──────────╫───── + ├───┤ ║ │ ║ + q_3: ┤ H ├─────╫──────────■──────────╫───── + └───┘┌────╨────┐┌────╨────┐┌────╨────┐ + c: 6/═════╡ c_1=0x1 ╞╡ c_0=0x1 ╞╡ c_4=0x0 ╞ + └─────────┘└─────────┘└─────────┘ + """ size = 4 q = QuantumRegister(size, "q") c = ClassicalRegister(size + 2, "c") @@ -701,7 +1110,21 @@ def test_circuit_connected_components_with_bit_cond2(self): self.assertEqual(qc.num_connected_components(), 5) def test_circuit_connected_components_with_bit_cond3(self): - """Test tensor components with register and bit conditional gates.""" + """Test tensor components with register and bit conditional gates. + + ┌───┐ ┌───┐ + q0_0: ┤ H ├───┤ H ├─────────────────────── + ├───┤ └─╥─┘ + q0_1: ┤ H ├─────╫─────────■─────────────── + ├───┤ ║ ┌─┴─┐ + q0_2: ┤ H ├─────╫───────┤ X ├───────────── + ├───┤ ║ └─╥─┘ ┌───┐ + q0_3: ┤ H ├─────╫─────────╫──────┤ X ├──── + └───┘ ║ ║ └─╥─┘ + ┌────╨─────┐┌──╨──┐┌────╨─────┐ + c0: 4/═════╡ c0_0=0x1 ╞╡ 0x1 ╞╡ c0_2=0x1 ╞ + └──────────┘└─────┘└──────────┘ + """ size = 4 q = QuantumRegister(size) c = ClassicalRegister(size) @@ -732,7 +1155,21 @@ def test_circuit_unitary_factors2(self): self.assertEqual(qc.num_unitary_factors(), 4) def test_circuit_unitary_factors3(self): - """Test unitary factors measurements and conditionals.""" + """Test unitary factors measurements and conditionals. + + ┌───┐ ┌─┐ + q_0: ┤ H ├────────■──────────■────■──────────■──┤M├─── + ├───┤ │ │ │ ┌─┐ │ └╥┘ + q_1: ┤ H ├──■─────┼─────■────┼────┼──┤M├─────┼───╫──── + ├───┤┌─┴─┐ │ ┌─┴─┐ │ │ └╥┘┌─┐ │ ║ + q_2: ┤ H ├┤ X ├───┼───┤ X ├──┼────┼───╫─┤M├──┼───╫──── + ├───┤└───┘ ┌─┴─┐ └───┘┌─┴─┐┌─┴─┐ ║ └╥┘┌─┴─┐ ║ ┌─┐ + q_3: ┤ H ├──────┤ X ├──────┤ X ├┤ X ├─╫──╫─┤ X ├─╫─┤M├ + └───┘ └─╥─┘ └───┘└───┘ ║ ║ └───┘ ║ └╥┘ + ┌──╨──┐ ║ ║ ║ ║ + c: 4/══════════╡ 0x2 ╞════════════════╩══╩═══════╩══╩═ + └─────┘ 1 2 0 3 + """ size = 4 q = QuantumRegister(size, "q") c = ClassicalRegister(size, "c") @@ -754,7 +1191,22 @@ def test_circuit_unitary_factors3(self): self.assertEqual(qc.num_unitary_factors(), 2) def test_circuit_unitary_factors4(self): - """Test unitary factors measurements go to same cbit.""" + """Test unitary factors measurements go to same cbit. + + ┌───┐┌─┐ + q_0: ┤ H ├┤M├───────── + ├───┤└╥┘┌─┐ + q_1: ┤ H ├─╫─┤M├────── + ├───┤ ║ └╥┘┌─┐ + q_2: ┤ H ├─╫──╫─┤M├─── + ├───┤ ║ ║ └╥┘┌─┐ + q_3: ┤ H ├─╫──╫──╫─┤M├ + └───┘ ║ ║ ║ └╥┘ + q_4: ──────╫──╫──╫──╫─ + ║ ║ ║ ║ + c: 5/══════╩══╩══╩══╩═ + 0 0 0 0 + """ size = 5 q = QuantumRegister(size, "q") c = ClassicalRegister(size, "c") diff --git a/test/python/circuit/test_controlled_gate.py b/test/python/circuit/test_controlled_gate.py index cb1e67c9eebb..3376c27a613f 100644 --- a/test/python/circuit/test_controlled_gate.py +++ b/test/python/circuit/test_controlled_gate.py @@ -914,6 +914,15 @@ def test_open_control_ccx_unrolling(self): unroller = Unroller(["x", "ccx"]) unrolled_dag = unroller.run(dag) + """ + ┌───┐ ┌───┐ + q0_0: ┤ X ├──■──┤ X ├ + ├───┤ │ ├───┤ + q0_1: ┤ X ├──■──┤ X ├ + └───┘┌─┴─┐└───┘ + q0_2: ─────┤ X ├───── + └───┘ + """ ref_circuit = QuantumCircuit(qreg) ref_circuit.x(qreg[0]) ref_circuit.x(qreg[1]) diff --git a/test/python/circuit/test_tensor.py b/test/python/circuit/test_tensor.py index 63c2525669c9..d37247d0ea3b 100644 --- a/test/python/circuit/test_tensor.py +++ b/test/python/circuit/test_tensor.py @@ -132,6 +132,19 @@ def test_multiple_registers(self): qrs = [QuantumRegister(1) for _ in range(6)] crs = [ClassicalRegister(1) for _ in range(2)] + """ + ┌───┐ + q0: ┤ H ├───────■────────────── + ├───┤┌───┐ │ + q1: ┤ X ├┤ H ├──■────────────── + └───┘└───┘ │ ┌───────┐┌─┐ + q2: ────────────┼──┤ Ry(p) ├┤M├ + ┌─┴─┐└───┬───┘└╥┘ + q3: ──────────┤ X ├────■─────╫─ + └───┘ ║ + c0: 1/═══════════════════════╩═ + 0 + """ top = QuantumCircuit(*qrs[:4], crs[0]) top.h(0) top.x(1) @@ -140,12 +153,41 @@ def test_multiple_registers(self): top.cry(p, 3, 2) top.measure(2, 0) + """ + ┌────┐┌──────┐ + q4: ┤ √X ├┤ P(q) ├──■───── + └────┘└──────┘┌─┴─┐┌─┐ + q5: ──────────────┤ X ├┤M├ + └───┘└╥┘ + c1: 1/══════════════════╩═ + 0 + """ bottom = QuantumCircuit(*qrs[4:], crs[1]) bottom.sx(0) bottom.p(q, 0) bottom.cx(0, 1) bottom.measure(1, 0) + """ + ┌───┐ + q0: ┤ H ├───────────■────────────── + ├───┤ ┌───┐ │ + q1: ┤ X ├──┤ H ├────■────────────── + └───┘ └───┘ │ ┌───────┐┌─┐ + q2: ────────────────┼──┤ Ry(p) ├┤M├ + ┌─┴─┐└───┬───┘└╥┘ + q3: ──────────────┤ X ├────■─────╫─ + ┌────┐┌──────┐└───┘ ║ + q4: ┤ √X ├┤ P(q) ├──■────────────╫─ + └────┘└──────┘┌─┴─┐ ┌─┐ ║ + q5: ──────────────┤ X ├───┤M├────╫─ + └───┘ └╥┘ ║ + c0: 1/═════════════════════╬═════╩═ + ║ 0 + ║ + c1: 1/═════════════════════╩═══════ + 0 + """ expect = QuantumCircuit(*qrs, *crs) expect.h(0) expect.x(1) From 30ba28358e9f3eed64160ce42b1259cf732d2219 Mon Sep 17 00:00:00 2001 From: Jintaoyu Date: Thu, 2 Dec 2021 11:59:46 +0800 Subject: [PATCH 08/18] Add circuit diagram to test/python/compiler --- test/python/compiler/test_compiler.py | 65 +++++++++++++++++++++++-- test/python/compiler/test_transpiler.py | 51 ++++++++++++++++--- 2 files changed, 103 insertions(+), 13 deletions(-) diff --git a/test/python/compiler/test_compiler.py b/test/python/compiler/test_compiler.py index b83d7930cdc9..9e247608c23f 100644 --- a/test/python/compiler/test_compiler.py +++ b/test/python/compiler/test_compiler.py @@ -142,6 +142,23 @@ def test_example_swap_bits(self): [14, 15], ] + """ + ┌───┐ ░ ┌─┐ + q0_0: ┤ X ├─X───────────░─┤M├─────────────── + └───┘ │ ░ └╥┘ ┌─┐ + q0_1: ──────┼─────X──X──░──╫────┤M├───────── + │ │ │ ░ ║ └╥┘ ┌─┐ + q0_2: ──────X──X──┼──┼──░──╫─────╫────┤M├─── + │ │ │ ░ ║ ┌─┐ ║ └╥┘ + q1_0: ─────────┼──┼──┼──░──╫─┤M├─╫─────╫──── + │ │ │ ░ ║ └╥┘ ║ ┌─┐ ║ + q1_1: ─────────┼──┼──X──░──╫──╫──╫─┤M├─╫──── + │ │ ░ ║ ║ ║ └╥┘ ║ ┌─┐ + q1_2: ─────────X──X─────░──╫──╫──╫──╫──╫─┤M├ + ░ ║ ║ ║ ║ ║ └╥┘ + c0: 6/═════════════════════╩══╩══╩══╩══╩══╩═ + 0 3 1 4 2 5 + """ n = 3 # make this at least 3 qr0 = QuantumRegister(n) qr1 = QuantumRegister(n) @@ -257,11 +274,19 @@ def test_mapper_overoptimization(self): The mapper should not change the semantics of the input. An overoptimization introduced issue #81: https://github.com/Qiskit/qiskit-terra/issues/81 + + ┌───┐ ┌─┐ + q0_0: ┤ X ├──■───────┤M├─────────── + ├───┤┌─┴─┐┌───┐└╥┘ ┌─┐ + q0_1: ┤ Y ├┤ X ├┤ S ├─╫───■──┤M├─── + ├───┤└───┘├───┤ ║ ┌─┴─┐└╥┘┌─┐ + q0_2: ┤ Z ├──■──┤ T ├─╫─┤ X ├─╫─┤M├ + └───┘┌─┴─┐├───┤ ║ └┬─┬┘ ║ └╥┘ + q0_3: ─────┤ X ├┤ H ├─╫──┤M├──╫──╫─ + └───┘└───┘ ║ └╥┘ ║ ║ + c0: 4/════════════════╩═══╩═══╩══╩═ + 0 3 1 2 """ - # -X-.----- - # -Y-+-S-.- - # -Z-.-T-+- - # ---+-H--- qr = QuantumRegister(4) cr = ClassicalRegister(4) circ = QuantumCircuit(qr, cr) @@ -307,7 +332,25 @@ def test_grovers_circuit(self): shots = 1000 coupling_map = None - # 6-qubit grovers + """ + 6-qubit grovers + + ┌───┐┌───┐ ┌───┐┌───┐ ┌───┐ ┌───┐┌───┐ ░ ┌─┐ + q0_0: ┤ H ├┤ X ├──■──┤ X ├┤ X ├──■──┤ X ├──■──┤ X ├┤ H ├──────░─┤M├─── + ├───┤└───┘ │ └───┘└───┘ │ ├───┤ │ ├───┤├───┤ ░ └╥┘┌─┐ + q0_1: ┤ H ├──■────┼─────────■────┼──┤ X ├──■──┤ X ├┤ H ├──────░──╫─┤M├ + ├───┤ │ ┌─┴─┐ │ ┌─┴─┐└───┘ │ └───┘└───┘ ░ ║ └╥┘ + q0_2: ┤ X ├──┼──┤ X ├──■────┼──┤ X ├───────┼──────────────────░──╫──╫─ + ├───┤┌─┴─┐└───┘ │ ┌─┴─┐└───┘ │ ░ ║ ║ + q0_3: ┤ X ├┤ X ├───────■──┤ X ├────────────┼──────────────────░──╫──╫─ + └───┘└───┘ ┌─┴─┐├───┤┌───┐ ┌─┴─┐┌───┐┌───┐┌───┐ ░ ║ ║ + q0_4: ───────────────┤ X ├┤ X ├┤ H ├─────┤ X ├┤ H ├┤ X ├┤ H ├─░──╫──╫─ + └───┘└───┘└───┘ └───┘└───┘└───┘└───┘ ░ ║ ║ + q0_5: ────────────────────────────────────────────────────────░──╫──╫─ + ░ ║ ║ + c0: 2/═══════════════════════════════════════════════════════════╩══╩═ + 0 1 + """ qr = QuantumRegister(6) cr = ClassicalRegister(2) circuit = QuantumCircuit(qr, cr, name="grovers") @@ -361,6 +404,18 @@ def test_math_domain_error(self): The math library operates over floats and introduces floating point errors that should be avoided. See: https://github.com/Qiskit/qiskit-terra/issues/111 + + ┌───┐┌───┐ ┌─┐ + q0_0: ┤ Y ├┤ X ├─────┤M├───────────────────── + └───┘└─┬─┘ └╥┘ ┌─┐ + q0_1: ───────■────────╫─────────────■──┤M├─── + ┌───┐┌───┐┌───┐ ║ ┌───┐┌───┐┌─┴─┐└╥┘┌─┐ + q0_2: ┤ Z ├┤ H ├┤ Y ├─╫─┤ T ├┤ Z ├┤ X ├─╫─┤M├ + └┬─┬┘└───┘└───┘ ║ └───┘└───┘└───┘ ║ └╥┘ + q0_3: ─┤M├────────────╫─────────────────╫──╫─ + └╥┘ ║ ║ ║ + c0: 4/══╩═════════════╩═════════════════╩══╩═ + 3 0 1 2 """ qr = QuantumRegister(4) cr = ClassicalRegister(4) diff --git a/test/python/compiler/test_transpiler.py b/test/python/compiler/test_transpiler.py index 2f4810115545..fd28705a17e6 100644 --- a/test/python/compiler/test_transpiler.py +++ b/test/python/compiler/test_transpiler.py @@ -105,13 +105,15 @@ def test_transpile_non_adjacent_layout(self): """Transpile pipeline can handle manual layout on non-adjacent qubits. circuit: - qr0:-[H]--.------------ -> 1 - | - qr1:-----(+)--.-------- -> 2 - | - qr2:---------(+)--.---- -> 3 - | - qr3:-------------(+)--- -> 5 + ┌───┐ + qr_0: ┤ H ├──■──────────── -> 1 + └───┘┌─┴─┐ + qr_1: ─────┤ X ├──■─────── -> 2 + └───┘┌─┴─┐ + qr_2: ──────────┤ X ├──■── -> 3 + └───┘┌─┴─┐ + qr_3: ───────────────┤ X ├ -> 5 + └───┘ device: 0 - 1 - 2 - 3 - 4 - 5 - 6 @@ -204,6 +206,32 @@ def test_already_mapped_via_layout(self): """Test that a manual layout that satisfies a coupling map does not get altered. See: https://github.com/Qiskit/qiskit-terra/issues/2036 + + circuit: + ┌───┐ ┌───┐ ░ ┌─┐ + qn_0: ┤ H ├──■────────────■──┤ H ├─░─┤M├─── -> 9 + └───┘ │ │ └───┘ ░ └╥┘ + qn_1: ───────┼────────────┼────────░──╫──── -> 6 + │ │ ░ ║ + qn_2: ───────┼────────────┼────────░──╫──── -> 5 + │ │ ░ ║ + qn_3: ───────┼────────────┼────────░──╫──── -> 0 + │ │ ░ ║ + qn_4: ───────┼────────────┼────────░──╫──── -> 1 + ┌───┐┌─┴─┐┌──────┐┌─┴─┐┌───┐ ░ ║ ┌─┐ + qn_5: ┤ H ├┤ X ├┤ P(2) ├┤ X ├┤ H ├─░──╫─┤M├ -> 4 + └───┘└───┘└──────┘└───┘└───┘ ░ ║ └╥┘ + cn: 2/════════════════════════════════╩══╩═ + 0 1 + + device: + 0 -- 1 -- 2 -- 3 -- 4 + | | + 5 -- 6 -- 7 -- 8 -- 9 + | | + 10 - 11 - 12 - 13 - 14 + | | + 15 - 16 - 17 - 18 - 19 """ basis_gates = ["u1", "u2", "u3", "cx", "id"] coupling_map = [ @@ -627,7 +655,14 @@ def test_do_not_run_gatedirection_with_symmetric_cm(self): def test_optimize_to_nothing(self): """Optimize gates up to fixed point in the default pipeline - See https://github.com/Qiskit/qiskit-terra/issues/2035""" + See https://github.com/Qiskit/qiskit-terra/issues/2035 + + ┌───┐ ┌───┐┌───┐┌───┐ ┌───┐ + q0_0: ┤ H ├──■──┤ X ├┤ Y ├┤ Z ├──■──┤ H ├──■────■── + └───┘┌─┴─┐└───┘└───┘└───┘┌─┴─┐└───┘┌─┴─┐┌─┴─┐ + q0_1: ─────┤ X ├───────────────┤ X ├─────┤ X ├┤ X ├ + └───┘ └───┘ └───┘└───┘ + """ qr = QuantumRegister(2) circ = QuantumCircuit(qr) circ.h(qr[0]) From f7a37d05c8c010205f81094adcb4e71034854b7b Mon Sep 17 00:00:00 2001 From: Jintaoyu Date: Thu, 2 Dec 2021 13:59:11 +0800 Subject: [PATCH 09/18] Add circuit diagram to test/python/dagcircuit --- test/python/dagcircuit/test_dagcircuit.py | 142 ++++++++++++++++++- test/python/dagcircuit/test_dagdependency.py | 14 ++ 2 files changed, 150 insertions(+), 6 deletions(-) diff --git a/test/python/dagcircuit/test_dagcircuit.py b/test/python/dagcircuit/test_dagcircuit.py index b9f273db2dbd..55406c865d60 100644 --- a/test/python/dagcircuit/test_dagcircuit.py +++ b/test/python/dagcircuit/test_dagcircuit.py @@ -1135,6 +1135,20 @@ class TestCircuitProperties(QiskitTestCase): """DAGCircuit properties test.""" def setUp(self): + """ + ┌───┐ ┌───┐ + q0_0: ┤ H ├────────────────┤ X ├────────── + └───┘ └─┬─┘ ┌───┐ + q0_1: ───────────────────────┼───────┤ H ├ + ┌───┐ │ ┌───┐└─┬─┘ + q0_2: ──■───────┤ H ├────────┼──┤ T ├──■── + ┌─┴─┐┌────┴───┴─────┐ │ └───┘ + q0_3: ┤ X ├┤ U(0,0.1,0.2) ├──┼──────────── + └───┘└──────────────┘ │ + q1_0: ───────────────────────■──────────── + │ + q1_1: ───────────────────────■──────────── + """ super().setUp() qr1 = QuantumRegister(4) qr2 = QuantumRegister(2) @@ -1199,6 +1213,20 @@ class TestDagEquivalence(QiskitTestCase): """DAGCircuit equivalence check.""" def setUp(self): + """ + ┌───┐ ┌───┐ + qr1_0: ┤ H ├────────────────┤ X ├────────── + └───┘ └─┬─┘ ┌───┐ + qr1_1: ───────────────────────┼───────┤ H ├ + ┌───┐ │ ┌───┐└─┬─┘ + qr1_2: ──■───────┤ H ├────────┼──┤ T ├──■── + ┌─┴─┐┌────┴───┴─────┐ │ └───┘ + qr1_3: ┤ X ├┤ U(0,0.1,0.2) ├──┼──────────── + └───┘└──────────────┘ │ + qr2_0: ───────────────────────■──────────── + │ + qr2_1: ───────────────────────■──────────── + """ super().setUp() self.qr1 = QuantumRegister(4, "qr1") self.qr2 = QuantumRegister(2, "qr2") @@ -1213,7 +1241,21 @@ def setUp(self): self.dag1 = circuit_to_dag(circ1) def test_dag_eq(self): - """DAG equivalence check: True.""" + """DAG equivalence check: True. + + ┌───┐ ┌───┐ + qr1_0: ┤ H ├────────────────┤ X ├────────── + └───┘ └─┬─┘ ┌───┐ + qr1_1: ───────────────────────┼───────┤ H ├ + ┌───┐ │ ┌───┐└─┬─┘ + qr1_2: ──■───────┤ H ├────────┼──┤ T ├──■── + ┌─┴─┐┌────┴───┴─────┐ │ └───┘ + qr1_3: ┤ X ├┤ U(0,0.1,0.2) ├──┼──────────── + └───┘└──────────────┘ │ + qr2_0: ───────────────────────■──────────── + │ + qr2_1: ───────────────────────■──────────── + """ circ2 = QuantumCircuit(self.qr1, self.qr2) circ2.cx(self.qr1[2], self.qr1[3]) circ2.u(0.0, 0.1, 0.2, self.qr1[3]) @@ -1227,7 +1269,21 @@ def test_dag_eq(self): self.assertEqual(self.dag1, dag2) def test_dag_neq_topology(self): - """DAG equivalence check: False. Different topology.""" + """DAG equivalence check: False. Different topology. + + ┌───┐ ┌───┐ + qr1_0: ┤ H ├───────■─────────────┤ X ├ + └───┘ ┌─┴─┐ └─┬─┘ + qr1_1: ──────────┤ H ├─────────────┼── + ├───┤ ┌───┐ │ + qr1_2: ──■───────┤ H ├──────┤ T ├──┼── + ┌─┴─┐┌────┴───┴─────┐└───┘ │ + qr1_3: ┤ X ├┤ U(0,0.1,0.2) ├───────┼── + └───┘└──────────────┘ │ + qr2_0: ────────────────────────────■── + │ + qr2_1: ────────────────────────────■── + """ circ2 = QuantumCircuit(self.qr1, self.qr2) circ2.cx(self.qr1[2], self.qr1[3]) circ2.u(0.0, 0.1, 0.2, self.qr1[3]) @@ -1241,7 +1297,21 @@ def test_dag_neq_topology(self): self.assertNotEqual(self.dag1, dag2) def test_dag_neq_same_topology(self): - """DAG equivalence check: False. Same topology.""" + """DAG equivalence check: False. Same topology. + + ┌───┐ ┌───┐ + qr1_0: ┤ H ├────────────────┤ X ├────────── + └───┘ └─┬─┘ ┌───┐ + qr1_1: ───────────────────────┼───────┤ X ├ + ┌───┐ │ ┌───┐└─┬─┘ + qr1_2: ──■───────┤ H ├────────┼──┤ T ├──■── + ┌─┴─┐┌────┴───┴─────┐ │ └───┘ + qr1_3: ┤ X ├┤ U(0,0.1,0.2) ├──┼──────────── + └───┘└──────────────┘ │ + qr2_0: ───────────────────────■──────────── + │ + qr2_1: ───────────────────────■──────────── + """ circ2 = QuantumCircuit(self.qr1, self.qr2) circ2.cx(self.qr1[2], self.qr1[3]) circ2.u(0.0, 0.1, 0.2, self.qr1[3]) @@ -1531,6 +1601,20 @@ class TestDagProperties(QiskitTestCase): """Test the DAG properties.""" def setUp(self): + """ + ┌───┐ ┌───┐ + q0_0: ┤ H ├────────────────┤ X ├────────── + └───┘ └─┬─┘ ┌───┐ + q0_1: ───────────────────────┼───────┤ H ├ + ┌───┐ │ ┌───┐└─┬─┘ + q0_2: ──■───────┤ H ├────────┼──┤ T ├──■── + ┌─┴─┐┌────┴───┴─────┐ │ └───┘ + q0_3: ┤ X ├┤ U(0,0.1,0.2) ├──┼──────────── + └───┘└──────────────┘ │ + q1_0: ───────────────────────■──────────── + │ + q1_1: ───────────────────────■──────────── + """ super().setUp() qr1 = QuantumRegister(4) qr2 = QuantumRegister(2) @@ -1586,7 +1670,21 @@ def test_dag_idle_wires(self): self.assertEqual(len(wires), 1) def test_dag_depth1(self): - """Test DAG depth #1""" + """Test DAG depth #1 + + ┌───┐ + q1_0: ┤ H ├──■────■───────────────── + ├───┤ │ ┌─┴─┐ + q1_1: ┤ H ├──┼──┤ X ├──■──────────── + ├───┤ │ └───┘ │ ┌───┐ + q1_2: ┤ H ├──┼─────────┼──┤ X ├──■── + ├───┤┌─┴─┐ │ └─┬─┘┌─┴─┐ + q2_0: ┤ H ├┤ X ├───────┼────┼──┤ X ├ + ├───┤└─┬─┘ ┌─┴─┐ │ └───┘ + q2_1: ┤ H ├──■───────┤ X ├──■─────── + └───┘ └───┘ + c: 5/══════════════════════════════ + """ qr1 = QuantumRegister(3, "q1") qr2 = QuantumRegister(2, "q2") c = ClassicalRegister(5, "c") @@ -1605,7 +1703,22 @@ def test_dag_depth1(self): self.assertEqual(dag.depth(), 6) def test_dag_depth2(self): - """Test barrier increases DAG depth""" + """Test barrier increases DAG depth + + ┌───┐ ░ + q_0: ┤ H ├──■──────────────────░──── + └───┘ │ ┌───┐ ░ ┌─┐ + q_1: ───────┼────────────┤ X ├─░─┤M├ + ┌───┐ │ ┌───┐┌───┐└─┬─┘ ░ └╥┘ + q_2: ┤ X ├──┼──┤ X ├┤ X ├──┼───░──╫─ + └───┘ │ └───┘└───┘ │ ░ ║ + q_3: ───────┼──────────────┼───░──╫─ + ┌─┴─┐┌───┐ │ ░ ║ + q_4: ─────┤ X ├┤ X ├───────■───░──╫─ + └───┘└───┘ ░ ║ + c: 1/═════════════════════════════╩═ + 0 + """ q = QuantumRegister(5, "q") c = ClassicalRegister(1, "c") qc = QuantumCircuit(q, c) @@ -1622,7 +1735,24 @@ def test_dag_depth2(self): self.assertEqual(dag.depth(), 6) def test_dag_depth3(self): - """Test DAG depth for silly circuit.""" + """Test DAG depth for silly circuit. + + ┌───┐ ░ ░ ┌─┐ + q_0: ┤ H ├──■────░────░───────┤M├───── + └───┘┌─┴─┐ ░ ░ └╥┘ + q_1: ─────┤ X ├──■─────────────╫────── + └───┘┌─┴─┐ ║ + q_2: ──────────┤ X ├──■────────╫────── + └───┘┌─┴─┐ ║ + q_3: ───────────────┤ X ├──■───╫────── + └───┘┌─┴─┐ ║ + q_4: ────────────────────┤ X ├─╫───■── + └───┘ ║ ┌─┴─┐ + q_5: ──────────────────────────╫─┤ X ├ + ║ └───┘ + c: 1/══════════════════════════╩══════ + 0 + """ q = QuantumRegister(6, "q") c = ClassicalRegister(1, "c") qc = QuantumCircuit(q, c) diff --git a/test/python/dagcircuit/test_dagdependency.py b/test/python/dagcircuit/test_dagdependency.py index ffd83bbcab30..d4d414a9b6d6 100644 --- a/test/python/dagcircuit/test_dagdependency.py +++ b/test/python/dagcircuit/test_dagdependency.py @@ -244,6 +244,20 @@ class TestDagProperties(QiskitTestCase): """Test the DAG properties.""" def setUp(self): + """ + ┌───┐ ┌───┐ + q0_0: ┤ H ├────────────────┤ X ├────────── + └───┘ └─┬─┘ ┌───┐ + q0_1: ───────────────────────┼───────┤ H ├ + ┌───┐ │ ┌───┐└─┬─┘ + q0_2: ──■───────┤ H ├────────┼──┤ T ├──■── + ┌─┴─┐┌────┴───┴─────┐ │ └───┘ + q0_3: ┤ X ├┤ U(0,0.1,0.2) ├──┼──────────── + └───┘└──────────────┘ │ + q1_0: ───────────────────────■──────────── + │ + q1_1: ───────────────────────■──────────── + """ super().setUp() qr1 = QuantumRegister(4) qr2 = QuantumRegister(2) From 07ff304e7877ecd84cafd44e78dea1981badb2a8 Mon Sep 17 00:00:00 2001 From: Jintaoyu Date: Fri, 3 Dec 2021 15:26:11 +0800 Subject: [PATCH 10/18] Add circuit diagram to test/python --- .../quantum_info/operators/test_dihedral.py | 173 ++++++++++- test/python/quantum_info/test_analyzation.py | 32 ++- test/python/scheduler/test_basic_scheduler.py | 34 ++- .../transpiler/test_basis_translator.py | 61 +++- test/python/transpiler/test_bip_mapping.py | 56 +++- .../transpiler/test_commutation_analysis.py | 15 +- .../test_commutative_cancellation.py | 14 +- .../transpiler/test_consolidate_blocks.py | 28 +- .../test_count_ops_longest_path_pass.py | 6 + test/python/transpiler/test_count_ops_pass.py | 9 +- .../python/transpiler/test_cx_cancellation.py | 23 +- .../transpiler/test_dag_longest_path_pass.py | 6 + test/python/transpiler/test_depth_pass.py | 9 +- test/python/transpiler/test_faulty_backend.py | 17 +- test/python/transpiler/test_gate_direction.py | 17 ++ test/python/transpiler/test_hoare_opt.py | 269 ++++++++---------- test/python/transpiler/test_lookahead_swap.py | 33 +++ .../test_optimize_1q_commutation.py | 40 +++ .../transpiler/test_optimize_1q_gates.py | 30 ++ .../test_remove_final_measurements.py | 20 ++ test/python/transpiler/test_sabre_layout.py | 32 ++- .../python/transpiler/test_stochastic_swap.py | 25 ++ test/python/transpiler/test_unroller.py | 126 +++++++- 23 files changed, 878 insertions(+), 197 deletions(-) diff --git a/test/python/quantum_info/operators/test_dihedral.py b/test/python/quantum_info/operators/test_dihedral.py index 926454e98f8c..91039c78e0d6 100644 --- a/test/python/quantum_info/operators/test_dihedral.py +++ b/test/python/quantum_info/operators/test_dihedral.py @@ -178,13 +178,29 @@ def test_2_qubit_identities(self): self.assertEqual(elem, elem1, "Error: 2-qubit SWAP identity does not hold") self.assertEqual(elem1, elem2, "Error: 2-qubit SWAP identity does not hold") - # CS01 = CS10 (symmetric) + """ + CS01 = CS10 (symmetric) + + ┌───┐ + q_0: ┤ T ├──■───────────■── + ├───┤┌─┴─┐┌─────┐┌─┴─┐ + q_1: ┤ T ├┤ X ├┤ Tdg ├┤ X ├ + └───┘└───┘└─────┘└───┘ + """ circ1 = QuantumCircuit(2) circ1.t(0) circ1.t(1) circ1.cx(0, 1) circ1.tdg(1) circ1.cx(0, 1) + + """ + ┌───┐┌───┐┌─────┐┌───┐ + q_0: ┤ T ├┤ X ├┤ Tdg ├┤ X ├ + ├───┤└─┬─┘└─────┘└─┬─┘ + q_1: ┤ T ├──■───────────■── + └───┘ + """ circ2 = QuantumCircuit(2) circ2.t(1) circ2.t(0) @@ -195,7 +211,15 @@ def test_2_qubit_identities(self): elem2 = CNOTDihedral(circ2) self.assertEqual(elem1, elem2, "Error: 2-qubit CS identity does not hold") - # TI*CS*TdgI = CS + """ + TI*CS*TdgI = CS + + ┌───┐┌───┐ ┌─────┐ + q_0: ┤ T ├┤ T ├──■───────────■──┤ Tdg ├ + ├───┤└───┘┌─┴─┐┌─────┐┌─┴─┐└─────┘ + q_1: ┤ T ├─────┤ X ├┤ Tdg ├┤ X ├─────── + └───┘ └───┘└─────┘└───┘ + """ circ3 = QuantumCircuit(2) circ3.t(0) circ3.t(0) @@ -207,7 +231,15 @@ def test_2_qubit_identities(self): elem3 = CNOTDihedral(circ3) self.assertEqual(elem1, elem3, "Error: 2-qubit CS identity does not hold") - # IT*CS*ITdg = CS + """ + IT*CS*ITdg = CS + + ┌───┐ + q_0: ┤ T ├───────■───────────■───────── + ├───┤┌───┐┌─┴─┐┌─────┐┌─┴─┐┌─────┐ + q_1: ┤ T ├┤ T ├┤ X ├┤ Tdg ├┤ X ├┤ Tdg ├ + └───┘└───┘└───┘└─────┘└───┘└─────┘ + """ circ4 = QuantumCircuit(2) circ4.t(1) circ4.t(0) @@ -219,7 +251,15 @@ def test_2_qubit_identities(self): elem4 = CNOTDihedral(circ4) self.assertEqual(elem1, elem4, "Error: 2-qubit CS identity does not hold") - # XX*CS*XX*SS = CS + """ + XX*CS*XX*SS = CS + + ┌───┐┌───┐ ┌───┐┌───┐ + q_0: ┤ X ├┤ T ├──■───────────■──┤ X ├┤ S ├ + ├───┤├───┤┌─┴─┐┌─────┐┌─┴─┐├───┤├───┤ + q_1: ┤ X ├┤ T ├┤ X ├┤ Tdg ├┤ X ├┤ X ├┤ S ├ + └───┘└───┘└───┘└─────┘└───┘└───┘└───┘ + """ circ5 = QuantumCircuit(2) circ5.x(0) circ5.x(1) @@ -235,13 +275,29 @@ def test_2_qubit_identities(self): elem5 = CNOTDihedral(circ5) self.assertEqual(elem1, elem5, "Error: 2-qubit CS identity does not hold") - # CSdg01 = CSdg10 (symmetric) + """ + CSdg01 = CSdg10 (symmetric) + + ┌─────┐ + q_0: ┤ Tdg ├──■─────────■── + ├─────┤┌─┴─┐┌───┐┌─┴─┐ + q_1: ┤ Tdg ├┤ X ├┤ T ├┤ X ├ + └─────┘└───┘└───┘└───┘ + """ circ1 = QuantumCircuit(2) circ1.tdg(0) circ1.tdg(1) circ1.cx(0, 1) circ1.t(1) circ1.cx(0, 1) + + """ + ┌─────┐┌───┐┌───┐┌───┐ + q_0: ┤ Tdg ├┤ X ├┤ T ├┤ X ├ + ├─────┤└─┬─┘└───┘└─┬─┘ + q_1: ┤ Tdg ├──■─────────■── + └─────┘ + """ circ2 = QuantumCircuit(2) circ2.tdg(1) circ2.tdg(0) @@ -252,7 +308,15 @@ def test_2_qubit_identities(self): elem2 = CNOTDihedral(circ2) self.assertEqual(elem1, elem2, "Error: 2-qubit CSdg identity does not hold") - # XI*CS*XI*ISdg = CSdg + """ + XI*CS*XI*ISdg = CSdg + + ┌───┐┌───┐ ┌───┐ + q_0: ┤ X ├┤ T ├──■───────────■───┤ X ├─ + ├───┤└───┘┌─┴─┐┌─────┐┌─┴─┐┌┴───┴┐ + q_1: ┤ T ├─────┤ X ├┤ Tdg ├┤ X ├┤ Sdg ├ + └───┘ └───┘└─────┘└───┘└─────┘ + """ circ3 = QuantumCircuit(2) circ3.x(0) circ3.t(0) @@ -265,7 +329,15 @@ def test_2_qubit_identities(self): elem3 = CNOTDihedral(circ3) self.assertEqual(elem1, elem3, "Error: 2-qubit CSdg identity does not hold") - # IX*CS*IX*SdgI = CSdg + """ + IX*CS*IX*SdgI = CSdg + + ┌───┐ ┌─────┐ + q_0: ┤ T ├───────■───────────■──┤ Sdg ├ + ├───┤┌───┐┌─┴─┐┌─────┐┌─┴─┐└┬───┬┘ + q_1: ┤ X ├┤ T ├┤ X ├┤ Tdg ├┤ X ├─┤ X ├─ + └───┘└───┘└───┘└─────┘└───┘ └───┘ + """ circ4 = QuantumCircuit(2) circ4.x(1) circ4.t(0) @@ -290,7 +362,15 @@ def test_2_qubit_identities(self): self.assertEqual(elem, elem1, "Error: 2-qubit CZ identity does not hold") self.assertEqual(elem1, elem2, "Error: 2-qubit CZ identity does not hold") - # CZ = CS * CS + """ + CZ = CS * CS + + ┌───┐ ┌───┐ + q_0: ┤ T ├──■───────────■──┤ T ├──■───────────■── + ├───┤┌─┴─┐┌─────┐┌─┴─┐├───┤┌─┴─┐┌─────┐┌─┴─┐ + q_1: ┤ T ├┤ X ├┤ Tdg ├┤ X ├┤ T ├┤ X ├┤ Tdg ├┤ X ├ + └───┘└───┘└─────┘└───┘└───┘└───┘└─────┘└───┘ + """ circ3 = QuantumCircuit(2) circ3.t(0) circ3.t(1) @@ -305,7 +385,15 @@ def test_2_qubit_identities(self): elem3 = CNOTDihedral(circ3) self.assertEqual(elem1, elem3, "Error: 2-qubit CZ identity does not hold") - # CZ = CSdg * CSdg + """ + CZ = CSdg * CSdg + + ┌─────┐ ┌─────┐ + q_0: ┤ Tdg ├──■─────────■──┤ Tdg ├──■─────────■── + ├─────┤┌─┴─┐┌───┐┌─┴─┐├─────┤┌─┴─┐┌───┐┌─┴─┐ + q_1: ┤ Tdg ├┤ X ├┤ T ├┤ X ├┤ Tdg ├┤ X ├┤ T ├┤ X ├ + └─────┘└───┘└───┘└───┘└─────┘└───┘└───┘└───┘ + """ circ4 = QuantumCircuit(2) circ4.tdg(0) circ4.tdg(1) @@ -320,7 +408,15 @@ def test_2_qubit_identities(self): elem4 = CNOTDihedral(circ4) self.assertEqual(elem1, elem4, "Error: 2-qubit CZ identity does not hold") - # CZ = TdgTdg * CX * T^2I * CX * TdgTdg + """ + CZ = TdgTdg * CX * T^2I * CX * TdgTdg + + ┌─────┐┌───┐┌───┐┌───┐┌───┐┌─────┐ + q_0: ┤ Tdg ├┤ X ├┤ T ├┤ T ├┤ X ├┤ Tdg ├ + ├─────┤└─┬─┘└───┘└───┘└─┬─┘├─────┤ + q_1: ┤ Tdg ├──■──────────────■──┤ Tdg ├ + └─────┘ └─────┘ + """ circ5 = QuantumCircuit(2) circ5.tdg(0) circ5.tdg(1) @@ -338,7 +434,15 @@ def test_2_qubit_identities(self): circ1.cx(0, 1) elem1 = CNOTDihedral(circ1) - # TI*CX*TdgI = CX + """ + TI*CX*TdgI = CX + + ┌───┐ ┌─────┐ + q_0: ┤ T ├──■──┤ Tdg ├ + └───┘┌─┴─┐└─────┘ + q_1: ─────┤ X ├─────── + └───┘ + """ circ2 = QuantumCircuit(2) circ2.t(0) circ2.cx(0, 1) @@ -346,7 +450,15 @@ def test_2_qubit_identities(self): elem2 = CNOTDihedral(circ2) self.assertEqual(elem1, elem2, "Error: 2-qubit CX identity does not hold") - # IZ*CX*ZZ = CX + """ + IZ*CX*ZZ = CX + + ┌───┐ + q_0: ───────■──┤ Z ├ + ┌───┐┌─┴─┐├───┤ + q_1: ┤ Z ├┤ X ├┤ Z ├ + └───┘└───┘└───┘ + """ circ3 = QuantumCircuit(2) circ3.z(1) circ3.cx(0, 1) @@ -355,7 +467,14 @@ def test_2_qubit_identities(self): elem3 = CNOTDihedral(circ3) self.assertEqual(elem1, elem3, "Error: 2-qubit CX identity does not hold") - # IX*CX*IX = CX + """ + IX*CX*IX = CX + + q_0: ───────■─────── + ┌───┐┌─┴─┐┌───┐ + q_1: ┤ X ├┤ X ├┤ X ├ + └───┘└───┘└───┘ + """ circ4 = QuantumCircuit(2) circ4.x(1) circ4.cx(0, 1) @@ -363,7 +482,15 @@ def test_2_qubit_identities(self): elem4 = CNOTDihedral(circ4) self.assertEqual(elem1, elem4, "Error: 2-qubit CX identity does not hold") - # XI*CX*XX = CX + """ + XI*CX*XX = CX + + ┌───┐ ┌───┐ + q_0: ┤ X ├──■──┤ X ├ + └───┘┌─┴─┐├───┤ + q_1: ─────┤ X ├┤ X ├ + └───┘└───┘ + """ circ5 = QuantumCircuit(2) circ5.x(0) circ5.cx(0, 1) @@ -372,10 +499,26 @@ def test_2_qubit_identities(self): elem5 = CNOTDihedral(circ5) self.assertEqual(elem1, elem5, "Error: 2-qubit CX identity does not hold") - # IT*CX01*CX10*TdgI = CX01*CX10 + """ + IT*CX01*CX10*TdgI = CX01*CX10 + + ┌───┐ + q_0: ──■──┤ X ├ + ┌─┴─┐└─┬─┘ + q_1: ┤ X ├──■── + └───┘ + """ circ1 = QuantumCircuit(2) circ1.cx(0, 1) circ1.cx(1, 0) + + """ + ┌───┐┌─────┐ + q_0: ───────■──┤ X ├┤ Tdg ├ + ┌───┐┌─┴─┐└─┬─┘└─────┘ + q_1: ┤ T ├┤ X ├──■───────── + └───┘└───┘ + """ circ2 = QuantumCircuit(2) circ2.t(1) circ2.cx(0, 1) diff --git a/test/python/quantum_info/test_analyzation.py b/test/python/quantum_info/test_analyzation.py index 08ef896f3129..295ad5c564ea 100644 --- a/test/python/quantum_info/test_analyzation.py +++ b/test/python/quantum_info/test_analyzation.py @@ -142,7 +142,22 @@ def test_hellinger_fidelity_same(self): self.assertEqual(ans, 1.0) def test_hellinger_fidelity_no_overlap(self): - """Test hellinger fidelity is zero for no overlap.""" + """Test hellinger fidelity is zero for no overlap. + + ┌───┐ ┌─┐ + q_0: ──────────┤ X ├─────┤M├──────────── + ┌───┐└─┬─┘ └╥┘┌─┐ + q_1: ─────┤ X ├──■────────╫─┤M├───────── + ┌───┐└─┬─┘ ║ └╥┘┌─┐ + q_2: ┤ H ├──■────■────────╫──╫─┤M├────── + └───┘ ┌─┴─┐ ║ ║ └╥┘┌─┐ + q_3: ──────────┤ X ├──■───╫──╫──╫─┤M├─── + └───┘┌─┴─┐ ║ ║ ║ └╥┘┌─┐ + q_4: ───────────────┤ X ├─╫──╫──╫──╫─┤M├ + └───┘ ║ ║ ║ ║ └╥┘ + c: 5/═════════════════════╩══╩══╩══╩══╩═ + 0 1 2 3 4 + """ qc = qiskit.QuantumCircuit(5, 5) qc.h(2) qc.cx(2, 1) @@ -151,6 +166,21 @@ def test_hellinger_fidelity_no_overlap(self): qc.cx(1, 0) qc.measure(range(5), range(5)) + """ + ┌───┐ ┌─┐ + q_0: ──────────┤ X ├─────┤M├───────── + ┌───┐└─┬─┘ └╥┘┌─┐ + q_1: ─────┤ X ├──■────────╫─┤M├────── + ┌───┐└─┬─┘┌───┐ ║ └╥┘┌─┐ + q_2: ┤ H ├──■──┤ Y ├──■───╫──╫─┤M├─── + └───┘ └───┘┌─┴─┐ ║ ║ └╥┘┌─┐ + q_3: ───────────────┤ X ├─╫──╫──╫─┤M├ + ┌─┐ └───┘ ║ ║ ║ └╥┘ + q_4: ─┤M├─────────────────╫──╫──╫──╫─ + └╥┘ ║ ║ ║ ║ + c: 5/══╩══════════════════╩══╩══╩══╩═ + 4 0 1 2 3 + """ qc2 = qiskit.QuantumCircuit(5, 5) qc2.h(2) qc2.cx(2, 1) diff --git a/test/python/scheduler/test_basic_scheduler.py b/test/python/scheduler/test_basic_scheduler.py index 937ff9af3ded..fa3b3bf8750c 100644 --- a/test/python/scheduler/test_basic_scheduler.py +++ b/test/python/scheduler/test_basic_scheduler.py @@ -50,7 +50,16 @@ def test_unavailable_defaults(self): self.assertRaises(QiskitError, lambda: schedule(qc, backend)) def test_alap_pass(self): - """Test ALAP scheduling.""" + """Test ALAP scheduling. + + ┌───────────────┐ ░ ┌─┐ + q0_0: ┤ U2(3.14,1.57) ├────────────────────░───■──┤M├─── + └┬──────────────┤ ░ ┌──────────────┐ ░ ┌─┴─┐└╥┘┌─┐ + q0_1: ─┤ U2(0.5,0.25) ├─░─┤ U2(0.5,0.25) ├─░─┤ X ├─╫─┤M├ + └──────────────┘ ░ └──────────────┘ ░ └───┘ ║ └╥┘ + c0: 2/═════════════════════════════════════════════╩══╩═ + 0 1 + """ q = QuantumRegister(2) c = ClassicalRegister(2) qc = QuantumCircuit(q, c) @@ -118,7 +127,16 @@ def test_alap_aligns_end(self): ) def test_asap_pass(self): - """Test ASAP scheduling.""" + """Test ASAP scheduling. + + ┌───────────────┐ ░ ┌─┐ + q0_0: ┤ U2(3.14,1.57) ├────────────────────░───■──┤M├─── + └┬──────────────┤ ░ ┌──────────────┐ ░ ┌─┴─┐└╥┘┌─┐ + q0_1: ─┤ U2(0.5,0.25) ├─░─┤ U2(0.5,0.25) ├─░─┤ X ├─╫─┤M├ + └──────────────┘ ░ └──────────────┘ ░ └───┘ ║ └╥┘ + c0: 2/═════════════════════════════════════════════╩══╩═ + 0 1 + """ q = QuantumRegister(2) c = ClassicalRegister(2) qc = QuantumCircuit(q, c) @@ -208,7 +226,17 @@ def test_measure_combined(self): self.assertEqual(sched.instructions, expected.instructions) def test_3q_schedule(self): - """Test a schedule that was recommended by David McKay :D""" + """Test a schedule that was recommended by David McKay :D + + ┌─────────────────┐ + q0_0: ─────────■─────────┤ U3(3.14,1.57,0) ├──────────────────────── + ┌─┴─┐ └┬───────────────┬┘ + q0_1: ───────┤ X ├────────┤ U2(3.14,1.57) ├───■───────────────────── + ┌──────┴───┴──────┐ └───────────────┘ ┌─┴─┐┌─────────────────┐ + q0_2: ┤ U2(0.778,0.122) ├───────────────────┤ X ├┤ U2(0.778,0.122) ├ + └─────────────────┘ └───┘└─────────────────┘ + c0: 3/══════════════════════════════════════════════════════════════ + """ backend = FakeOpenPulse3Q() inst_map = backend.defaults().instruction_schedule_map q = QuantumRegister(3) diff --git a/test/python/transpiler/test_basis_translator.py b/test/python/transpiler/test_basis_translator.py index 6236438a4d13..7510feb92b26 100644 --- a/test/python/transpiler/test_basis_translator.py +++ b/test/python/transpiler/test_basis_translator.py @@ -409,7 +409,21 @@ def test_unroll_toffoli(self): self.assertIn(node.name, ["h", "t", "tdg", "cx"]) def test_unroll_1q_chain_conditional(self): - """Test unroll chain of 1-qubit gates interrupted by conditional.""" + """Test unroll chain of 1-qubit gates interrupted by conditional. + + ┌───┐┌─────┐┌───┐┌───┐┌─────────┐┌─────────┐┌─────────┐┌─┐ ┌───┐ ┌───┐ » + qr: ┤ H ├┤ Tdg ├┤ Z ├┤ T ├┤ Ry(0.5) ├┤ Rz(0.3) ├┤ Rx(0.1) ├┤M├─┤ X ├──┤ Y ├─» + └───┘└─────┘└───┘└───┘└─────────┘└─────────┘└─────────┘└╥┘ └─╥─┘ └─╥─┘ » + ║ ┌──╨──┐┌──╨──┐» + cr: 1/══════════════════════════════════════════════════════╩═╡ 0x1 ╞╡ 0x1 ╞» + 0 └─────┘└─────┘» + « ┌───┐ + « qr: ─┤ Z ├─ + « └─╥─┘ + « ┌──╨──┐ + «cr: 1/╡ 0x1 ╞ + « └─────┘ + """ qr = QuantumRegister(1, "qr") cr = ClassicalRegister(1, "cr") circuit = QuantumCircuit(qr, cr) @@ -431,7 +445,22 @@ def test_unroll_1q_chain_conditional(self): pass_ = BasisTranslator(std_eqlib, ["u1", "u2", "u3"]) unrolled_dag = pass_.run(dag) - # Pick up -1 * 0.3 / 2 global phase for one RZ -> U1. + """ + Pick up -1 * 0.3 / 2 global phase for one RZ -> U1. + + global phase: 6.1332 + ┌─────────┐┌──────────┐┌───────┐┌─────────┐┌─────────────┐┌─────────┐» + qr: ┤ U2(0,π) ├┤ U1(-π/4) ├┤ U1(π) ├┤ U1(π/4) ├┤ U3(0.5,0,0) ├┤ U1(0.3) ├» + └─────────┘└──────────┘└───────┘└─────────┘└─────────────┘└─────────┘» + cr: 1/═══════════════════════════════════════════════════════════════════» + » + « ┌──────────────────┐┌─┐┌───────────┐┌───────────────┐┌───────┐ + « qr: ┤ U3(0.1,-π/2,π/2) ├┤M├┤ U3(π,0,π) ├┤ U3(π,π/2,π/2) ├┤ U1(π) ├ + « └──────────────────┘└╥┘└─────╥─────┘└───────╥───────┘└───╥───┘ + « ║ ┌──╨──┐ ┌──╨──┐ ┌──╨──┐ + «cr: 1/═════════════════════╩════╡ 0x1 ╞════════╡ 0x1 ╞══════╡ 0x1 ╞═ + « 0 └─────┘ └─────┘ └─────┘ + """ ref_circuit = QuantumCircuit(qr, cr, global_phase=-0.3 / 2) ref_circuit.append(U2Gate(0, pi), [qr[0]]) ref_circuit.append(U1Gate(-pi / 4), [qr[0]]) @@ -765,6 +794,13 @@ def test_cx_bell_to_ecr(self): in_dag = circuit_to_dag(bell) out_dag = BasisTranslator(std_eqlib, ["ecr", "u"]).run(in_dag) + """ + ┌────────────┐ ┌─────────────┐┌──────────┐┌──────┐ + q_0: ───┤ U(π/2,0,π) ├──┤ U(0,0,-π/2) ├┤ U(π,0,0) ├┤0 ├ + ┌──┴────────────┴─┐└─────────────┘└──────────┘│ Ecr │ + q_1: ┤ U(π/2,-π/2,π/2) ├───────────────────────────┤1 ├ + └─────────────────┘ └──────┘ + """ qr = QuantumRegister(2, "q") expected = QuantumCircuit(2) expected.u(pi / 2, 0, pi, qr[0]) @@ -798,7 +834,16 @@ def test_global_phase(self): self.assertEqual(Operator(dag_to_circuit(out_dag)), Operator(expected)) def test_condition_set_substitute_node(self): - """Verify condition is set in BasisTranslator on substitute_node""" + """Verify condition is set in BasisTranslator on substitute_node + + ┌───┐ ┌───┐ + q_0: ┤ H ├──■──────┤ H ├─ + └───┘┌─┴─┐┌─┐ └─╥─┘ + q_1: ─────┤ X ├┤M├───╫─── + └───┘└╥┘┌──╨──┐ + c: 2/═══════════╩═╡ 0x1 ╞ + 1 └─────┘ + """ qr = QuantumRegister(2, "q") cr = ClassicalRegister(2, "c") circ = QuantumCircuit(qr, cr) @@ -809,6 +854,16 @@ def test_condition_set_substitute_node(self): circ_transpiled = transpile( circ, optimization_level=3, basis_gates=["cx", "id", "u1", "u2", "u3"] ) + + """ + ┌─────────┐ ┌─────────┐ + q_0: ┤ U2(0,π) ├──■─────┤ U2(0,π) ├ + └─────────┘┌─┴─┐┌─┐└────╥────┘ + q_1: ───────────┤ X ├┤M├─────╫───── + └───┘└╥┘ ┌──╨──┐ + c: 2/═════════════════╩═══╡ 0x1 ╞══ + 1 └─────┘ + """ qr = QuantumRegister(2, "q") cr = ClassicalRegister(2, "c") expected = QuantumCircuit(qr, cr) diff --git a/test/python/transpiler/test_bip_mapping.py b/test/python/transpiler/test_bip_mapping.py index 917d92bcb414..9fdb436b44b6 100644 --- a/test/python/transpiler/test_bip_mapping.py +++ b/test/python/transpiler/test_bip_mapping.py @@ -192,7 +192,23 @@ def test_unmappable_cnots_in_a_layer(self): self.assertEqual(circuit, actual) def test_multi_cregs(self): - """Test for multiple ClassicalRegisters.""" + """Test for multiple ClassicalRegisters. + + ┌───┐ ░ ┌─┐ + qr_0: ──■────────────┤ X ├─░─┤M├───────── + ┌─┴─┐ ┌───┐└─┬─┘ ░ └╥┘┌─┐ + qr_1: ┤ X ├──■──┤ H ├──■───░──╫─┤M├────── + └───┘┌─┴─┐└───┘ ░ ║ └╥┘┌─┐ + qr_2: ──■──┤ X ├───────────░──╫──╫─┤M├─── + ┌─┴─┐└───┘ ░ ║ ║ └╥┘┌─┐ + qr_3: ┤ X ├────────────────░──╫──╫──╫─┤M├ + └───┘ ░ ║ ║ ║ └╥┘ + c: 2/════════════════════════╩══╬══╩══╬═ + 0 ║ 1 ║ + ║ ║ + d: 2/═══════════════════════════╩═════╩═ + 0 1 + """ qr = QuantumRegister(4, "qr") cr1 = ClassicalRegister(2, "c") cr2 = ClassicalRegister(2, "d") @@ -217,7 +233,18 @@ def test_multi_cregs(self): self.assertTrue(property_set["is_swap_mapped"]) def test_swaps_in_dummy_steps(self): - """Test the case when swaps are inserted in dummy steps.""" + """Test the case when swaps are inserted in dummy steps. + + ┌───┐ ░ ░ + q_0: ──■──┤ H ├─░───■────────░───■─────── + ┌─┴─┐├───┤ ░ │ ░ │ + q_1: ┤ X ├┤ H ├─░───┼────■───░───┼────■── + └───┘├───┤ ░ │ ┌─┴─┐ ░ ┌─┴─┐ │ + q_2: ──■──┤ H ├─░───┼──┤ X ├─░─┤ X ├──┼── + ┌─┴─┐├───┤ ░ ┌─┴─┐└───┘ ░ └───┘┌─┴─┐ + q_3: ┤ X ├┤ H ├─░─┤ X ├──────░──────┤ X ├ + └───┘└───┘ ░ └───┘ ░ └───┘ + """ circuit = QuantumCircuit(4) circuit.cx(0, 1) circuit.cx(2, 3) @@ -244,7 +271,17 @@ def test_swaps_in_dummy_steps(self): self.assertFalse(isinstance(inst, SwapGate)) def test_different_number_of_virtual_and_physical_qubits(self): - """Test the case when number of virtual and physical qubits are different.""" + """Test the case when number of virtual and physical qubits are different. + + q_0: ──■────■─────── + ┌─┴─┐ │ + q_1: ┤ X ├──┼────■── + └───┘ │ ┌─┴─┐ + q_2: ──■────┼──┤ X ├ + ┌─┴─┐┌─┴─┐└───┘ + q_3: ┤ X ├┤ X ├───── + └───┘└───┘ + """ circuit = QuantumCircuit(4) circuit.cx(0, 1) circuit.cx(2, 3) @@ -284,7 +321,18 @@ def test_unconnected_qubit_subset(self): BIPMapping(coupling, qubit_subset=[0, 1, 2])(circuit) def test_objective_function(self): - """Test if ``objective`` functions priorities metrics correctly.""" + """Test if ``objective`` functions priorities metrics correctly. + + ┌──────┐┌──────┐ ┌──────┐ + q_0: ┤0 ├┤0 ├─────┤0 ├ + │ Dcx ││ │ │ Dcx │ + q_1: ┤1 ├┤ Dcx ├──■──┤1 ├ + └──────┘│ │ │ └──────┘ + q_2: ───■────┤1 ├──┼─────■──── + ┌─┴─┐ └──────┘┌─┴─┐ ┌─┴─┐ + q_3: ─┤ X ├──────────┤ X ├─┤ X ├── + └───┘ └───┘ └───┘ + """ qc = QuantumCircuit(4) qc.dcx(0, 1) qc.cx(2, 3) diff --git a/test/python/transpiler/test_commutation_analysis.py b/test/python/transpiler/test_commutation_analysis.py index 0ff2e366de7f..4772b4b96d8f 100644 --- a/test/python/transpiler/test_commutation_analysis.py +++ b/test/python/transpiler/test_commutation_analysis.py @@ -258,7 +258,20 @@ def test_jordan_wigner_type_circuit(self): self.assertCommutationSet(self.pset["commutation_set"], expected) def test_all_commute_circuit(self): - """Test circuit with that all commute""" + """Test circuit with that all commute + + ┌───┐ + qr_0: ──■──┤ Z ├──■──────────── + ┌─┴─┐├───┤┌─┴─┐┌───┐ + qr_1: ┤ X ├┤ X ├┤ X ├┤ X ├───── + └───┘└─┬─┘└───┘└─┬─┘ + qr_2: ───────■────■────■────■── + ┌───┐ ┌─┴─┐┌───┐┌─┴─┐ + qr_3: ┤ X ├─────┤ X ├┤ X ├┤ X ├ + └─┬─┘┌───┐└───┘└─┬─┘└───┘ + qr_4: ──■──┤ Z ├───────■─────── + └───┘ + """ qr = QuantumRegister(5, "qr") circuit = QuantumCircuit(qr) circuit.cx(qr[0], qr[1]) diff --git a/test/python/transpiler/test_commutative_cancellation.py b/test/python/transpiler/test_commutative_cancellation.py index 36615019b6e7..a124348dd4bb 100644 --- a/test/python/transpiler/test_commutative_cancellation.py +++ b/test/python/transpiler/test_commutative_cancellation.py @@ -517,7 +517,19 @@ def test_cnot_cascade1(self): self.assertEqual(expected, new_circuit) def test_conditional_gates_dont_commute(self): - """Conditional gates do not commute and do not cancel""" + """Conditional gates do not commute and do not cancel + + ┌───┐┌─┐ + q_0: ┤ H ├┤M├───────────── + └───┘└╥┘ ┌─┐ + q_1: ──■───╫────■───┤M├─── + ┌─┴─┐ ║ ┌─┴─┐ └╥┘┌─┐ + q_2: ┤ X ├─╫──┤ X ├──╫─┤M├ + └───┘ ║ └─╥─┘ ║ └╥┘ + ║ ┌──╨──┐ ║ ║ + c: 2/══════╩═╡ 0x0 ╞═╩══╩═ + 0 └─────┘ 0 1 + """ circuit = QuantumCircuit(3, 2) circuit.h(0) circuit.measure(0, 0) diff --git a/test/python/transpiler/test_consolidate_blocks.py b/test/python/transpiler/test_consolidate_blocks.py index e888f020b230..c6ba7229e361 100644 --- a/test/python/transpiler/test_consolidate_blocks.py +++ b/test/python/transpiler/test_consolidate_blocks.py @@ -101,7 +101,15 @@ def test_topological_order_preserved(self): self.assertEqual(new_topo_ops[1].qargs, [qr[0], qr[1]]) def test_3q_blocks(self): - """blocks of more than 2 qubits work.""" + """blocks of more than 2 qubits work. + + ┌────────┐ + qr_0: ──────┤ P(0.5) ├────────────■── + ┌─────┴────────┴────┐┌───┐┌─┴─┐ + qr_1: ┤ U(1.5708,0.2,0.6) ├┤ X ├┤ X ├ + └───────────────────┘└─┬─┘└───┘ + qr_2: ───────────────────────■─────── + """ qr = QuantumRegister(3, "qr") qc = QuantumCircuit(qr) qc.p(0.5, qr[0]) @@ -120,7 +128,14 @@ def test_3q_blocks(self): self.assertAlmostEqual(fidelity, 1.0, places=7) def test_block_spanning_two_regs(self): - """blocks spanning wires on different quantum registers work.""" + """blocks spanning wires on different quantum registers work. + + ┌────────┐ + qr0: ──────┤ P(0.5) ├───────■── + ┌─────┴────────┴────┐┌─┴─┐ + qr1: ┤ U(1.5708,0.2,0.6) ├┤ X ├ + └───────────────────┘└───┘ + """ qr0 = QuantumRegister(1, "qr0") qr1 = QuantumRegister(1, "qr1") qc = QuantumCircuit(qr0, qr1) @@ -283,7 +298,14 @@ def test_node_middle_of_blocks(self): self.assertEqual(qc, qc1) def test_overlapping_block_and_run(self): - """Test that an overlapping block and run only consolidate once""" + """Test that an overlapping block and run only consolidate once + + ┌───┐┌───┐┌─────┐ + q_0: ┤ H ├┤ T ├┤ Sdg ├──■──────────────────────── + └───┘└───┘└─────┘┌─┴─┐┌───┐┌─────┐┌───┐┌───┐ + q_1: ─────────────────┤ X ├┤ T ├┤ Sdg ├┤ Z ├┤ I ├ + └───┘└───┘└─────┘└───┘└───┘ + """ qc = QuantumCircuit(2) qc.h(0) qc.t(0) diff --git a/test/python/transpiler/test_count_ops_longest_path_pass.py b/test/python/transpiler/test_count_ops_longest_path_pass.py index 8cb3fef95747..37de6eac708b 100644 --- a/test/python/transpiler/test_count_ops_longest_path_pass.py +++ b/test/python/transpiler/test_count_ops_longest_path_pass.py @@ -36,6 +36,12 @@ def test_empty_dag(self): def test_just_qubits(self): """A dag with 9 operations (3 CXs, 2Xs, 2Ys and 2 Hs) on the longest path + + ┌───┐┌───┐┌───┐ + q0_0: ──■──┤ X ├┤ Y ├┤ H ├──■───────────────────■── + ┌─┴─┐└───┘└───┘└───┘┌─┴─┐┌───┐┌───┐┌───┐┌─┴─┐ + q0_1: ┤ X ├───────────────┤ X ├┤ X ├┤ Y ├┤ H ├┤ X ├ + └───┘ └───┘└───┘└───┘└───┘└───┘ """ qr = QuantumRegister(2) circuit = QuantumCircuit(qr) diff --git a/test/python/transpiler/test_count_ops_pass.py b/test/python/transpiler/test_count_ops_pass.py index e9c0cfe3bfaa..76033dd4ac54 100644 --- a/test/python/transpiler/test_count_ops_pass.py +++ b/test/python/transpiler/test_count_ops_pass.py @@ -34,7 +34,14 @@ def test_empty_dag(self): self.assertDictEqual(pass_.property_set["count_ops"], {}) def test_just_qubits(self): - """A dag with 8 operations (6 CXs and 2 Hs)""" + """A dag with 8 operations (6 CXs and 2 Hs) + + ┌───┐ ┌───┐┌───┐ + q0_0: ┤ H ├──■────■────■────■──┤ X ├┤ X ├ + ├───┤┌─┴─┐┌─┴─┐┌─┴─┐┌─┴─┐└─┬─┘└─┬─┘ + q0_1: ┤ H ├┤ X ├┤ X ├┤ X ├┤ X ├──■────■── + └───┘└───┘└───┘└───┘└───┘ + """ qr = QuantumRegister(2) circuit = QuantumCircuit(qr) circuit.h(qr[0]) diff --git a/test/python/transpiler/test_cx_cancellation.py b/test/python/transpiler/test_cx_cancellation.py index 52e3e84d3f50..a42518c97dce 100644 --- a/test/python/transpiler/test_cx_cancellation.py +++ b/test/python/transpiler/test_cx_cancellation.py @@ -69,7 +69,18 @@ def test_pass_cx_cancellation_intermixed_ops(self): self.assertEqual(out_circuit, expected) def test_pass_cx_cancellation_chained_cx(self): - """Include a test were not all operations can be cancelled.""" + """Include a test were not all operations can be cancelled. + + ┌───┐ + q0_0: ┤ H ├──■─────────■─────── + ├───┤┌─┴─┐ ┌─┴─┐ + q0_1: ┤ H ├┤ X ├──■──┤ X ├───── + └───┘└───┘┌─┴─┐└───┘ + q0_2: ──────────┤ X ├──■────■── + └───┘┌─┴─┐┌─┴─┐ + q0_3: ───────────────┤ X ├┤ X ├ + └───┘└───┘ + """ qr = QuantumRegister(4) circuit = QuantumCircuit(qr) circuit.h(qr[0]) @@ -84,6 +95,16 @@ def test_pass_cx_cancellation_chained_cx(self): pass_manager.append(CXCancellation()) out_circuit = pass_manager.run(circuit) + """ + ┌───┐ + q0_0: ┤ H ├──■─────────■── + ├───┤┌─┴─┐ ┌─┴─┐ + q0_1: ┤ H ├┤ X ├──■──┤ X ├ + └───┘└───┘┌─┴─┐└───┘ + q0_2: ──────────┤ X ├───── + └───┘ + q0_3: ──────────────────── + """ expected = QuantumCircuit(qr) expected.h(qr[0]) expected.h(qr[1]) diff --git a/test/python/transpiler/test_dag_longest_path_pass.py b/test/python/transpiler/test_dag_longest_path_pass.py index 1ab164a2b2a2..ac07fe4041fd 100644 --- a/test/python/transpiler/test_dag_longest_path_pass.py +++ b/test/python/transpiler/test_dag_longest_path_pass.py @@ -34,6 +34,12 @@ def test_empty_dag_true(self): def test_nonempty_dag_false(self): """Test the dag longest path non-empty dag. path length = 11 = 9 ops + 2 qubits at start and end of path + + ┌───┐┌───┐┌───┐ + q0_0: ──■──┤ X ├┤ Y ├┤ H ├──■───────────────────■── + ┌─┴─┐└───┘└───┘└───┘┌─┴─┐┌───┐┌───┐┌───┐┌─┴─┐ + q0_1: ┤ X ├───────────────┤ X ├┤ X ├┤ Y ├┤ H ├┤ X ├ + └───┘ └───┘└───┘└───┘└───┘└───┘ """ qr = QuantumRegister(2) circuit = QuantumCircuit(qr) diff --git a/test/python/transpiler/test_depth_pass.py b/test/python/transpiler/test_depth_pass.py index 32dc019734ef..0f37950e624c 100644 --- a/test/python/transpiler/test_depth_pass.py +++ b/test/python/transpiler/test_depth_pass.py @@ -34,7 +34,14 @@ def test_empty_dag(self): self.assertEqual(pass_.property_set["depth"], 0) def test_just_qubits(self): - """A dag with 8 operations and no classic bits""" + """A dag with 8 operations and no classic bits + + ┌───┐ ┌───┐┌───┐ + q0_0: ┤ H ├──■────■────■────■──┤ X ├┤ X ├ + ├───┤┌─┴─┐┌─┴─┐┌─┴─┐┌─┴─┐└─┬─┘└─┬─┘ + q0_1: ┤ H ├┤ X ├┤ X ├┤ X ├┤ X ├──■────■── + └───┘└───┘└───┘└───┘└───┘ + """ qr = QuantumRegister(2) circuit = QuantumCircuit(qr) circuit.h(qr[0]) diff --git a/test/python/transpiler/test_faulty_backend.py b/test/python/transpiler/test_faulty_backend.py index 4997b312950a..0137ba241b6d 100644 --- a/test/python/transpiler/test_faulty_backend.py +++ b/test/python/transpiler/test_faulty_backend.py @@ -254,7 +254,22 @@ def test_level(self, level): @data(0, 1, 2) # TODO: add 3 once https://github.com/Qiskit/qiskit-terra/issues/6406 is fixed def test_layout_level(self, level): - """Test level {level} with a faulty CX(Q1, Q3) with a working initial layout""" + """Test level {level} with a faulty CX(Q1, Q3) with a working initial layout + + ┌───┐ ┌───┐ ░ ┌─┐ + qr_0: ┤ H ├──■──┤ X ├───────────────────────────────░─┤M├──────────── + ├───┤┌─┴─┐└─┬─┘ ┌───┐ ┌───┐ ░ └╥┘┌─┐ + qr_1: ┤ H ├┤ X ├──■────■──┤ X ├──■──┤ X ├───────────░──╫─┤M├───────── + ├───┤└───┘ ┌─┴─┐└─┬─┘ │ └─┬─┘ ░ ║ └╥┘┌─┐ + qr_2: ┤ H ├──────────┤ X ├──■────┼────┼─────────────░──╫──╫─┤M├────── + └───┘ └───┘ ┌─┴─┐ │ ┌───┐ ░ ║ ║ └╥┘┌─┐ + qr_3: ─────────────────────────┤ X ├──■────■──┤ X ├─░──╫──╫──╫─┤M├─── + └───┘ ┌─┴─┐└─┬─┘ ░ ║ ║ ║ └╥┘┌─┐ + qr_4: ───────────────────────────────────┤ X ├──■───░──╫──╫──╫──╫─┤M├ + └───┘ ░ ║ ║ ║ ║ └╥┘ + meas: 5/═══════════════════════════════════════════════╩══╩══╩══╩══╩═ + 0 1 2 3 4 + """ circuit = QuantumCircuit(QuantumRegister(5, "qr")) circuit.h(range(3)) circuit.cx(0, 1) diff --git a/test/python/transpiler/test_gate_direction.py b/test/python/transpiler/test_gate_direction.py index 54dca5f9c161..838b02d30e61 100644 --- a/test/python/transpiler/test_gate_direction.py +++ b/test/python/transpiler/test_gate_direction.py @@ -132,6 +132,13 @@ def test_ecr_flip(self): coupling = CouplingMap([[0, 1]]) dag = circuit_to_dag(circuit) + """ + ┌─────────┐ ┌──────┐┌───┐ + qr_0: ┤ Ry(π/2) ├─┤0 ├┤ H ├ + ├─────────┴┐│ Ecr │├───┤ + qr_1: ┤ Ry(-π/2) ├┤1 ├┤ H ├ + └──────────┘└──────┘└───┘ + """ expected = QuantumCircuit(qr) expected.ry(pi / 2, qr[0]) expected.ry(-pi / 2, qr[1]) @@ -208,6 +215,16 @@ def test_preserves_conditions(self): coupling = CouplingMap([[0, 1]]) dag = circuit_to_dag(circuit) + """ + ┌───┐ ┌───┐ ┌───┐ ┌───┐ + q_0: ───■───────────┤ H ├────■───────────┤ H ├───■──┤ H ├──■──┤ H ├ + ┌─┴─┐ ┌───┐ └─╥─┘ ┌─┴─┐ ┌───┐ └─╥─┘ ┌─┴─┐├───┤┌─┴─┐├───┤ + q_1: ─┤ X ├──┤ H ├────╫────┤ X ├──┤ H ├────╫───┤ X ├┤ H ├┤ X ├┤ H ├ + └─╥─┘ └─╥─┘ ║ └─╥─┘ └─╥─┘ ║ └───┘└───┘└───┘└───┘ + ┌──╨──┐┌──╨──┐┌──╨──┐┌──╨──┐┌──╨──┐┌──╨──┐ + c: 1/╡ 0x0 ╞╡ 0x0 ╞╡ 0x0 ╞╡ 0x0 ╞╡ 0x0 ╞╡ 0x0 ╞════════════════════ + └─────┘└─────┘└─────┘└─────┘└─────┘└─────┘ + """ expected = QuantumCircuit(qr, cr) expected.cx(qr[0], qr[1]).c_if(cr, 0) diff --git a/test/python/transpiler/test_hoare_opt.py b/test/python/transpiler/test_hoare_opt.py index 620673043190..d4c466f4a851 100644 --- a/test/python/transpiler/test_hoare_opt.py +++ b/test/python/transpiler/test_hoare_opt.py @@ -32,8 +32,6 @@ def test_phasegate_removal(self): """Should remove the phase on a classical state, but not on a superposition state. - (circuit) - ┌───┐ q_0: ┤ Z ├────── ├───┤┌───┐ @@ -41,8 +39,13 @@ def test_phasegate_removal(self): └───┘└───┘ q_2: ─────────── - (expected) + """ + circuit = QuantumCircuit(3) + circuit.z(0) + circuit.h(1) + circuit.z(1) + """ q_0: ─────────── ┌───┐┌───┐ q_1:─┤ H ├┤ Z ├─ @@ -50,11 +53,6 @@ def test_phasegate_removal(self): q_2: ─────────── """ - circuit = QuantumCircuit(3) - circuit.z(0) - circuit.h(1) - circuit.z(1) - expected = QuantumCircuit(3) expected.h(1) expected.z(1) @@ -71,8 +69,6 @@ def test_cswap_removal(self): """Should remove Fredkin gates because the optimizer can deduce the targets are in the same state - (circuit) - ┌───┐┌───┐ ┌───┐ ┌───┐ ┌───┐ q_0: ┤ X ├┤ X ├──■──┤ X ├──■──┤ X ├──■────■──┤ X ├───────────────────────────────── └───┘└─┬─┘┌─┴─┐└─┬─┘ │ └─┬─┘┌─┴─┐ │ └─┬─┘ @@ -94,30 +90,6 @@ def test_cswap_removal(self): │ │ │ │ q_9: ─────────────────────────────────────────────────X──X─────X───────────X─────── - - (expected) - - ┌───┐┌───┐ ┌───┐ ┌───┐ ┌───┐ - q_0: ┤ X ├┤ X ├──■──┤ X ├──■──┤ X ├──■────■──┤ X ├─────────────── - └───┘└─┬─┘┌─┴─┐└─┬─┘ │ └─┬─┘┌─┴─┐ │ └─┬─┘ - q_1: ───────┼──┤ X ├──■────┼────┼──┤ X ├──┼────■───■──■──■─────── - │ └─┬─┘ ┌─┴─┐ │ └─┬─┘┌─┴─┐ │ │ │ │ - q_2: ───────┼────┼───────┤ X ├──■────┼──┤ X ├──■───┼──┼──┼──■──■─ - ┌───┐ │ │ └─┬─┘ │ └─┬─┘ │ │ │ │ │ - q_3: ┤ H ├──■────┼─────────┼─────────┼────┼────────X──┼──┼──X──┼─ - ├───┤ │ │ │ │ │ │ │ │ │ - q_4: ┤ H ├───────■─────────┼─────────┼────┼────────X──X──┼──┼──X─ - ├───┤ │ │ │ │ │ │ │ - q_5: ┤ H ├─────────────────■─────────┼────┼───────────X──X──X──┼─ - ├───┤ │ │ │ │ - q_6: ┤ H ├───────────────────────────■────■──────────────X─────X─ - └───┘ - q_7: ──────────────────────────────────────────────────────────── - - q_8: ──────────────────────────────────────────────────────────── - - q_9: ──────────────────────────────────────────────────────────── - """ circuit = QuantumCircuit(10) # prep @@ -148,6 +120,29 @@ def test_cswap_removal(self): circuit.cswap(2, 3, 5) circuit.cswap(2, 4, 6) + """ + ┌───┐┌───┐ ┌───┐ ┌───┐ ┌───┐ + q_0: ┤ X ├┤ X ├──■──┤ X ├──■──┤ X ├──■────■──┤ X ├─────────────── + └───┘└─┬─┘┌─┴─┐└─┬─┘ │ └─┬─┘┌─┴─┐ │ └─┬─┘ + q_1: ───────┼──┤ X ├──■────┼────┼──┤ X ├──┼────■───■──■──■─────── + │ └─┬─┘ ┌─┴─┐ │ └─┬─┘┌─┴─┐ │ │ │ │ + q_2: ───────┼────┼───────┤ X ├──■────┼──┤ X ├──■───┼──┼──┼──■──■─ + ┌───┐ │ │ └─┬─┘ │ └─┬─┘ │ │ │ │ │ + q_3: ┤ H ├──■────┼─────────┼─────────┼────┼────────X──┼──┼──X──┼─ + ├───┤ │ │ │ │ │ │ │ │ │ + q_4: ┤ H ├───────■─────────┼─────────┼────┼────────X──X──┼──┼──X─ + ├───┤ │ │ │ │ │ │ │ + q_5: ┤ H ├─────────────────■─────────┼────┼───────────X──X──X──┼─ + ├───┤ │ │ │ │ + q_6: ┤ H ├───────────────────────────■────■──────────────X─────X─ + └───┘ + q_7: ──────────────────────────────────────────────────────────── + + q_8: ──────────────────────────────────────────────────────────── + + q_9: ──────────────────────────────────────────────────────────── + + """ expected = QuantumCircuit(10) # prep expected.x(0) @@ -184,8 +179,6 @@ def test_lnn_cnot_removal(self): because of linear nearest architecture. Only uses single-gate optimization techniques. - (circuit) - ┌───┐ ┌───┐ » q_0: ┤ H ├──■──┤ X ├──■────────────────────────────────────────────────────» └───┘┌─┴─┐└─┬─┘┌─┴─┐ ┌───┐ » @@ -208,9 +201,19 @@ def test_lnn_cnot_removal(self): « «q_4: ─────────────── « + """ + circuit = QuantumCircuit(5) + circuit.h(0) + for i in range(0, 3): + circuit.cx(i, i + 1) + circuit.cx(i + 1, i) + circuit.cx(i, i + 1) + circuit.cx(3, 4) + for i in range(3, 0, -1): + circuit.cx(i - 1, i) + circuit.cx(i, i - 1) - (expected) - + """ ┌───┐ ┌───┐ ┌───┐ q_0: ┤ H ├──■──┤ X ├───────────────────────────────────┤ X ├ └───┘┌─┴─┐└─┬─┘ ┌───┐ ┌───┐└─┬─┘ @@ -223,17 +226,6 @@ def test_lnn_cnot_removal(self): q_4: ───────────────────────────────────┤ X ├─────────────── └───┘ """ - circuit = QuantumCircuit(5) - circuit.h(0) - for i in range(0, 3): - circuit.cx(i, i + 1) - circuit.cx(i + 1, i) - circuit.cx(i, i + 1) - circuit.cx(3, 4) - for i in range(3, 0, -1): - circuit.cx(i - 1, i) - circuit.cx(i, i - 1) - expected = QuantumCircuit(5) expected.h(0) for i in range(0, 3): @@ -256,8 +248,6 @@ def test_lnncnot_advanced_removal(self): because of linear nearest architecture. This time using multi-gate optimization techniques. - (circuit) - ┌───┐ ┌───┐ » q_0: ┤ H ├──■──┤ X ├──■────────────────────────────────────────────────────» └───┘┌─┴─┐└─┬─┘┌─┴─┐ ┌───┐ » @@ -280,9 +270,19 @@ def test_lnncnot_advanced_removal(self): « «q_4: ─────────────── « + """ + circuit = QuantumCircuit(5) + circuit.h(0) + for i in range(0, 3): + circuit.cx(i, i + 1) + circuit.cx(i + 1, i) + circuit.cx(i, i + 1) + circuit.cx(3, 4) + for i in range(3, 0, -1): + circuit.cx(i - 1, i) + circuit.cx(i, i - 1) - (expected) - + """ ┌───┐ q_0: ┤ H ├──■───────────────── └───┘┌─┴─┐ @@ -295,17 +295,6 @@ def test_lnncnot_advanced_removal(self): q_4: ────────────────────┤ X ├ └───┘ """ - circuit = QuantumCircuit(5) - circuit.h(0) - for i in range(0, 3): - circuit.cx(i, i + 1) - circuit.cx(i + 1, i) - circuit.cx(i, i + 1) - circuit.cx(3, 4) - for i in range(3, 0, -1): - circuit.cx(i - 1, i) - circuit.cx(i, i - 1) - expected = QuantumCircuit(5) expected.h(0) for i in range(0, 4): @@ -344,8 +333,6 @@ def test_targetsuccessive_identity_removal(self): which are the inverse of each other, if they can be identified to be executed as a unit (either both or none). - (circuit) - ┌───┐ ┌───┐┌───┐ q_0: ┤ H ├──■──┤ X ├┤ X ├──■── ├───┤ │ └─┬─┘└───┘ │ @@ -353,16 +340,6 @@ def test_targetsuccessive_identity_removal(self): ├───┤┌─┴─┐ ┌─┴─┐ q_2: ┤ H ├┤ X ├──────────┤ X ├ └───┘└───┘ └───┘ - - (expected) - - ┌───┐┌───┐┌───┐ - q_0: ┤ H ├┤ X ├┤ X ├ - ├───┤└─┬─┘└───┘ - q_1: ┤ H ├──■─────── - ├───┤ - q_2: ┤ H ├────────── - └───┘ """ circuit = QuantumCircuit(3) circuit.h(0) @@ -373,6 +350,15 @@ def test_targetsuccessive_identity_removal(self): circuit.x(0) circuit.ccx(0, 1, 2) + """ + ┌───┐┌───┐┌───┐ + q_0: ┤ H ├┤ X ├┤ X ├ + ├───┤└─┬─┘└───┘ + q_1: ┤ H ├──■─────── + ├───┤ + q_2: ┤ H ├────────── + └───┘ + """ expected = QuantumCircuit(3) expected.h(0) expected.h(1) @@ -393,8 +379,6 @@ def test_targetsuccessive_identity_advanced_removal(self): with DIFFERENT sets of control qubits. In this case CCCX(4,5,6,7) & CCX(5,6,7). - (circuit) - ┌───┐┌───┐ » q_0: ┤ H ├┤ X ├───────■─────────────────────────────■───────────────────■──» ├───┤└─┬─┘ │ │ │ » @@ -446,9 +430,47 @@ def test_targetsuccessive_identity_advanced_removal(self): « ┌─┴─┐ «q_7: ──────────┤ X ├ « └───┘ + """ + circuit = QuantumCircuit(8) + circuit.h(0) + circuit.h(1) + circuit.h(2) + circuit.h(3) + circuit.h(4) + circuit.h(5) + for i in range(3): + circuit.cx(i * 2 + 1, i * 2) + circuit.cx(3, 5) + for i in range(2): + circuit.ccx(i * 2, i * 2 + 1, i * 2 + 3) + circuit.cx(i * 2 + 3, i * 2 + 2) + circuit.ccx(4, 5, 6) + for i in range(1, -1, -1): + circuit.ccx(i * 2, i * 2 + 1, i * 2 + 3) + circuit.cx(3, 5) + circuit.cx(5, 6) + circuit.cx(3, 5) + circuit.x(6) + for i in range(2): + circuit.ccx(i * 2, i * 2 + 1, i * 2 + 3) + for i in range(1, -1, -1): + circuit.cx(i * 2 + 3, i * 2 + 2) + circuit.ccx(i * 2, i * 2 + 1, i * 2 + 3) + circuit.cx(1, 0) + circuit.ccx(6, 1, 0) + circuit.ccx(0, 1, 3) + circuit.ccx(6, 3, 2) + circuit.ccx(2, 3, 5) + circuit.ccx(6, 5, 4) + circuit.append(XGate().control(3), [4, 5, 6, 7], []) + for i in range(1, -1, -1): + circuit.ccx(i * 2, i * 2 + 1, i * 2 + 3) + circuit.cx(3, 5) + for i in range(1, 3): + circuit.cx(i * 2 + 1, i * 2) + circuit.ccx(5, 6, 7) - (expected) - + """ ┌───┐┌───┐ » q_0: ┤ H ├┤ X ├───────■─────────────────────────────■───────────────────■──» ├───┤└─┬─┘ │ │ │ » @@ -501,45 +523,6 @@ def test_targetsuccessive_identity_advanced_removal(self): «q_7: ───── « """ - circuit = QuantumCircuit(8) - circuit.h(0) - circuit.h(1) - circuit.h(2) - circuit.h(3) - circuit.h(4) - circuit.h(5) - for i in range(3): - circuit.cx(i * 2 + 1, i * 2) - circuit.cx(3, 5) - for i in range(2): - circuit.ccx(i * 2, i * 2 + 1, i * 2 + 3) - circuit.cx(i * 2 + 3, i * 2 + 2) - circuit.ccx(4, 5, 6) - for i in range(1, -1, -1): - circuit.ccx(i * 2, i * 2 + 1, i * 2 + 3) - circuit.cx(3, 5) - circuit.cx(5, 6) - circuit.cx(3, 5) - circuit.x(6) - for i in range(2): - circuit.ccx(i * 2, i * 2 + 1, i * 2 + 3) - for i in range(1, -1, -1): - circuit.cx(i * 2 + 3, i * 2 + 2) - circuit.ccx(i * 2, i * 2 + 1, i * 2 + 3) - circuit.cx(1, 0) - circuit.ccx(6, 1, 0) - circuit.ccx(0, 1, 3) - circuit.ccx(6, 3, 2) - circuit.ccx(2, 3, 5) - circuit.ccx(6, 5, 4) - circuit.append(XGate().control(3), [4, 5, 6, 7], []) - for i in range(1, -1, -1): - circuit.ccx(i * 2, i * 2 + 1, i * 2 + 3) - circuit.cx(3, 5) - for i in range(1, 3): - circuit.cx(i * 2 + 1, i * 2) - circuit.ccx(5, 6, 7) - expected = QuantumCircuit(8) expected.h(0) expected.h(1) @@ -588,26 +571,23 @@ def test_targetsuccessive_identity_advanced_removal(self): def test_control_removal(self): """Should replace CX by X. - (circuit) - ┌───┐ q_0: ┤ X ├──■── └───┘┌─┴─┐ q_1: ─────┤ X ├ └───┘ + """ + circuit = QuantumCircuit(2) + circuit.x(0) + circuit.cx(0, 1) - (expected) - + """ ┌───┐ q_0: ┤ X ├ ├───┤ q_1: ┤ X ├ └───┘ """ - circuit = QuantumCircuit(2) - circuit.x(0) - circuit.cx(0, 1) - expected = QuantumCircuit(2) expected.x(0) expected.x(1) @@ -623,29 +603,25 @@ def test_control_removal(self): """ Should replace CZ by Z - (circuit) - ┌───┐ ┌───┐ q_0: ┤ H ├─■─┤ H ├ ├───┤ │ └───┘ q_1: ┤ X ├─■────── └───┘ - - (expected) - - ┌───┐┌───┐┌───┐ - q_0: ┤ H ├┤ Z ├┤ H ├ - ├───┤└───┘└───┘ - q_1: ┤ X ├────────── - └───┘ """ - circuit = QuantumCircuit(2) circuit.h(0) circuit.x(1) circuit.cz(0, 1) circuit.h(0) + """ + ┌───┐┌───┐┌───┐ + q_0: ┤ H ├┤ Z ├┤ H ├ + ├───┤└───┘└───┘ + q_1: ┤ X ├────────── + └───┘ + """ expected = QuantumCircuit(2) expected.h(0) expected.x(1) @@ -680,21 +656,11 @@ def test_multiple_pass(self): """Verify that multiple pass can be run with the same Hoare instance. - (circuit2) - ┌───┐┌───┐ q_0:─┤ H ├┤ Z ├─ ├───┤└───┘ q_1: ┤ Z ├────── └───┘ - - (expected) - - ┌───┐┌───┐ - q_0:─┤ H ├┤ Z ├─ - └───┘└───┘ - q_1: ─────────── - """ circuit1 = QuantumCircuit(2) circuit1.z(0) @@ -706,6 +672,13 @@ def test_multiple_pass(self): circuit2.h(0) circuit2.z(0) + """ + ┌───┐┌───┐ + q_0:─┤ H ├┤ Z ├─ + └───┘└───┘ + q_1: ─────────── + + """ expected = QuantumCircuit(2) expected.h(0) expected.z(0) diff --git a/test/python/transpiler/test_lookahead_swap.py b/test/python/transpiler/test_lookahead_swap.py index 932fa28b37b7..65b8fb8aefe7 100644 --- a/test/python/transpiler/test_lookahead_swap.py +++ b/test/python/transpiler/test_lookahead_swap.py @@ -157,6 +157,39 @@ def test_lookahead_swap_higher_depth_width_is_better(self): Increasing the tree width and depth is expected to yield a better (or same) quality circuit, in the form of fewer SWAPs. + + q_0: ──■───────────────────■───────────────────────────────────────────────» + ┌─┴─┐ │ ┌───┐ » + q_1: ┤ X ├──■──────────────┼─────────────────┤ X ├─────────────────────────» + └───┘┌─┴─┐ │ └─┬─┘┌───┐ ┌───┐ » + q_2: ─────┤ X ├──■─────────┼───────────────────┼──┤ X ├──────────┤ X ├──■──» + └───┘┌─┴─┐ ┌─┴─┐ │ └─┬─┘ ┌───┐└─┬─┘ │ » + q_3: ──────────┤ X ├──■──┤ X ├─────────────────┼────┼────■──┤ X ├──┼────┼──» + └───┘┌─┴─┐└───┘ ┌───┐ │ │ │ └─┬─┘ │ │ » + q_4: ───────────────┤ X ├──■────────────┤ X ├──┼────■────┼────┼────┼────┼──» + └───┘┌─┴─┐ └─┬─┘ │ │ │ │ │ » + q_5: ────────────────────┤ X ├──■─────────┼────┼─────────┼────■────┼────┼──» + └───┘┌─┴─┐ │ │ │ │ │ » + q_6: ─────────────────────────┤ X ├──■────■────┼─────────┼─────────■────┼──» + └───┘┌─┴─┐ │ ┌─┴─┐ ┌─┴─┐» + q_7: ──────────────────────────────┤ X ├───────■───────┤ X ├──────────┤ X ├» + └───┘ └───┘ └───┘» + «q_0: ──■─────── + « │ + «q_1: ──┼─────── + « │ + «q_2: ──┼─────── + « │ + «q_3: ──┼─────── + « │ + «q_4: ──┼─────── + « │ + «q_5: ──┼────■── + « ┌─┴─┐ │ + «q_6: ┤ X ├──┼── + « └───┘┌─┴─┐ + «q_7: ─────┤ X ├ + « └───┘ """ qr = QuantumRegister(8, name="q") diff --git a/test/python/transpiler/test_optimize_1q_commutation.py b/test/python/transpiler/test_optimize_1q_commutation.py index 59f6131eeba4..ef879f4320e5 100644 --- a/test/python/transpiler/test_optimize_1q_commutation.py +++ b/test/python/transpiler/test_optimize_1q_commutation.py @@ -34,6 +34,11 @@ class TestOptimize1qSimpleCommutation(QiskitTestCase): def test_successor_commutation(self): """ Check that Optimize1qGatesSimpleCommutation correctly moves 1Q gates later. + + q_0: ────────■───────────────────────── + ┌────┐┌─┴─┐┌───────┐┌────┐┌──────┐ + q_1: ┤ √X ├┤ X ├┤ P(-π) ├┤ √X ├┤ P(π) ├ + └────┘└───┘└───────┘└────┘└──────┘ """ qc = QuantumCircuit(2) qc.sx(1) @@ -53,6 +58,11 @@ def test_successor_commutation(self): def test_predecessor_commutation(self): """ Check that Optimize1qGatesSimpleCommutation correctly moves 1Q gates earlier. + + q_0: ─────────────────────────■──────── + ┌───────┐┌────┐┌──────┐┌─┴─┐┌────┐ + q_1: ┤ P(-π) ├┤ √X ├┤ P(π) ├┤ X ├┤ √X ├ + └───────┘└────┘└──────┘└───┘└────┘ """ qc = QuantumCircuit(2) qc.p(-np.pi, 1) @@ -72,6 +82,12 @@ def test_predecessor_commutation(self): def test_elaborate_commutation(self): """ Check that Optimize1qGatesSimpleCommutation can perform several steps without fumbling. + + ┌────────┐┌────┐┌────────┐ ┌────────┐┌────┐┌────────┐ + q_0: ┤ P(π/8) ├┤ √X ├┤ P(π/7) ├──■──┤ P(π/7) ├┤ √X ├┤ P(π/8) ├ + ├────────┤├────┤└────────┘┌─┴─┐├───────┬┘├────┤├───────┬┘ + q_1: ┤ P(π/4) ├┤ √X ├──────────┤ X ├┤ P(-π) ├─┤ √X ├┤ P(-π) ├─ + └────────┘└────┘ └───┘└───────┘ └────┘└───────┘ """ qc = QuantumCircuit(2) @@ -95,6 +111,14 @@ def test_elaborate_commutation(self): optimize_pass = Optimize1qGatesSimpleCommutation(basis=["sx", "p"], run_to_completion=True) result = optimize_pass(qc) + """ + global phase: π/2 + ┌────────┐┌────┐ ┌─────────┐┌────┐┌────────┐ + q_0: ┤ P(π/8) ├┤ √X ├──■──┤ P(2π/7) ├┤ √X ├┤ P(π/8) ├ + ├────────┤└────┘┌─┴─┐└─────────┘└────┘└────────┘ + q_1: ┤ P(π/4) ├──────┤ X ├─────────────────────────── + └────────┘ └───┘ + """ expected = QuantumCircuit(2, global_phase=np.pi / 2) expected.p(np.pi / 8, 0) expected.sx(0) @@ -114,6 +138,22 @@ def test_midcircuit_double_commutation(self): """ Check that Optimize1qGatesSimpleCommutation can push gates forward and backward out of a run in the middle of a circuit. + + ┌──────────┐┌────┐┌───────────┐┌────┐┌───────────┐┌───┐┌────┐┌──────────┐» + q_0: ─┤ Rz(2.15) ├┤ √X ├┤ Rz(-2.75) ├┤ √X ├┤ Rz(0.255) ├┤ X ├┤ √X ├┤ Rz(1.03) ├» + ┌┴──────────┤├────┤├───────────┤├────┤└┬──────────┤└─┬─┘├────┤├──────────┤» + q_1: ┤ Rz(0.138) ├┤ √X ├┤ Rz(-2.87) ├┤ √X ├─┤ Rz(-2.1) ├──■──┤ √X ├┤ Rz(1.45) ├» + └───────────┘└────┘└───────────┘└────┘ └──────────┘ └────┘└──────────┘» + « ┌────┐ ┌───┐ ┌──────────┐ ┌────┐┌───────────┐┌────┐» + «q_0: ┤ √X ├────────────┤ X ├─┤ Rz(2.01) ├─┤ √X ├┤ Rz(-1.62) ├┤ √X ├» + « ├────┤┌──────────┐└─┬─┘┌┴──────────┴┐├────┤├───────────┤├────┤» + «q_1: ┤ √X ├┤ Rz(1.33) ├──■──┤ Rz(-0.732) ├┤ √X ├┤ Rz(-2.65) ├┤ √X ├» + « └────┘└──────────┘ └────────────┘└────┘└───────────┘└────┘» + « ┌───────────┐ + «q_0: ┤ Rz(-1.16) ├ + « └┬──────────┤ + «q_1: ─┤ Rz(2.17) ├ + « └──────────┘ """ qc = QuantumCircuit(2) diff --git a/test/python/transpiler/test_optimize_1q_gates.py b/test/python/transpiler/test_optimize_1q_gates.py index 6690d4c9d73d..1fd37cc4abba 100644 --- a/test/python/transpiler/test_optimize_1q_gates.py +++ b/test/python/transpiler/test_optimize_1q_gates.py @@ -67,6 +67,21 @@ def test_optimize_1q_gates_collapse_identity_equivalent(self): """test optimize_1q_gates removes u1(2*pi) rotations. See: https://github.com/Qiskit/qiskit-terra/issues/159 + + ┌───┐┌───┐┌────────┐┌───┐┌─────────┐┌───────┐┌─────────┐┌───┐ ┌─┐» + qr_0: ┤ H ├┤ X ├┤ U1(2π) ├┤ X ├┤ U1(π/2) ├┤ U1(π) ├┤ U1(π/2) ├┤ X ├─────────┤M├» + └───┘└─┬─┘└────────┘└─┬─┘└─────────┘└───────┘└─────────┘└─┬─┘┌───────┐└╥┘» + qr_1: ───────■──────────────■───────────────────────────────────■──┤ U1(π) ├─╫─» + └───────┘ ║ » + cr: 2/═══════════════════════════════════════════════════════════════════════╩═» + 0 » + « + «qr_0: ──────────── + « ┌───────┐┌─┐ + «qr_1: ┤ U1(π) ├┤M├ + « └───────┘└╥┘ + «cr: 2/══════════╩═ + « 1 """ qr = QuantumRegister(2, "qr") cr = ClassicalRegister(2, "cr") @@ -94,6 +109,21 @@ def test_optimize_1q_gates_collapse_identity_equivalent_phase_gate(self): """test optimize_1q_gates removes u1(2*pi) rotations. See: https://github.com/Qiskit/qiskit-terra/issues/159 + + ┌───┐┌───┐┌───────┐┌───┐┌────────┐┌──────┐┌────────┐┌───┐ ┌─┐» + qr_0: ┤ H ├┤ X ├┤ P(2π) ├┤ X ├┤ P(π/2) ├┤ P(π) ├┤ P(π/2) ├┤ X ├────────┤M├» + └───┘└─┬─┘└───────┘└─┬─┘└────────┘└──────┘└────────┘└─┬─┘┌──────┐└╥┘» + qr_1: ───────■─────────────■────────────────────────────────■──┤ P(π) ├─╫─» + └──────┘ ║ » + cr: 2/══════════════════════════════════════════════════════════════════╩═» + 0 » + « + «qr_0: ─────────── + « ┌──────┐┌─┐ + «qr_1: ┤ P(π) ├┤M├ + « └──────┘└╥┘ + «cr: 2/═════════╩═ + « 1 """ qr = QuantumRegister(2, "qr") cr = ClassicalRegister(2, "cr") diff --git a/test/python/transpiler/test_remove_final_measurements.py b/test/python/transpiler/test_remove_final_measurements.py index d6caa01c1b6c..00ac271dc222 100644 --- a/test/python/transpiler/test_remove_final_measurements.py +++ b/test/python/transpiler/test_remove_final_measurements.py @@ -292,6 +292,26 @@ def expected_dag(): qc.h(q0[0]) return circuit_to_dag(qc) + """ + ┌───┐┌─┐ ░ ░ ┌─┐ + q0_0: ┤ H ├┤M├─░─────░─┤M├─────────────── + └┬─┬┘└╥┘ ░ ░ └╥┘┌─┐ + q0_1: ─┤M├──╫──░─────░──╫─┤M├──────────── + └╥┘ ║ ░ ░ ░ ║ └╥┘┌─┐ + q0_2: ──╫───╫──░──░──░──╫──╫─┤M├───────── + ║ ║ ░ ░ ░ ║ ║ └╥┘┌─┐ + q0_3: ──╫───╫──░──░──░──╫──╫──╫─┤M├────── + ║ ║ ░ ░ ░ ║ ║ ║ └╥┘┌─┐ ░ + q0_4: ──╫───╫──░─────░──╫──╫──╫──╫─┤M├─░─ + ║ ║ ░ ░ ║ ║ ║ ║ └╥┘ ░ + c0: 1/══╩═══╩═══════════╬══╬══╬══╬══╬════ + 0 0 ║ ║ ║ ║ ║ + ║ ║ ║ ║ ║ + c1: 1/══════════════════╬══╬══╬══╬══╬════ + ║ ║ ║ ║ ║ + meas: 5/════════════════╩══╩══╩══╩══╩════ + 0 1 2 3 4 + """ q0 = QuantumRegister(5, "q0") c0 = ClassicalRegister(1, "c0") c1 = ClassicalRegister(1, "c1") diff --git a/test/python/transpiler/test_sabre_layout.py b/test/python/transpiler/test_sabre_layout.py index d7aee7699c60..f45dea5e9bac 100644 --- a/test/python/transpiler/test_sabre_layout.py +++ b/test/python/transpiler/test_sabre_layout.py @@ -30,7 +30,20 @@ def setUp(self): self.cmap20 = FakeAlmaden().configuration().coupling_map def test_5q_circuit_20q_coupling(self): - """Test finds layout for 5q circuit on 20q device.""" + """Test finds layout for 5q circuit on 20q device. + + ┌───┐ + q_0: ──■───────┤ X ├─────────────── + │ └─┬─┘┌───┐ + q_1: ──┼────■────┼──┤ X ├───────■── + ┌─┴─┐ │ │ ├───┤┌───┐┌─┴─┐ + q_2: ┤ X ├──┼────┼──┤ X ├┤ X ├┤ X ├ + └───┘┌─┴─┐ │ └───┘└─┬─┘└───┘ + q_3: ─────┤ X ├──■─────────┼─────── + └───┘ │ + q_4: ──────────────────────■─────── + + """ qr = QuantumRegister(5, "q") circuit = QuantumCircuit(qr) circuit.cx(qr[0], qr[2]) @@ -53,7 +66,22 @@ def test_5q_circuit_20q_coupling(self): self.assertEqual(layout[qr[4]], 13) def test_6q_circuit_20q_coupling(self): - """Test finds layout for 6q circuit on 20q device.""" + """Test finds layout for 6q circuit on 20q device. + + ┌───┐┌───┐┌───┐┌───┐┌───┐ + q0_0: ┤ X ├┤ X ├┤ X ├┤ X ├┤ X ├ + └─┬─┘└─┬─┘└─┬─┘└─┬─┘└─┬─┘ + q0_1: ──┼────■────┼────┼────┼── + │ ┌───┐ │ │ │ + q0_2: ──┼──┤ X ├──┼────■────┼── + │ └───┘ │ │ + q1_0: ──■─────────┼─────────┼── + ┌───┐ │ │ + q1_1: ─────┤ X ├──┼─────────■── + └───┘ │ + q1_2: ────────────■──────────── + + """ qr0 = QuantumRegister(3, "q0") qr1 = QuantumRegister(3, "q1") circuit = QuantumCircuit(qr0, qr1) diff --git a/test/python/transpiler/test_stochastic_swap.py b/test/python/transpiler/test_stochastic_swap.py index 69ab283002ad..e98a893dd9fe 100644 --- a/test/python/transpiler/test_stochastic_swap.py +++ b/test/python/transpiler/test_stochastic_swap.py @@ -534,6 +534,20 @@ def test_single_gates_omitted(self): """Test if single qubit gates are omitted.""" coupling_map = [[0, 1], [1, 0], [1, 2], [1, 3], [2, 1], [3, 1], [3, 4], [4, 3]] + + """ + q_0: ──■────────────────── + │ + q_1: ──┼─────────■──────── + │ ┌─┴─┐ + q_2: ──┼───────┤ X ├────── + │ ┌────┴───┴─────┐ + q_3: ──┼──┤ U(1,1.5,0.7) ├ + ┌─┴─┐└──────────────┘ + q_4: ┤ X ├──────────────── + └───┘ + c: 5/═════════════════════ + """ qr = QuantumRegister(5, "q") cr = ClassicalRegister(5, "c") circuit = QuantumCircuit(qr, cr) @@ -541,6 +555,17 @@ def test_single_gates_omitted(self): circuit.cx(qr[1], qr[2]) circuit.u(1, 1.5, 0.7, qr[3]) + """ + q_0: ─────────────────X────── + │ + q_1: ───────■─────────X───■── + ┌─┴─┐ │ + q_2: ─────┤ X ├───────────┼── + ┌────┴───┴─────┐ ┌─┴─┐ + q_3: ┤ U(1,1.5,0.7) ├─X─┤ X ├ + └──────────────┘ │ └───┘ + q_4: ─────────────────X────── + """ expected = QuantumCircuit(qr, cr) expected.cx(qr[1], qr[2]) expected.u(1, 1.5, 0.7, qr[3]) diff --git a/test/python/transpiler/test_unroller.py b/test/python/transpiler/test_unroller.py index d9f51bb4104e..306baac730df 100644 --- a/test/python/transpiler/test_unroller.py +++ b/test/python/transpiler/test_unroller.py @@ -317,7 +317,13 @@ def compare_dags(self): self.assertEqual(unrolled_dag, ref_dag) def test_unroll_crx(self): - """test unroll crx""" + """test unroll crx + + qr_1: ─────■───── qr_1: ─────────────────■─────────────────────■───────────────────── + ┌────┴────┐ = ┌─────────────┐┌─┴─┐┌───────────────┐┌─┴─┐┌─────────────────┐ + qr_2: ┤ Rx(0.5) ├ qr_2: ┤ U3(0,0,π/2) ├┤ X ├┤ U3(-0.25,0,0) ├┤ X ├┤ U3(0.25,-π/2,0) ├ + └─────────┘ └─────────────┘└───┘└───────────────┘└───┘└─────────────────┘ + """ self.circuit.crx(0.5, 1, 2) self.ref_circuit.append(U3Gate(0, 0, pi / 2), [2]) self.ref_circuit.cx(1, 2) @@ -327,7 +333,13 @@ def test_unroll_crx(self): self.compare_dags() def test_unroll_cry(self): - """test unroll cry""" + """test unroll cry + + qr_1: ─────■───── qr_1: ──────────────────■─────────────────────■── + ┌────┴────┐ = ┌──────────────┐┌─┴─┐┌───────────────┐┌─┴─┐ + qr_2: ┤ Ry(0.5) ├ qr_2: ┤ U3(0.25,0,0) ├┤ X ├┤ U3(-0.25,0,0) ├┤ X ├ + └─────────┘ └──────────────┘└───┘└───────────────┘└───┘ + """ self.circuit.cry(0.5, 1, 2) self.ref_circuit.append(U3Gate(0.25, 0, 0), [2]) self.ref_circuit.cx(1, 2) @@ -336,7 +348,22 @@ def test_unroll_cry(self): self.compare_dags() def test_unroll_ccx(self): - """test unroll ccx""" + """test unroll ccx + + qr_0: ──■── qr_0: ──────────────────────────────────────■──────────────────────» + │ │ » + qr_1: ──■── = qr_1: ─────────────────■────────────────────┼───────────────────■──» + ┌─┴─┐ ┌─────────────┐┌─┴─┐┌──────────────┐┌─┴─┐┌─────────────┐┌─┴─┐» + qr_2: ┤ X ├ qr_2: ┤ U3(π/2,0,π) ├┤ X ├┤ U3(0,0,-π/4) ├┤ X ├┤ U3(0,0,π/4) ├┤ X ├» + └───┘ └─────────────┘└───┘└──────────────┘└───┘└─────────────┘└───┘» + « ┌─────────────┐ + «qr_0: ──────────────────■─────────■───────┤ U3(0,0,π/4) ├───■── + « ┌─────────────┐ │ ┌─┴─┐ ├─────────────┴┐┌─┴─┐ + «qr_1: ┤ U3(0,0,π/4) ├───┼───────┤ X ├─────┤ U3(0,0,-π/4) ├┤ X ├ + « ├─────────────┴┐┌─┴─┐┌────┴───┴────┐├─────────────┬┘└───┘ + «qr_2: ┤ U3(0,0,-π/4) ├┤ X ├┤ U3(0,0,π/4) ├┤ U3(π/2,0,π) ├────── + « └──────────────┘└───┘└─────────────┘└─────────────┘ + """ self.circuit.ccx(0, 1, 2) self.ref_circuit.append(U3Gate(pi / 2, 0, pi), [2]) self.ref_circuit.cx(1, 2) @@ -356,7 +383,18 @@ def test_unroll_ccx(self): self.compare_dags() def test_unroll_ch(self): - """test unroll ch""" + """test unroll ch + + qr_0: ──■── qr_0: ───────────────────────────────────────────────■──────────────────» + ┌─┴─┐ = ┌─────────────┐┌─────────────┐┌─────────────┐┌─┴─┐┌──────────────┐» + qr_2: ┤ H ├ qr_2: ┤ U3(0,0,π/2) ├┤ U3(π/2,0,π) ├┤ U3(0,0,π/4) ├┤ X ├┤ U3(0,0,-π/4) ├» + └───┘ └─────────────┘└─────────────┘└─────────────┘└───┘└──────────────┘» + « + «qr_0: ─────────────────────────────── + « ┌─────────────┐┌──────────────┐ + «qr_2: ┤ U3(π/2,0,π) ├┤ U3(0,0,-π/2) ├ + « └─────────────┘└──────────────┘ + """ self.circuit.ch(0, 2) self.ref_circuit.append(U3Gate(0, 0, pi / 2), [2]) self.ref_circuit.append(U3Gate(pi / 2, 0, pi), [2]) @@ -368,7 +406,13 @@ def test_unroll_ch(self): self.compare_dags() def test_unroll_crz(self): - """test unroll crz""" + """test unroll crz + + qr_1: ─────■───── qr_1: ──────────────────■─────────────────────■── + ┌────┴────┐ = ┌──────────────┐┌─┴─┐┌───────────────┐┌─┴─┐ + qr_2: ┤ Rz(0.5) ├ qr_2: ┤ U3(0,0,0.25) ├┤ X ├┤ U3(0,0,-0.25) ├┤ X ├ + └─────────┘ └──────────────┘└───┘└───────────────┘└───┘ + """ self.circuit.crz(0.5, 1, 2) self.ref_circuit.append(U3Gate(0, 0, 0.25), [2]) self.ref_circuit.cx(1, 2) @@ -376,7 +420,23 @@ def test_unroll_crz(self): self.ref_circuit.cx(1, 2) def test_unroll_cswap(self): - """test unroll cswap""" + """test unroll cswap + + ┌───┐ » + qr_0: ─X─ qr_0: ┤ X ├─────────────────■────────────────────────────────────────■──» + │ └─┬─┘ │ │ » + qr_1: ─■─ = qr_1: ──┼───────────────────┼────────────────────■───────────────────┼──» + │ │ ┌─────────────┐┌─┴─┐┌──────────────┐┌─┴─┐┌─────────────┐┌─┴─┐» + qr_2: ─X─ qr_2: ──■──┤ U3(π/2,0,π) ├┤ X ├┤ U3(0,0,-π/4) ├┤ X ├┤ U3(0,0,π/4) ├┤ X ├» + └─────────────┘└───┘└──────────────┘└───┘└─────────────┘└───┘» + « ┌─────────────┐ ┌───┐ ┌──────────────┐┌───┐┌───┐ + «qr_0: ┤ U3(0,0,π/4) ├───────────┤ X ├─────┤ U3(0,0,-π/4) ├┤ X ├┤ X ├ + « └─────────────┘ └─┬─┘ ├─────────────┬┘└─┬─┘└─┬─┘ + «qr_1: ──────────────────■─────────■───────┤ U3(0,0,π/4) ├───■────┼── + « ┌──────────────┐┌─┴─┐┌─────────────┐├─────────────┤ │ + «qr_2: ┤ U3(0,0,-π/4) ├┤ X ├┤ U3(0,0,π/4) ├┤ U3(π/2,0,π) ├────────■── + « └──────────────┘└───┘└─────────────┘└─────────────┘ + """ self.circuit.cswap(1, 0, 2) self.ref_circuit.cx(2, 0) self.ref_circuit.append(U3Gate(pi / 2, 0, pi), [2]) @@ -398,7 +458,14 @@ def test_unroll_cswap(self): self.compare_dags() def test_unroll_cu1(self): - """test unroll cu1""" + """test unroll cu1 + + ┌──────────────┐ + qr_0: ─■──────── qr_0: ┤ U3(0,0,0.05) ├──■─────────────────────■────────────────── + │U1(0.1) = └──────────────┘┌─┴─┐┌───────────────┐┌─┴─┐┌──────────────┐ + qr_2: ─■──────── qr_2: ────────────────┤ X ├┤ U3(0,0,-0.05) ├┤ X ├┤ U3(0,0,0.05) ├ + └───┘└───────────────┘└───┘└──────────────┘ + """ self.circuit.append(CU1Gate(0.1), [0, 2]) self.ref_circuit.append(U3Gate(0, 0, 0.05), [0]) self.ref_circuit.cx(0, 2) @@ -408,7 +475,14 @@ def test_unroll_cu1(self): self.compare_dags() def test_unroll_cu3(self): - """test unroll cu3""" + """test unroll cu3 + + ┌──────────────┐ + qr_1: ────────■──────── qr_1: ─┤ U3(0,0,0.05) ├──■────────────────────────■─────────────────── + ┌───────┴───────┐ = ┌┴──────────────┤┌─┴─┐┌──────────────────┐┌─┴─┐┌───────────────┐ + qr_2: ┤ U3(0.2,0.1,0) ├ qr_2: ┤ U3(0,0,-0.05) ├┤ X ├┤ U3(-0.1,0,-0.05) ├┤ X ├┤ U3(0.1,0.1,0) ├ + └───────────────┘ └───────────────┘└───┘└──────────────────┘└───┘└───────────────┘ + """ self.circuit.append(CU3Gate(0.2, 0.1, 0.0), [1, 2]) self.ref_circuit.append(U3Gate(0, 0, 0.05), [1]) self.ref_circuit.append(U3Gate(0, 0, -0.05), [2]) @@ -425,7 +499,13 @@ def test_unroll_cx(self): self.compare_dags() def test_unroll_cy(self): - """test unroll cy""" + """test unroll cy + + qr_1: ──■── qr_1: ──────────────────■───────────────── + ┌─┴─┐ = ┌──────────────┐┌─┴─┐┌─────────────┐ + qr_2: ┤ Y ├ qr_2: ┤ U3(0,0,-π/2) ├┤ X ├┤ U3(0,0,π/2) ├ + └───┘ └──────────────┘└───┘└─────────────┘ + """ self.circuit.cy(1, 2) self.ref_circuit.append(U3Gate(0, 0, -pi / 2), [2]) self.ref_circuit.cx(1, 2) @@ -433,7 +513,14 @@ def test_unroll_cy(self): self.compare_dags() def test_unroll_cz(self): - """test unroll cz""" + """test unroll cz + + ┌─────────────┐┌───┐┌─────────────┐ + qr_0: ─■─ qr_0: ┤ U3(π/2,0,π) ├┤ X ├┤ U3(π/2,0,π) ├ + │ = └─────────────┘└─┬─┘└─────────────┘ + qr_2: ─■─ qr_2: ─────────────────■───────────────── + + """ self.circuit.cz(2, 0) self.ref_circuit.append(U3Gate(pi / 2, 0, pi), [0]) self.ref_circuit.cx(2, 0) @@ -472,7 +559,15 @@ def test_unroll_rz(self): self.compare_dags() def test_unroll_rzz(self): - """test unroll rzz""" + """test unroll rzz + + global phase: 5.9832 + ┌───┐┌─────────────┐┌───┐ + qr_0: ─■──────── qr_0: ┤ X ├┤ U3(0,0,0.6) ├┤ X ├ + │ZZ(0.6) = └─┬─┘└─────────────┘└─┬─┘ + qr_1: ─■──────── qr_1: ──■───────────────────■── + + """ self.circuit.rzz(0.6, 1, 0) self.ref_circuit.global_phase = -1 * 0.6 / 2 self.ref_circuit.cx(1, 0) @@ -493,7 +588,14 @@ def test_unroll_sdg(self): self.compare_dags() def test_unroll_swap(self): - """test unroll swap""" + """test unroll swap + + ┌───┐ + qr_1: ─X─ qr_1: ──■──┤ X ├──■── + │ = ┌─┴─┐└─┬─┘┌─┴─┐ + qr_2: ─X─ qr_2: ┤ X ├──■──┤ X ├ + └───┘ └───┘ + """ self.circuit.swap(1, 2) self.ref_circuit.cx(1, 2) self.ref_circuit.cx(2, 1) From 1843a2d067e04034ec00cff4c7835b9afbc086bd Mon Sep 17 00:00:00 2001 From: Jintaoyu Date: Fri, 3 Dec 2021 16:03:30 +0800 Subject: [PATCH 11/18] Format source code with black --- .../standard_gates/equivalence_library.py | 17 +++-------------- .../optimization/echo_rzx_weyl_decomposition.py | 2 +- .../passes/utils/merge_adjacent_barriers.py | 2 +- 3 files changed, 5 insertions(+), 16 deletions(-) diff --git a/qiskit/circuit/library/standard_gates/equivalence_library.py b/qiskit/circuit/library/standard_gates/equivalence_library.py index b04398af24b1..6ab21f2a9771 100644 --- a/qiskit/circuit/library/standard_gates/equivalence_library.py +++ b/qiskit/circuit/library/standard_gates/equivalence_library.py @@ -598,11 +598,7 @@ """ q = QuantumRegister(1, "q") def_sx = QuantumCircuit(q, global_phase=pi / 4) -for inst, qargs, cargs in [ - (SdgGate(), [q[0]], []), - (HGate(), [q[0]], []), - (SdgGate(), [q[0]], []) -]: +for inst, qargs, cargs in [(SdgGate(), [q[0]], []), (HGate(), [q[0]], []), (SdgGate(), [q[0]], [])]: def_sx.append(inst, qargs, cargs) _sel.add_equivalence(SXGate(), def_sx) @@ -627,11 +623,7 @@ """ q = QuantumRegister(1, "q") def_sxdg = QuantumCircuit(q, global_phase=-pi / 4) -for inst, qargs, cargs in [ - (SGate(), [q[0]], []), - (HGate(), [q[0]], []), - (SGate(), [q[0]], []) -]: +for inst, qargs, cargs in [(SGate(), [q[0]], []), (HGate(), [q[0]], []), (SGate(), [q[0]], [])]: def_sxdg.append(inst, qargs, cargs) _sel.add_equivalence(SXdgGate(), def_sxdg) @@ -698,10 +690,7 @@ """ q = QuantumRegister(2, "q") def_dcx = QuantumCircuit(q) -for inst, qargs, cargs in [ - (CXGate(), [q[0], q[1]], []), - (CXGate(), [q[1], q[0]], []) -]: +for inst, qargs, cargs in [(CXGate(), [q[0], q[1]], []), (CXGate(), [q[1], q[0]], [])]: def_dcx.append(inst, qargs, cargs) _sel.add_equivalence(DCXGate(), def_dcx) diff --git a/qiskit/transpiler/passes/optimization/echo_rzx_weyl_decomposition.py b/qiskit/transpiler/passes/optimization/echo_rzx_weyl_decomposition.py index 302674140b6f..15e087a526a5 100644 --- a/qiskit/transpiler/passes/optimization/echo_rzx_weyl_decomposition.py +++ b/qiskit/transpiler/passes/optimization/echo_rzx_weyl_decomposition.py @@ -69,7 +69,7 @@ def _echo_rzx_dag(theta): @staticmethod def _reverse_echo_rzx_dag(theta): """Return the following circuit:: - + ┌───┐┌───────────────┐ ┌────────────────┐┌───┐ q_0: ┤ H ├┤1 ├─────┤1 ├┤ H ├───── ├───┤│ Rzx(theta/2) │┌───┐│ Rzx(-theta/2) │├───┤┌───┐ diff --git a/qiskit/transpiler/passes/utils/merge_adjacent_barriers.py b/qiskit/transpiler/passes/utils/merge_adjacent_barriers.py index d939271f1125..03c9b87c3dff 100644 --- a/qiskit/transpiler/passes/utils/merge_adjacent_barriers.py +++ b/qiskit/transpiler/passes/utils/merge_adjacent_barriers.py @@ -38,7 +38,7 @@ class MergeAdjacentBarriers(TransformationPass): circuit.barrier(qr[0]) circuit.barrier(qr) - i.e, + i.e, ░ ░ ░ ░ q_0: ─░──░─ q_0: ─░──░─ From 9f1678c07b5a2959d2c0728d302388a5583581d8 Mon Sep 17 00:00:00 2001 From: Jintaoyu Date: Fri, 3 Dec 2021 19:07:59 +0800 Subject: [PATCH 12/18] Chang block comment from string to line annotation --- .../standard_gates/equivalence_library.py | 967 ++++++++---------- .../algorithms/test_skip_qobj_validation.py | 18 +- test/python/basicaer/test_qasm_simulator.py | 44 +- .../circuit/library/test_evolution_gate.py | 12 +- test/python/circuit/library/test_iqp.py | 18 +- test/python/circuit/library/test_nlocal.py | 162 ++- .../circuit/library/test_pauli_feature_map.py | 78 +- .../circuit/library/test_phase_estimation.py | 32 +- .../circuit/library/test_random_pauli.py | 24 +- test/python/circuit/test_controlled_gate.py | 16 +- test/python/circuit/test_tensor.py | 77 +- test/python/compiler/test_compiler.py | 68 +- .../quantum_info/operators/test_dihedral.py | 274 +++-- test/python/quantum_info/test_analyzation.py | 59 +- .../transpiler/test_basis_translator.py | 77 +- .../python/transpiler/test_cx_cancellation.py | 18 +- test/python/transpiler/test_gate_direction.py | 30 +- test/python/transpiler/test_hoare_opt.py | 583 +++++------ .../test_optimize_1q_commutation.py | 14 +- .../test_remove_final_measurements.py | 38 +- .../python/transpiler/test_stochastic_swap.py | 43 +- test/python/transpiler/test_unroller.py | 10 +- 22 files changed, 1187 insertions(+), 1475 deletions(-) diff --git a/qiskit/circuit/library/standard_gates/equivalence_library.py b/qiskit/circuit/library/standard_gates/equivalence_library.py index 6ab21f2a9771..636cfab8f1f0 100644 --- a/qiskit/circuit/library/standard_gates/equivalence_library.py +++ b/qiskit/circuit/library/standard_gates/equivalence_library.py @@ -71,26 +71,22 @@ # Import existing gate definitions -""" -HGate - - ┌───┐ ┌─────────┐ -q: ┤ H ├ ≡ q: ┤ U2(0,π) ├ - └───┘ └─────────┘ -""" +# HGate +# +# ┌───┐ ┌─────────┐ +# q: ┤ H ├ ≡ q: ┤ U2(0,π) ├ +# └───┘ └─────────┘ q = QuantumRegister(1, "q") def_h = QuantumCircuit(q) def_h.append(U2Gate(0, pi), [q[0]], []) _sel.add_equivalence(HGate(), def_h) -""" -CHGate - -q_0: ──■── q_0: ─────────────────■───────────────────── - ┌─┴─┐ ≡ ┌───┐┌───┐┌───┐┌─┴─┐┌─────┐┌───┐┌─────┐ -q_1: ┤ H ├ q_1: ┤ S ├┤ H ├┤ T ├┤ X ├┤ Tdg ├┤ H ├┤ Sdg ├ - └───┘ └───┘└───┘└───┘└───┘└─────┘└───┘└─────┘ -""" +# CHGate +# +# q_0: ──■── q_0: ─────────────────■───────────────────── +# ┌─┴─┐ ≡ ┌───┐┌───┐┌───┐┌─┴─┐┌─────┐┌───┐┌─────┐ +# q_1: ┤ H ├ q_1: ┤ S ├┤ H ├┤ T ├┤ X ├┤ Tdg ├┤ H ├┤ Sdg ├ +# └───┘ └───┘└───┘└───┘└───┘└─────┘└───┘└─────┘ q = QuantumRegister(2, "q") def_ch = QuantumCircuit(q) for inst, qargs, cargs in [ @@ -118,13 +114,11 @@ warnings.filterwarnings("ignore", category=DeprecationWarning) _sel.add_equivalence(MSGate(num_qubits, theta), def_ms) -""" -PhaseGate - - ┌──────┐ ┌───────┐ -q: ┤ P(ϴ) ├ ≡ q: ┤ U1(ϴ) ├ - └──────┘ └───────┘ -""" +# PhaseGate +# +# ┌──────┐ ┌───────┐ +# q: ┤ P(ϴ) ├ ≡ q: ┤ U1(ϴ) ├ +# └──────┘ └───────┘ q = QuantumRegister(1, "q") theta = Parameter("theta") phase_to_u1 = QuantumCircuit(q) @@ -137,14 +131,12 @@ phase_to_u.u(0, 0, theta, 0) _sel.add_equivalence(PhaseGate(theta), phase_to_u) -""" -CPhaseGate - ┌────────┐ -q_0: ─■──── q_0: ┤ P(ϴ/2) ├──■───────────────■──────────── - │P(ϴ) ≡ └────────┘┌─┴─┐┌─────────┐┌─┴─┐┌────────┐ -q_1: ─■──── q_1: ──────────┤ X ├┤ P(-ϴ/2) ├┤ X ├┤ P(ϴ/2) ├ - └───┘└─────────┘└───┘└────────┘ -""" +# CPhaseGate +# ┌────────┐ +# q_0: ─■──── q_0: ┤ P(ϴ/2) ├──■───────────────■──────────── +# │P(ϴ) ≡ └────────┘┌─┴─┐┌─────────┐┌─┴─┐┌────────┐ +# q_1: ─■──── q_1: ──────────┤ X ├┤ P(-ϴ/2) ├┤ X ├┤ P(ϴ/2) ├ +# └───┘└─────────┘└───┘└────────┘ q = QuantumRegister(2, "q") theta = Parameter("theta") def_cphase = QuantumCircuit(q) @@ -155,26 +147,22 @@ def_cphase.p(theta / 2, 1) _sel.add_equivalence(CPhaseGate(theta), def_cphase) -""" -CPhaseGate - -q_0: ─■──── q_0: ─■──── - │P(ϴ) ≡ │U1(ϴ) -q_1: ─■──── q_1: ─■──── -""" +# CPhaseGate +# +# q_0: ─■──── q_0: ─■──── +# │P(ϴ) ≡ │U1(ϴ) +# q_1: ─■──── q_1: ─■──── q = QuantumRegister(2, "q") theta = Parameter("theta") cphase_to_cu1 = QuantumCircuit(q) cphase_to_cu1.append(CU1Gate(theta), [0, 1]) _sel.add_equivalence(CPhaseGate(theta), cphase_to_cu1) -""" -RGate - - ┌────────┐ ┌───────────────────────┐ -q: ┤ R(ϴ,φ) ├ ≡ q: ┤ U3(ϴ,φ - π/2,π/2 - φ) ├ - └────────┘ └───────────────────────┘ -""" +# RGate +# +# ┌────────┐ ┌───────────────────────┐ +# q: ┤ R(ϴ,φ) ├ ≡ q: ┤ U3(ϴ,φ - π/2,π/2 - φ) ├ +# └────────┘ └───────────────────────┘ q = QuantumRegister(1, "q") theta = Parameter("theta") phi = Parameter("phi") @@ -182,17 +170,15 @@ def_r.append(U3Gate(theta, phi - pi / 2, -phi + pi / 2), [q[0]]) _sel.add_equivalence(RGate(theta, phi), def_r) -""" -RCCXGate - - ┌───────┐ -q_0: ┤0 ├ q_0: ────────────────────────■──────────────────────── - │ │ │ -q_1: ┤1 Rccx ├ ≡ q_1: ────────────■───────────┼─────────■────────────── - │ │ ┌───┐┌───┐┌─┴─┐┌─────┐┌─┴─┐┌───┐┌─┴─┐┌─────┐┌───┐ -q_2: ┤2 ├ q_2: ┤ H ├┤ T ├┤ X ├┤ Tdg ├┤ X ├┤ T ├┤ X ├┤ Tdg ├┤ H ├ - └───────┘ └───┘└───┘└───┘└─────┘└───┘└───┘└───┘└─────┘└───┘ -""" +# RCCXGate +# +# ┌───────┐ +# q_0: ┤0 ├ q_0: ────────────────────────■──────────────────────── +# │ │ │ +# q_1: ┤1 Rccx ├ ≡ q_1: ────────────■───────────┼─────────■────────────── +# │ │ ┌───┐┌───┐┌─┴─┐┌─────┐┌─┴─┐┌───┐┌─┴─┐┌─────┐┌───┐ +# q_2: ┤2 ├ q_2: ┤ H ├┤ T ├┤ X ├┤ Tdg ├┤ X ├┤ T ├┤ X ├┤ Tdg ├┤ H ├ +# └───────┘ └───┘└───┘└───┘└─────┘└───┘└───┘└───┘└─────┘└───┘ q = QuantumRegister(3, "q") def_rccx = QuantumCircuit(q) for inst, qargs, cargs in [ @@ -209,27 +195,23 @@ def_rccx.append(inst, qargs, cargs) _sel.add_equivalence(RCCXGate(), def_rccx) -""" -RXGate - - ┌───────┐ ┌────────┐ -q: ┤ Rx(ϴ) ├ ≡ q: ┤ R(ϴ,0) ├ - └───────┘ └────────┘ -""" +# RXGate +# +# ┌───────┐ ┌────────┐ +# q: ┤ Rx(ϴ) ├ ≡ q: ┤ R(ϴ,0) ├ +# └───────┘ └────────┘ q = QuantumRegister(1, "q") theta = Parameter("theta") def_rx = QuantumCircuit(q) def_rx.append(RGate(theta, 0), [q[0]], []) _sel.add_equivalence(RXGate(theta), def_rx) -""" -CRXGate - -q_0: ────■──── q_0: ─────────────■────────────────────■──────────────────── - ┌───┴───┐ ≡ ┌─────────┐┌─┴─┐┌──────────────┐┌─┴─┐┌────────────────┐ -q_1: ┤ Rx(ϴ) ├ q_1: ┤ U1(π/2) ├┤ X ├┤ U3(-ϴ/2,0,0) ├┤ X ├┤ U3(ϴ/2,-π/2,0) ├ - └───────┘ └─────────┘└───┘└──────────────┘└───┘└────────────────┘ -""" +# CRXGate +# +# q_0: ────■──── q_0: ─────────────■────────────────────■──────────────────── +# ┌───┴───┐ ≡ ┌─────────┐┌─┴─┐┌──────────────┐┌─┴─┐┌────────────────┐ +# q_1: ┤ Rx(ϴ) ├ q_1: ┤ U1(π/2) ├┤ X ├┤ U3(-ϴ/2,0,0) ├┤ X ├┤ U3(ϴ/2,-π/2,0) ├ +# └───────┘ └─────────┘└───┘└──────────────┘└───┘└────────────────┘ q = QuantumRegister(2, "q") theta = Parameter("theta") def_crx = QuantumCircuit(q) @@ -243,14 +225,12 @@ def_crx.append(inst, qargs, cargs) _sel.add_equivalence(CRXGate(theta), def_crx) -""" -CRXGate - -q_0: ────■──── q_0: ───────■────────────────■──────────────────── - ┌───┴───┐ ≡ ┌───┐┌─┴─┐┌──────────┐┌─┴─┐┌─────────┐┌─────┐ -q_1: ┤ Rx(ϴ) ├ q_1: ┤ S ├┤ X ├┤ Ry(-ϴ/2) ├┤ X ├┤ Ry(ϴ/2) ├┤ Sdg ├ - └───────┘ └───┘└───┘└──────────┘└───┘└─────────┘└─────┘ -""" +# CRXGate +# +# q_0: ────■──── q_0: ───────■────────────────■──────────────────── +# ┌───┴───┐ ≡ ┌───┐┌─┴─┐┌──────────┐┌─┴─┐┌─────────┐┌─────┐ +# q_1: ┤ Rx(ϴ) ├ q_1: ┤ S ├┤ X ├┤ Ry(-ϴ/2) ├┤ X ├┤ Ry(ϴ/2) ├┤ Sdg ├ +# └───────┘ └───┘└───┘└──────────┘└───┘└─────────┘└─────┘ q = QuantumRegister(2, "q") theta = Parameter("theta") crx_to_srycx = QuantumCircuit(q) @@ -265,15 +245,13 @@ crx_to_srycx.append(inst, qargs, cargs) _sel.add_equivalence(CRXGate(theta), crx_to_srycx) -""" -RXXGate - - ┌─────────┐ ┌───┐ ┌───┐ -q_0: ┤0 ├ q_0: ┤ H ├──■─────────────■──┤ H ├ - │ Rxx(ϴ) │ ≡ ├───┤┌─┴─┐┌───────┐┌─┴─┐├───┤ -q_1: ┤1 ├ q_1: ┤ H ├┤ X ├┤ Rz(ϴ) ├┤ X ├┤ H ├ - └─────────┘ └───┘└───┘└───────┘└───┘└───┘ -""" +# RXXGate +# +# ┌─────────┐ ┌───┐ ┌───┐ +# q_0: ┤0 ├ q_0: ┤ H ├──■─────────────■──┤ H ├ +# │ Rxx(ϴ) │ ≡ ├───┤┌─┴─┐┌───────┐┌─┴─┐├───┤ +# q_1: ┤1 ├ q_1: ┤ H ├┤ X ├┤ Rz(ϴ) ├┤ X ├┤ H ├ +# └─────────┘ └───┘└───┘└───────┘└───┘└───┘ q = QuantumRegister(2, "q") theta = Parameter("theta") def_rxx = QuantumCircuit(q) @@ -289,15 +267,13 @@ def_rxx.append(inst, qargs, cargs) _sel.add_equivalence(RXXGate(theta), def_rxx) -""" -RZXGate - - ┌─────────┐ -q_0: ┤0 ├ q_0: ───────■─────────────■─────── - │ Rzx(ϴ) │ ≡ ┌───┐┌─┴─┐┌───────┐┌─┴─┐┌───┐ -q_1: ┤1 ├ q_1: ┤ H ├┤ X ├┤ Rz(ϴ) ├┤ X ├┤ H ├ - └─────────┘ └───┘└───┘└───────┘└───┘└───┘ -""" +# RZXGate +# +# ┌─────────┐ +# q_0: ┤0 ├ q_0: ───────■─────────────■─────── +# │ Rzx(ϴ) │ ≡ ┌───┐┌─┴─┐┌───────┐┌─┴─┐┌───┐ +# q_1: ┤1 ├ q_1: ┤ H ├┤ X ├┤ Rz(ϴ) ├┤ X ├┤ H ├ +# └─────────┘ └───┘└───┘└───────┘└───┘└───┘ q = QuantumRegister(2, "q") theta = Parameter("theta") def_rzx = QuantumCircuit(q) @@ -312,27 +288,23 @@ _sel.add_equivalence(RZXGate(theta), def_rzx) -""" -RYGate - - ┌───────┐ ┌──────────┐ -q: ┤ Ry(ϴ) ├ ≡ q: ┤ R(ϴ,π/2) ├ - └───────┘ └──────────┘ -""" +# RYGate +# +# ┌───────┐ ┌──────────┐ +# q: ┤ Ry(ϴ) ├ ≡ q: ┤ R(ϴ,π/2) ├ +# └───────┘ └──────────┘ q = QuantumRegister(1, "q") theta = Parameter("theta") def_ry = QuantumCircuit(q) def_ry.append(RGate(theta, pi / 2), [q[0]], []) _sel.add_equivalence(RYGate(theta), def_ry) -""" -CRYGate - -q_0: ────■──── q_0: ─────────────■────────────────■── - ┌───┴───┐ ≡ ┌─────────┐┌─┴─┐┌──────────┐┌─┴─┐ -q_1: ┤ Ry(ϴ) ├ q_1: ┤ Ry(ϴ/2) ├┤ X ├┤ Ry(-ϴ/2) ├┤ X ├ - └───────┘ └─────────┘└───┘└──────────┘└───┘ -""" +# CRYGate +# +# q_0: ────■──── q_0: ─────────────■────────────────■── +# ┌───┴───┐ ≡ ┌─────────┐┌─┴─┐┌──────────┐┌─┴─┐ +# q_1: ┤ Ry(ϴ) ├ q_1: ┤ Ry(ϴ/2) ├┤ X ├┤ Ry(-ϴ/2) ├┤ X ├ +# └───────┘ └─────────┘└───┘└──────────┘└───┘ q = QuantumRegister(2, "q") theta = Parameter("theta") def_cry = QuantumCircuit(q) @@ -345,15 +317,13 @@ def_cry.append(inst, qargs, cargs) _sel.add_equivalence(CRYGate(theta), def_cry) -""" -RYYGate - - ┌─────────┐ ┌─────────┐ ┌──────────┐ -q_0: ┤0 ├ q_0: ┤ Rx(π/2) ├──■─────────────■──┤ Rx(-π/2) ├ - │ Ryy(ϴ) │ ≡ ├─────────┤┌─┴─┐┌───────┐┌─┴─┐├──────────┤ -q_1: ┤1 ├ q_1: ┤ Rx(π/2) ├┤ X ├┤ Rz(ϴ) ├┤ X ├┤ Rx(-π/2) ├ - └─────────┘ └─────────┘└───┘└───────┘└───┘└──────────┘ -""" +# RYYGate +# +# ┌─────────┐ ┌─────────┐ ┌──────────┐ +# q_0: ┤0 ├ q_0: ┤ Rx(π/2) ├──■─────────────■──┤ Rx(-π/2) ├ +# │ Ryy(ϴ) │ ≡ ├─────────┤┌─┴─┐┌───────┐┌─┴─┐├──────────┤ +# q_1: ┤1 ├ q_1: ┤ Rx(π/2) ├┤ X ├┤ Rz(ϴ) ├┤ X ├┤ Rx(-π/2) ├ +# └─────────┘ └─────────┘└───┘└───────┘└───┘└──────────┘ q = QuantumRegister(2, "q") theta = Parameter("theta") def_ryy = QuantumCircuit(q) @@ -369,26 +339,22 @@ def_ryy.append(inst, qargs, cargs) _sel.add_equivalence(RYYGate(theta), def_ryy) -""" -RZGate - global phase: -ϴ/2 - ┌───────┐ ┌───────┐ -q: ┤ Rz(ϴ) ├ ≡ q: ┤ U1(ϴ) ├ - └───────┘ └───────┘ -""" +# RZGate +# global phase: -ϴ/2 +# ┌───────┐ ┌───────┐ +# q: ┤ Rz(ϴ) ├ ≡ q: ┤ U1(ϴ) ├ +# └───────┘ └───────┘ q = QuantumRegister(1, "q") theta = Parameter("theta") def_rz = QuantumCircuit(q, global_phase=-theta / 2) def_rz.append(U1Gate(theta), [q[0]], []) _sel.add_equivalence(RZGate(theta), def_rz) -""" -RZGate - - ┌───────┐ ┌────┐┌────────┐┌──────┐ -q: ┤ Rz(ϴ) ├ ≡ q: ┤ √X ├┤ Ry(-ϴ) ├┤ √Xdg ├ - └───────┘ └────┘└────────┘└──────┘ -""" +# RZGate +# +# ┌───────┐ ┌────┐┌────────┐┌──────┐ +# q: ┤ Rz(ϴ) ├ ≡ q: ┤ √X ├┤ Ry(-ϴ) ├┤ √Xdg ├ +# └───────┘ └────┘└────────┘└──────┘ q = QuantumRegister(1, "q") rz_to_sxry = QuantumCircuit(q) rz_to_sxry.sx(0) @@ -396,14 +362,12 @@ rz_to_sxry.sxdg(0) _sel.add_equivalence(RZGate(theta), rz_to_sxry) -""" -CRZGate - -q_0: ────■──── q_0: ─────────────■────────────────■── - ┌───┴───┐ ≡ ┌─────────┐┌─┴─┐┌──────────┐┌─┴─┐ -q_1: ┤ Rz(ϴ) ├ q_1: ┤ Rz(ϴ/2) ├┤ X ├┤ Rz(-ϴ/2) ├┤ X ├ - └───────┘ └─────────┘└───┘└──────────┘└───┘ -""" +# CRZGate +# +# q_0: ────■──── q_0: ─────────────■────────────────■── +# ┌───┴───┐ ≡ ┌─────────┐┌─┴─┐┌──────────┐┌─┴─┐ +# q_1: ┤ Rz(ϴ) ├ q_1: ┤ Rz(ϴ/2) ├┤ X ├┤ Rz(-ϴ/2) ├┤ X ├ +# └───────┘ └─────────┘└───┘└──────────┘└───┘ q = QuantumRegister(2, "q") theta = Parameter("theta") def_crz = QuantumCircuit(q) @@ -416,14 +380,12 @@ def_crz.append(inst, qargs, cargs) _sel.add_equivalence(CRZGate(theta), def_crz) -""" -RZZGate - -q_0: ─■───── q_0: ──■─────────────■── - │ZZ(ϴ) ≡ ┌─┴─┐┌───────┐┌─┴─┐ -q_1: ─■───── q_1: ┤ X ├┤ Rz(ϴ) ├┤ X ├ - └───┘└───────┘└───┘ -""" +# RZZGate +# +# q_0: ─■───── q_0: ──■─────────────■── +# │ZZ(ϴ) ≡ ┌─┴─┐┌───────┐┌─┴─┐ +# q_1: ─■───── q_1: ┤ X ├┤ Rz(ϴ) ├┤ X ├ +# └───┘└───────┘└───┘ q = QuantumRegister(2, "q") theta = Parameter("theta") def_rzz = QuantumCircuit(q) @@ -435,15 +397,13 @@ def_rzz.append(inst, qargs, cargs) _sel.add_equivalence(RZZGate(theta), def_rzz) -""" -RZXGate - - ┌─────────┐ -q_0: ┤0 ├ q_0: ───────■─────────────■─────── - │ Rzx(ϴ) │ ≡ ┌───┐┌─┴─┐┌───────┐┌─┴─┐┌───┐ -q_1: ┤1 ├ q_1: ┤ H ├┤ X ├┤ Rz(ϴ) ├┤ X ├┤ H ├ - └─────────┘ └───┘└───┘└───────┘└───┘└───┘ -""" +# RZXGate +# +# ┌─────────┐ +# q_0: ┤0 ├ q_0: ───────■─────────────■─────── +# │ Rzx(ϴ) │ ≡ ┌───┐┌─┴─┐┌───────┐┌─┴─┐┌───┐ +# q_1: ┤1 ├ q_1: ┤ H ├┤ X ├┤ Rz(ϴ) ├┤ X ├┤ H ├ +# └─────────┘ └───┘└───┘└───────┘└───┘└───┘ q = QuantumRegister(2, "q") theta = Parameter("theta") def_rzx = QuantumCircuit(q) @@ -457,15 +417,13 @@ def_rzx.append(inst, qargs, cargs) _sel.add_equivalence(RZXGate(theta), def_rzx) -""" -ECRGate - - ┌──────┐ ┌───────────┐┌───┐┌────────────┐ -q_0: ┤0 ├ q_0: ┤0 ├┤ X ├┤0 ├ - │ Ecr │ ≡ │ Rzx(π/4) │└───┘│ Rzx(-π/4) │ -q_1: ┤1 ├ q_1: ┤1 ├─────┤1 ├ - └──────┘ └───────────┘ └────────────┘ -""" +# ECRGate +# +# ┌──────┐ ┌───────────┐┌───┐┌────────────┐ +# q_0: ┤0 ├ q_0: ┤0 ├┤ X ├┤0 ├ +# │ Ecr │ ≡ │ Rzx(π/4) │└───┘│ Rzx(-π/4) │ +# q_1: ┤1 ├ q_1: ┤1 ├─────┤1 ├ +# └──────┘ └───────────┘ └────────────┘ q = QuantumRegister(2, "q") def_ecr = QuantumCircuit(q) for inst, qargs, cargs in [ @@ -476,37 +434,31 @@ def_ecr.append(inst, qargs, cargs) _sel.add_equivalence(ECRGate(), def_ecr) -""" -SGate - - ┌───┐ ┌─────────┐ -q: ┤ S ├ ≡ q: ┤ U1(π/2) ├ - └───┘ └─────────┘ -""" +# SGate +# +# ┌───┐ ┌─────────┐ +# q: ┤ S ├ ≡ q: ┤ U1(π/2) ├ +# └───┘ └─────────┘ q = QuantumRegister(1, "q") def_s = QuantumCircuit(q) def_s.append(U1Gate(pi / 2), [q[0]], []) _sel.add_equivalence(SGate(), def_s) -""" -SdgGate - - ┌─────┐ ┌──────────┐ -q: ┤ Sdg ├ ≡ q: ┤ U1(-π/2) ├ - └─────┘ └──────────┘ -""" +# SdgGate +# +# ┌─────┐ ┌──────────┐ +# q: ┤ Sdg ├ ≡ q: ┤ U1(-π/2) ├ +# └─────┘ └──────────┘ q = QuantumRegister(1, "q") def_sdg = QuantumCircuit(q) def_sdg.append(U1Gate(-pi / 2), [q[0]], []) _sel.add_equivalence(SdgGate(), def_sdg) -""" -SdgGate - - ┌─────┐ ┌───┐┌───┐ -q: ┤ Sdg ├ ≡ q: ┤ S ├┤ Z ├ - └─────┘ └───┘└───┘ -""" +# SdgGate +# +# ┌─────┐ ┌───┐┌───┐ +# q: ┤ Sdg ├ ≡ q: ┤ S ├┤ Z ├ +# └─────┘ └───┘└───┘ q = QuantumRegister(1, "q") def_sdg = QuantumCircuit(q) for inst, qargs, cargs in [ @@ -516,13 +468,11 @@ def_sdg.append(inst, qargs, cargs) _sel.add_equivalence(SdgGate(), def_sdg) -""" -SdgGate - - ┌─────┐ ┌───┐┌───┐ -q: ┤ Sdg ├ ≡ q: ┤ Z ├┤ S ├ - └─────┘ └───┘└───┘ -""" +# SdgGate +# +# ┌─────┐ ┌───┐┌───┐ +# q: ┤ Sdg ├ ≡ q: ┤ Z ├┤ S ├ +# └─────┘ └───┘└───┘ q = QuantumRegister(1, "q") def_sdg = QuantumCircuit(q) for inst, qargs, cargs in [ @@ -532,13 +482,11 @@ def_sdg.append(inst, qargs, cargs) _sel.add_equivalence(SdgGate(), def_sdg) -""" -SdgGate - - ┌─────┐ ┌───┐┌───┐┌───┐ -q: ┤ Sdg ├ ≡ q: ┤ S ├┤ S ├┤ S ├ - └─────┘ └───┘└───┘└───┘ -""" +# SdgGate +# +# ┌─────┐ ┌───┐┌───┐┌───┐ +# q: ┤ Sdg ├ ≡ q: ┤ S ├┤ S ├┤ S ├ +# └─────┘ └───┘└───┘└───┘ q = QuantumRegister(1, "q") def_sdg = QuantumCircuit(q) for inst, qargs, cargs in [ @@ -549,14 +497,12 @@ def_sdg.append(inst, qargs, cargs) _sel.add_equivalence(SdgGate(), def_sdg) -""" -SwapGate - ┌───┐ -q_0: ─X─ q_0: ──■──┤ X ├──■── - │ ≡ ┌─┴─┐└─┬─┘┌─┴─┐ -q_1: ─X─ q_1: ┤ X ├──■──┤ X ├ - └───┘ └───┘ -""" +# SwapGate +# ┌───┐ +# q_0: ─X─ q_0: ──■──┤ X ├──■── +# │ ≡ ┌─┴─┐└─┬─┘┌─┴─┐ +# q_1: ─X─ q_1: ┤ X ├──■──┤ X ├ +# └───┘ └───┘ q = QuantumRegister(2, "q") def_swap = QuantumCircuit(q) for inst, qargs, cargs in [ @@ -567,15 +513,13 @@ def_swap.append(inst, qargs, cargs) _sel.add_equivalence(SwapGate(), def_swap) -""" -iSwapGate - - ┌────────┐ ┌───┐┌───┐ ┌───┐ -q_0: ┤0 ├ q_0: ┤ S ├┤ H ├──■──┤ X ├───── - │ Iswap │ ≡ ├───┤└───┘┌─┴─┐└─┬─┘┌───┐ -q_1: ┤1 ├ q_1: ┤ S ├─────┤ X ├──■──┤ H ├ - └────────┘ └───┘ └───┘ └───┘ -""" +# iSwapGate +# +# ┌────────┐ ┌───┐┌───┐ ┌───┐ +# q_0: ┤0 ├ q_0: ┤ S ├┤ H ├──■──┤ X ├───── +# │ Iswap │ ≡ ├───┤└───┘┌─┴─┐└─┬─┘┌───┐ +# q_1: ┤1 ├ q_1: ┤ S ├─────┤ X ├──■──┤ H ├ +# └────────┘ └───┘ └───┘ └───┘ q = QuantumRegister(2, "q") def_iswap = QuantumCircuit(q) for inst, qargs, cargs in [ @@ -589,64 +533,54 @@ def_iswap.append(inst, qargs, cargs) _sel.add_equivalence(iSwapGate(), def_iswap) -""" -SXGate - global phase: π/4 - ┌────┐ ┌─────┐┌───┐┌─────┐ -q: ┤ √X ├ ≡ q: ┤ Sdg ├┤ H ├┤ Sdg ├ - └────┘ └─────┘└───┘└─────┘ -""" +# SXGate +# global phase: π/4 +# ┌────┐ ┌─────┐┌───┐┌─────┐ +# q: ┤ √X ├ ≡ q: ┤ Sdg ├┤ H ├┤ Sdg ├ +# └────┘ └─────┘└───┘└─────┘ q = QuantumRegister(1, "q") def_sx = QuantumCircuit(q, global_phase=pi / 4) for inst, qargs, cargs in [(SdgGate(), [q[0]], []), (HGate(), [q[0]], []), (SdgGate(), [q[0]], [])]: def_sx.append(inst, qargs, cargs) _sel.add_equivalence(SXGate(), def_sx) -""" -SXGate - global phase: π/4 - ┌────┐ ┌─────────┐ -q: ┤ √X ├ ≡ q: ┤ Rx(π/2) ├ - └────┘ └─────────┘ -""" +# SXGate +# global phase: π/4 +# ┌────┐ ┌─────────┐ +# q: ┤ √X ├ ≡ q: ┤ Rx(π/2) ├ +# └────┘ └─────────┘ q = QuantumRegister(1, "q") sx_to_rx = QuantumCircuit(q, global_phase=pi / 4) sx_to_rx.rx(pi / 2, 0) _sel.add_equivalence(SXGate(), sx_to_rx) -""" -SXdgGate - global phase: 7π/4 - ┌──────┐ ┌───┐┌───┐┌───┐ -q: ┤ √Xdg ├ ≡ q: ┤ S ├┤ H ├┤ S ├ - └──────┘ └───┘└───┘└───┘ -""" +# SXdgGate +# global phase: 7π/4 +# ┌──────┐ ┌───┐┌───┐┌───┐ +# q: ┤ √Xdg ├ ≡ q: ┤ S ├┤ H ├┤ S ├ +# └──────┘ └───┘└───┘└───┘ q = QuantumRegister(1, "q") def_sxdg = QuantumCircuit(q, global_phase=-pi / 4) for inst, qargs, cargs in [(SGate(), [q[0]], []), (HGate(), [q[0]], []), (SGate(), [q[0]], [])]: def_sxdg.append(inst, qargs, cargs) _sel.add_equivalence(SXdgGate(), def_sxdg) -""" -SXdgGate - global phase: 7π/4 - ┌──────┐ ┌──────────┐ -q: ┤ √Xdg ├ ≡ q: ┤ Rx(-π/2) ├ - └──────┘ └──────────┘ -""" +# SXdgGate +# global phase: 7π/4 +# ┌──────┐ ┌──────────┐ +# q: ┤ √Xdg ├ ≡ q: ┤ Rx(-π/2) ├ +# └──────┘ └──────────┘ q = QuantumRegister(1, "q") sxdg_to_rx = QuantumCircuit(q, global_phase=-pi / 4) sxdg_to_rx.rx(-pi / 2, 0) _sel.add_equivalence(SXdgGate(), sxdg_to_rx) -""" -CSXGate - -q_0: ──■─── q_0: ──────■───────────── - ┌─┴──┐ ≡ ┌───┐ │U1(π/2) ┌───┐ -q_1: ┤ Sx ├ q_1: ┤ H ├─■────────┤ H ├ - └────┘ └───┘ └───┘ -""" +# CSXGate +# +# q_0: ──■─── q_0: ──────■───────────── +# ┌─┴──┐ ≡ ┌───┐ │U1(π/2) ┌───┐ +# q_1: ┤ Sx ├ q_1: ┤ H ├─■────────┤ H ├ +# └────┘ └───┘ └───┘ q = QuantumRegister(2, "q") def_csx = QuantumCircuit(q) for inst, qargs, cargs in [ @@ -657,15 +591,13 @@ def_csx.append(inst, qargs, cargs) _sel.add_equivalence(CSXGate(), def_csx) -""" -CSXGate - global phase: π/8 - ┌───┐┌───────────┐ ┌─────┐ ┌───┐ -q_0: ──■─── q_0: ┤ X ├┤0 ├─┤ Tdg ├──┤ X ├ - ┌─┴──┐ ≡ └───┘│ Rzx(π/4) │┌┴─────┴─┐└───┘ -q_1: ┤ Sx ├ q_1: ─────┤1 ├┤ sx^0.5 ├───── - └────┘ └───────────┘└────────┘ -""" +# CSXGate +# global phase: π/8 +# ┌───┐┌───────────┐ ┌─────┐ ┌───┐ +# q_0: ──■─── q_0: ┤ X ├┤0 ├─┤ Tdg ├──┤ X ├ +# ┌─┴──┐ ≡ └───┘│ Rzx(π/4) │┌┴─────┴─┐└───┘ +# q_1: ┤ Sx ├ q_1: ─────┤1 ├┤ sx^0.5 ├───── +# └────┘ └───────────┘└────────┘ q = QuantumRegister(2, "q") csx_to_zx45 = QuantumCircuit(q, global_phase=pi / 8) for inst, qargs, cargs in [ @@ -679,30 +611,26 @@ _sel.add_equivalence(CSXGate(), csx_to_zx45) -""" -DCXGate - - ┌──────┐ ┌───┐ -q_0: ┤0 ├ q_0: ──■──┤ X ├ - │ Dcx │ ≡ ┌─┴─┐└─┬─┘ -q_1: ┤1 ├ q_1: ┤ X ├──■── - └──────┘ └───┘ -""" +# DCXGate +# +# ┌──────┐ ┌───┐ +# q_0: ┤0 ├ q_0: ──■──┤ X ├ +# │ Dcx │ ≡ ┌─┴─┐└─┬─┘ +# q_1: ┤1 ├ q_1: ┤ X ├──■── +# └──────┘ └───┘ q = QuantumRegister(2, "q") def_dcx = QuantumCircuit(q) for inst, qargs, cargs in [(CXGate(), [q[0], q[1]], []), (CXGate(), [q[1], q[0]], [])]: def_dcx.append(inst, qargs, cargs) _sel.add_equivalence(DCXGate(), def_dcx) -""" -DCXGate - - ┌──────┐ ┌───┐ ┌─────┐┌────────┐ -q_0: ┤0 ├ q_0: ─┤ H ├─┤ Sdg ├┤0 ├───── - │ Dcx │ ≡ ┌┴───┴┐└─────┘│ Iswap │┌───┐ -q_1: ┤1 ├ q_1: ┤ Sdg ├───────┤1 ├┤ H ├ - └──────┘ └─────┘ └────────┘└───┘ -""" +# DCXGate +# +# ┌──────┐ ┌───┐ ┌─────┐┌────────┐ +# q_0: ┤0 ├ q_0: ─┤ H ├─┤ Sdg ├┤0 ├───── +# │ Dcx │ ≡ ┌┴───┴┐└─────┘│ Iswap │┌───┐ +# q_1: ┤1 ├ q_1: ┤ Sdg ├───────┤1 ├┤ H ├ +# └──────┘ └─────┘ └────────┘└───┘ q = QuantumRegister(2, "q") dcx_to_iswap = QuantumCircuit(q) for inst, qargs, cargs in [ @@ -715,16 +643,14 @@ dcx_to_iswap.append(inst, qargs, cargs) _sel.add_equivalence(DCXGate(), dcx_to_iswap) -""" -CSwapGate - -q_0: ─■─ q_0: ───────■─────── - │ ┌───┐ │ ┌───┐ -q_1: ─X─ ≡ q_1: ┤ X ├──■──┤ X ├ - │ └─┬─┘┌─┴─┐└─┬─┘ -q_2: ─X─ q_2: ──■──┤ X ├──■── - └───┘ -""" +# CSwapGate +# +# q_0: ─■─ q_0: ───────■─────── +# │ ┌───┐ │ ┌───┐ +# q_1: ─X─ ≡ q_1: ┤ X ├──■──┤ X ├ +# │ └─┬─┘┌─┴─┐└─┬─┘ +# q_2: ─X─ q_2: ──■──┤ X ├──■── +# └───┘ q = QuantumRegister(3, "q") def_cswap = QuantumCircuit(q) for inst, qargs, cargs in [ @@ -735,37 +661,31 @@ def_cswap.append(inst, qargs, cargs) _sel.add_equivalence(CSwapGate(), def_cswap) -""" -TGate - - ┌───┐ ┌─────────┐ -q: ┤ T ├ ≡ q: ┤ U1(π/4) ├ - └───┘ └─────────┘ -""" +# TGate +# +# ┌───┐ ┌─────────┐ +# q: ┤ T ├ ≡ q: ┤ U1(π/4) ├ +# └───┘ └─────────┘ q = QuantumRegister(1, "q") def_t = QuantumCircuit(q) def_t.append(U1Gate(pi / 4), [q[0]], []) _sel.add_equivalence(TGate(), def_t) -""" -TdgGate - - ┌─────┐ ┌──────────┐ -q: ┤ Tdg ├ ≡ q: ┤ U1(-π/4) ├ - └─────┘ └──────────┘ -""" +# TdgGate +# +# ┌─────┐ ┌──────────┐ +# q: ┤ Tdg ├ ≡ q: ┤ U1(-π/4) ├ +# └─────┘ └──────────┘ q = QuantumRegister(1, "q") def_tdg = QuantumCircuit(q) def_tdg.append(U1Gate(-pi / 4), [q[0]], []) _sel.add_equivalence(TdgGate(), def_tdg) -""" -UGate - - ┌──────────┐ ┌───────────┐ -q: ┤ U(θ,ϕ,λ) ├ ≡ q: ┤ U3(θ,ϕ,λ) ├ - └──────────┘ └───────────┘ -""" +# UGate +# +# ┌──────────┐ ┌───────────┐ +# q: ┤ U(θ,ϕ,λ) ├ ≡ q: ┤ U3(θ,ϕ,λ) ├ +# └──────────┘ └───────────┘ q = QuantumRegister(1, "q") theta = Parameter("theta") phi = Parameter("phi") @@ -774,19 +694,17 @@ u_to_u3.append(U3Gate(theta, phi, lam), [0]) _sel.add_equivalence(UGate(theta, phi, lam), u_to_u3) -""" -CUGate - ┌──────┐ ┌──────────────┐ » -q_0: ──────■─────── q_0: ────┤ P(γ) ├────┤ P(λ/2 + ϕ/2) ├──■──» - ┌─────┴──────┐ ≡ ┌───┴──────┴───┐└──────────────┘┌─┴─┐» -q_1: ┤ U(θ,ϕ,λ,γ) ├ q_1: ┤ P(λ/2 - ϕ/2) ├────────────────┤ X ├» - └────────────┘ └──────────────┘ └───┘» -« -«q_0: ──────────────────────────■──────────────── -« ┌──────────────────────┐┌─┴─┐┌────────────┐ -«q_1: ┤ U(-θ/2,ϕ,-λ/2 - ϕ/2) ├┤ X ├┤ U(θ/2,ϕ,0) ├ -« └──────────────────────┘└───┘└────────────┘ -""" +# CUGate +# ┌──────┐ ┌──────────────┐ » +# q_0: ──────■─────── q_0: ────┤ P(γ) ├────┤ P(λ/2 + ϕ/2) ├──■──» +# ┌─────┴──────┐ ≡ ┌───┴──────┴───┐└──────────────┘┌─┴─┐» +# q_1: ┤ U(θ,ϕ,λ,γ) ├ q_1: ┤ P(λ/2 - ϕ/2) ├────────────────┤ X ├» +# └────────────┘ └──────────────┘ └───┘» +# « +# «q_0: ──────────────────────────■──────────────── +# « ┌──────────────────────┐┌─┴─┐┌────────────┐ +# «q_1: ┤ U(-θ/2,ϕ,-λ/2 - ϕ/2) ├┤ X ├┤ U(θ/2,ϕ,0) ├ +# « └──────────────────────┘└───┘└────────────┘ q = QuantumRegister(2, "q") theta = Parameter("theta") phi = Parameter("phi") @@ -802,14 +720,12 @@ def_cu.u(theta / 2, phi, 0, 1) _sel.add_equivalence(CUGate(theta, phi, lam, gamma), def_cu) -""" -CUGate - ┌──────┐ -q_0: ──────■─────── q_0: ┤ P(γ) ├──────■────── - ┌─────┴──────┐ ≡ └──────┘┌─────┴─────┐ -q_1: ┤ U(θ,ϕ,λ,γ) ├ q_1: ────────┤ U3(θ,ϕ,λ) ├ - └────────────┘ └───────────┘ -""" +# CUGate +# ┌──────┐ +# q_0: ──────■─────── q_0: ┤ P(γ) ├──────■────── +# ┌─────┴──────┐ ≡ └──────┘┌─────┴─────┐ +# q_1: ┤ U(θ,ϕ,λ,γ) ├ q_1: ────────┤ U3(θ,ϕ,λ) ├ +# └────────────┘ └───────────┘ q = QuantumRegister(2, "q") theta = Parameter("theta") phi = Parameter("phi") @@ -820,53 +736,45 @@ cu_to_cu3.append(CU3Gate(theta, phi, lam), [0, 1]) _sel.add_equivalence(CUGate(theta, phi, lam, gamma), cu_to_cu3) -""" -U1Gate - - ┌───────┐ ┌───────────┐ -q: ┤ U1(θ) ├ ≡ q: ┤ U3(0,0,θ) ├ - └───────┘ └───────────┘ -""" +# U1Gate +# +# ┌───────┐ ┌───────────┐ +# q: ┤ U1(θ) ├ ≡ q: ┤ U3(0,0,θ) ├ +# └───────┘ └───────────┘ q = QuantumRegister(1, "q") theta = Parameter("theta") def_u1 = QuantumCircuit(q) def_u1.append(U3Gate(0, 0, theta), [q[0]], []) _sel.add_equivalence(U1Gate(theta), def_u1) -""" -U1Gate - - ┌───────┐ ┌──────┐ -q: ┤ U1(θ) ├ ≡ q: ┤ P(0) ├ - └───────┘ └──────┘ -""" +# U1Gate +# +# ┌───────┐ ┌──────┐ +# q: ┤ U1(θ) ├ ≡ q: ┤ P(0) ├ +# └───────┘ └──────┘ q = QuantumRegister(1, "q") theta = Parameter("theta") u1_to_phase = QuantumCircuit(q) u1_to_phase.p(theta, 0) _sel.add_equivalence(U1Gate(theta), u1_to_phase) -""" -U1Gate - global phase: θ/2 - ┌───────┐ ┌───────┐ -q: ┤ U1(θ) ├ ≡ q: ┤ Rz(θ) ├ - └───────┘ └───────┘ -""" +# U1Gate +# global phase: θ/2 +# ┌───────┐ ┌───────┐ +# q: ┤ U1(θ) ├ ≡ q: ┤ Rz(θ) ├ +# └───────┘ └───────┘ q = QuantumRegister(1, "q") theta = Parameter("theta") u1_to_rz = QuantumCircuit(q, global_phase=theta / 2) u1_to_rz.append(RZGate(theta), [q[0]], []) _sel.add_equivalence(U1Gate(theta), u1_to_rz) -""" -CU1Gate - ┌─────────┐ -q_0: ─■───── q_0: ┤ U1(θ/2) ├──■────────────────■───────────── - │U1(θ) ≡ └─────────┘┌─┴─┐┌──────────┐┌─┴─┐┌─────────┐ -q_1: ─■───── q_1: ───────────┤ X ├┤ U1(-θ/2) ├┤ X ├┤ U1(θ/2) ├ - └───┘└──────────┘└───┘└─────────┘ -""" +# CU1Gate +# ┌─────────┐ +# q_0: ─■───── q_0: ┤ U1(θ/2) ├──■────────────────■───────────── +# │U1(θ) ≡ └─────────┘┌─┴─┐┌──────────┐┌─┴─┐┌─────────┐ +# q_1: ─■───── q_1: ───────────┤ X ├┤ U1(-θ/2) ├┤ X ├┤ U1(θ/2) ├ +# └───┘└──────────┘└───┘└─────────┘ q = QuantumRegister(2, "q") theta = Parameter("theta") def_cu1 = QuantumCircuit(q) @@ -880,13 +788,11 @@ def_cu1.append(inst, qargs, cargs) _sel.add_equivalence(CU1Gate(theta), def_cu1) -""" -U2Gate - - ┌─────────┐ ┌─────────────┐ -q: ┤ U2(ϕ,λ) ├ ≡ q: ┤ U3(π/2,ϕ,λ) ├ - └─────────┘ └─────────────┘ -""" +# U2Gate +# +# ┌─────────┐ ┌─────────────┐ +# q: ┤ U2(ϕ,λ) ├ ≡ q: ┤ U3(π/2,ϕ,λ) ├ +# └─────────┘ └─────────────┘ q = QuantumRegister(1, "q") phi = Parameter("phi") lam = Parameter("lam") @@ -894,13 +800,11 @@ def_u2.append(U3Gate(pi / 2, phi, lam), [q[0]], []) _sel.add_equivalence(U2Gate(phi, lam), def_u2) -""" -U2Gate - global phase: 7π/4 - ┌─────────┐ ┌─────────────┐┌────┐┌─────────────┐ -q: ┤ U2(ϕ,λ) ├ ≡ q: ┤ U1(λ - π/2) ├┤ √X ├┤ U1(ϕ + π/2) ├ - └─────────┘ └─────────────┘└────┘└─────────────┘ -""" +# U2Gate +# global phase: 7π/4 +# ┌─────────┐ ┌─────────────┐┌────┐┌─────────────┐ +# q: ┤ U2(ϕ,λ) ├ ≡ q: ┤ U1(λ - π/2) ├┤ √X ├┤ U1(ϕ + π/2) ├ +# └─────────┘ └─────────────┘└────┘└─────────────┘ q = QuantumRegister(1, "q") phi = Parameter("phi") lam = Parameter("lam") @@ -910,13 +814,11 @@ u2_to_u1sx.append(U1Gate(phi + pi / 2), [0]) _sel.add_equivalence(U2Gate(phi, lam), u2_to_u1sx) -""" -U3Gate - global phase: λ/2 + ϕ/2 - π/2 - ┌───────────┐ ┌───────┐┌────┐┌───────────┐┌────┐┌────────────┐ -q: ┤ U3(θ,ϕ,λ) ├ ≡ q: ┤ Rz(λ) ├┤ √X ├┤ Rz(θ + π) ├┤ √X ├┤ Rz(ϕ + 3π) ├ - └───────────┘ └───────┘└────┘└───────────┘└────┘└────────────┘ -""" +# U3Gate +# global phase: λ/2 + ϕ/2 - π/2 +# ┌───────────┐ ┌───────┐┌────┐┌───────────┐┌────┐┌────────────┐ +# q: ┤ U3(θ,ϕ,λ) ├ ≡ q: ┤ Rz(λ) ├┤ √X ├┤ Rz(θ + π) ├┤ √X ├┤ Rz(ϕ + 3π) ├ +# └───────────┘ └───────┘└────┘└───────────┘└────┘└────────────┘ q = QuantumRegister(1, "q") theta = Parameter("theta") phi = Parameter("phi") @@ -929,13 +831,11 @@ u3_qasm_def.rz(phi + 3 * pi, 0) _sel.add_equivalence(U3Gate(theta, phi, lam), u3_qasm_def) -""" -U3Gate - - ┌───────────┐ ┌──────────┐ -q: ┤ U3(θ,ϕ,λ) ├ ≡ q: ┤ U(θ,ϕ,λ) ├ - └───────────┘ └──────────┘ -""" +# U3Gate +# +# ┌───────────┐ ┌──────────┐ +# q: ┤ U3(θ,ϕ,λ) ├ ≡ q: ┤ U(θ,ϕ,λ) ├ +# └───────────┘ └──────────┘ q = QuantumRegister(1, "q") theta = Parameter("theta") phi = Parameter("phi") @@ -944,19 +844,17 @@ u3_to_u.u(theta, phi, lam, 0) _sel.add_equivalence(U3Gate(theta, phi, lam), u3_to_u) -""" -CU3Gate - ┌───────────────┐ » -q_0: ──────■────── q_0: ┤ U1(λ/2 + ϕ/2) ├──■─────────────────────────────■──» - ┌─────┴─────┐ ≡ ├───────────────┤┌─┴─┐┌───────────────────────┐┌─┴─┐» -q_1: ┤ U3(θ,ϕ,λ) ├ q_1: ┤ U1(λ/2 - ϕ/2) ├┤ X ├┤ U3(-θ/2,0,-λ/2 - ϕ/2) ├┤ X ├» - └───────────┘ └───────────────┘└───┘└───────────────────────┘└───┘» -« -«q_0: ─────────────── -« ┌─────────────┐ -«q_1: ┤ U3(θ/2,ϕ,0) ├ -« └─────────────┘ -""" +# CU3Gate +# ┌───────────────┐ » +# q_0: ──────■────── q_0: ┤ U1(λ/2 + ϕ/2) ├──■─────────────────────────────■──» +# ┌─────┴─────┐ ≡ ├───────────────┤┌─┴─┐┌───────────────────────┐┌─┴─┐» +# q_1: ┤ U3(θ,ϕ,λ) ├ q_1: ┤ U1(λ/2 - ϕ/2) ├┤ X ├┤ U3(-θ/2,0,-λ/2 - ϕ/2) ├┤ X ├» +# └───────────┘ └───────────────┘└───┘└───────────────────────┘└───┘» +# « +# «q_0: ─────────────── +# « ┌─────────────┐ +# «q_1: ┤ U3(θ/2,ϕ,0) ├ +# « └─────────────┘ q = QuantumRegister(2, "q") theta = Parameter("theta") phi = Parameter("phi") @@ -980,25 +878,21 @@ cu3_to_cu = QuantumCircuit(q) cu3_to_cu.cu(theta, phi, lam, 0, 0, 1) -""" -XGate - - ┌───┐ ┌───────────┐ -q: ┤ X ├ ≡ q: ┤ U3(π,0,π) ├ - └───┘ └───────────┘ -""" +# XGate +# +# ┌───┐ ┌───────────┐ +# q: ┤ X ├ ≡ q: ┤ U3(π,0,π) ├ +# └───┘ └───────────┘ q = QuantumRegister(1, "q") def_x = QuantumCircuit(q) def_x.append(U3Gate(pi, 0, pi), [q[0]], []) _sel.add_equivalence(XGate(), def_x) -""" -XGate - - ┌───┐ ┌───┐┌───┐┌───┐┌───┐ -q: ┤ X ├ ≡ q: ┤ H ├┤ S ├┤ S ├┤ H ├ - └───┘ └───┘└───┘└───┘└───┘ -""" +# XGate +# +# ┌───┐ ┌───┐┌───┐┌───┐┌───┐ +# q: ┤ X ├ ≡ q: ┤ H ├┤ S ├┤ S ├┤ H ├ +# └───┘ └───┘└───┘└───┘└───┘ q = QuantumRegister(1, "q") def_x = QuantumCircuit(q) for inst, qargs, cargs in [ @@ -1018,14 +912,12 @@ cx_to_rxx = cnot_rxx_decompose(plus_ry, plus_rxx) _sel.add_equivalence(CXGate(), cx_to_rxx) -""" -CXGate - -q_0: ──■── q_0: ──────■────── - ┌─┴─┐ ≡ ┌───┐ │ ┌───┐ -q_1: ┤ X ├ q_1: ┤ H ├─■─┤ H ├ - └───┘ └───┘ └───┘ -""" +# CXGate +# +# q_0: ──■── q_0: ──────■────── +# ┌─┴─┐ ≡ ┌───┐ │ ┌───┐ +# q_1: ┤ X ├ q_1: ┤ H ├─■─┤ H ├ +# └───┘ └───┘ └───┘ q = QuantumRegister(2, "q") cx_to_cz = QuantumCircuit(q) for inst, qargs, cargs in [ @@ -1036,15 +928,13 @@ cx_to_cz.append(inst, qargs, cargs) _sel.add_equivalence(CXGate(), cx_to_cz) -""" -CXGate - global phase: 3π/4 - ┌───┐ ┌────────┐┌───┐ ┌────────┐┌───┐┌───┐ -q_0: ──■── q_0: ┤ H ├─────┤0 ├┤ X ├─────┤0 ├┤ H ├┤ S ├───── - ┌─┴─┐ ≡ ├───┤┌───┐│ Iswap │├───┤┌───┐│ Iswap │├───┤├───┤┌───┐ -q_1: ┤ X ├ q_1: ┤ X ├┤ H ├┤1 ├┤ X ├┤ H ├┤1 ├┤ S ├┤ X ├┤ H ├ - └───┘ └───┘└───┘└────────┘└───┘└───┘└────────┘└───┘└───┘└───┘ -""" +# CXGate +# global phase: 3π/4 +# ┌───┐ ┌────────┐┌───┐ ┌────────┐┌───┐┌───┐ +# q_0: ──■── q_0: ┤ H ├─────┤0 ├┤ X ├─────┤0 ├┤ H ├┤ S ├───── +# ┌─┴─┐ ≡ ├───┤┌───┐│ Iswap │├───┤┌───┐│ Iswap │├───┤├───┤┌───┐ +# q_1: ┤ X ├ q_1: ┤ X ├┤ H ├┤1 ├┤ X ├┤ H ├┤1 ├┤ S ├┤ X ├┤ H ├ +# └───┘ └───┘└───┘└────────┘└───┘└───┘└────────┘└───┘└───┘└───┘ q = QuantumRegister(2, "q") cx_to_iswap = QuantumCircuit(q, global_phase=3 * pi / 4) for inst, qargs, cargs in [ @@ -1065,15 +955,13 @@ cx_to_iswap.append(inst, qargs, cargs) _sel.add_equivalence(CXGate(), cx_to_iswap) -""" -CXGate - global phase: 7π/4 - ┌──────────┐┌───────┐┌──────┐ -q_0: ──■── q_0: ┤ Rz(-π/2) ├┤ Ry(π) ├┤0 ├ - ┌─┴─┐ ≡ ├─────────┬┘└───────┘│ Ecr │ -q_1: ┤ X ├ q_1: ┤ Rx(π/2) ├──────────┤1 ├ - └───┘ └─────────┘ └──────┘ -""" +# CXGate +# global phase: 7π/4 +# ┌──────────┐┌───────┐┌──────┐ +# q_0: ──■── q_0: ┤ Rz(-π/2) ├┤ Ry(π) ├┤0 ├ +# ┌─┴─┐ ≡ ├─────────┬┘└───────┘│ Ecr │ +# q_1: ┤ X ├ q_1: ┤ Rx(π/2) ├──────────┤1 ├ +# └───┘ └─────────┘ └──────┘ q = QuantumRegister(2, "q") cx_to_ecr = QuantumCircuit(q, global_phase=-pi / 4) for inst, qargs, cargs in [ @@ -1085,15 +973,13 @@ cx_to_ecr.append(inst, qargs, cargs) _sel.add_equivalence(CXGate(), cx_to_ecr) -""" -CXGate - global phase: π/4 - ┌───────────┐┌─────┐ -q_0: ──■── q_0: ┤0 ├┤ Sdg ├─ - ┌─┴─┐ ≡ │ Rzx(π/2) │├─────┴┐ -q_1: ┤ X ├ q_1: ┤1 ├┤ √Xdg ├ - └───┘ └───────────┘└──────┘ -""" +# CXGate +# global phase: π/4 +# ┌───────────┐┌─────┐ +# q_0: ──■── q_0: ┤0 ├┤ Sdg ├─ +# ┌─┴─┐ ≡ │ Rzx(π/2) │├─────┴┐ +# q_1: ┤ X ├ q_1: ┤1 ├┤ √Xdg ├ +# └───┘ └───────────┘└──────┘ q = QuantumRegister(2, "q") cx_to_zx90 = QuantumCircuit(q, global_phase=pi / 4) for inst, qargs, cargs in [ @@ -1104,16 +990,14 @@ cx_to_zx90.append(inst, qargs, cargs) _sel.add_equivalence(CXGate(), cx_to_zx90) -""" -CCXGate - ┌───┐ -q_0: ──■── q_0: ───────────────────■─────────────────────■────■───┤ T ├───■── - │ │ ┌───┐ │ ┌─┴─┐┌┴───┴┐┌─┴─┐ -q_1: ──■── ≡ q_1: ───────■───────────┼─────────■───┤ T ├───┼──┤ X ├┤ Tdg ├┤ X ├ - ┌─┴─┐ ┌───┐┌─┴─┐┌─────┐┌─┴─┐┌───┐┌─┴─┐┌┴───┴┐┌─┴─┐├───┤└┬───┬┘└───┘ -q_2: ┤ X ├ q_2: ┤ H ├┤ X ├┤ Tdg ├┤ X ├┤ T ├┤ X ├┤ Tdg ├┤ X ├┤ T ├─┤ H ├────── - └───┘ └───┘└───┘└─────┘└───┘└───┘└───┘└─────┘└───┘└───┘ └───┘ -""" +# CCXGate +# ┌───┐ +# q_0: ──■── q_0: ───────────────────■─────────────────────■────■───┤ T ├───■── +# │ │ ┌───┐ │ ┌─┴─┐┌┴───┴┐┌─┴─┐ +# q_1: ──■── ≡ q_1: ───────■───────────┼─────────■───┤ T ├───┼──┤ X ├┤ Tdg ├┤ X ├ +# ┌─┴─┐ ┌───┐┌─┴─┐┌─────┐┌─┴─┐┌───┐┌─┴─┐┌┴───┴┐┌─┴─┐├───┤└┬───┬┘└───┘ +# q_2: ┤ X ├ q_2: ┤ H ├┤ X ├┤ Tdg ├┤ X ├┤ T ├┤ X ├┤ Tdg ├┤ X ├┤ T ├─┤ H ├────── +# └───┘ └───┘└───┘└─────┘└───┘└───┘└───┘└─────┘└───┘└───┘ └───┘ q = QuantumRegister(3, "q") def_ccx = QuantumCircuit(q) for inst, qargs, cargs in [ @@ -1136,16 +1020,14 @@ def_ccx.append(inst, qargs, cargs) _sel.add_equivalence(CCXGate(), def_ccx) -""" -CCXGate - -q_0: ──■── q_0: ────────■─────────────────■────■─── - │ ┌─┴─┐┌─────┐ ┌─┴─┐ │ -q_1: ──■── ≡ q_1: ──■───┤ X ├┤ Sdg ├──■───┤ X ├──┼─── - ┌─┴─┐ ┌─┴──┐├───┤└─────┘┌─┴──┐├───┤┌─┴──┐ -q_2: ┤ X ├ q_2: ┤ Sx ├┤ Z ├───────┤ Sx ├┤ Z ├┤ Sx ├ - └───┘ └────┘└───┘ └────┘└───┘└────┘ -""" +# CCXGate +# +# q_0: ──■── q_0: ────────■─────────────────■────■─── +# │ ┌─┴─┐┌─────┐ ┌─┴─┐ │ +# q_1: ──■── ≡ q_1: ──■───┤ X ├┤ Sdg ├──■───┤ X ├──┼─── +# ┌─┴─┐ ┌─┴──┐├───┤└─────┘┌─┴──┐├───┤┌─┴──┐ +# q_2: ┤ X ├ q_2: ┤ Sx ├┤ Z ├───────┤ Sx ├┤ Z ├┤ Sx ├ +# └───┘ └────┘└───┘ └────┘└───┘└────┘ q = QuantumRegister(3, "q") ccx_to_cx_csx = QuantumCircuit(q) for inst, qargs, cargs in [ @@ -1161,25 +1043,21 @@ ccx_to_cx_csx.append(inst, qargs, cargs) _sel.add_equivalence(CCXGate(), ccx_to_cx_csx) -""" -YGate - - ┌───┐ ┌───────────────┐ -q: ┤ Y ├ ≡ q: ┤ U3(π,π/2,π/2) ├ - └───┘ └───────────────┘ -""" +# YGate +# +# ┌───┐ ┌───────────────┐ +# q: ┤ Y ├ ≡ q: ┤ U3(π,π/2,π/2) ├ +# └───┘ └───────────────┘ q = QuantumRegister(1, "q") def_y = QuantumCircuit(q) def_y.append(U3Gate(pi, pi / 2, pi / 2), [q[0]], []) _sel.add_equivalence(YGate(), def_y) -""" -YGate - global phase: 3π/2 - ┌───┐ ┌───┐┌───┐┌───┐┌───┐┌───┐┌───┐ -q: ┤ Y ├ ≡ q: ┤ H ├┤ S ├┤ S ├┤ H ├┤ S ├┤ S ├ - └───┘ └───┘└───┘└───┘└───┘└───┘└───┘ -""" +# YGate +# global phase: 3π/2 +# ┌───┐ ┌───┐┌───┐┌───┐┌───┐┌───┐┌───┐ +# q: ┤ Y ├ ≡ q: ┤ H ├┤ S ├┤ S ├┤ H ├┤ S ├┤ S ├ +# └───┘ └───┘└───┘└───┘└───┘└───┘└───┘ q = QuantumRegister(1, "q") def_y = QuantumCircuit(q) def_y.global_phase = 3 * pi / 2 @@ -1194,13 +1072,11 @@ def_y.append(inst, qargs, cargs) _sel.add_equivalence(YGate(), def_y) -""" -YGate - global phase: π/2 - ┌───┐ ┌───┐┌───┐┌───┐┌───┐┌───┐┌───┐ -q: ┤ Y ├ ≡ q: ┤ S ├┤ S ├┤ H ├┤ S ├┤ S ├┤ H ├ - └───┘ └───┘└───┘└───┘└───┘└───┘└───┘ -""" +# YGate +# global phase: π/2 +# ┌───┐ ┌───┐┌───┐┌───┐┌───┐┌───┐┌───┐ +# q: ┤ Y ├ ≡ q: ┤ S ├┤ S ├┤ H ├┤ S ├┤ S ├┤ H ├ +# └───┘ └───┘└───┘└───┘└───┘└───┘└───┘ q = QuantumRegister(1, "q") def_y = QuantumCircuit(q) def_y.global_phase = pi / 2 @@ -1215,14 +1091,12 @@ def_y.append(inst, qargs, cargs) _sel.add_equivalence(YGate(), def_y) -""" -CYGate - -q_0: ──■── q_0: ─────────■─────── - ┌─┴─┐ ≡ ┌─────┐┌─┴─┐┌───┐ -q_1: ┤ Y ├ q_1: ┤ Sdg ├┤ X ├┤ S ├ - └───┘ └─────┘└───┘└───┘ -""" +# CYGate +# +# q_0: ──■── q_0: ─────────■─────── +# ┌─┴─┐ ≡ ┌─────┐┌─┴─┐┌───┐ +# q_1: ┤ Y ├ q_1: ┤ Sdg ├┤ X ├┤ S ├ +# └───┘ └─────┘└───┘└───┘ q = QuantumRegister(2, "q") def_cy = QuantumCircuit(q) for inst, qargs, cargs in [ @@ -1233,25 +1107,22 @@ def_cy.append(inst, qargs, cargs) _sel.add_equivalence(CYGate(), def_cy) -""" -ZGate - - ┌───┐ ┌───────┐ -q: ┤ Z ├ ≡ q: ┤ U1(π) ├ - └───┘ └───────┘ -""" +# ZGate +# +# ┌───┐ ┌───────┐ +# q: ┤ Z ├ ≡ q: ┤ U1(π) ├ +# └───┘ └───────┘ q = QuantumRegister(1, "q") def_z = QuantumCircuit(q) def_z.append(U1Gate(pi), [q[0]], []) _sel.add_equivalence(ZGate(), def_z) -""" -ZGate - - ┌───┐ ┌───┐┌───┐ -q: ┤ Z ├ ≡ q: ┤ S ├┤ S ├ - └───┘ └───┘└───┘ -""" +# """ +# ZGate +# +# ┌───┐ ┌───┐┌───┐ +# q: ┤ Z ├ ≡ q: ┤ S ├┤ S ├ +# └───┘ └───┘└───┘ q = QuantumRegister(1, "q") def_z = QuantumCircuit(q) for inst, qargs, cargs in [ @@ -1261,14 +1132,12 @@ def_z.append(inst, qargs, cargs) _sel.add_equivalence(ZGate(), def_z) -""" -CZGate - -q_0: ─■─ q_0: ───────■─────── - │ ≡ ┌───┐┌─┴─┐┌───┐ -q_1: ─■─ q_1: ┤ H ├┤ X ├┤ H ├ - └───┘└───┘└───┘ -""" +# CZGate +# +# q_0: ─■─ q_0: ───────■─────── +# │ ≡ ┌───┐┌─┴─┐┌───┐ +# q_1: ─■─ q_1: ┤ H ├┤ X ├┤ H ├ +# └───┘└───┘└───┘ q = QuantumRegister(2, "q") def_cz = QuantumCircuit(q) for inst, qargs, cargs in [ @@ -1279,39 +1148,33 @@ def_cz.append(inst, qargs, cargs) _sel.add_equivalence(CZGate(), def_cz) -""" -XGate - global phase: π/2 - ┌───┐ ┌───────┐ -q: ┤ X ├ ≡ q: ┤ Rx(π) ├ - └───┘ └───────┘ -""" +# XGate +# global phase: π/2 +# ┌───┐ ┌───────┐ +# q: ┤ X ├ ≡ q: ┤ Rx(π) ├ +# └───┘ └───────┘ q = QuantumRegister(1, "q") x_to_rx = QuantumCircuit(q) x_to_rx.append(RXGate(theta=pi), [q[0]]) x_to_rx.global_phase = pi / 2 _sel.add_equivalence(XGate(), x_to_rx) -""" -YGate - global phase: π/2 - ┌───┐ ┌───────┐ -q: ┤ Y ├ ≡ q: ┤ Ry(π) ├ - └───┘ └───────┘ -""" +# YGate +# global phase: π/2 +# ┌───┐ ┌───────┐ +# q: ┤ Y ├ ≡ q: ┤ Ry(π) ├ +# └───┘ └───────┘ q = QuantumRegister(1, "q") y_to_ry = QuantumCircuit(q) y_to_ry.append(RYGate(theta=pi), [q[0]]) y_to_ry.global_phase = pi / 2 _sel.add_equivalence(YGate(), y_to_ry) -""" -HGate - global phase: π/2 - ┌───┐ ┌─────────┐┌───────┐ -q: ┤ H ├ ≡ q: ┤ Ry(π/2) ├┤ Rx(π) ├ - └───┘ └─────────┘└───────┘ -""" +# HGate +# global phase: π/2 +# ┌───┐ ┌─────────┐┌───────┐ +# q: ┤ H ├ ≡ q: ┤ Ry(π/2) ├┤ Rx(π) ├ +# └───┘ └─────────┘└───────┘ q = QuantumRegister(1, "q") h_to_rxry = QuantumCircuit(q) h_to_rxry.append(RYGate(theta=pi / 2), [q[0]]) @@ -1319,13 +1182,11 @@ h_to_rxry.global_phase = pi / 2 _sel.add_equivalence(HGate(), h_to_rxry) -""" -HGate - global phase: π/2 - ┌───┐ ┌────────────┐┌────────┐ -q: ┤ H ├ ≡ q: ┤ R(π/2,π/2) ├┤ R(π,0) ├ - └───┘ └────────────┘└────────┘ -""" +# HGate +# global phase: π/2 +# ┌───┐ ┌────────────┐┌────────┐ +# q: ┤ H ├ ≡ q: ┤ R(π/2,π/2) ├┤ R(π,0) ├ +# └───┘ └────────────┘└────────┘ q = QuantumRegister(1, "q") h_to_rr = QuantumCircuit(q) h_to_rr.append(RGate(theta=pi / 2, phi=pi / 2), [q[0]]) diff --git a/test/python/algorithms/test_skip_qobj_validation.py b/test/python/algorithms/test_skip_qobj_validation.py index 1c76140db78d..dc7b7a0e5c19 100644 --- a/test/python/algorithms/test_skip_qobj_validation.py +++ b/test/python/algorithms/test_skip_qobj_validation.py @@ -40,17 +40,13 @@ def setUp(self): super().setUp() self.random_seed = 10598 - """ - (qc) - - ┌───┐ ░ ┌─┐ ░ - q0_0: ┤ H ├──■───░─┤M├─░──── - └───┘┌─┴─┐ ░ └╥┘ ░ ┌─┐ - q0_1: ─────┤ X ├─░──╫──░─┤M├ - └───┘ ░ ║ ░ └╥┘ - c0: 2/══════════════╩═════╩═ - 0 1 - """ + # ┌───┐ ░ ┌─┐ ░ + # q0_0: ┤ H ├──■───░─┤M├─░──── + # └───┘┌─┴─┐ ░ └╥┘ ░ ┌─┐ + # q0_1: ─────┤ X ├─░──╫──░─┤M├ + # └───┘ ░ ║ ░ └╥┘ + # c0: 2/══════════════╩═════╩═ + # 0 1 qr = QuantumRegister(2) cr = ClassicalRegister(2) qc = QuantumCircuit(qr, cr) diff --git a/test/python/basicaer/test_qasm_simulator.py b/test/python/basicaer/test_qasm_simulator.py index 2ae9f09c5751..b0ef864ca419 100644 --- a/test/python/basicaer/test_qasm_simulator.py +++ b/test/python/basicaer/test_qasm_simulator.py @@ -178,18 +178,16 @@ def test_if_statement(self): qr = QuantumRegister(3, "qr") cr = ClassicalRegister(3, "cr") - """ - ┌───┐┌─┐ ┌─┐ - qr_0: ┤ X ├┤M├──────────┤M├────── - ├───┤└╥┘┌─┐ └╥┘┌─┐ - qr_1: ┤ X ├─╫─┤M├────────╫─┤M├─── - └───┘ ║ └╥┘ ┌───┐ ║ └╥┘┌─┐ - qr_2: ──────╫──╫──┤ X ├──╫──╫─┤M├ - ║ ║ └─╥─┘ ║ ║ └╥┘ - ║ ║ ┌──╨──┐ ║ ║ ║ - cr: 3/══════╩══╩═╡ 0x3 ╞═╩══╩══╩═ - 0 1 └─────┘ 0 1 2 - """ + # ┌───┐┌─┐ ┌─┐ + # qr_0: ┤ X ├┤M├──────────┤M├────── + # ├───┤└╥┘┌─┐ └╥┘┌─┐ + # qr_1: ┤ X ├─╫─┤M├────────╫─┤M├─── + # └───┘ ║ └╥┘ ┌───┐ ║ └╥┘┌─┐ + # qr_2: ──────╫──╫──┤ X ├──╫──╫─┤M├ + # ║ ║ └─╥─┘ ║ ║ └╥┘ + # ║ ║ ┌──╨──┐ ║ ║ ║ + # cr: 3/══════╩══╩═╡ 0x3 ╞═╩══╩══╩═ + # 0 1 └─────┘ 0 1 2 circuit_if_true = QuantumCircuit(qr, cr) circuit_if_true.x(qr[0]) circuit_if_true.x(qr[1]) @@ -200,18 +198,16 @@ def test_if_statement(self): circuit_if_true.measure(qr[1], cr[1]) circuit_if_true.measure(qr[2], cr[2]) - """ - ┌───┐┌─┐ ┌─┐ - qr_0: ┤ X ├┤M├───────┤M├────── - └┬─┬┘└╥┘ └╥┘┌─┐ - qr_1: ─┤M├──╫─────────╫─┤M├─── - └╥┘ ║ ┌───┐ ║ └╥┘┌─┐ - qr_2: ──╫───╫──┤ X ├──╫──╫─┤M├ - ║ ║ └─╥─┘ ║ ║ └╥┘ - ║ ║ ┌──╨──┐ ║ ║ ║ - cr: 3/══╩═══╩═╡ 0x3 ╞═╩══╩══╩═ - 1 0 └─────┘ 0 1 2 - """ + # ┌───┐┌─┐ ┌─┐ + # qr_0: ┤ X ├┤M├───────┤M├────── + # └┬─┬┘└╥┘ └╥┘┌─┐ + # qr_1: ─┤M├──╫─────────╫─┤M├─── + # └╥┘ ║ ┌───┐ ║ └╥┘┌─┐ + # qr_2: ──╫───╫──┤ X ├──╫──╫─┤M├ + # ║ ║ └─╥─┘ ║ ║ └╥┘ + # ║ ║ ┌──╨──┐ ║ ║ ║ + # cr: 3/══╩═══╩═╡ 0x3 ╞═╩══╩══╩═ + # 1 0 └─────┘ 0 1 2 circuit_if_false = QuantumCircuit(qr, cr) circuit_if_false.x(qr[0]) circuit_if_false.measure(qr[0], cr[0]) diff --git a/test/python/circuit/library/test_evolution_gate.py b/test/python/circuit/library/test_evolution_gate.py index f786f1f09d4f..f5e15bc31c5f 100644 --- a/test/python/circuit/library/test_evolution_gate.py +++ b/test/python/circuit/library/test_evolution_gate.py @@ -61,13 +61,11 @@ def test_rzx_order(self): evo_gate = PauliEvolutionGate(X ^ Z) decomposed = evo_gate.definition.decompose() - """ - ┌───┐┌───────┐┌───┐ - q_0: ─────┤ X ├┤ Rz(2) ├┤ X ├───── - ┌───┐└─┬─┘└───────┘└─┬─┘┌───┐ - q_1: ┤ H ├──■─────────────■──┤ H ├ - └───┘ └───┘ - """ + # ┌───┐┌───────┐┌───┐ + # q_0: ─────┤ X ├┤ Rz(2) ├┤ X ├───── + # ┌───┐└─┬─┘└───────┘└─┬─┘┌───┐ + # q_1: ┤ H ├──■─────────────■──┤ H ├ + # └───┘ └───┘ ref = QuantumCircuit(2) ref.h(1) ref.cx(1, 0) diff --git a/test/python/circuit/library/test_iqp.py b/test/python/circuit/library/test_iqp.py index 41d4cd9551bd..6fb6c90a03ca 100644 --- a/test/python/circuit/library/test_iqp.py +++ b/test/python/circuit/library/test_iqp.py @@ -29,17 +29,13 @@ def test_iqp(self): """Test iqp circuit.""" circuit = IQP(interactions=np.array([[6, 5, 1], [5, 4, 3], [1, 3, 2]])) - """ - (expected) - - ┌───┐ ┌─────────┐┌───┐ - q_0: ┤ H ├─■───────────────────■───────┤ P(3π/4) ├┤ H ├ - ├───┤ │P(5π/2) │ └┬────────┤├───┤ - q_1: ┤ H ├─■─────────■─────────┼────────┤ P(π/2) ├┤ H ├ - ├───┤ │P(3π/2) │P(π/2) ├────────┤├───┤ - q_2: ┤ H ├───────────■─────────■────────┤ P(π/4) ├┤ H ├ - └───┘ └────────┘└───┘ - """ + # ┌───┐ ┌─────────┐┌───┐ + # q_0: ┤ H ├─■───────────────────■───────┤ P(3π/4) ├┤ H ├ + # ├───┤ │P(5π/2) │ └┬────────┤├───┤ + # q_1: ┤ H ├─■─────────■─────────┼────────┤ P(π/2) ├┤ H ├ + # ├───┤ │P(3π/2) │P(π/2) ├────────┤├───┤ + # q_2: ┤ H ├───────────■─────────■────────┤ P(π/4) ├┤ H ├ + # └───┘ └────────┘└───┘ expected = QuantumCircuit(3) expected.h([0, 1, 2]) expected.cp(5 * np.pi / 2, 0, 1) diff --git a/test/python/circuit/library/test_nlocal.py b/test/python/circuit/library/test_nlocal.py index c5acb93660b2..38b0b83f7b04 100644 --- a/test/python/circuit/library/test_nlocal.py +++ b/test/python/circuit/library/test_nlocal.py @@ -574,15 +574,13 @@ def test_compose_inplace_to_circuit(self): circuit = QuantumCircuit(3) circuit.compose(two, inplace=True) - """ - ┌──────────┐┌──────────┐ ░ ░ ┌──────────┐ ┌──────────┐ - q_0: ┤ Ry(θ[0]) ├┤ Rz(θ[3]) ├─░──■──■─────░─┤ Ry(θ[6]) ├─┤ Rz(θ[9]) ├ - ├──────────┤├──────────┤ ░ │ │ ░ ├──────────┤┌┴──────────┤ - q_1: ┤ Ry(θ[1]) ├┤ Rz(θ[4]) ├─░──■──┼──■──░─┤ Ry(θ[7]) ├┤ Rz(θ[10]) ├ - ├──────────┤├──────────┤ ░ │ │ ░ ├──────────┤├───────────┤ - q_2: ┤ Ry(θ[2]) ├┤ Rz(θ[5]) ├─░─────■──■──░─┤ Ry(θ[8]) ├┤ Rz(θ[11]) ├ - └──────────┘└──────────┘ ░ ░ └──────────┘└───────────┘ - """ + # ┌──────────┐┌──────────┐ ░ ░ ┌──────────┐ ┌──────────┐ + # q_0: ┤ Ry(θ[0]) ├┤ Rz(θ[3]) ├─░──■──■─────░─┤ Ry(θ[6]) ├─┤ Rz(θ[9]) ├ + # ├──────────┤├──────────┤ ░ │ │ ░ ├──────────┤┌┴──────────┤ + # q_1: ┤ Ry(θ[1]) ├┤ Rz(θ[4]) ├─░──■──┼──■──░─┤ Ry(θ[7]) ├┤ Rz(θ[10]) ├ + # ├──────────┤├──────────┤ ░ │ │ ░ ├──────────┤├───────────┤ + # q_2: ┤ Ry(θ[2]) ├┤ Rz(θ[5]) ├─░─────■──■──░─┤ Ry(θ[8]) ├┤ Rz(θ[11]) ├ + # └──────────┘└──────────┘ ░ ░ └──────────┘└───────────┘ reference = QuantumCircuit(3) param_iter = iter(two.ordered_parameters) for i in range(3): @@ -634,15 +632,13 @@ def test_ry_circuit(self): parameters = ParameterVector("theta", num_qubits * (reps + 1)) param_iter = iter(parameters) - """ - ┌──────────┐ ┌──────────┐ ┌──────────┐ - q_0: ┤ Ry(θ[0]) ├──■────■──┤ Ry(θ[3]) ├──────────────■────■──┤ Ry(θ[6]) ├──────────── - ├──────────┤┌─┴─┐ │ └──────────┘┌──────────┐┌─┴─┐ │ └──────────┘┌──────────┐ - q_1: ┤ Ry(θ[1]) ├┤ X ├──┼─────────■────┤ Ry(θ[4]) ├┤ X ├──┼─────────■────┤ Ry(θ[7]) ├ - ├──────────┤└───┘┌─┴─┐ ┌─┴─┐ ├──────────┤└───┘┌─┴─┐ ┌─┴─┐ ├──────────┤ - q_2: ┤ Ry(θ[2]) ├─────┤ X ├─────┤ X ├──┤ Ry(θ[5]) ├─────┤ X ├─────┤ X ├──┤ Ry(θ[8]) ├ - └──────────┘ └───┘ └───┘ └──────────┘ └───┘ └───┘ └──────────┘ - """ + # ┌──────────┐ ┌──────────┐ ┌──────────┐ + # q_0: ┤ Ry(θ[0]) ├──■────■──┤ Ry(θ[3]) ├──────────────■────■──┤ Ry(θ[6]) ├──────────── + # ├──────────┤┌─┴─┐ │ └──────────┘┌──────────┐┌─┴─┐ │ └──────────┘┌──────────┐ + # q_1: ┤ Ry(θ[1]) ├┤ X ├──┼─────────■────┤ Ry(θ[4]) ├┤ X ├──┼─────────■────┤ Ry(θ[7]) ├ + # ├──────────┤└───┘┌─┴─┐ ┌─┴─┐ ├──────────┤└───┘┌─┴─┐ ┌─┴─┐ ├──────────┤ + # q_2: ┤ Ry(θ[2]) ├─────┤ X ├─────┤ X ├──┤ Ry(θ[5]) ├─────┤ X ├─────┤ X ├──┤ Ry(θ[8]) ├ + # └──────────┘ └───┘ └───┘ └──────────┘ └───┘ └───┘ └──────────┘ expected = QuantumCircuit(3) for _ in range(reps): for i in range(num_qubits): @@ -679,22 +675,20 @@ def test_ryrz_circuit(self): parameters = ParameterVector("theta", 2 * num_qubits * (reps + 1)) param_iter = iter(parameters) - """ - ┌──────────┐┌──────────┐┌───┐ ┌──────────┐┌──────────┐ » - q_0: ┤ Ry(θ[0]) ├┤ Rz(θ[3]) ├┤ X ├──■──┤ Ry(θ[6]) ├┤ Rz(θ[9]) ├─────────────» - ├──────────┤├──────────┤└─┬─┘┌─┴─┐└──────────┘├──────────┤┌───────────┐» - q_1: ┤ Ry(θ[1]) ├┤ Rz(θ[4]) ├──┼──┤ X ├─────■──────┤ Ry(θ[7]) ├┤ Rz(θ[10]) ├» - ├──────────┤├──────────┤ │ └───┘ ┌─┴─┐ ├──────────┤├───────────┤» - q_2: ┤ Ry(θ[2]) ├┤ Rz(θ[5]) ├──■──────────┤ X ├────┤ Ry(θ[8]) ├┤ Rz(θ[11]) ├» - └──────────┘└──────────┘ └───┘ └──────────┘└───────────┘» - « ┌───┐ ┌───────────┐┌───────────┐ - «q_0: ┤ X ├──■──┤ Ry(θ[12]) ├┤ Rz(θ[15]) ├───────────── - « └─┬─┘┌─┴─┐└───────────┘├───────────┤┌───────────┐ - «q_1: ──┼──┤ X ├──────■──────┤ Ry(θ[13]) ├┤ Rz(θ[16]) ├ - « │ └───┘ ┌─┴─┐ ├───────────┤├───────────┤ - «q_2: ──■───────────┤ X ├────┤ Ry(θ[14]) ├┤ Rz(θ[17]) ├ - « └───┘ └───────────┘└───────────┘ - """ + # ┌──────────┐┌──────────┐┌───┐ ┌──────────┐┌──────────┐ » + # q_0: ┤ Ry(θ[0]) ├┤ Rz(θ[3]) ├┤ X ├──■──┤ Ry(θ[6]) ├┤ Rz(θ[9]) ├─────────────» + # ├──────────┤├──────────┤└─┬─┘┌─┴─┐└──────────┘├──────────┤┌───────────┐» + # q_1: ┤ Ry(θ[1]) ├┤ Rz(θ[4]) ├──┼──┤ X ├─────■──────┤ Ry(θ[7]) ├┤ Rz(θ[10]) ├» + # ├──────────┤├──────────┤ │ └───┘ ┌─┴─┐ ├──────────┤├───────────┤» + # q_2: ┤ Ry(θ[2]) ├┤ Rz(θ[5]) ├──■──────────┤ X ├────┤ Ry(θ[8]) ├┤ Rz(θ[11]) ├» + # └──────────┘└──────────┘ └───┘ └──────────┘└───────────┘» + # « ┌───┐ ┌───────────┐┌───────────┐ + # «q_0: ┤ X ├──■──┤ Ry(θ[12]) ├┤ Rz(θ[15]) ├───────────── + # « └─┬─┘┌─┴─┐└───────────┘├───────────┤┌───────────┐ + # «q_1: ──┼──┤ X ├──────■──────┤ Ry(θ[13]) ├┤ Rz(θ[16]) ├ + # « │ └───┘ ┌─┴─┐ ├───────────┤├───────────┤ + # «q_2: ──■───────────┤ X ├────┤ Ry(θ[14]) ├┤ Rz(θ[17]) ├ + # « └───┘ └───────────┘└───────────┘ expected = QuantumCircuit(3) for _ in range(reps): for i in range(num_qubits): @@ -741,29 +735,27 @@ def test_swaprz_circuit(self): parameters = ParameterVector("theta", num_qubits * (reps + 1) + reps * (num_qubits - 1)) param_iter = iter(parameters) - """ - ┌──────────┐┌────────────┐┌────────────┐ ┌──────────┐ » - q_0: ┤ Rz(θ[0]) ├┤0 ├┤0 ├─┤ Rz(θ[5]) ├───────────────» - ├──────────┤│ Rxx(θ[3]) ││ Ryy(θ[3]) │┌┴──────────┴┐┌────────────┐» - q_1: ┤ Rz(θ[1]) ├┤1 ├┤1 ├┤0 ├┤0 ├» - ├──────────┤└────────────┘└────────────┘│ Rxx(θ[4]) ││ Ryy(θ[4]) │» - q_2: ┤ Rz(θ[2]) ├────────────────────────────┤1 ├┤1 ├» - └──────────┘ └────────────┘└────────────┘» - « ┌────────────┐┌────────────┐┌───────────┐ » - «q_0: ────────────┤0 ├┤0 ├┤ Rz(θ[10]) ├───────────────» - « ┌──────────┐│ Rxx(θ[8]) ││ Ryy(θ[8]) │├───────────┴┐┌────────────┐» - «q_1: ┤ Rz(θ[6]) ├┤1 ├┤1 ├┤0 ├┤0 ├» - « ├──────────┤└────────────┘└────────────┘│ Rxx(θ[9]) ││ Ryy(θ[9]) │» - «q_2: ┤ Rz(θ[7]) ├────────────────────────────┤1 ├┤1 ├» - « └──────────┘ └────────────┘└────────────┘» - « - «q_0: ───────────── - « ┌───────────┐ - «q_1: ┤ Rz(θ[11]) ├ - « ├───────────┤ - «q_2: ┤ Rz(θ[12]) ├ - « └───────────┘ - """ + # ┌──────────┐┌────────────┐┌────────────┐ ┌──────────┐ » + # q_0: ┤ Rz(θ[0]) ├┤0 ├┤0 ├─┤ Rz(θ[5]) ├───────────────» + # ├──────────┤│ Rxx(θ[3]) ││ Ryy(θ[3]) │┌┴──────────┴┐┌────────────┐» + # q_1: ┤ Rz(θ[1]) ├┤1 ├┤1 ├┤0 ├┤0 ├» + # ├──────────┤└────────────┘└────────────┘│ Rxx(θ[4]) ││ Ryy(θ[4]) │» + # q_2: ┤ Rz(θ[2]) ├────────────────────────────┤1 ├┤1 ├» + # └──────────┘ └────────────┘└────────────┘» + # « ┌────────────┐┌────────────┐┌───────────┐ » + # «q_0: ────────────┤0 ├┤0 ├┤ Rz(θ[10]) ├───────────────» + # « ┌──────────┐│ Rxx(θ[8]) ││ Ryy(θ[8]) │├───────────┴┐┌────────────┐» + # «q_1: ┤ Rz(θ[6]) ├┤1 ├┤1 ├┤0 ├┤0 ├» + # « ├──────────┤└────────────┘└────────────┘│ Rxx(θ[9]) ││ Ryy(θ[9]) │» + # «q_2: ┤ Rz(θ[7]) ├────────────────────────────┤1 ├┤1 ├» + # « └──────────┘ └────────────┘└────────────┘» + # « + # «q_0: ───────────── + # « ┌───────────┐ + # «q_1: ┤ Rz(θ[11]) ├ + # « ├───────────┤ + # «q_2: ┤ Rz(θ[12]) ├ + # « └───────────┘ expected = QuantumCircuit(3) for _ in range(reps): for i in range(num_qubits): @@ -793,29 +785,27 @@ def test_fsim_circuit(self): parameters = [1] * (num_qubits * (reps + 1) + reps * (1 + num_qubits)) param_iter = iter(parameters) - """ - ┌───────┐┌─────────┐┌─────────┐ ┌───────┐ » - q_0: ┤ Rz(1) ├┤0 ├┤0 ├─■──────┤ Rz(1) ├───────────────────» - ├───────┤│ Rxx(1) ││ Ryy(1) │ │P(1) ┌┴───────┴┐┌─────────┐ » - q_1: ┤ Rz(1) ├┤1 ├┤1 ├─■─────┤0 ├┤0 ├─■─────» - ├───────┤└─────────┘└─────────┘ │ Rxx(1) ││ Ryy(1) │ │P(1) » - q_2: ┤ Rz(1) ├─────────────────────────────┤1 ├┤1 ├─■─────» - └───────┘ └─────────┘└─────────┘ » - « ┌─────────┐┌─────────┐ ┌───────┐ » - «q_0: ─────────┤0 ├┤0 ├─■──────┤ Rz(1) ├───────────────────» - « ┌───────┐│ Rxx(1) ││ Ryy(1) │ │P(1) ┌┴───────┴┐┌─────────┐ » - «q_1: ┤ Rz(1) ├┤1 ├┤1 ├─■─────┤0 ├┤0 ├─■─────» - « ├───────┤└─────────┘└─────────┘ │ Rxx(1) ││ Ryy(1) │ │P(1) » - «q_2: ┤ Rz(1) ├─────────────────────────────┤1 ├┤1 ├─■─────» - « └───────┘ └─────────┘└─────────┘ » - « - «q_0: ───────── - « ┌───────┐ - «q_1: ┤ Rz(1) ├ - « ├───────┤ - «q_2: ┤ Rz(1) ├ - « └───────┘ - """ + # ┌───────┐┌─────────┐┌─────────┐ ┌───────┐ » + # q_0: ┤ Rz(1) ├┤0 ├┤0 ├─■──────┤ Rz(1) ├───────────────────» + # ├───────┤│ Rxx(1) ││ Ryy(1) │ │P(1) ┌┴───────┴┐┌─────────┐ » + # q_1: ┤ Rz(1) ├┤1 ├┤1 ├─■─────┤0 ├┤0 ├─■─────» + # ├───────┤└─────────┘└─────────┘ │ Rxx(1) ││ Ryy(1) │ │P(1) » + # q_2: ┤ Rz(1) ├─────────────────────────────┤1 ├┤1 ├─■─────» + # └───────┘ └─────────┘└─────────┘ » + # « ┌─────────┐┌─────────┐ ┌───────┐ » + # «q_0: ─────────┤0 ├┤0 ├─■──────┤ Rz(1) ├───────────────────» + # « ┌───────┐│ Rxx(1) ││ Ryy(1) │ │P(1) ┌┴───────┴┐┌─────────┐ » + # «q_1: ┤ Rz(1) ├┤1 ├┤1 ├─■─────┤0 ├┤0 ├─■─────» + # « ├───────┤└─────────┘└─────────┘ │ Rxx(1) ││ Ryy(1) │ │P(1) » + # «q_2: ┤ Rz(1) ├─────────────────────────────┤1 ├┤1 ├─■─────» + # « └───────┘ └─────────┘└─────────┘ » + # « + # «q_0: ───────── + # « ┌───────┐ + # «q_1: ┤ Rz(1) ├ + # « ├───────┤ + # «q_2: ┤ Rz(1) ├ + # « └───────┘ expected = QuantumCircuit(3) for _ in range(reps): for i in range(num_qubits): @@ -843,13 +833,11 @@ def test_circular_on_same_block_and_circuit_size(self): two = TwoLocal(2, "ry", "cx", entanglement="circular", reps=1) parameters = np.arange(two.num_parameters) - """ - ┌───────┐ ┌───────┐ - q_0: ┤ Ry(0) ├──■──┤ Ry(2) ├ - ├───────┤┌─┴─┐├───────┤ - q_1: ┤ Ry(1) ├┤ X ├┤ Ry(3) ├ - └───────┘└───┘└───────┘ - """ + # ┌───────┐ ┌───────┐ + # q_0: ┤ Ry(0) ├──■──┤ Ry(2) ├ + # ├───────┤┌─┴─┐├───────┤ + # q_1: ┤ Ry(1) ├┤ X ├┤ Ry(3) ├ + # └───────┘└───┘└───────┘ ref = QuantumCircuit(2) ref.ry(parameters[0], 0) ref.ry(parameters[1], 1) diff --git a/test/python/circuit/library/test_pauli_feature_map.py b/test/python/circuit/library/test_pauli_feature_map.py index f222cf3507b2..3b707893199f 100644 --- a/test/python/circuit/library/test_pauli_feature_map.py +++ b/test/python/circuit/library/test_pauli_feature_map.py @@ -61,14 +61,12 @@ def test_pauli_evolution(self): self.assertTrue(Operator(pauli).equiv(evo)) with self.subTest(pauli_string="XYZ"): - """ - q_0: ─────────────■────────────────────────■────────────── - ┌─────────┐┌─┴─┐ ┌─┴─┐┌──────────┐ - q_1: ┤ Rx(π/2) ├┤ X ├──■──────────────■──┤ X ├┤ Rx(-π/2) ├ - └──┬───┬──┘└───┘┌─┴─┐┌────────┐┌─┴─┐├───┤└──────────┘ - q_2: ───┤ H ├────────┤ X ├┤ P(2.8) ├┤ X ├┤ H ├──────────── - └───┘ └───┘└────────┘└───┘└───┘ - """ + # q_0: ─────────────■────────────────────────■────────────── + # ┌─────────┐┌─┴─┐ ┌─┴─┐┌──────────┐ + # q_1: ┤ Rx(π/2) ├┤ X ├──■──────────────■──┤ X ├┤ Rx(-π/2) ├ + # └──┬───┬──┘└───┘┌─┴─┐┌────────┐┌─┴─┐├───┤└──────────┘ + # q_2: ───┤ H ├────────┤ X ├┤ P(2.8) ├┤ X ├┤ H ├──────────── + # └───┘ └───┘└────────┘└───┘└───┘ evo = QuantumCircuit(3) # X on the most-significant, bottom qubit, Z on the top evo.h(2) @@ -94,17 +92,15 @@ def test_first_order_circuit(self): times = [0.2, 1, np.pi, -1.2] encoding = ZFeatureMap(4, reps=3).assign_parameters(times) - """ - ┌───┐ ┌────────┐┌───┐ ┌────────┐┌───┐ ┌────────┐ - q_0: ┤ H ├─┤ P(0.4) ├┤ H ├─┤ P(0.4) ├┤ H ├─┤ P(0.4) ├ - ├───┤ └┬──────┬┘├───┤ └┬──────┬┘├───┤ └┬──────┬┘ - q_1: ┤ H ├──┤ P(2) ├─┤ H ├──┤ P(2) ├─┤ H ├──┤ P(2) ├─ - ├───┤ ┌┴──────┤ ├───┤ ┌┴──────┤ ├───┤ ┌┴──────┤ - q_2: ┤ H ├─┤ P(2π) ├─┤ H ├─┤ P(2π) ├─┤ H ├─┤ P(2π) ├─ - ├───┤┌┴───────┴┐├───┤┌┴───────┴┐├───┤┌┴───────┴┐ - q_3: ┤ H ├┤ P(-2.4) ├┤ H ├┤ P(-2.4) ├┤ H ├┤ P(-2.4) ├ - └───┘└─────────┘└───┘└─────────┘└───┘└─────────┘ - """ + # ┌───┐ ┌────────┐┌───┐ ┌────────┐┌───┐ ┌────────┐ + # q_0: ┤ H ├─┤ P(0.4) ├┤ H ├─┤ P(0.4) ├┤ H ├─┤ P(0.4) ├ + # ├───┤ └┬──────┬┘├───┤ └┬──────┬┘├───┤ └┬──────┬┘ + # q_1: ┤ H ├──┤ P(2) ├─┤ H ├──┤ P(2) ├─┤ H ├──┤ P(2) ├─ + # ├───┤ ┌┴──────┤ ├───┤ ┌┴──────┤ ├───┤ ┌┴──────┤ + # q_2: ┤ H ├─┤ P(2π) ├─┤ H ├─┤ P(2π) ├─┤ H ├─┤ P(2π) ├─ + # ├───┤┌┴───────┴┐├───┤┌┴───────┴┐├───┤┌┴───────┴┐ + # q_3: ┤ H ├┤ P(-2.4) ├┤ H ├┤ P(-2.4) ├┤ H ├┤ P(-2.4) ├ + # └───┘└─────────┘└───┘└─────────┘└───┘└─────────┘ ref = QuantumCircuit(4) for _ in range(3): ref.h([0, 1, 2, 3]) @@ -124,29 +120,27 @@ def zz_evolution(circuit, qubit1, qubit2): circuit.p(2 * time, qubit2) circuit.cx(qubit1, qubit2) - """ - ┌───┐┌────────┐ ┌───┐┌────────┐» - q_0: ┤ H ├┤ P(0.4) ├──■─────────────────■────■────────────■──┤ H ├┤ P(0.4) ├» - ├───┤└┬──────┬┘┌─┴─┐┌───────────┐┌─┴─┐ │ │ └───┘└────────┘» - q_1: ┤ H ├─┤ P(2) ├─┤ X ├┤ P(12.599) ├┤ X ├──┼────────────┼────■────────────» - ├───┤┌┴──────┤ └───┘└───────────┘└───┘┌─┴─┐┌──────┐┌─┴─┐┌─┴─┐ ┌──────┐ » - q_2: ┤ H ├┤ P(2π) ├────────────────────────┤ X ├┤ P(0) ├┤ X ├┤ X ├─┤ P(0) ├─» - └───┘└───────┘ └───┘└──────┘└───┘└───┘ └──────┘ » - « » - «q_0: ─────────────────────■─────────────────■────■────────────■───────────────» - « ┌───┐ ┌──────┐┌─┴─┐┌───────────┐┌─┴─┐ │ │ » - «q_1: ──■──┤ H ├─┤ P(2) ├┤ X ├┤ P(12.599) ├┤ X ├──┼────────────┼────■──────────» - « ┌─┴─┐├───┤┌┴──────┤└───┘└───────────┘└───┘┌─┴─┐┌──────┐┌─┴─┐┌─┴─┐┌──────┐» - «q_2: ┤ X ├┤ H ├┤ P(2π) ├───────────────────────┤ X ├┤ P(0) ├┤ X ├┤ X ├┤ P(0) ├» - « └───┘└───┘└───────┘ └───┘└──────┘└───┘└───┘└──────┘» - « - «q_0: ───── - « - «q_1: ──■── - « ┌─┴─┐ - «q_2: ┤ X ├ - « └───┘ - """ + # ┌───┐┌────────┐ ┌───┐┌────────┐» + # q_0: ┤ H ├┤ P(0.4) ├──■─────────────────■────■────────────■──┤ H ├┤ P(0.4) ├» + # ├───┤└┬──────┬┘┌─┴─┐┌───────────┐┌─┴─┐ │ │ └───┘└────────┘» + # q_1: ┤ H ├─┤ P(2) ├─┤ X ├┤ P(12.599) ├┤ X ├──┼────────────┼────■────────────» + # ├───┤┌┴──────┤ └───┘└───────────┘└───┘┌─┴─┐┌──────┐┌─┴─┐┌─┴─┐ ┌──────┐ » + # q_2: ┤ H ├┤ P(2π) ├────────────────────────┤ X ├┤ P(0) ├┤ X ├┤ X ├─┤ P(0) ├─» + # └───┘└───────┘ └───┘└──────┘└───┘└───┘ └──────┘ » + # « » + # «q_0: ─────────────────────■─────────────────■────■────────────■───────────────» + # « ┌───┐ ┌──────┐┌─┴─┐┌───────────┐┌─┴─┐ │ │ » + # «q_1: ──■──┤ H ├─┤ P(2) ├┤ X ├┤ P(12.599) ├┤ X ├──┼────────────┼────■──────────» + # « ┌─┴─┐├───┤┌┴──────┤└───┘└───────────┘└───┘┌─┴─┐┌──────┐┌─┴─┐┌─┴─┐┌──────┐» + # «q_2: ┤ X ├┤ H ├┤ P(2π) ├───────────────────────┤ X ├┤ P(0) ├┤ X ├┤ X ├┤ P(0) ├» + # « └───┘└───┘└───────┘ └───┘└──────┘└───┘└───┘└──────┘» + # « + # «q_0: ───── + # « + # «q_1: ──■── + # « ┌─┴─┐ + # «q_2: ┤ X ├ + # « └───┘ ref = QuantumCircuit(3) for _ in range(2): ref.h([0, 1, 2]) diff --git a/test/python/circuit/library/test_phase_estimation.py b/test/python/circuit/library/test_phase_estimation.py index dc4bea0c25cc..e1d220d53ffc 100644 --- a/test/python/circuit/library/test_phase_estimation.py +++ b/test/python/circuit/library/test_phase_estimation.py @@ -105,15 +105,13 @@ def test_phase_estimation(self): self.assertPhaseEstimationIsCorrect(pec, eigenstate, phase_as_binary) with self.subTest("a 3-q unitary"): - """ - ┌───┐ - q_0: ┤ X ├──■────■─────── - ├───┤ │ │ - q_1: ┤ X ├──■────■─────── - ├───┤┌───┐┌─┴─┐┌───┐ - q_2: ┤ X ├┤ H ├┤ X ├┤ H ├ - └───┘└───┘└───┘└───┘ - """ + # ┌───┐ + # q_0: ┤ X ├──■────■─────── + # ├───┤ │ │ + # q_1: ┤ X ├──■────■─────── + # ├───┤┌───┐┌─┴─┐┌───┐ + # q_2: ┤ X ├┤ H ├┤ X ├┤ H ├ + # └───┘└───┘└───┘└───┘ unitary = QuantumCircuit(3) unitary.x([0, 1, 2]) unitary.cz(0, 1) @@ -121,15 +119,13 @@ def test_phase_estimation(self): unitary.ccx(0, 1, 2) unitary.h(2) - """ - ┌───┐ - q_0: ┤ H ├──■────■── - └───┘┌─┴─┐ │ - q_1: ─────┤ X ├──┼── - └───┘┌─┴─┐ - q_2: ──────────┤ X ├ - └───┘ - """ + # ┌───┐ + # q_0: ┤ H ├──■────■── + # └───┘┌─┴─┐ │ + # q_1: ─────┤ X ├──┼── + # └───┘┌─┴─┐ + # q_2: ──────────┤ X ├ + # └───┘ eigenstate = QuantumCircuit(3) eigenstate.h(0) eigenstate.cx(0, 1) diff --git a/test/python/circuit/library/test_random_pauli.py b/test/python/circuit/library/test_random_pauli.py index 8d64950d271b..6ffd43068861 100644 --- a/test/python/circuit/library/test_random_pauli.py +++ b/test/python/circuit/library/test_random_pauli.py @@ -31,19 +31,17 @@ def test_random_pauli(self): qr = QuantumRegister(4, "q") params = circuit.ordered_parameters - """ - expected circuit for the random seed 12 - - ┌─────────┐┌──────────┐ ┌──────────┐ - q_0: ┤ Ry(π/4) ├┤ Ry(θ[0]) ├─■─┤ Rx(θ[4]) ├──────────── - ├─────────┤├──────────┤ │ └──────────┘┌──────────┐ - q_1: ┤ Ry(π/4) ├┤ Rx(θ[1]) ├─■──────■──────┤ Rx(θ[5]) ├ - ├─────────┤├──────────┤ │ ├──────────┤ - q_2: ┤ Ry(π/4) ├┤ Rz(θ[2]) ├─■──────■──────┤ Rx(θ[6]) ├ - ├─────────┤├──────────┤ │ ┌──────────┐└──────────┘ - q_3: ┤ Ry(π/4) ├┤ Rz(θ[3]) ├─■─┤ Rx(θ[7]) ├──────────── - └─────────┘└──────────┘ └──────────┘ - """ + # expected circuit for the random seed 12 + # + # ┌─────────┐┌──────────┐ ┌──────────┐ + # q_0: ┤ Ry(π/4) ├┤ Ry(θ[0]) ├─■─┤ Rx(θ[4]) ├──────────── + # ├─────────┤├──────────┤ │ └──────────┘┌──────────┐ + # q_1: ┤ Ry(π/4) ├┤ Rx(θ[1]) ├─■──────■──────┤ Rx(θ[5]) ├ + # ├─────────┤├──────────┤ │ ├──────────┤ + # q_2: ┤ Ry(π/4) ├┤ Rz(θ[2]) ├─■──────■──────┤ Rx(θ[6]) ├ + # ├─────────┤├──────────┤ │ ┌──────────┐└──────────┘ + # q_3: ┤ Ry(π/4) ├┤ Rz(θ[3]) ├─■─┤ Rx(θ[7]) ├──────────── + # └─────────┘└──────────┘ └──────────┘ expected = QuantumCircuit(qr) # initial RYs diff --git a/test/python/circuit/test_controlled_gate.py b/test/python/circuit/test_controlled_gate.py index 3376c27a613f..79069b657de4 100644 --- a/test/python/circuit/test_controlled_gate.py +++ b/test/python/circuit/test_controlled_gate.py @@ -914,15 +914,13 @@ def test_open_control_ccx_unrolling(self): unroller = Unroller(["x", "ccx"]) unrolled_dag = unroller.run(dag) - """ - ┌───┐ ┌───┐ - q0_0: ┤ X ├──■──┤ X ├ - ├───┤ │ ├───┤ - q0_1: ┤ X ├──■──┤ X ├ - └───┘┌─┴─┐└───┘ - q0_2: ─────┤ X ├───── - └───┘ - """ + # ┌───┐ ┌───┐ + # q0_0: ┤ X ├──■──┤ X ├ + # ├───┤ │ ├───┤ + # q0_1: ┤ X ├──■──┤ X ├ + # └───┘┌─┴─┐└───┘ + # q0_2: ─────┤ X ├───── + # └───┘ ref_circuit = QuantumCircuit(qreg) ref_circuit.x(qreg[0]) ref_circuit.x(qreg[1]) diff --git a/test/python/circuit/test_tensor.py b/test/python/circuit/test_tensor.py index d37247d0ea3b..442cfbb4ccd5 100644 --- a/test/python/circuit/test_tensor.py +++ b/test/python/circuit/test_tensor.py @@ -132,19 +132,17 @@ def test_multiple_registers(self): qrs = [QuantumRegister(1) for _ in range(6)] crs = [ClassicalRegister(1) for _ in range(2)] - """ - ┌───┐ - q0: ┤ H ├───────■────────────── - ├───┤┌───┐ │ - q1: ┤ X ├┤ H ├──■────────────── - └───┘└───┘ │ ┌───────┐┌─┐ - q2: ────────────┼──┤ Ry(p) ├┤M├ - ┌─┴─┐└───┬───┘└╥┘ - q3: ──────────┤ X ├────■─────╫─ - └───┘ ║ - c0: 1/═══════════════════════╩═ - 0 - """ + # ┌───┐ + # q0: ┤ H ├───────■────────────── + # ├───┤┌───┐ │ + # q1: ┤ X ├┤ H ├──■────────────── + # └───┘└───┘ │ ┌───────┐┌─┐ + # q2: ────────────┼──┤ Ry(p) ├┤M├ + # ┌─┴─┐└───┬───┘└╥┘ + # q3: ──────────┤ X ├────■─────╫─ + # └───┘ ║ + # c0: 1/═══════════════════════╩═ + # 0 top = QuantumCircuit(*qrs[:4], crs[0]) top.h(0) top.x(1) @@ -153,41 +151,36 @@ def test_multiple_registers(self): top.cry(p, 3, 2) top.measure(2, 0) - """ - ┌────┐┌──────┐ - q4: ┤ √X ├┤ P(q) ├──■───── - └────┘└──────┘┌─┴─┐┌─┐ - q5: ──────────────┤ X ├┤M├ - └───┘└╥┘ - c1: 1/══════════════════╩═ - 0 - """ + # ┌────┐┌──────┐ + # q4: ┤ √X ├┤ P(q) ├──■───── + # └────┘└──────┘┌─┴─┐┌─┐ + # q5: ──────────────┤ X ├┤M├ + # └───┘└╥┘ + # c1: 1/══════════════════╩═ + # 0 bottom = QuantumCircuit(*qrs[4:], crs[1]) bottom.sx(0) bottom.p(q, 0) bottom.cx(0, 1) bottom.measure(1, 0) - """ - ┌───┐ - q0: ┤ H ├───────────■────────────── - ├───┤ ┌───┐ │ - q1: ┤ X ├──┤ H ├────■────────────── - └───┘ └───┘ │ ┌───────┐┌─┐ - q2: ────────────────┼──┤ Ry(p) ├┤M├ - ┌─┴─┐└───┬───┘└╥┘ - q3: ──────────────┤ X ├────■─────╫─ - ┌────┐┌──────┐└───┘ ║ - q4: ┤ √X ├┤ P(q) ├──■────────────╫─ - └────┘└──────┘┌─┴─┐ ┌─┐ ║ - q5: ──────────────┤ X ├───┤M├────╫─ - └───┘ └╥┘ ║ - c0: 1/═════════════════════╬═════╩═ - ║ 0 - ║ - c1: 1/═════════════════════╩═══════ - 0 - """ + # ┌───┐ + # q0: ┤ H ├───────────■────────────── + # ├───┤ ┌───┐ │ + # q1: ┤ X ├──┤ H ├────■────────────── + # └───┘ └───┘ │ ┌───────┐┌─┐ + # q2: ────────────────┼──┤ Ry(p) ├┤M├ + # ┌─┴─┐└───┬───┘└╥┘ + # q3: ──────────────┤ X ├────■─────╫─ + # ┌────┐┌──────┐└───┘ ║ + # q4: ┤ √X ├┤ P(q) ├──■────────────╫─ + # └────┘└──────┘┌─┴─┐ ┌─┐ ║ + # q5: ──────────────┤ X ├───┤M├────╫─ + # └───┘ └╥┘ ║ + # c0: 1/═════════════════════╬═════╩═ + # ║ 0 + # c1: 1/═════════════════════╩═══════ + # 0 expect = QuantumCircuit(*qrs, *crs) expect.h(0) expect.x(1) diff --git a/test/python/compiler/test_compiler.py b/test/python/compiler/test_compiler.py index 9e247608c23f..d602fffcf627 100644 --- a/test/python/compiler/test_compiler.py +++ b/test/python/compiler/test_compiler.py @@ -142,23 +142,21 @@ def test_example_swap_bits(self): [14, 15], ] - """ - ┌───┐ ░ ┌─┐ - q0_0: ┤ X ├─X───────────░─┤M├─────────────── - └───┘ │ ░ └╥┘ ┌─┐ - q0_1: ──────┼─────X──X──░──╫────┤M├───────── - │ │ │ ░ ║ └╥┘ ┌─┐ - q0_2: ──────X──X──┼──┼──░──╫─────╫────┤M├─── - │ │ │ ░ ║ ┌─┐ ║ └╥┘ - q1_0: ─────────┼──┼──┼──░──╫─┤M├─╫─────╫──── - │ │ │ ░ ║ └╥┘ ║ ┌─┐ ║ - q1_1: ─────────┼──┼──X──░──╫──╫──╫─┤M├─╫──── - │ │ ░ ║ ║ ║ └╥┘ ║ ┌─┐ - q1_2: ─────────X──X─────░──╫──╫──╫──╫──╫─┤M├ - ░ ║ ║ ║ ║ ║ └╥┘ - c0: 6/═════════════════════╩══╩══╩══╩══╩══╩═ - 0 3 1 4 2 5 - """ + # ┌───┐ ░ ┌─┐ + # q0_0: ┤ X ├─X───────────░─┤M├─────────────── + # └───┘ │ ░ └╥┘ ┌─┐ + # q0_1: ──────┼─────X──X──░──╫────┤M├───────── + # │ │ │ ░ ║ └╥┘ ┌─┐ + # q0_2: ──────X──X──┼──┼──░──╫─────╫────┤M├─── + # │ │ │ ░ ║ ┌─┐ ║ └╥┘ + # q1_0: ─────────┼──┼──┼──░──╫─┤M├─╫─────╫──── + # │ │ │ ░ ║ └╥┘ ║ ┌─┐ ║ + # q1_1: ─────────┼──┼──X──░──╫──╫──╫─┤M├─╫──── + # │ │ ░ ║ ║ ║ └╥┘ ║ ┌─┐ + # q1_2: ─────────X──X─────░──╫──╫──╫──╫──╫─┤M├ + # ░ ║ ║ ║ ║ ║ └╥┘ + # c0: 6/═════════════════════╩══╩══╩══╩══╩══╩═ + # 0 3 1 4 2 5 n = 3 # make this at least 3 qr0 = QuantumRegister(n) qr1 = QuantumRegister(n) @@ -332,25 +330,23 @@ def test_grovers_circuit(self): shots = 1000 coupling_map = None - """ - 6-qubit grovers - - ┌───┐┌───┐ ┌───┐┌───┐ ┌───┐ ┌───┐┌───┐ ░ ┌─┐ - q0_0: ┤ H ├┤ X ├──■──┤ X ├┤ X ├──■──┤ X ├──■──┤ X ├┤ H ├──────░─┤M├─── - ├───┤└───┘ │ └───┘└───┘ │ ├───┤ │ ├───┤├───┤ ░ └╥┘┌─┐ - q0_1: ┤ H ├──■────┼─────────■────┼──┤ X ├──■──┤ X ├┤ H ├──────░──╫─┤M├ - ├───┤ │ ┌─┴─┐ │ ┌─┴─┐└───┘ │ └───┘└───┘ ░ ║ └╥┘ - q0_2: ┤ X ├──┼──┤ X ├──■────┼──┤ X ├───────┼──────────────────░──╫──╫─ - ├───┤┌─┴─┐└───┘ │ ┌─┴─┐└───┘ │ ░ ║ ║ - q0_3: ┤ X ├┤ X ├───────■──┤ X ├────────────┼──────────────────░──╫──╫─ - └───┘└───┘ ┌─┴─┐├───┤┌───┐ ┌─┴─┐┌───┐┌───┐┌───┐ ░ ║ ║ - q0_4: ───────────────┤ X ├┤ X ├┤ H ├─────┤ X ├┤ H ├┤ X ├┤ H ├─░──╫──╫─ - └───┘└───┘└───┘ └───┘└───┘└───┘└───┘ ░ ║ ║ - q0_5: ────────────────────────────────────────────────────────░──╫──╫─ - ░ ║ ║ - c0: 2/═══════════════════════════════════════════════════════════╩══╩═ - 0 1 - """ + # 6-qubit grovers + # + # ┌───┐┌───┐ ┌───┐┌───┐ ┌───┐ ┌───┐┌───┐ ░ ┌─┐ + # q0_0: ┤ H ├┤ X ├──■──┤ X ├┤ X ├──■──┤ X ├──■──┤ X ├┤ H ├──────░─┤M├─── + # ├───┤└───┘ │ └───┘└───┘ │ ├───┤ │ ├───┤├───┤ ░ └╥┘┌─┐ + # q0_1: ┤ H ├──■────┼─────────■────┼──┤ X ├──■──┤ X ├┤ H ├──────░──╫─┤M├ + # ├───┤ │ ┌─┴─┐ │ ┌─┴─┐└───┘ │ └───┘└───┘ ░ ║ └╥┘ + # q0_2: ┤ X ├──┼──┤ X ├──■────┼──┤ X ├───────┼──────────────────░──╫──╫─ + # ├───┤┌─┴─┐└───┘ │ ┌─┴─┐└───┘ │ ░ ║ ║ + # q0_3: ┤ X ├┤ X ├───────■──┤ X ├────────────┼──────────────────░──╫──╫─ + # └───┘└───┘ ┌─┴─┐├───┤┌───┐ ┌─┴─┐┌───┐┌───┐┌───┐ ░ ║ ║ + # q0_4: ───────────────┤ X ├┤ X ├┤ H ├─────┤ X ├┤ H ├┤ X ├┤ H ├─░──╫──╫─ + # └───┘└───┘└───┘ └───┘└───┘└───┘└───┘ ░ ║ ║ + # q0_5: ────────────────────────────────────────────────────────░──╫──╫─ + # ░ ║ ║ + # c0: 2/═══════════════════════════════════════════════════════════╩══╩═ + # 0 1 qr = QuantumRegister(6) cr = ClassicalRegister(2) circuit = QuantumCircuit(qr, cr, name="grovers") diff --git a/test/python/quantum_info/operators/test_dihedral.py b/test/python/quantum_info/operators/test_dihedral.py index 91039c78e0d6..b1b013d33a5f 100644 --- a/test/python/quantum_info/operators/test_dihedral.py +++ b/test/python/quantum_info/operators/test_dihedral.py @@ -178,15 +178,13 @@ def test_2_qubit_identities(self): self.assertEqual(elem, elem1, "Error: 2-qubit SWAP identity does not hold") self.assertEqual(elem1, elem2, "Error: 2-qubit SWAP identity does not hold") - """ - CS01 = CS10 (symmetric) - - ┌───┐ - q_0: ┤ T ├──■───────────■── - ├───┤┌─┴─┐┌─────┐┌─┴─┐ - q_1: ┤ T ├┤ X ├┤ Tdg ├┤ X ├ - └───┘└───┘└─────┘└───┘ - """ + # CS01 = CS10 (symmetric) + # + # ┌───┐ + # q_0: ┤ T ├──■───────────■── + # ├───┤┌─┴─┐┌─────┐┌─┴─┐ + # q_1: ┤ T ├┤ X ├┤ Tdg ├┤ X ├ + # └───┘└───┘└─────┘└───┘ circ1 = QuantumCircuit(2) circ1.t(0) circ1.t(1) @@ -194,13 +192,11 @@ def test_2_qubit_identities(self): circ1.tdg(1) circ1.cx(0, 1) - """ - ┌───┐┌───┐┌─────┐┌───┐ - q_0: ┤ T ├┤ X ├┤ Tdg ├┤ X ├ - ├───┤└─┬─┘└─────┘└─┬─┘ - q_1: ┤ T ├──■───────────■── - └───┘ - """ + # ┌───┐┌───┐┌─────┐┌───┐ + # q_0: ┤ T ├┤ X ├┤ Tdg ├┤ X ├ + # ├───┤└─┬─┘└─────┘└─┬─┘ + # q_1: ┤ T ├──■───────────■── + # └───┘ circ2 = QuantumCircuit(2) circ2.t(1) circ2.t(0) @@ -211,15 +207,13 @@ def test_2_qubit_identities(self): elem2 = CNOTDihedral(circ2) self.assertEqual(elem1, elem2, "Error: 2-qubit CS identity does not hold") - """ - TI*CS*TdgI = CS - - ┌───┐┌───┐ ┌─────┐ - q_0: ┤ T ├┤ T ├──■───────────■──┤ Tdg ├ - ├───┤└───┘┌─┴─┐┌─────┐┌─┴─┐└─────┘ - q_1: ┤ T ├─────┤ X ├┤ Tdg ├┤ X ├─────── - └───┘ └───┘└─────┘└───┘ - """ + # TI*CS*TdgI = CS + # + # ┌───┐┌───┐ ┌─────┐ + # q_0: ┤ T ├┤ T ├──■───────────■──┤ Tdg ├ + # ├───┤└───┘┌─┴─┐┌─────┐┌─┴─┐└─────┘ + # q_1: ┤ T ├─────┤ X ├┤ Tdg ├┤ X ├─────── + # └───┘ └───┘└─────┘└───┘ circ3 = QuantumCircuit(2) circ3.t(0) circ3.t(0) @@ -231,15 +225,13 @@ def test_2_qubit_identities(self): elem3 = CNOTDihedral(circ3) self.assertEqual(elem1, elem3, "Error: 2-qubit CS identity does not hold") - """ - IT*CS*ITdg = CS - - ┌───┐ - q_0: ┤ T ├───────■───────────■───────── - ├───┤┌───┐┌─┴─┐┌─────┐┌─┴─┐┌─────┐ - q_1: ┤ T ├┤ T ├┤ X ├┤ Tdg ├┤ X ├┤ Tdg ├ - └───┘└───┘└───┘└─────┘└───┘└─────┘ - """ + # IT*CS*ITdg = CS + # + # ┌───┐ + # q_0: ┤ T ├───────■───────────■───────── + # ├───┤┌───┐┌─┴─┐┌─────┐┌─┴─┐┌─────┐ + # q_1: ┤ T ├┤ T ├┤ X ├┤ Tdg ├┤ X ├┤ Tdg ├ + # └───┘└───┘└───┘└─────┘└───┘└─────┘ circ4 = QuantumCircuit(2) circ4.t(1) circ4.t(0) @@ -251,15 +243,13 @@ def test_2_qubit_identities(self): elem4 = CNOTDihedral(circ4) self.assertEqual(elem1, elem4, "Error: 2-qubit CS identity does not hold") - """ - XX*CS*XX*SS = CS - - ┌───┐┌───┐ ┌───┐┌───┐ - q_0: ┤ X ├┤ T ├──■───────────■──┤ X ├┤ S ├ - ├───┤├───┤┌─┴─┐┌─────┐┌─┴─┐├───┤├───┤ - q_1: ┤ X ├┤ T ├┤ X ├┤ Tdg ├┤ X ├┤ X ├┤ S ├ - └───┘└───┘└───┘└─────┘└───┘└───┘└───┘ - """ + # XX*CS*XX*SS = CS + # + # ┌───┐┌───┐ ┌───┐┌───┐ + # q_0: ┤ X ├┤ T ├──■───────────■──┤ X ├┤ S ├ + # ├───┤├───┤┌─┴─┐┌─────┐┌─┴─┐├───┤├───┤ + # q_1: ┤ X ├┤ T ├┤ X ├┤ Tdg ├┤ X ├┤ X ├┤ S ├ + # └───┘└───┘└───┘└─────┘└───┘└───┘└───┘ circ5 = QuantumCircuit(2) circ5.x(0) circ5.x(1) @@ -275,15 +265,13 @@ def test_2_qubit_identities(self): elem5 = CNOTDihedral(circ5) self.assertEqual(elem1, elem5, "Error: 2-qubit CS identity does not hold") - """ - CSdg01 = CSdg10 (symmetric) - - ┌─────┐ - q_0: ┤ Tdg ├──■─────────■── - ├─────┤┌─┴─┐┌───┐┌─┴─┐ - q_1: ┤ Tdg ├┤ X ├┤ T ├┤ X ├ - └─────┘└───┘└───┘└───┘ - """ + # CSdg01 = CSdg10 (symmetric) + # + # ┌─────┐ + # q_0: ┤ Tdg ├──■─────────■── + # ├─────┤┌─┴─┐┌───┐┌─┴─┐ + # q_1: ┤ Tdg ├┤ X ├┤ T ├┤ X ├ + # └─────┘└───┘└───┘└───┘ circ1 = QuantumCircuit(2) circ1.tdg(0) circ1.tdg(1) @@ -291,13 +279,11 @@ def test_2_qubit_identities(self): circ1.t(1) circ1.cx(0, 1) - """ - ┌─────┐┌───┐┌───┐┌───┐ - q_0: ┤ Tdg ├┤ X ├┤ T ├┤ X ├ - ├─────┤└─┬─┘└───┘└─┬─┘ - q_1: ┤ Tdg ├──■─────────■── - └─────┘ - """ + # ┌─────┐┌───┐┌───┐┌───┐ + # q_0: ┤ Tdg ├┤ X ├┤ T ├┤ X ├ + # ├─────┤└─┬─┘└───┘└─┬─┘ + # q_1: ┤ Tdg ├──■─────────■── + # └─────┘ circ2 = QuantumCircuit(2) circ2.tdg(1) circ2.tdg(0) @@ -308,15 +294,13 @@ def test_2_qubit_identities(self): elem2 = CNOTDihedral(circ2) self.assertEqual(elem1, elem2, "Error: 2-qubit CSdg identity does not hold") - """ - XI*CS*XI*ISdg = CSdg - - ┌───┐┌───┐ ┌───┐ - q_0: ┤ X ├┤ T ├──■───────────■───┤ X ├─ - ├───┤└───┘┌─┴─┐┌─────┐┌─┴─┐┌┴───┴┐ - q_1: ┤ T ├─────┤ X ├┤ Tdg ├┤ X ├┤ Sdg ├ - └───┘ └───┘└─────┘└───┘└─────┘ - """ + # XI*CS*XI*ISdg = CSdg + # + # ┌───┐┌───┐ ┌───┐ + # q_0: ┤ X ├┤ T ├──■───────────■───┤ X ├─ + # ├───┤└───┘┌─┴─┐┌─────┐┌─┴─┐┌┴───┴┐ + # q_1: ┤ T ├─────┤ X ├┤ Tdg ├┤ X ├┤ Sdg ├ + # └───┘ └───┘└─────┘└───┘└─────┘ circ3 = QuantumCircuit(2) circ3.x(0) circ3.t(0) @@ -329,15 +313,13 @@ def test_2_qubit_identities(self): elem3 = CNOTDihedral(circ3) self.assertEqual(elem1, elem3, "Error: 2-qubit CSdg identity does not hold") - """ - IX*CS*IX*SdgI = CSdg - - ┌───┐ ┌─────┐ - q_0: ┤ T ├───────■───────────■──┤ Sdg ├ - ├───┤┌───┐┌─┴─┐┌─────┐┌─┴─┐└┬───┬┘ - q_1: ┤ X ├┤ T ├┤ X ├┤ Tdg ├┤ X ├─┤ X ├─ - └───┘└───┘└───┘└─────┘└───┘ └───┘ - """ + # IX*CS*IX*SdgI = CSdg + # + # ┌───┐ ┌─────┐ + # q_0: ┤ T ├───────■───────────■──┤ Sdg ├ + # ├───┤┌───┐┌─┴─┐┌─────┐┌─┴─┐└┬───┬┘ + # q_1: ┤ X ├┤ T ├┤ X ├┤ Tdg ├┤ X ├─┤ X ├─ + # └───┘└───┘└───┘└─────┘└───┘ └───┘ circ4 = QuantumCircuit(2) circ4.x(1) circ4.t(0) @@ -362,15 +344,13 @@ def test_2_qubit_identities(self): self.assertEqual(elem, elem1, "Error: 2-qubit CZ identity does not hold") self.assertEqual(elem1, elem2, "Error: 2-qubit CZ identity does not hold") - """ - CZ = CS * CS - - ┌───┐ ┌───┐ - q_0: ┤ T ├──■───────────■──┤ T ├──■───────────■── - ├───┤┌─┴─┐┌─────┐┌─┴─┐├───┤┌─┴─┐┌─────┐┌─┴─┐ - q_1: ┤ T ├┤ X ├┤ Tdg ├┤ X ├┤ T ├┤ X ├┤ Tdg ├┤ X ├ - └───┘└───┘└─────┘└───┘└───┘└───┘└─────┘└───┘ - """ + # CZ = CS * CS + # + # ┌───┐ ┌───┐ + # q_0: ┤ T ├──■───────────■──┤ T ├──■───────────■── + # ├───┤┌─┴─┐┌─────┐┌─┴─┐├───┤┌─┴─┐┌─────┐┌─┴─┐ + # q_1: ┤ T ├┤ X ├┤ Tdg ├┤ X ├┤ T ├┤ X ├┤ Tdg ├┤ X ├ + # └───┘└───┘└─────┘└───┘└───┘└───┘└─────┘└───┘ circ3 = QuantumCircuit(2) circ3.t(0) circ3.t(1) @@ -385,15 +365,13 @@ def test_2_qubit_identities(self): elem3 = CNOTDihedral(circ3) self.assertEqual(elem1, elem3, "Error: 2-qubit CZ identity does not hold") - """ - CZ = CSdg * CSdg - - ┌─────┐ ┌─────┐ - q_0: ┤ Tdg ├──■─────────■──┤ Tdg ├──■─────────■── - ├─────┤┌─┴─┐┌───┐┌─┴─┐├─────┤┌─┴─┐┌───┐┌─┴─┐ - q_1: ┤ Tdg ├┤ X ├┤ T ├┤ X ├┤ Tdg ├┤ X ├┤ T ├┤ X ├ - └─────┘└───┘└───┘└───┘└─────┘└───┘└───┘└───┘ - """ + # CZ = CSdg * CSdg + # + # ┌─────┐ ┌─────┐ + # q_0: ┤ Tdg ├──■─────────■──┤ Tdg ├──■─────────■── + # ├─────┤┌─┴─┐┌───┐┌─┴─┐├─────┤┌─┴─┐┌───┐┌─┴─┐ + # q_1: ┤ Tdg ├┤ X ├┤ T ├┤ X ├┤ Tdg ├┤ X ├┤ T ├┤ X ├ + # └─────┘└───┘└───┘└───┘└─────┘└───┘└───┘└───┘ circ4 = QuantumCircuit(2) circ4.tdg(0) circ4.tdg(1) @@ -408,15 +386,13 @@ def test_2_qubit_identities(self): elem4 = CNOTDihedral(circ4) self.assertEqual(elem1, elem4, "Error: 2-qubit CZ identity does not hold") - """ - CZ = TdgTdg * CX * T^2I * CX * TdgTdg - - ┌─────┐┌───┐┌───┐┌───┐┌───┐┌─────┐ - q_0: ┤ Tdg ├┤ X ├┤ T ├┤ T ├┤ X ├┤ Tdg ├ - ├─────┤└─┬─┘└───┘└───┘└─┬─┘├─────┤ - q_1: ┤ Tdg ├──■──────────────■──┤ Tdg ├ - └─────┘ └─────┘ - """ + # CZ = TdgTdg * CX * T^2I * CX * TdgTdg + # + # ┌─────┐┌───┐┌───┐┌───┐┌───┐┌─────┐ + # q_0: ┤ Tdg ├┤ X ├┤ T ├┤ T ├┤ X ├┤ Tdg ├ + # ├─────┤└─┬─┘└───┘└───┘└─┬─┘├─────┤ + # q_1: ┤ Tdg ├──■──────────────■──┤ Tdg ├ + # └─────┘ └─────┘ circ5 = QuantumCircuit(2) circ5.tdg(0) circ5.tdg(1) @@ -434,15 +410,13 @@ def test_2_qubit_identities(self): circ1.cx(0, 1) elem1 = CNOTDihedral(circ1) - """ - TI*CX*TdgI = CX - - ┌───┐ ┌─────┐ - q_0: ┤ T ├──■──┤ Tdg ├ - └───┘┌─┴─┐└─────┘ - q_1: ─────┤ X ├─────── - └───┘ - """ + # TI*CX*TdgI = CX + # + # ┌───┐ ┌─────┐ + # q_0: ┤ T ├──■──┤ Tdg ├ + # └───┘┌─┴─┐└─────┘ + # q_1: ─────┤ X ├─────── + # └───┘ circ2 = QuantumCircuit(2) circ2.t(0) circ2.cx(0, 1) @@ -450,15 +424,13 @@ def test_2_qubit_identities(self): elem2 = CNOTDihedral(circ2) self.assertEqual(elem1, elem2, "Error: 2-qubit CX identity does not hold") - """ - IZ*CX*ZZ = CX - - ┌───┐ - q_0: ───────■──┤ Z ├ - ┌───┐┌─┴─┐├───┤ - q_1: ┤ Z ├┤ X ├┤ Z ├ - └───┘└───┘└───┘ - """ + # IZ*CX*ZZ = CX + # + # ┌───┐ + # q_0: ───────■──┤ Z ├ + # ┌───┐┌─┴─┐├───┤ + # q_1: ┤ Z ├┤ X ├┤ Z ├ + # └───┘└───┘└───┘ circ3 = QuantumCircuit(2) circ3.z(1) circ3.cx(0, 1) @@ -467,14 +439,12 @@ def test_2_qubit_identities(self): elem3 = CNOTDihedral(circ3) self.assertEqual(elem1, elem3, "Error: 2-qubit CX identity does not hold") - """ - IX*CX*IX = CX - - q_0: ───────■─────── - ┌───┐┌─┴─┐┌───┐ - q_1: ┤ X ├┤ X ├┤ X ├ - └───┘└───┘└───┘ - """ + # IX*CX*IX = CX + # + # q_0: ───────■─────── + # ┌───┐┌─┴─┐┌───┐ + # q_1: ┤ X ├┤ X ├┤ X ├ + # └───┘└───┘└───┘ circ4 = QuantumCircuit(2) circ4.x(1) circ4.cx(0, 1) @@ -482,15 +452,13 @@ def test_2_qubit_identities(self): elem4 = CNOTDihedral(circ4) self.assertEqual(elem1, elem4, "Error: 2-qubit CX identity does not hold") - """ - XI*CX*XX = CX - - ┌───┐ ┌───┐ - q_0: ┤ X ├──■──┤ X ├ - └───┘┌─┴─┐├───┤ - q_1: ─────┤ X ├┤ X ├ - └───┘└───┘ - """ + # XI*CX*XX = CX + # + # ┌───┐ ┌───┐ + # q_0: ┤ X ├──■──┤ X ├ + # └───┘┌─┴─┐├───┤ + # q_1: ─────┤ X ├┤ X ├ + # └───┘└───┘ circ5 = QuantumCircuit(2) circ5.x(0) circ5.cx(0, 1) @@ -499,26 +467,22 @@ def test_2_qubit_identities(self): elem5 = CNOTDihedral(circ5) self.assertEqual(elem1, elem5, "Error: 2-qubit CX identity does not hold") - """ - IT*CX01*CX10*TdgI = CX01*CX10 - - ┌───┐ - q_0: ──■──┤ X ├ - ┌─┴─┐└─┬─┘ - q_1: ┤ X ├──■── - └───┘ - """ + # IT*CX01*CX10*TdgI = CX01*CX10 + # + # ┌───┐ + # q_0: ──■──┤ X ├ + # ┌─┴─┐└─┬─┘ + # q_1: ┤ X ├──■── + # └───┘ circ1 = QuantumCircuit(2) circ1.cx(0, 1) circ1.cx(1, 0) - """ - ┌───┐┌─────┐ - q_0: ───────■──┤ X ├┤ Tdg ├ - ┌───┐┌─┴─┐└─┬─┘└─────┘ - q_1: ┤ T ├┤ X ├──■───────── - └───┘└───┘ - """ + # ┌───┐┌─────┐ + # q_0: ───────■──┤ X ├┤ Tdg ├ + # ┌───┐┌─┴─┐└─┬─┘└─────┘ + # q_1: ┤ T ├┤ X ├──■───────── + # └───┘└───┘ circ2 = QuantumCircuit(2) circ2.t(1) circ2.cx(0, 1) diff --git a/test/python/quantum_info/test_analyzation.py b/test/python/quantum_info/test_analyzation.py index 295ad5c564ea..9feed4f390f1 100644 --- a/test/python/quantum_info/test_analyzation.py +++ b/test/python/quantum_info/test_analyzation.py @@ -142,22 +142,21 @@ def test_hellinger_fidelity_same(self): self.assertEqual(ans, 1.0) def test_hellinger_fidelity_no_overlap(self): - """Test hellinger fidelity is zero for no overlap. - - ┌───┐ ┌─┐ - q_0: ──────────┤ X ├─────┤M├──────────── - ┌───┐└─┬─┘ └╥┘┌─┐ - q_1: ─────┤ X ├──■────────╫─┤M├───────── - ┌───┐└─┬─┘ ║ └╥┘┌─┐ - q_2: ┤ H ├──■────■────────╫──╫─┤M├────── - └───┘ ┌─┴─┐ ║ ║ └╥┘┌─┐ - q_3: ──────────┤ X ├──■───╫──╫──╫─┤M├─── - └───┘┌─┴─┐ ║ ║ ║ └╥┘┌─┐ - q_4: ───────────────┤ X ├─╫──╫──╫──╫─┤M├ - └───┘ ║ ║ ║ ║ └╥┘ - c: 5/═════════════════════╩══╩══╩══╩══╩═ - 0 1 2 3 4 - """ + """Test hellinger fidelity is zero for no overlap.""" + + # ┌───┐ ┌─┐ + # q_0: ──────────┤ X ├─────┤M├──────────── + # ┌───┐└─┬─┘ └╥┘┌─┐ + # q_1: ─────┤ X ├──■────────╫─┤M├───────── + # ┌───┐└─┬─┘ ║ └╥┘┌─┐ + # q_2: ┤ H ├──■────■────────╫──╫─┤M├────── + # └───┘ ┌─┴─┐ ║ ║ └╥┘┌─┐ + # q_3: ──────────┤ X ├──■───╫──╫──╫─┤M├─── + # └───┘┌─┴─┐ ║ ║ ║ └╥┘┌─┐ + # q_4: ───────────────┤ X ├─╫──╫──╫──╫─┤M├ + # └───┘ ║ ║ ║ ║ └╥┘ + # c: 5/═════════════════════╩══╩══╩══╩══╩═ + # 0 1 2 3 4 qc = qiskit.QuantumCircuit(5, 5) qc.h(2) qc.cx(2, 1) @@ -166,21 +165,19 @@ def test_hellinger_fidelity_no_overlap(self): qc.cx(1, 0) qc.measure(range(5), range(5)) - """ - ┌───┐ ┌─┐ - q_0: ──────────┤ X ├─────┤M├───────── - ┌───┐└─┬─┘ └╥┘┌─┐ - q_1: ─────┤ X ├──■────────╫─┤M├────── - ┌───┐└─┬─┘┌───┐ ║ └╥┘┌─┐ - q_2: ┤ H ├──■──┤ Y ├──■───╫──╫─┤M├─── - └───┘ └───┘┌─┴─┐ ║ ║ └╥┘┌─┐ - q_3: ───────────────┤ X ├─╫──╫──╫─┤M├ - ┌─┐ └───┘ ║ ║ ║ └╥┘ - q_4: ─┤M├─────────────────╫──╫──╫──╫─ - └╥┘ ║ ║ ║ ║ - c: 5/══╩══════════════════╩══╩══╩══╩═ - 4 0 1 2 3 - """ + # ┌───┐ ┌─┐ + # q_0: ──────────┤ X ├─────┤M├───────── + # ┌───┐└─┬─┘ └╥┘┌─┐ + # q_1: ─────┤ X ├──■────────╫─┤M├────── + # ┌───┐└─┬─┘┌───┐ ║ └╥┘┌─┐ + # q_2: ┤ H ├──■──┤ Y ├──■───╫──╫─┤M├─── + # └───┘ └───┘┌─┴─┐ ║ ║ └╥┘┌─┐ + # q_3: ───────────────┤ X ├─╫──╫──╫─┤M├ + # ┌─┐ └───┘ ║ ║ ║ └╥┘ + # q_4: ─┤M├─────────────────╫──╫──╫──╫─ + # └╥┘ ║ ║ ║ ║ + # c: 5/══╩══════════════════╩══╩══╩══╩═ + # 4 0 1 2 3 qc2 = qiskit.QuantumCircuit(5, 5) qc2.h(2) qc2.cx(2, 1) diff --git a/test/python/transpiler/test_basis_translator.py b/test/python/transpiler/test_basis_translator.py index 7510feb92b26..b9d2bd0c8d77 100644 --- a/test/python/transpiler/test_basis_translator.py +++ b/test/python/transpiler/test_basis_translator.py @@ -445,22 +445,20 @@ def test_unroll_1q_chain_conditional(self): pass_ = BasisTranslator(std_eqlib, ["u1", "u2", "u3"]) unrolled_dag = pass_.run(dag) - """ - Pick up -1 * 0.3 / 2 global phase for one RZ -> U1. - - global phase: 6.1332 - ┌─────────┐┌──────────┐┌───────┐┌─────────┐┌─────────────┐┌─────────┐» - qr: ┤ U2(0,π) ├┤ U1(-π/4) ├┤ U1(π) ├┤ U1(π/4) ├┤ U3(0.5,0,0) ├┤ U1(0.3) ├» - └─────────┘└──────────┘└───────┘└─────────┘└─────────────┘└─────────┘» - cr: 1/═══════════════════════════════════════════════════════════════════» - » - « ┌──────────────────┐┌─┐┌───────────┐┌───────────────┐┌───────┐ - « qr: ┤ U3(0.1,-π/2,π/2) ├┤M├┤ U3(π,0,π) ├┤ U3(π,π/2,π/2) ├┤ U1(π) ├ - « └──────────────────┘└╥┘└─────╥─────┘└───────╥───────┘└───╥───┘ - « ║ ┌──╨──┐ ┌──╨──┐ ┌──╨──┐ - «cr: 1/═════════════════════╩════╡ 0x1 ╞════════╡ 0x1 ╞══════╡ 0x1 ╞═ - « 0 └─────┘ └─────┘ └─────┘ - """ + # Pick up -1 * 0.3 / 2 global phase for one RZ -> U1. + # + # global phase: 6.1332 + # ┌─────────┐┌──────────┐┌───────┐┌─────────┐┌─────────────┐┌─────────┐» + # qr: ┤ U2(0,π) ├┤ U1(-π/4) ├┤ U1(π) ├┤ U1(π/4) ├┤ U3(0.5,0,0) ├┤ U1(0.3) ├» + # └─────────┘└──────────┘└───────┘└─────────┘└─────────────┘└─────────┘» + # cr: 1/═══════════════════════════════════════════════════════════════════» + # » + # « ┌──────────────────┐┌─┐┌───────────┐┌───────────────┐┌───────┐ + # « qr: ┤ U3(0.1,-π/2,π/2) ├┤M├┤ U3(π,0,π) ├┤ U3(π,π/2,π/2) ├┤ U1(π) ├ + # « └──────────────────┘└╥┘└─────╥─────┘└───────╥───────┘└───╥───┘ + # « ║ ┌──╨──┐ ┌──╨──┐ ┌──╨──┐ + # «cr: 1/═════════════════════╩════╡ 0x1 ╞════════╡ 0x1 ╞══════╡ 0x1 ╞═ + # « 0 └─────┘ └─────┘ └─────┘ ref_circuit = QuantumCircuit(qr, cr, global_phase=-0.3 / 2) ref_circuit.append(U2Gate(0, pi), [qr[0]]) ref_circuit.append(U1Gate(-pi / 4), [qr[0]]) @@ -794,13 +792,11 @@ def test_cx_bell_to_ecr(self): in_dag = circuit_to_dag(bell) out_dag = BasisTranslator(std_eqlib, ["ecr", "u"]).run(in_dag) - """ - ┌────────────┐ ┌─────────────┐┌──────────┐┌──────┐ - q_0: ───┤ U(π/2,0,π) ├──┤ U(0,0,-π/2) ├┤ U(π,0,0) ├┤0 ├ - ┌──┴────────────┴─┐└─────────────┘└──────────┘│ Ecr │ - q_1: ┤ U(π/2,-π/2,π/2) ├───────────────────────────┤1 ├ - └─────────────────┘ └──────┘ - """ + # ┌────────────┐ ┌─────────────┐┌──────────┐┌──────┐ + # q_0: ───┤ U(π/2,0,π) ├──┤ U(0,0,-π/2) ├┤ U(π,0,0) ├┤0 ├ + # ┌──┴────────────┴─┐└─────────────┘└──────────┘│ Ecr │ + # q_1: ┤ U(π/2,-π/2,π/2) ├───────────────────────────┤1 ├ + # └─────────────────┘ └──────┘ qr = QuantumRegister(2, "q") expected = QuantumCircuit(2) expected.u(pi / 2, 0, pi, qr[0]) @@ -834,16 +830,15 @@ def test_global_phase(self): self.assertEqual(Operator(dag_to_circuit(out_dag)), Operator(expected)) def test_condition_set_substitute_node(self): - """Verify condition is set in BasisTranslator on substitute_node - - ┌───┐ ┌───┐ - q_0: ┤ H ├──■──────┤ H ├─ - └───┘┌─┴─┐┌─┐ └─╥─┘ - q_1: ─────┤ X ├┤M├───╫─── - └───┘└╥┘┌──╨──┐ - c: 2/═══════════╩═╡ 0x1 ╞ - 1 └─────┘ - """ + """Verify condition is set in BasisTranslator on substitute_node""" + + # ┌───┐ ┌───┐ + # q_0: ┤ H ├──■──────┤ H ├─ + # └───┘┌─┴─┐┌─┐ └─╥─┘ + # q_1: ─────┤ X ├┤M├───╫─── + # └───┘└╥┘┌──╨──┐ + # c: 2/═══════════╩═╡ 0x1 ╞ + # 1 └─────┘ qr = QuantumRegister(2, "q") cr = ClassicalRegister(2, "c") circ = QuantumCircuit(qr, cr) @@ -855,15 +850,13 @@ def test_condition_set_substitute_node(self): circ, optimization_level=3, basis_gates=["cx", "id", "u1", "u2", "u3"] ) - """ - ┌─────────┐ ┌─────────┐ - q_0: ┤ U2(0,π) ├──■─────┤ U2(0,π) ├ - └─────────┘┌─┴─┐┌─┐└────╥────┘ - q_1: ───────────┤ X ├┤M├─────╫───── - └───┘└╥┘ ┌──╨──┐ - c: 2/═════════════════╩═══╡ 0x1 ╞══ - 1 └─────┘ - """ + # ┌─────────┐ ┌─────────┐ + # q_0: ┤ U2(0,π) ├──■─────┤ U2(0,π) ├ + # └─────────┘┌─┴─┐┌─┐└────╥────┘ + # q_1: ───────────┤ X ├┤M├─────╫───── + # └───┘└╥┘ ┌──╨──┐ + # c: 2/═════════════════╩═══╡ 0x1 ╞══ + # 1 └─────┘ qr = QuantumRegister(2, "q") cr = ClassicalRegister(2, "c") expected = QuantumCircuit(qr, cr) diff --git a/test/python/transpiler/test_cx_cancellation.py b/test/python/transpiler/test_cx_cancellation.py index a42518c97dce..129d86a41bfe 100644 --- a/test/python/transpiler/test_cx_cancellation.py +++ b/test/python/transpiler/test_cx_cancellation.py @@ -95,16 +95,14 @@ def test_pass_cx_cancellation_chained_cx(self): pass_manager.append(CXCancellation()) out_circuit = pass_manager.run(circuit) - """ - ┌───┐ - q0_0: ┤ H ├──■─────────■── - ├───┤┌─┴─┐ ┌─┴─┐ - q0_1: ┤ H ├┤ X ├──■──┤ X ├ - └───┘└───┘┌─┴─┐└───┘ - q0_2: ──────────┤ X ├───── - └───┘ - q0_3: ──────────────────── - """ + # ┌───┐ + # q0_0: ┤ H ├──■─────────■── + # ├───┤┌─┴─┐ ┌─┴─┐ + # q0_1: ┤ H ├┤ X ├──■──┤ X ├ + # └───┘└───┘┌─┴─┐└───┘ + # q0_2: ──────────┤ X ├───── + # └───┘ + # q0_3: ──────────────────── expected = QuantumCircuit(qr) expected.h(qr[0]) expected.h(qr[1]) diff --git a/test/python/transpiler/test_gate_direction.py b/test/python/transpiler/test_gate_direction.py index 838b02d30e61..0960c840ddad 100644 --- a/test/python/transpiler/test_gate_direction.py +++ b/test/python/transpiler/test_gate_direction.py @@ -132,13 +132,11 @@ def test_ecr_flip(self): coupling = CouplingMap([[0, 1]]) dag = circuit_to_dag(circuit) - """ - ┌─────────┐ ┌──────┐┌───┐ - qr_0: ┤ Ry(π/2) ├─┤0 ├┤ H ├ - ├─────────┴┐│ Ecr │├───┤ - qr_1: ┤ Ry(-π/2) ├┤1 ├┤ H ├ - └──────────┘└──────┘└───┘ - """ + # ┌─────────┐ ┌──────┐┌───┐ + # qr_0: ┤ Ry(π/2) ├─┤0 ├┤ H ├ + # ├─────────┴┐│ Ecr │├───┤ + # qr_1: ┤ Ry(-π/2) ├┤1 ├┤ H ├ + # └──────────┘└──────┘└───┘ expected = QuantumCircuit(qr) expected.ry(pi / 2, qr[0]) expected.ry(-pi / 2, qr[1]) @@ -215,16 +213,14 @@ def test_preserves_conditions(self): coupling = CouplingMap([[0, 1]]) dag = circuit_to_dag(circuit) - """ - ┌───┐ ┌───┐ ┌───┐ ┌───┐ - q_0: ───■───────────┤ H ├────■───────────┤ H ├───■──┤ H ├──■──┤ H ├ - ┌─┴─┐ ┌───┐ └─╥─┘ ┌─┴─┐ ┌───┐ └─╥─┘ ┌─┴─┐├───┤┌─┴─┐├───┤ - q_1: ─┤ X ├──┤ H ├────╫────┤ X ├──┤ H ├────╫───┤ X ├┤ H ├┤ X ├┤ H ├ - └─╥─┘ └─╥─┘ ║ └─╥─┘ └─╥─┘ ║ └───┘└───┘└───┘└───┘ - ┌──╨──┐┌──╨──┐┌──╨──┐┌──╨──┐┌──╨──┐┌──╨──┐ - c: 1/╡ 0x0 ╞╡ 0x0 ╞╡ 0x0 ╞╡ 0x0 ╞╡ 0x0 ╞╡ 0x0 ╞════════════════════ - └─────┘└─────┘└─────┘└─────┘└─────┘└─────┘ - """ + # ┌───┐ ┌───┐ ┌───┐ ┌───┐ + # q_0: ───■───────────┤ H ├────■───────────┤ H ├───■──┤ H ├──■──┤ H ├ + # ┌─┴─┐ ┌───┐ └─╥─┘ ┌─┴─┐ ┌───┐ └─╥─┘ ┌─┴─┐├───┤┌─┴─┐├───┤ + # q_1: ─┤ X ├──┤ H ├────╫────┤ X ├──┤ H ├────╫───┤ X ├┤ H ├┤ X ├┤ H ├ + # └─╥─┘ └─╥─┘ ║ └─╥─┘ └─╥─┘ ║ └───┘└───┘└───┘└───┘ + # ┌──╨──┐┌──╨──┐┌──╨──┐┌──╨──┐┌──╨──┐┌──╨──┐ + # c: 1/╡ 0x0 ╞╡ 0x0 ╞╡ 0x0 ╞╡ 0x0 ╞╡ 0x0 ╞╡ 0x0 ╞════════════════════ + # └─────┘└─────┘└─────┘└─────┘└─────┘└─────┘ expected = QuantumCircuit(qr, cr) expected.cx(qr[0], qr[1]).c_if(cr, 0) diff --git a/test/python/transpiler/test_hoare_opt.py b/test/python/transpiler/test_hoare_opt.py index d4c466f4a851..e5fd9f166e14 100644 --- a/test/python/transpiler/test_hoare_opt.py +++ b/test/python/transpiler/test_hoare_opt.py @@ -30,29 +30,22 @@ class TestHoareOptimizer(QiskitTestCase): def test_phasegate_removal(self): """Should remove the phase on a classical state, - but not on a superposition state. + but not on a superposition state.""" - ┌───┐ - q_0: ┤ Z ├────── - ├───┤┌───┐ - q_1:─┤ H ├┤ Z ├─ - └───┘└───┘ - q_2: ─────────── - - """ + # ┌───┐ + # q_0: ┤ Z ├────── + # ├───┤┌───┐ + # q_1:─┤ H ├┤ Z ├─ + # └───┘└───┘ circuit = QuantumCircuit(3) circuit.z(0) circuit.h(1) circuit.z(1) - """ - q_0: ─────────── - ┌───┐┌───┐ - q_1:─┤ H ├┤ Z ├─ - └───┘└───┘ - q_2: ─────────── - - """ + # q_0: ─────────── + # ┌───┐┌───┐ + # q_1:─┤ H ├┤ Z ├─ + # └───┘└───┘ expected = QuantumCircuit(3) expected.h(1) expected.z(1) @@ -67,30 +60,28 @@ def test_phasegate_removal(self): def test_cswap_removal(self): """Should remove Fredkin gates because the optimizer - can deduce the targets are in the same state - - ┌───┐┌───┐ ┌───┐ ┌───┐ ┌───┐ - q_0: ┤ X ├┤ X ├──■──┤ X ├──■──┤ X ├──■────■──┤ X ├───────────────────────────────── - └───┘└─┬─┘┌─┴─┐└─┬─┘ │ └─┬─┘┌─┴─┐ │ └─┬─┘ - q_1: ───────┼──┤ X ├──■────┼────┼──┤ X ├──┼────■───■──■──■──■─────■─────■────────── - │ └─┬─┘ ┌─┴─┐ │ └─┬─┘┌─┴─┐ │ │ │ │ │ │ │ - q_2: ───────┼────┼───────┤ X ├──■────┼──┤ X ├──■───┼──┼──┼──┼──■──┼──■──┼──■──■──■─ - ┌───┐ │ │ └─┬─┘ │ └─┬─┘ │ │ │ │ │ │ │ │ │ │ │ - q_3: ┤ H ├──■────┼─────────┼─────────┼────┼────────┼──┼──X──X──┼──┼──X──┼──┼──X──┼─ - ├───┤ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ - q_4: ┤ H ├───────■─────────┼─────────┼────┼────────┼──┼──┼──X──┼──X──┼──┼──X──┼──X─ - ├───┤ │ │ │ │ │ │ │ │ │ │ │ │ │ - q_5: ┤ H ├─────────────────■─────────┼────┼────────┼──┼──┼─────┼──X──┼──X──┼──X──┼─ - ├───┤ │ │ │ │ │ │ │ │ │ │ - q_6: ┤ H ├───────────────────────────■────■────────┼──┼──┼─────┼─────┼──X──┼─────X─ - └───┘ │ │ │ │ │ │ - q_7: ──────────────────────────────────────────────X──┼──┼─────X─────┼─────┼─────── - │ │ │ │ │ │ - q_8: ──────────────────────────────────────────────X──X──┼─────┼─────X─────┼─────── - │ │ │ │ - q_9: ─────────────────────────────────────────────────X──X─────X───────────X─────── - - """ + can deduce the targets are in the same state""" + + # ┌───┐┌───┐ ┌───┐ ┌───┐ ┌───┐ + # q_0: ┤ X ├┤ X ├──■──┤ X ├──■──┤ X ├──■────■──┤ X ├───────────────────────────────── + # └───┘└─┬─┘┌─┴─┐└─┬─┘ │ └─┬─┘┌─┴─┐ │ └─┬─┘ + # q_1: ───────┼──┤ X ├──■────┼────┼──┤ X ├──┼────■───■──■──■──■─────■─────■────────── + # │ └─┬─┘ ┌─┴─┐ │ └─┬─┘┌─┴─┐ │ │ │ │ │ │ │ + # q_2: ───────┼────┼───────┤ X ├──■────┼──┤ X ├──■───┼──┼──┼──┼──■──┼──■──┼──■──■──■─ + # ┌───┐ │ │ └─┬─┘ │ └─┬─┘ │ │ │ │ │ │ │ │ │ │ │ + # q_3: ┤ H ├──■────┼─────────┼─────────┼────┼────────┼──┼──X──X──┼──┼──X──┼──┼──X──┼─ + # ├───┤ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ + # q_4: ┤ H ├───────■─────────┼─────────┼────┼────────┼──┼──┼──X──┼──X──┼──┼──X──┼──X─ + # ├───┤ │ │ │ │ │ │ │ │ │ │ │ │ │ + # q_5: ┤ H ├─────────────────■─────────┼────┼────────┼──┼──┼─────┼──X──┼──X──┼──X──┼─ + # ├───┤ │ │ │ │ │ │ │ │ │ │ + # q_6: ┤ H ├───────────────────────────■────■────────┼──┼──┼─────┼─────┼──X──┼─────X─ + # └───┘ │ │ │ │ │ │ + # q_7: ──────────────────────────────────────────────X──┼──┼─────X─────┼─────┼─────── + # │ │ │ │ │ │ + # q_8: ──────────────────────────────────────────────X──X──┼─────┼─────X─────┼─────── + # │ │ │ │ + # q_9: ─────────────────────────────────────────────────X──X─────X───────────X─────── circuit = QuantumCircuit(10) # prep circuit.x(0) @@ -120,29 +111,26 @@ def test_cswap_removal(self): circuit.cswap(2, 3, 5) circuit.cswap(2, 4, 6) - """ - ┌───┐┌───┐ ┌───┐ ┌───┐ ┌───┐ - q_0: ┤ X ├┤ X ├──■──┤ X ├──■──┤ X ├──■────■──┤ X ├─────────────── - └───┘└─┬─┘┌─┴─┐└─┬─┘ │ └─┬─┘┌─┴─┐ │ └─┬─┘ - q_1: ───────┼──┤ X ├──■────┼────┼──┤ X ├──┼────■───■──■──■─────── - │ └─┬─┘ ┌─┴─┐ │ └─┬─┘┌─┴─┐ │ │ │ │ - q_2: ───────┼────┼───────┤ X ├──■────┼──┤ X ├──■───┼──┼──┼──■──■─ - ┌───┐ │ │ └─┬─┘ │ └─┬─┘ │ │ │ │ │ - q_3: ┤ H ├──■────┼─────────┼─────────┼────┼────────X──┼──┼──X──┼─ - ├───┤ │ │ │ │ │ │ │ │ │ - q_4: ┤ H ├───────■─────────┼─────────┼────┼────────X──X──┼──┼──X─ - ├───┤ │ │ │ │ │ │ │ - q_5: ┤ H ├─────────────────■─────────┼────┼───────────X──X──X──┼─ - ├───┤ │ │ │ │ - q_6: ┤ H ├───────────────────────────■────■──────────────X─────X─ - └───┘ - q_7: ──────────────────────────────────────────────────────────── - - q_8: ──────────────────────────────────────────────────────────── - - q_9: ──────────────────────────────────────────────────────────── - - """ + # ┌───┐┌───┐ ┌───┐ ┌───┐ ┌───┐ + # q_0: ┤ X ├┤ X ├──■──┤ X ├──■──┤ X ├──■────■──┤ X ├─────────────── + # └───┘└─┬─┘┌─┴─┐└─┬─┘ │ └─┬─┘┌─┴─┐ │ └─┬─┘ + # q_1: ───────┼──┤ X ├──■────┼────┼──┤ X ├──┼────■───■──■──■─────── + # │ └─┬─┘ ┌─┴─┐ │ └─┬─┘┌─┴─┐ │ │ │ │ + # q_2: ───────┼────┼───────┤ X ├──■────┼──┤ X ├──■───┼──┼──┼──■──■─ + # ┌───┐ │ │ └─┬─┘ │ └─┬─┘ │ │ │ │ │ + # q_3: ┤ H ├──■────┼─────────┼─────────┼────┼────────X──┼──┼──X──┼─ + # ├───┤ │ │ │ │ │ │ │ │ │ + # q_4: ┤ H ├───────■─────────┼─────────┼────┼────────X──X──┼──┼──X─ + # ├───┤ │ │ │ │ │ │ │ + # q_5: ┤ H ├─────────────────■─────────┼────┼───────────X──X──X──┼─ + # ├───┤ │ │ │ │ + # q_6: ┤ H ├───────────────────────────■────■──────────────X─────X─ + # └───┘ + # q_7: ──────────────────────────────────────────────────────────── + # + # q_8: ──────────────────────────────────────────────────────────── + # + # q_9: ──────────────────────────────────────────────────────────── expected = QuantumCircuit(10) # prep expected.x(0) @@ -177,31 +165,29 @@ def test_cswap_removal(self): def test_lnn_cnot_removal(self): """Should remove some cnots from swaps introduced because of linear nearest architecture. Only uses - single-gate optimization techniques. - - ┌───┐ ┌───┐ » - q_0: ┤ H ├──■──┤ X ├──■────────────────────────────────────────────────────» - └───┘┌─┴─┐└─┬─┘┌─┴─┐ ┌───┐ » - q_1: ─────┤ X ├──■──┤ X ├──■──┤ X ├──■──────────────────────────────────■──» - └───┘ └───┘┌─┴─┐└─┬─┘┌─┴─┐ ┌───┐ ┌───┐┌─┴─┐» - q_2: ────────────────────┤ X ├──■──┤ X ├──■──┤ X ├──■─────────■──┤ X ├┤ X ├» - └───┘ └───┘┌─┴─┐└─┬─┘┌─┴─┐ ┌─┴─┐└─┬─┘└───┘» - q_3: ───────────────────────────────────┤ X ├──■──┤ X ├──■──┤ X ├──■───────» - └───┘ └───┘┌─┴─┐└───┘ » - q_4: ──────────────────────────────────────────────────┤ X ├───────────────» - └───┘ » - « ┌───┐ - «q_0: ───────■──┤ X ├ - « ┌───┐┌─┴─┐└─┬─┘ - «q_1: ┤ X ├┤ X ├──■── - « └─┬─┘└───┘ - «q_2: ──■──────────── - « - «q_3: ─────────────── - « - «q_4: ─────────────── - « - """ + single-gate optimization techniques.""" + + # ┌───┐ ┌───┐ » + # q_0: ┤ H ├──■──┤ X ├──■────────────────────────────────────────────────────» + # └───┘┌─┴─┐└─┬─┘┌─┴─┐ ┌───┐ » + # q_1: ─────┤ X ├──■──┤ X ├──■──┤ X ├──■──────────────────────────────────■──» + # └───┘ └───┘┌─┴─┐└─┬─┘┌─┴─┐ ┌───┐ ┌───┐┌─┴─┐» + # q_2: ────────────────────┤ X ├──■──┤ X ├──■──┤ X ├──■─────────■──┤ X ├┤ X ├» + # └───┘ └───┘┌─┴─┐└─┬─┘┌─┴─┐ ┌─┴─┐└─┬─┘└───┘» + # q_3: ───────────────────────────────────┤ X ├──■──┤ X ├──■──┤ X ├──■───────» + # └───┘ └───┘┌─┴─┐└───┘ » + # q_4: ──────────────────────────────────────────────────┤ X ├───────────────» + # └───┘ » + # « ┌───┐ + # «q_0: ───────■──┤ X ├ + # « ┌───┐┌─┴─┐└─┬─┘ + # «q_1: ┤ X ├┤ X ├──■── + # « └─┬─┘└───┘ + # «q_2: ──■──────────── + # « + # «q_3: ─────────────── + # « + # «q_4: ─────────────── circuit = QuantumCircuit(5) circuit.h(0) for i in range(0, 3): @@ -213,19 +199,17 @@ def test_lnn_cnot_removal(self): circuit.cx(i - 1, i) circuit.cx(i, i - 1) - """ - ┌───┐ ┌───┐ ┌───┐ - q_0: ┤ H ├──■──┤ X ├───────────────────────────────────┤ X ├ - └───┘┌─┴─┐└─┬─┘ ┌───┐ ┌───┐└─┬─┘ - q_1: ─────┤ X ├──■────■──┤ X ├────────────────────┤ X ├──■── - └───┘ ┌─┴─┐└─┬─┘ ┌───┐ ┌───┐└─┬─┘ - q_2: ───────────────┤ X ├──■────■──┤ X ├─────┤ X ├──■─────── - └───┘ ┌─┴─┐└─┬─┘ └─┬─┘ - q_3: ─────────────────────────┤ X ├──■────■────■──────────── - └───┘ ┌─┴─┐ - q_4: ───────────────────────────────────┤ X ├─────────────── - └───┘ - """ + # ┌───┐ ┌───┐ ┌───┐ + # q_0: ┤ H ├──■──┤ X ├───────────────────────────────────┤ X ├ + # └───┘┌─┴─┐└─┬─┘ ┌───┐ ┌───┐└─┬─┘ + # q_1: ─────┤ X ├──■────■──┤ X ├────────────────────┤ X ├──■── + # └───┘ ┌─┴─┐└─┬─┘ ┌───┐ ┌───┐└─┬─┘ + # q_2: ───────────────┤ X ├──■────■──┤ X ├─────┤ X ├──■─────── + # └───┘ ┌─┴─┐└─┬─┘ └─┬─┘ + # q_3: ─────────────────────────┤ X ├──■────■────■──────────── + # └───┘ ┌─┴─┐ + # q_4: ───────────────────────────────────┤ X ├─────────────── + # └───┘ expected = QuantumCircuit(5) expected.h(0) for i in range(0, 3): @@ -246,31 +230,29 @@ def test_lnn_cnot_removal(self): def test_lnncnot_advanced_removal(self): """Should remove all cnots from swaps introduced because of linear nearest architecture. This time - using multi-gate optimization techniques. - - ┌───┐ ┌───┐ » - q_0: ┤ H ├──■──┤ X ├──■────────────────────────────────────────────────────» - └───┘┌─┴─┐└─┬─┘┌─┴─┐ ┌───┐ » - q_1: ─────┤ X ├──■──┤ X ├──■──┤ X ├──■──────────────────────────────────■──» - └───┘ └───┘┌─┴─┐└─┬─┘┌─┴─┐ ┌───┐ ┌───┐┌─┴─┐» - q_2: ────────────────────┤ X ├──■──┤ X ├──■──┤ X ├──■─────────■──┤ X ├┤ X ├» - └───┘ └───┘┌─┴─┐└─┬─┘┌─┴─┐ ┌─┴─┐└─┬─┘└───┘» - q_3: ───────────────────────────────────┤ X ├──■──┤ X ├──■──┤ X ├──■───────» - └───┘ └───┘┌─┴─┐└───┘ » - q_4: ──────────────────────────────────────────────────┤ X ├───────────────» - └───┘ » - « ┌───┐ - «q_0: ───────■──┤ X ├ - « ┌───┐┌─┴─┐└─┬─┘ - «q_1: ┤ X ├┤ X ├──■── - « └─┬─┘└───┘ - «q_2: ──■──────────── - « - «q_3: ─────────────── - « - «q_4: ─────────────── - « - """ + using multi-gate optimization techniques.""" + + # ┌───┐ ┌───┐ » + # q_0: ┤ H ├──■──┤ X ├──■────────────────────────────────────────────────────» + # └───┘┌─┴─┐└─┬─┘┌─┴─┐ ┌───┐ » + # q_1: ─────┤ X ├──■──┤ X ├──■──┤ X ├──■──────────────────────────────────■──» + # └───┘ └───┘┌─┴─┐└─┬─┘┌─┴─┐ ┌───┐ ┌───┐┌─┴─┐» + # q_2: ────────────────────┤ X ├──■──┤ X ├──■──┤ X ├──■─────────■──┤ X ├┤ X ├» + # └───┘ └───┘┌─┴─┐└─┬─┘┌─┴─┐ ┌─┴─┐└─┬─┘└───┘» + # q_3: ───────────────────────────────────┤ X ├──■──┤ X ├──■──┤ X ├──■───────» + # └───┘ └───┘┌─┴─┐└───┘ » + # q_4: ──────────────────────────────────────────────────┤ X ├───────────────» + # └───┘ » + # « ┌───┐ + # «q_0: ───────■──┤ X ├ + # « ┌───┐┌─┴─┐└─┬─┘ + # «q_1: ┤ X ├┤ X ├──■── + # « └─┬─┘└───┘ + # «q_2: ──■──────────── + # « + # «q_3: ─────────────── + # « + # «q_4: ─────────────── circuit = QuantumCircuit(5) circuit.h(0) for i in range(0, 3): @@ -282,19 +264,17 @@ def test_lnncnot_advanced_removal(self): circuit.cx(i - 1, i) circuit.cx(i, i - 1) - """ - ┌───┐ - q_0: ┤ H ├──■───────────────── - └───┘┌─┴─┐ - q_1: ─────┤ X ├──■──────────── - └───┘┌─┴─┐ - q_2: ──────────┤ X ├──■─────── - └───┘┌─┴─┐ - q_3: ───────────────┤ X ├──■── - └───┘┌─┴─┐ - q_4: ────────────────────┤ X ├ - └───┘ - """ + # ┌───┐ + # q_0: ┤ H ├──■───────────────── + # └───┘┌─┴─┐ + # q_1: ─────┤ X ├──■──────────── + # └───┘┌─┴─┐ + # q_2: ──────────┤ X ├──■─────── + # └───┘┌─┴─┐ + # q_3: ───────────────┤ X ├──■── + # └───┘┌─┴─┐ + # q_4: ────────────────────┤ X ├ + # └───┘ expected = QuantumCircuit(5) expected.h(0) for i in range(0, 4): @@ -331,16 +311,15 @@ def test_successive_identity_removal(self): def test_targetsuccessive_identity_removal(self): """Should remove pair of controlled target successive which are the inverse of each other, if they can be - identified to be executed as a unit (either both or none). - - ┌───┐ ┌───┐┌───┐ - q_0: ┤ H ├──■──┤ X ├┤ X ├──■── - ├───┤ │ └─┬─┘└───┘ │ - q_1: ┤ H ├──■────■─────────■── - ├───┤┌─┴─┐ ┌─┴─┐ - q_2: ┤ H ├┤ X ├──────────┤ X ├ - └───┘└───┘ └───┘ - """ + identified to be executed as a unit (either both or none).""" + + # ┌───┐ ┌───┐┌───┐ + # q_0: ┤ H ├──■──┤ X ├┤ X ├──■── + # ├───┤ │ └─┬─┘└───┘ │ + # q_1: ┤ H ├──■────■─────────■── + # ├───┤┌─┴─┐ ┌─┴─┐ + # q_2: ┤ H ├┤ X ├──────────┤ X ├ + # └───┘└───┘ └───┘ circuit = QuantumCircuit(3) circuit.h(0) circuit.h(1) @@ -350,15 +329,13 @@ def test_targetsuccessive_identity_removal(self): circuit.x(0) circuit.ccx(0, 1, 2) - """ - ┌───┐┌───┐┌───┐ - q_0: ┤ H ├┤ X ├┤ X ├ - ├───┤└─┬─┘└───┘ - q_1: ┤ H ├──■─────── - ├───┤ - q_2: ┤ H ├────────── - └───┘ - """ + # ┌───┐┌───┐┌───┐ + # q_0: ┤ H ├┤ X ├┤ X ├ + # ├───┤└─┬─┘└───┘ + # q_1: ┤ H ├──■─────── + # ├───┤ + # q_2: ┤ H ├────────── + # └───┘ expected = QuantumCircuit(3) expected.h(0) expected.h(1) @@ -377,60 +354,59 @@ def test_targetsuccessive_identity_removal(self): def test_targetsuccessive_identity_advanced_removal(self): """Should remove target successive identity gates with DIFFERENT sets of control qubits. - In this case CCCX(4,5,6,7) & CCX(5,6,7). - - ┌───┐┌───┐ » - q_0: ┤ H ├┤ X ├───────■─────────────────────────────■───────────────────■──» - ├───┤└─┬─┘ │ │ │ » - q_1: ┤ H ├──■─────────■─────────────────────────────■───────────────────■──» - ├───┤┌───┐ │ ┌───┐ │ │ » - q_2: ┤ H ├┤ X ├───────┼──┤ X ├──■──────────────■────┼───────────────────┼──» - ├───┤└─┬─┘ ┌─┴─┐└─┬─┘ │ │ ┌─┴─┐ ┌─┴─┐» - q_3: ┤ H ├──■────■──┤ X ├──■────■──────────────■──┤ X ├──■─────────■──┤ X ├» - ├───┤┌───┐ │ └───┘ │ ┌───┐ │ └───┘ │ │ └───┘» - q_4: ┤ H ├┤ X ├──┼──────────────┼──┤ X ├──■────┼─────────┼─────────┼───────» - ├───┤└─┬─┘┌─┴─┐ ┌─┴─┐└─┬─┘ │ ┌─┴─┐ ┌─┴─┐ ┌─┴─┐ » - q_5: ┤ H ├──■──┤ X ├──────────┤ X ├──■────■──┤ X ├─────┤ X ├──■──┤ X ├─────» - └───┘ └───┘ └───┘ ┌─┴─┐└───┘ └───┘┌─┴─┐├───┤ » - q_6: ───────────────────────────────────┤ X ├───────────────┤ X ├┤ X ├─────» - └───┘ └───┘└───┘ » - q_7: ──────────────────────────────────────────────────────────────────────» - » - « ┌───┐┌───┐ » - «q_0: ──────────────────────■──┤ X ├┤ X ├──■─────────────────────────────■──» - « │ └─┬─┘└─┬─┘ │ │ » - «q_1: ──────────────────────■────■────■────■─────────────────────────────■──» - « ┌───┐ │ │ │ ┌───┐ │ » - «q_2: ──■─────────■──┤ X ├──┼─────────┼────┼──┤ X ├──■──────────────■────┼──» - « │ │ └─┬─┘┌─┴─┐ │ ┌─┴─┐└─┬─┘ │ │ ┌─┴─┐» - «q_3: ──■─────────■────■──┤ X ├───────┼──┤ X ├──■────■──────────────■──┤ X ├» - « │ ┌───┐ │ └───┘ │ └───┘ │ │ ┌───┐ │ └───┘» - «q_4: ──┼──┤ X ├──┼───────────────────┼─────────┼────┼──┤ X ├──■────┼───────» - « ┌─┴─┐└─┬─┘┌─┴─┐ │ │ ┌─┴─┐└─┬─┘ │ ┌─┴─┐ » - «q_5: ┤ X ├──■──┤ X ├─────────────────┼─────────┼──┤ X ├──■────■──┤ X ├─────» - « └───┘ └───┘ │ │ └───┘ │ │ └───┘ » - «q_6: ────────────────────────────────■─────────■─────────■────■────────────» - « ┌─┴─┐ » - «q_7: ───────────────────────────────────────────────────────┤ X ├──────────» - « └───┘ » - « - «q_0: ─────────────── - « - «q_1: ─────────────── - « ┌───┐ - «q_2: ─────┤ X ├───── - « └─┬─┘ - «q_3: ──■────■─────── - « │ ┌───┐ - «q_4: ──┼──┤ X ├───── - « ┌─┴─┐└─┬─┘ - «q_5: ┤ X ├──■────■── - « └───┘ │ - «q_6: ────────────■── - « ┌─┴─┐ - «q_7: ──────────┤ X ├ - « └───┘ - """ + In this case CCCX(4,5,6,7) & CCX(5,6,7).""" + + # ┌───┐┌───┐ » + # q_0: ┤ H ├┤ X ├───────■─────────────────────────────■───────────────────■──» + # ├───┤└─┬─┘ │ │ │ » + # q_1: ┤ H ├──■─────────■─────────────────────────────■───────────────────■──» + # ├───┤┌───┐ │ ┌───┐ │ │ » + # q_2: ┤ H ├┤ X ├───────┼──┤ X ├──■──────────────■────┼───────────────────┼──» + # ├───┤└─┬─┘ ┌─┴─┐└─┬─┘ │ │ ┌─┴─┐ ┌─┴─┐» + # q_3: ┤ H ├──■────■──┤ X ├──■────■──────────────■──┤ X ├──■─────────■──┤ X ├» + # ├───┤┌───┐ │ └───┘ │ ┌───┐ │ └───┘ │ │ └───┘» + # q_4: ┤ H ├┤ X ├──┼──────────────┼──┤ X ├──■────┼─────────┼─────────┼───────» + # ├───┤└─┬─┘┌─┴─┐ ┌─┴─┐└─┬─┘ │ ┌─┴─┐ ┌─┴─┐ ┌─┴─┐ » + # q_5: ┤ H ├──■──┤ X ├──────────┤ X ├──■────■──┤ X ├─────┤ X ├──■──┤ X ├─────» + # └───┘ └───┘ └───┘ ┌─┴─┐└───┘ └───┘┌─┴─┐├───┤ » + # q_6: ───────────────────────────────────┤ X ├───────────────┤ X ├┤ X ├─────» + # └───┘ └───┘└───┘ » + # q_7: ──────────────────────────────────────────────────────────────────────» + # » + # « ┌───┐┌───┐ » + # «q_0: ──────────────────────■──┤ X ├┤ X ├──■─────────────────────────────■──» + # « │ └─┬─┘└─┬─┘ │ │ » + # «q_1: ──────────────────────■────■────■────■─────────────────────────────■──» + # « ┌───┐ │ │ │ ┌───┐ │ » + # «q_2: ──■─────────■──┤ X ├──┼─────────┼────┼──┤ X ├──■──────────────■────┼──» + # « │ │ └─┬─┘┌─┴─┐ │ ┌─┴─┐└─┬─┘ │ │ ┌─┴─┐» + # «q_3: ──■─────────■────■──┤ X ├───────┼──┤ X ├──■────■──────────────■──┤ X ├» + # « │ ┌───┐ │ └───┘ │ └───┘ │ │ ┌───┐ │ └───┘» + # «q_4: ──┼──┤ X ├──┼───────────────────┼─────────┼────┼──┤ X ├──■────┼───────» + # « ┌─┴─┐└─┬─┘┌─┴─┐ │ │ ┌─┴─┐└─┬─┘ │ ┌─┴─┐ » + # «q_5: ┤ X ├──■──┤ X ├─────────────────┼─────────┼──┤ X ├──■────■──┤ X ├─────» + # « └───┘ └───┘ │ │ └───┘ │ │ └───┘ » + # «q_6: ────────────────────────────────■─────────■─────────■────■────────────» + # « ┌─┴─┐ » + # «q_7: ───────────────────────────────────────────────────────┤ X ├──────────» + # « └───┘ » + # « + # «q_0: ─────────────── + # « + # «q_1: ─────────────── + # « ┌───┐ + # «q_2: ─────┤ X ├───── + # « └─┬─┘ + # «q_3: ──■────■─────── + # « │ ┌───┐ + # «q_4: ──┼──┤ X ├───── + # « ┌─┴─┐└─┬─┘ + # «q_5: ┤ X ├──■────■── + # « └───┘ │ + # «q_6: ────────────■── + # « ┌─┴─┐ + # «q_7: ──────────┤ X ├ + # « └───┘ circuit = QuantumCircuit(8) circuit.h(0) circuit.h(1) @@ -470,59 +446,57 @@ def test_targetsuccessive_identity_advanced_removal(self): circuit.cx(i * 2 + 1, i * 2) circuit.ccx(5, 6, 7) - """ - ┌───┐┌───┐ » - q_0: ┤ H ├┤ X ├───────■─────────────────────────────■───────────────────■──» - ├───┤└─┬─┘ │ │ │ » - q_1: ┤ H ├──■─────────■─────────────────────────────■───────────────────■──» - ├───┤┌───┐ │ ┌───┐ │ │ » - q_2: ┤ H ├┤ X ├───────┼──┤ X ├──■──────────────■────┼───────────────────┼──» - ├───┤└─┬─┘ ┌─┴─┐└─┬─┘ │ │ ┌─┴─┐ ┌─┴─┐» - q_3: ┤ H ├──■────■──┤ X ├──■────■──────────────■──┤ X ├──■─────────■──┤ X ├» - ├───┤┌───┐ │ └───┘ │ ┌───┐ │ └───┘ │ │ └───┘» - q_4: ┤ H ├┤ X ├──┼──────────────┼──┤ X ├──■────┼─────────┼─────────┼───────» - ├───┤└─┬─┘┌─┴─┐ ┌─┴─┐└─┬─┘ │ ┌─┴─┐ ┌─┴─┐ ┌─┴─┐ » - q_5: ┤ H ├──■──┤ X ├──────────┤ X ├──■────■──┤ X ├─────┤ X ├──■──┤ X ├─────» - └───┘ └───┘ └───┘ ┌─┴─┐└───┘ └───┘┌─┴─┐├───┤ » - q_6: ───────────────────────────────────┤ X ├───────────────┤ X ├┤ X ├─────» - └───┘ └───┘└───┘ » - q_7: ──────────────────────────────────────────────────────────────────────» - » - « ┌───┐┌───┐ » - «q_0: ──────────────────────■──┤ X ├┤ X ├──■────────────────────────■───────» - « │ └─┬─┘└─┬─┘ │ │ » - «q_1: ──────────────────────■────■────■────■────────────────────────■───────» - « ┌───┐ │ │ │ ┌───┐ │ » - «q_2: ──■─────────■──┤ X ├──┼─────────┼────┼──┤ X ├──■─────────■────┼───────» - « │ │ └─┬─┘┌─┴─┐ │ ┌─┴─┐└─┬─┘ │ │ ┌─┴─┐ » - «q_3: ──■─────────■────■──┤ X ├───────┼──┤ X ├──■────■─────────■──┤ X ├──■──» - « │ ┌───┐ │ └───┘ │ └───┘ │ │ ┌───┐ │ └───┘ │ » - «q_4: ──┼──┤ X ├──┼───────────────────┼─────────┼────┼──┤ X ├──┼─────────┼──» - « ┌─┴─┐└─┬─┘┌─┴─┐ │ │ ┌─┴─┐└─┬─┘┌─┴─┐ ┌─┴─┐» - «q_5: ┤ X ├──■──┤ X ├─────────────────┼─────────┼──┤ X ├──■──┤ X ├─────┤ X ├» - « └───┘ └───┘ │ │ └───┘ │ └───┘ └───┘» - «q_6: ────────────────────────────────■─────────■─────────■─────────────────» - « » - «q_7: ──────────────────────────────────────────────────────────────────────» - « » - « - «q_0: ───── - « - «q_1: ───── - « ┌───┐ - «q_2: ┤ X ├ - « └─┬─┘ - «q_3: ──■── - « ┌───┐ - «q_4: ┤ X ├ - « └─┬─┘ - «q_5: ──■── - « - «q_6: ───── - « - «q_7: ───── - « - """ + # ┌───┐┌───┐ » + # q_0: ┤ H ├┤ X ├───────■─────────────────────────────■───────────────────■──» + # ├───┤└─┬─┘ │ │ │ » + # q_1: ┤ H ├──■─────────■─────────────────────────────■───────────────────■──» + # ├───┤┌───┐ │ ┌───┐ │ │ » + # q_2: ┤ H ├┤ X ├───────┼──┤ X ├──■──────────────■────┼───────────────────┼──» + # ├───┤└─┬─┘ ┌─┴─┐└─┬─┘ │ │ ┌─┴─┐ ┌─┴─┐» + # q_3: ┤ H ├──■────■──┤ X ├──■────■──────────────■──┤ X ├──■─────────■──┤ X ├» + # ├───┤┌───┐ │ └───┘ │ ┌───┐ │ └───┘ │ │ └───┘» + # q_4: ┤ H ├┤ X ├──┼──────────────┼──┤ X ├──■────┼─────────┼─────────┼───────» + # ├───┤└─┬─┘┌─┴─┐ ┌─┴─┐└─┬─┘ │ ┌─┴─┐ ┌─┴─┐ ┌─┴─┐ » + # q_5: ┤ H ├──■──┤ X ├──────────┤ X ├──■────■──┤ X ├─────┤ X ├──■──┤ X ├─────» + # └───┘ └───┘ └───┘ ┌─┴─┐└───┘ └───┘┌─┴─┐├───┤ » + # q_6: ───────────────────────────────────┤ X ├───────────────┤ X ├┤ X ├─────» + # └───┘ └───┘└───┘ » + # q_7: ──────────────────────────────────────────────────────────────────────» + # » + # « ┌───┐┌───┐ » + # «q_0: ──────────────────────■──┤ X ├┤ X ├──■────────────────────────■───────» + # « │ └─┬─┘└─┬─┘ │ │ » + # «q_1: ──────────────────────■────■────■────■────────────────────────■───────» + # « ┌───┐ │ │ │ ┌───┐ │ » + # «q_2: ──■─────────■──┤ X ├──┼─────────┼────┼──┤ X ├──■─────────■────┼───────» + # « │ │ └─┬─┘┌─┴─┐ │ ┌─┴─┐└─┬─┘ │ │ ┌─┴─┐ » + # «q_3: ──■─────────■────■──┤ X ├───────┼──┤ X ├──■────■─────────■──┤ X ├──■──» + # « │ ┌───┐ │ └───┘ │ └───┘ │ │ ┌───┐ │ └───┘ │ » + # «q_4: ──┼──┤ X ├──┼───────────────────┼─────────┼────┼──┤ X ├──┼─────────┼──» + # « ┌─┴─┐└─┬─┘┌─┴─┐ │ │ ┌─┴─┐└─┬─┘┌─┴─┐ ┌─┴─┐» + # «q_5: ┤ X ├──■──┤ X ├─────────────────┼─────────┼──┤ X ├──■──┤ X ├─────┤ X ├» + # « └───┘ └───┘ │ │ └───┘ │ └───┘ └───┘» + # «q_6: ────────────────────────────────■─────────■─────────■─────────────────» + # « » + # «q_7: ──────────────────────────────────────────────────────────────────────» + # « » + # « + # «q_0: ───── + # « + # «q_1: ───── + # « ┌───┐ + # «q_2: ┤ X ├ + # « └─┬─┘ + # «q_3: ──■── + # « ┌───┐ + # «q_4: ┤ X ├ + # « └─┬─┘ + # «q_5: ──■── + # « + # «q_6: ───── + # « + # «q_7: ───── + # « expected = QuantumCircuit(8) expected.h(0) expected.h(1) @@ -569,25 +543,22 @@ def test_targetsuccessive_identity_advanced_removal(self): self.assertEqual(result, circuit_to_dag(expected)) def test_control_removal(self): - """Should replace CX by X. + """Should replace CX by X.""" - ┌───┐ - q_0: ┤ X ├──■── - └───┘┌─┴─┐ - q_1: ─────┤ X ├ - └───┘ - """ + # ┌───┐ + # q_0: ┤ X ├──■── + # └───┘┌─┴─┐ + # q_1: ─────┤ X ├ + # └───┘ circuit = QuantumCircuit(2) circuit.x(0) circuit.cx(0, 1) - """ - ┌───┐ - q_0: ┤ X ├ - ├───┤ - q_1: ┤ X ├ - └───┘ - """ + # ┌───┐ + # q_0: ┤ X ├ + # ├───┤ + # q_1: ┤ X ├ + # └───┘ expected = QuantumCircuit(2) expected.x(0) expected.x(1) @@ -600,28 +571,24 @@ def test_control_removal(self): self.assertEqual(result, circuit_to_dag(expected)) - """ - Should replace CZ by Z - - ┌───┐ ┌───┐ - q_0: ┤ H ├─■─┤ H ├ - ├───┤ │ └───┘ - q_1: ┤ X ├─■────── - └───┘ - """ + # Should replace CZ by Z + # + # ┌───┐ ┌───┐ + # q_0: ┤ H ├─■─┤ H ├ + # ├───┤ │ └───┘ + # q_1: ┤ X ├─■────── + # └───┘ circuit = QuantumCircuit(2) circuit.h(0) circuit.x(1) circuit.cz(0, 1) circuit.h(0) - """ - ┌───┐┌───┐┌───┐ - q_0: ┤ H ├┤ Z ├┤ H ├ - ├───┤└───┘└───┘ - q_1: ┤ X ├────────── - └───┘ - """ + # ┌───┐┌───┐┌───┐ + # q_0: ┤ H ├┤ Z ├┤ H ├ + # ├───┤└───┘└───┘ + # q_1: ┤ X ├────────── + # └───┘ expected = QuantumCircuit(2) expected.h(0) expected.x(1) @@ -654,14 +621,13 @@ def test_is_identity(self): def test_multiple_pass(self): """Verify that multiple pass can be run - with the same Hoare instance. + with the same Hoare instance.""" - ┌───┐┌───┐ - q_0:─┤ H ├┤ Z ├─ - ├───┤└───┘ - q_1: ┤ Z ├────── - └───┘ - """ + # ┌───┐┌───┐ + # q_0:─┤ H ├┤ Z ├─ + # ├───┤└───┘ + # q_1: ┤ Z ├────── + # └───┘ circuit1 = QuantumCircuit(2) circuit1.z(0) circuit1.h(1) @@ -672,13 +638,10 @@ def test_multiple_pass(self): circuit2.h(0) circuit2.z(0) - """ - ┌───┐┌───┐ - q_0:─┤ H ├┤ Z ├─ - └───┘└───┘ - q_1: ─────────── - - """ + # ┌───┐┌───┐ + # q_0:─┤ H ├┤ Z ├─ + # └───┘└───┘ + # q_1: ─────────── expected = QuantumCircuit(2) expected.h(0) expected.z(0) diff --git a/test/python/transpiler/test_optimize_1q_commutation.py b/test/python/transpiler/test_optimize_1q_commutation.py index ef879f4320e5..9daa51c0dd31 100644 --- a/test/python/transpiler/test_optimize_1q_commutation.py +++ b/test/python/transpiler/test_optimize_1q_commutation.py @@ -111,14 +111,12 @@ def test_elaborate_commutation(self): optimize_pass = Optimize1qGatesSimpleCommutation(basis=["sx", "p"], run_to_completion=True) result = optimize_pass(qc) - """ - global phase: π/2 - ┌────────┐┌────┐ ┌─────────┐┌────┐┌────────┐ - q_0: ┤ P(π/8) ├┤ √X ├──■──┤ P(2π/7) ├┤ √X ├┤ P(π/8) ├ - ├────────┤└────┘┌─┴─┐└─────────┘└────┘└────────┘ - q_1: ┤ P(π/4) ├──────┤ X ├─────────────────────────── - └────────┘ └───┘ - """ + # global phase: π/2 + # ┌────────┐┌────┐ ┌─────────┐┌────┐┌────────┐ + # q_0: ┤ P(π/8) ├┤ √X ├──■──┤ P(2π/7) ├┤ √X ├┤ P(π/8) ├ + # ├────────┤└────┘┌─┴─┐└─────────┘└────┘└────────┘ + # q_1: ┤ P(π/4) ├──────┤ X ├─────────────────────────── + # └────────┘ └───┘ expected = QuantumCircuit(2, global_phase=np.pi / 2) expected.p(np.pi / 8, 0) expected.sx(0) diff --git a/test/python/transpiler/test_remove_final_measurements.py b/test/python/transpiler/test_remove_final_measurements.py index 00ac271dc222..eabd3c068ac0 100644 --- a/test/python/transpiler/test_remove_final_measurements.py +++ b/test/python/transpiler/test_remove_final_measurements.py @@ -292,26 +292,24 @@ def expected_dag(): qc.h(q0[0]) return circuit_to_dag(qc) - """ - ┌───┐┌─┐ ░ ░ ┌─┐ - q0_0: ┤ H ├┤M├─░─────░─┤M├─────────────── - └┬─┬┘└╥┘ ░ ░ └╥┘┌─┐ - q0_1: ─┤M├──╫──░─────░──╫─┤M├──────────── - └╥┘ ║ ░ ░ ░ ║ └╥┘┌─┐ - q0_2: ──╫───╫──░──░──░──╫──╫─┤M├───────── - ║ ║ ░ ░ ░ ║ ║ └╥┘┌─┐ - q0_3: ──╫───╫──░──░──░──╫──╫──╫─┤M├────── - ║ ║ ░ ░ ░ ║ ║ ║ └╥┘┌─┐ ░ - q0_4: ──╫───╫──░─────░──╫──╫──╫──╫─┤M├─░─ - ║ ║ ░ ░ ║ ║ ║ ║ └╥┘ ░ - c0: 1/══╩═══╩═══════════╬══╬══╬══╬══╬════ - 0 0 ║ ║ ║ ║ ║ - ║ ║ ║ ║ ║ - c1: 1/══════════════════╬══╬══╬══╬══╬════ - ║ ║ ║ ║ ║ - meas: 5/════════════════╩══╩══╩══╩══╩════ - 0 1 2 3 4 - """ + # ┌───┐┌─┐ ░ ░ ┌─┐ + # q0_0: ┤ H ├┤M├─░─────░─┤M├─────────────── + # └┬─┬┘└╥┘ ░ ░ └╥┘┌─┐ + # q0_1: ─┤M├──╫──░─────░──╫─┤M├──────────── + # └╥┘ ║ ░ ░ ░ ║ └╥┘┌─┐ + # q0_2: ──╫───╫──░──░──░──╫──╫─┤M├───────── + # ║ ║ ░ ░ ░ ║ ║ └╥┘┌─┐ + # q0_3: ──╫───╫──░──░──░──╫──╫──╫─┤M├────── + # ║ ║ ░ ░ ░ ║ ║ ║ └╥┘┌─┐ ░ + # q0_4: ──╫───╫──░─────░──╫──╫──╫──╫─┤M├─░─ + # ║ ║ ░ ░ ║ ║ ║ ║ └╥┘ ░ + # c0: 1/══╩═══╩═══════════╬══╬══╬══╬══╬════ + # 0 0 ║ ║ ║ ║ ║ + # ║ ║ ║ ║ ║ + # c1: 1/══════════════════╬══╬══╬══╬══╬════ + # ║ ║ ║ ║ ║ + # meas: 5/════════════════╩══╩══╩══╩══╩════ + # 0 1 2 3 4 q0 = QuantumRegister(5, "q0") c0 = ClassicalRegister(1, "c0") c1 = ClassicalRegister(1, "c1") diff --git a/test/python/transpiler/test_stochastic_swap.py b/test/python/transpiler/test_stochastic_swap.py index e98a893dd9fe..d1e2a233bde9 100644 --- a/test/python/transpiler/test_stochastic_swap.py +++ b/test/python/transpiler/test_stochastic_swap.py @@ -535,19 +535,16 @@ def test_single_gates_omitted(self): coupling_map = [[0, 1], [1, 0], [1, 2], [1, 3], [2, 1], [3, 1], [3, 4], [4, 3]] - """ - q_0: ──■────────────────── - │ - q_1: ──┼─────────■──────── - │ ┌─┴─┐ - q_2: ──┼───────┤ X ├────── - │ ┌────┴───┴─────┐ - q_3: ──┼──┤ U(1,1.5,0.7) ├ - ┌─┴─┐└──────────────┘ - q_4: ┤ X ├──────────────── - └───┘ - c: 5/═════════════════════ - """ + # q_0: ──■────────────────── + # │ + # q_1: ──┼─────────■──────── + # │ ┌─┴─┐ + # q_2: ──┼───────┤ X ├────── + # │ ┌────┴───┴─────┐ + # q_3: ──┼──┤ U(1,1.5,0.7) ├ + # ┌─┴─┐└──────────────┘ + # q_4: ┤ X ├──────────────── + # └───┘ qr = QuantumRegister(5, "q") cr = ClassicalRegister(5, "c") circuit = QuantumCircuit(qr, cr) @@ -555,17 +552,15 @@ def test_single_gates_omitted(self): circuit.cx(qr[1], qr[2]) circuit.u(1, 1.5, 0.7, qr[3]) - """ - q_0: ─────────────────X────── - │ - q_1: ───────■─────────X───■── - ┌─┴─┐ │ - q_2: ─────┤ X ├───────────┼── - ┌────┴───┴─────┐ ┌─┴─┐ - q_3: ┤ U(1,1.5,0.7) ├─X─┤ X ├ - └──────────────┘ │ └───┘ - q_4: ─────────────────X────── - """ + # q_0: ─────────────────X────── + # │ + # q_1: ───────■─────────X───■── + # ┌─┴─┐ │ + # q_2: ─────┤ X ├───────────┼── + # ┌────┴───┴─────┐ ┌─┴─┐ + # q_3: ┤ U(1,1.5,0.7) ├─X─┤ X ├ + # └──────────────┘ │ └───┘ + # q_4: ─────────────────X────── expected = QuantumCircuit(qr, cr) expected.cx(qr[1], qr[2]) expected.u(1, 1.5, 0.7, qr[3]) diff --git a/test/python/transpiler/test_unroller.py b/test/python/transpiler/test_unroller.py index 306baac730df..b8bb28df30ea 100644 --- a/test/python/transpiler/test_unroller.py +++ b/test/python/transpiler/test_unroller.py @@ -477,11 +477,11 @@ def test_unroll_cu1(self): def test_unroll_cu3(self): """test unroll cu3 - ┌──────────────┐ - qr_1: ────────■──────── qr_1: ─┤ U3(0,0,0.05) ├──■────────────────────────■─────────────────── - ┌───────┴───────┐ = ┌┴──────────────┤┌─┴─┐┌──────────────────┐┌─┴─┐┌───────────────┐ - qr_2: ┤ U3(0.2,0.1,0) ├ qr_2: ┤ U3(0,0,-0.05) ├┤ X ├┤ U3(-0.1,0,-0.05) ├┤ X ├┤ U3(0.1,0.1,0) ├ - └───────────────┘ └───────────────┘└───┘└──────────────────┘└───┘└───────────────┘ + ┌──────────────┐ + qr_1: ────────■──────── qr_1: ─┤ U3(0,0,0.05) ├──■────────────────────────■─────────────────── + ┌───────┴───────┐ = ┌┴──────────────┤┌─┴─┐┌──────────────────┐┌─┴─┐┌───────────────┐ + qr_2: ┤ U3(0.2,0.1,0) ├ qr_2: ┤ U3(0,0,-0.05) ├┤ X ├┤ U3(-0.1,0,-0.05) ├┤ X ├┤ U3(0.1,0.1,0) ├ + └───────────────┘ └───────────────┘└───┘└──────────────────┘└───┘└───────────────┘ """ self.circuit.append(CU3Gate(0.2, 0.1, 0.0), [1, 2]) self.ref_circuit.append(U3Gate(0, 0, 0.05), [1]) From 6bb957dd1baf5ff70e45c206f23757d97228fed5 Mon Sep 17 00:00:00 2001 From: Jintaoyu Date: Thu, 9 Dec 2021 16:41:56 +0800 Subject: [PATCH 13/18] Add circuit diagram to standard_gates --- .../library/standard_gates/multi_control_rotation_gates.py | 5 +++++ qiskit/circuit/library/standard_gates/p.py | 5 +++++ qiskit/circuit/library/standard_gates/rx.py | 4 ++++ qiskit/circuit/library/standard_gates/rxx.py | 5 +++++ qiskit/circuit/library/standard_gates/ry.py | 4 ++++ qiskit/circuit/library/standard_gates/ryy.py | 5 +++++ qiskit/circuit/library/standard_gates/rz.py | 4 ++++ qiskit/circuit/library/standard_gates/rzx.py | 4 ++++ qiskit/circuit/library/standard_gates/rzz.py | 4 ++++ qiskit/circuit/library/standard_gates/u.py | 5 +++++ qiskit/circuit/library/standard_gates/u1.py | 5 +++++ qiskit/circuit/library/standard_gates/u3.py | 5 +++++ qiskit/circuit/library/standard_gates/x.py | 7 +++++++ 13 files changed, 62 insertions(+) diff --git a/qiskit/circuit/library/standard_gates/multi_control_rotation_gates.py b/qiskit/circuit/library/standard_gates/multi_control_rotation_gates.py index c7014e3e7406..dda1dba3f165 100644 --- a/qiskit/circuit/library/standard_gates/multi_control_rotation_gates.py +++ b/qiskit/circuit/library/standard_gates/multi_control_rotation_gates.py @@ -25,6 +25,11 @@ def _apply_cu(circuit, theta, phi, lam, control, target, use_basis_gates=True): if use_basis_gates: # pylint: disable=cyclic-import + # ┌──────────────┐ + # control: ┤ P(λ/2 + φ/2) ├──■──────────────────────────────────■──────────────── + # ├──────────────┤┌─┴─┐┌────────────────────────────┐┌─┴─┐┌────────────┐ + # target: ┤ P(λ/2 - φ/2) ├┤ X ├┤ U(-0.5*0,0,-0.5*λ - 0.5*φ) ├┤ X ├┤ U(0/2,φ,0) ├ + # └──────────────┘└───┘└────────────────────────────┘└───┘└────────────┘ circuit.p((lam + phi) / 2, [control]) circuit.p((lam - phi) / 2, [target]) circuit.cx(control, target) diff --git a/qiskit/circuit/library/standard_gates/p.py b/qiskit/circuit/library/standard_gates/p.py index 9fc53e6390b3..825206421279 100644 --- a/qiskit/circuit/library/standard_gates/p.py +++ b/qiskit/circuit/library/standard_gates/p.py @@ -188,6 +188,11 @@ def _define(self): # pylint: disable=cyclic-import from qiskit.circuit.quantumcircuit import QuantumCircuit + # ┌────────┐ + # q_0: ┤ P(λ/2) ├──■──────────────■──────────── + # └────────┘┌─┴─┐┌────────┐┌─┴─┐┌────────┐ + # q_1: ──────────┤ X ├┤ P(λ/2) ├┤ X ├┤ P(λ/2) ├ + # └───┘└────────┘└───┘└────────┘ q = QuantumRegister(2, "q") qc = QuantumCircuit(q, name=self.name) qc.p(self.params[0] / 2, 0) diff --git a/qiskit/circuit/library/standard_gates/rx.py b/qiskit/circuit/library/standard_gates/rx.py index 062642097737..dac290490503 100644 --- a/qiskit/circuit/library/standard_gates/rx.py +++ b/qiskit/circuit/library/standard_gates/rx.py @@ -192,6 +192,10 @@ def _define(self): from .u3 import U3Gate from .x import CXGate + # q_0: ─────────────■───────────────────■──────────────────── + # ┌─────────┐┌─┴─┐┌─────────────┐┌─┴─┐┌────────────────┐ + # q_1: ┤ U1(π/2) ├┤ X ├┤ U3(0/2,0,0) ├┤ X ├┤ U3(0/2,-π/2,0) ├ + # └─────────┘└───┘└─────────────┘└───┘└────────────────┘ q = QuantumRegister(2, "q") qc = QuantumCircuit(q, name=self.name) rules = [ diff --git a/qiskit/circuit/library/standard_gates/rxx.py b/qiskit/circuit/library/standard_gates/rxx.py index d46e074327a0..7086872b221a 100644 --- a/qiskit/circuit/library/standard_gates/rxx.py +++ b/qiskit/circuit/library/standard_gates/rxx.py @@ -80,6 +80,11 @@ def _define(self): from .h import HGate from .rz import RZGate + # ┌───┐ ┌───┐ + # q_0: ┤ H ├──■─────────────■──┤ H ├ + # ├───┤┌─┴─┐┌───────┐┌─┴─┐├───┤ + # q_1: ┤ H ├┤ X ├┤ Rz(0) ├┤ X ├┤ H ├ + # └───┘└───┘└───────┘└───┘└───┘ theta = self.params[0] q = QuantumRegister(2, "q") qc = QuantumCircuit(q, name=self.name) diff --git a/qiskit/circuit/library/standard_gates/ry.py b/qiskit/circuit/library/standard_gates/ry.py index eea2d4272332..c33d3a4a9332 100644 --- a/qiskit/circuit/library/standard_gates/ry.py +++ b/qiskit/circuit/library/standard_gates/ry.py @@ -186,6 +186,10 @@ def _define(self): from qiskit.circuit.quantumcircuit import QuantumCircuit from .x import CXGate + # q_0: ─────────────■───────────────■── + # ┌─────────┐┌─┴─┐┌─────────┐┌─┴─┐ + # q_1: ┤ Ry(λ/2) ├┤ X ├┤ Ry(λ/2) ├┤ X ├ + # └─────────┘└───┘└─────────┘└───┘ q = QuantumRegister(2, "q") qc = QuantumCircuit(q, name=self.name) rules = [ diff --git a/qiskit/circuit/library/standard_gates/ryy.py b/qiskit/circuit/library/standard_gates/ryy.py index 54001cb0f84e..79b5dc3e82df 100644 --- a/qiskit/circuit/library/standard_gates/ryy.py +++ b/qiskit/circuit/library/standard_gates/ryy.py @@ -81,6 +81,11 @@ def _define(self): from .rx import RXGate from .rz import RZGate + # ┌─────────┐ ┌──────────┐ + # q_0: ┤ Rx(π/2) ├──■─────────────■──┤ Rx(-π/2) ├ + # ├─────────┤┌─┴─┐┌───────┐┌─┴─┐├──────────┤ + # q_1: ┤ Rx(π/2) ├┤ X ├┤ Rz(0) ├┤ X ├┤ Rx(-π/2) ├ + # └─────────┘└───┘└───────┘└───┘└──────────┘ q = QuantumRegister(2, "q") theta = self.params[0] qc = QuantumCircuit(q, name=self.name) diff --git a/qiskit/circuit/library/standard_gates/rz.py b/qiskit/circuit/library/standard_gates/rz.py index 9591b8532083..9cfe789f0906 100644 --- a/qiskit/circuit/library/standard_gates/rz.py +++ b/qiskit/circuit/library/standard_gates/rz.py @@ -204,6 +204,10 @@ def _define(self): from qiskit.circuit.quantumcircuit import QuantumCircuit from .x import CXGate + # q_0: ─────────────■────────────────■── + # ┌─────────┐┌─┴─┐┌──────────┐┌─┴─┐ + # q_1: ┤ Rz(λ/2) ├┤ X ├┤ Rz(-λ/2) ├┤ X ├ + # └─────────┘└───┘└──────────┘└───┘ q = QuantumRegister(2, "q") qc = QuantumCircuit(q, name=self.name) rules = [ diff --git a/qiskit/circuit/library/standard_gates/rzx.py b/qiskit/circuit/library/standard_gates/rzx.py index 203a827f34e0..24420b0f9e6b 100644 --- a/qiskit/circuit/library/standard_gates/rzx.py +++ b/qiskit/circuit/library/standard_gates/rzx.py @@ -128,6 +128,10 @@ def _define(self): from .x import CXGate from .rz import RZGate + # q_0: ───────■─────────────■─────── + # ┌───┐┌─┴─┐┌───────┐┌─┴─┐┌───┐ + # q_1: ┤ H ├┤ X ├┤ Rz(0) ├┤ X ├┤ H ├ + # └───┘└───┘└───────┘└───┘└───┘ theta = self.params[0] q = QuantumRegister(2, "q") qc = QuantumCircuit(q, name=self.name) diff --git a/qiskit/circuit/library/standard_gates/rzz.py b/qiskit/circuit/library/standard_gates/rzz.py index 80c9e4693141..3f8655db527d 100644 --- a/qiskit/circuit/library/standard_gates/rzz.py +++ b/qiskit/circuit/library/standard_gates/rzz.py @@ -94,6 +94,10 @@ def _define(self): from .x import CXGate from .rz import RZGate + # q_0: ──■─────────────■── + # ┌─┴─┐┌───────┐┌─┴─┐ + # q_1: ┤ X ├┤ Rz(0) ├┤ X ├ + # └───┘└───────┘└───┘ q = QuantumRegister(2, "q") theta = self.params[0] qc = QuantumCircuit(q, name=self.name) diff --git a/qiskit/circuit/library/standard_gates/u.py b/qiskit/circuit/library/standard_gates/u.py index d6033f0454b5..d9c5c11a2abd 100644 --- a/qiskit/circuit/library/standard_gates/u.py +++ b/qiskit/circuit/library/standard_gates/u.py @@ -216,6 +216,11 @@ def _define(self): # pylint: disable=cyclic-import from qiskit.circuit.quantumcircuit import QuantumCircuit + # ┌──────┐ ┌──────────────┐ + # q_0: ────┤ P(γ) ├────┤ P(λ/2 + φ/2) ├──■────────────────────────────■──────────────── + # ┌───┴──────┴───┐└──────────────┘┌─┴─┐┌──────────────────────┐┌─┴─┐┌────────────┐ + # q_1: ┤ P(λ/2 - φ/2) ├────────────────┤ X ├┤ U(-0/2,0,-λ/2 - φ/2) ├┤ X ├┤ U(0/2,φ,0) ├ + # └──────────────┘ └───┘└──────────────────────┘└───┘└────────────┘ q = QuantumRegister(2, "q") qc = QuantumCircuit(q, name=self.name) qc.p(self.params[3], 0) diff --git a/qiskit/circuit/library/standard_gates/u1.py b/qiskit/circuit/library/standard_gates/u1.py index 5828987747cf..bcb744819cc6 100644 --- a/qiskit/circuit/library/standard_gates/u1.py +++ b/qiskit/circuit/library/standard_gates/u1.py @@ -197,6 +197,11 @@ def _define(self): from qiskit.circuit.quantumcircuit import QuantumCircuit from .x import CXGate # pylint: disable=cyclic-import + # ┌─────────┐ + # q_0: ┤ U1(λ/2) ├──■────────────────■───────────── + # └─────────┘┌─┴─┐┌──────────┐┌─┴─┐┌─────────┐ + # q_1: ───────────┤ X ├┤ U1(-λ/2) ├┤ X ├┤ U1(λ/2) ├ + # └───┘└──────────┘└───┘└─────────┘ q = QuantumRegister(2, "q") qc = QuantumCircuit(q, name=self.name) rules = [ diff --git a/qiskit/circuit/library/standard_gates/u3.py b/qiskit/circuit/library/standard_gates/u3.py index 58947a6b439d..0d2eb0f73704 100644 --- a/qiskit/circuit/library/standard_gates/u3.py +++ b/qiskit/circuit/library/standard_gates/u3.py @@ -217,6 +217,11 @@ def _define(self): from .u1 import U1Gate from .x import CXGate # pylint: disable=cyclic-import + # ┌───────────────┐ + # q_0: ┤ U1(λ/2 + φ/2) ├──■─────────────────────────────■───────────────── + # ├───────────────┤┌─┴─┐┌───────────────────────┐┌─┴─┐┌─────────────┐ + # q_1: ┤ U1(λ/2 - φ/2) ├┤ X ├┤ U3(-0/2,0,-λ/2 - φ/2) ├┤ X ├┤ U3(0/2,φ,0) ├ + # └───────────────┘└───┘└───────────────────────┘└───┘└─────────────┘ q = QuantumRegister(2, "q") qc = QuantumCircuit(q, name=self.name) rules = [ diff --git a/qiskit/circuit/library/standard_gates/x.py b/qiskit/circuit/library/standard_gates/x.py index ba265e7ba525..08e7ec0364ca 100644 --- a/qiskit/circuit/library/standard_gates/x.py +++ b/qiskit/circuit/library/standard_gates/x.py @@ -335,6 +335,13 @@ def _define(self): # pylint: disable=cyclic-import from qiskit.circuit.quantumcircuit import QuantumCircuit + # ┌───┐ + # q_0: ───────────────────■─────────────────────■────■───┤ T ├───■── + # │ ┌───┐ │ ┌─┴─┐┌┴───┴┐┌─┴─┐ + # q_1: ───────■───────────┼─────────■───┤ T ├───┼──┤ X ├┤ Tdg ├┤ X ├ + # ┌───┐┌─┴─┐┌─────┐┌─┴─┐┌───┐┌─┴─┐┌┴───┴┐┌─┴─┐├───┤└┬───┬┘└───┘ + # q_2: ┤ H ├┤ X ├┤ Tdg ├┤ X ├┤ T ├┤ X ├┤ Tdg ├┤ X ├┤ T ├─┤ H ├────── + # └───┘└───┘└─────┘└───┘└───┘└───┘└─────┘└───┘└───┘ └───┘ q = QuantumRegister(3, "q") qc = QuantumCircuit(q, name=self.name) rules = [ From b442a50b69b4ea3d7d52092514db19cb69ad7729 Mon Sep 17 00:00:00 2001 From: Jintaoyu Date: Fri, 10 Dec 2021 18:47:50 +0800 Subject: [PATCH 14/18] Add parsed-literal before circuit diagram --- qiskit/circuit/quantumcircuit.py | 74 ++++++++++--------- .../quantum_initializer/initializer.py | 30 ++++---- qiskit/synthesis/evolution/product_formula.py | 4 +- .../echo_rzx_weyl_decomposition.py | 30 ++++---- .../template_substitution.py | 30 +++++--- .../passes/utils/merge_adjacent_barriers.py | 15 ++-- 6 files changed, 101 insertions(+), 82 deletions(-) diff --git a/qiskit/circuit/quantumcircuit.py b/qiskit/circuit/quantumcircuit.py index 5551b64ac023..3bb8be5ed7d2 100644 --- a/qiskit/circuit/quantumcircuit.py +++ b/qiskit/circuit/quantumcircuit.py @@ -425,18 +425,20 @@ def reverse_ops(self) -> "QuantumCircuit": Examples: input: - ┌───┐ - q_0: ┤ H ├─────■────── - └───┘┌────┴─────┐ - q_1: ─────┤ RX(1.57) ├ - └──────────┘ + .. parsed-literal:: + ┌───┐ + q_0: ┤ H ├─────■────── + └───┘┌────┴─────┐ + q_1: ─────┤ RX(1.57) ├ + └──────────┘ output: - ┌───┐ - q_0: ─────■──────┤ H ├ - ┌────┴─────┐└───┘ - q_1: ┤ RX(1.57) ├───── - └──────────┘ + .. parsed-literal:: + ┌───┐ + q_0: ─────■──────┤ H ├ + ┌────┴─────┐└───┘ + q_1: ┤ RX(1.57) ├───── + └──────────┘ """ reverse_circ = QuantumCircuit( self.qubits, self.clbits, *self.qregs, *self.cregs, name=self.name + "_reverse" @@ -465,18 +467,20 @@ def reverse_bits(self) -> "QuantumCircuit": Examples: input: - ┌───┐ - q_0: ┤ H ├─────■────── - └───┘┌────┴─────┐ - q_1: ─────┤ RX(1.57) ├ - └──────────┘ + .. parsed-literal:: + ┌───┐ + q_0: ┤ H ├─────■────── + └───┘┌────┴─────┐ + q_1: ─────┤ RX(1.57) ├ + └──────────┘ output: - ┌──────────┐ - q_0: ─────┤ RX(1.57) ├ - ┌───┐└────┬─────┘ - q_1: ┤ H ├─────■────── - └───┘ + .. parsed-literal:: + ┌──────────┐ + q_0: ─────┤ RX(1.57) ├ + ┌───┐└────┬─────┘ + q_1: ┤ H ├─────■────── + └───┘ """ circ = QuantumCircuit( *reversed(self.qregs), @@ -511,18 +515,20 @@ def inverse(self) -> "QuantumCircuit": Examples: input: - ┌───┐ - q_0: ┤ H ├─────■────── - └───┘┌────┴─────┐ - q_1: ─────┤ RX(1.57) ├ - └──────────┘ + .. parsed-literal:: + ┌───┐ + q_0: ┤ H ├─────■────── + └───┘┌────┴─────┐ + q_1: ─────┤ RX(1.57) ├ + └──────────┘ output: - ┌───┐ - q_0: ──────■──────┤ H ├ - ┌─────┴─────┐└───┘ - q_1: ┤ RX(-1.57) ├───── - └───────────┘ + .. parsed-literal:: + ┌───┐ + q_0: ──────■──────┤ H ├ + ┌─────┴─────┐└───┘ + q_1: ┤ RX(-1.57) ├───── + └───────────┘ """ inverse_circ = QuantumCircuit( self.qubits, @@ -910,11 +916,11 @@ def tensor(self, other: "QuantumCircuit", inplace: bool = False) -> Optional["Qu .. parsed-literal:: - ┌────────┐ ┌─────┐ ┌─────┐ + ┌────────┐ ┌─────┐ ┌─────┐ q_0: ┤ bottom ├ ⊗ q_0: ┤ top ├ = q_0: ─┤ top ├── - └────────┘ └─────┘ ┌┴─────┴─┐ - q_1: ┤ bottom ├ - └────────┘ + └────────┘ └─────┘ ┌┴─────┴─┐ + q_1: ┤ bottom ├ + └────────┘ Args: other (QuantumCircuit): The other circuit to tensor this circuit with. diff --git a/qiskit/extensions/quantum_initializer/initializer.py b/qiskit/extensions/quantum_initializer/initializer.py index daa07b54ba3a..398485c3c748 100644 --- a/qiskit/extensions/quantum_initializer/initializer.py +++ b/qiskit/extensions/quantum_initializer/initializer.py @@ -402,9 +402,11 @@ def initialize(self, params, qubits=None): circuit.draw() output: - ┌──────────────────────────────┐ - q_0: ┤ initialize(0.70711,-0.70711) ├ - └──────────────────────────────┘ + .. parsed-literal:: + + ┌──────────────────────────────┐ + q_0: ┤ initialize(0.70711,-0.70711) ├ + └──────────────────────────────┘ Initialize from a string two qubits in the state `|10>`. @@ -422,11 +424,12 @@ def initialize(self, params, qubits=None): circuit.draw() output: - ┌──────────────────┐ - q_0: ┤0 ├ - │ initialize(0,1) │ - q_1: ┤1 ├ - └──────────────────┘ + .. parsed-literal:: + ┌──────────────────┐ + q_0: ┤0 ├ + │ initialize(0,1) │ + q_1: ┤1 ├ + └──────────────────┘ Initialize two qubits from an array of complex amplitudes @@ -440,11 +443,12 @@ def initialize(self, params, qubits=None): circuit.draw() output: - ┌────────────────────────────────────┐ - q_0: ┤0 ├ - │ initialize(0,0.70711,-0.70711j,0) │ - q_1: ┤1 ├ - └────────────────────────────────────┘ + .. parsed-literal:: + ┌────────────────────────────────────┐ + q_0: ┤0 ├ + │ initialize(0,0.70711,-0.70711j,0) │ + q_1: ┤1 ├ + └────────────────────────────────────┘ """ if qubits is None: qubits = self.qubits diff --git a/qiskit/synthesis/evolution/product_formula.py b/qiskit/synthesis/evolution/product_formula.py index 66b543110804..caaf8a15ce6e 100644 --- a/qiskit/synthesis/evolution/product_formula.py +++ b/qiskit/synthesis/evolution/product_formula.py @@ -199,7 +199,7 @@ def cnot_chain(pauli: Pauli) -> QuantumCircuit: For example, for the Pauli with the label 'XYZIX'. - .. code-block:: + .. parsed-literal:: ┌───┐ q_0: ──────────┤ X ├ @@ -244,7 +244,7 @@ def cnot_fountain(pauli: Pauli) -> QuantumCircuit: For example, for the Pauli with the label 'XYZIX'. - .. code-block:: + .. parsed-literal:: ┌───┐┌───┐┌───┐ q_0: ┤ X ├┤ X ├┤ X ├ diff --git a/qiskit/transpiler/passes/optimization/echo_rzx_weyl_decomposition.py b/qiskit/transpiler/passes/optimization/echo_rzx_weyl_decomposition.py index 15e087a526a5..adbcc4055252 100644 --- a/qiskit/transpiler/passes/optimization/echo_rzx_weyl_decomposition.py +++ b/qiskit/transpiler/passes/optimization/echo_rzx_weyl_decomposition.py @@ -49,13 +49,14 @@ def _is_native(self, qubit_pair: Tuple) -> bool: @staticmethod def _echo_rzx_dag(theta): - """Return the following circuit:: - - ┌───────────────┐┌───┐┌────────────────┐┌───┐ - q_0: ┤0 ├┤ X ├┤0 ├┤ X ├ - │ Rzx(theta/2) │└───┘│ Rzx(-theta/2) │└───┘ - q_1: ┤1 ├─────┤1 ├───── - └───────────────┘ └────────────────┘ + """Return the following circuit + + .. parsed-literal:: + ┌───────────────┐┌───┐┌────────────────┐┌───┐ + q_0: ┤0 ├┤ X ├┤0 ├┤ X ├ + │ Rzx(theta/2) │└───┘│ Rzx(-theta/2) │└───┘ + q_1: ┤1 ├─────┤1 ├───── + └───────────────┘ └────────────────┘ """ rzx_dag = DAGCircuit() qr = QuantumRegister(2) @@ -68,13 +69,14 @@ def _echo_rzx_dag(theta): @staticmethod def _reverse_echo_rzx_dag(theta): - """Return the following circuit:: - - ┌───┐┌───────────────┐ ┌────────────────┐┌───┐ - q_0: ┤ H ├┤1 ├─────┤1 ├┤ H ├───── - ├───┤│ Rzx(theta/2) │┌───┐│ Rzx(-theta/2) │├───┤┌───┐ - q_1: ┤ H ├┤0 ├┤ X ├┤0 ├┤ X ├┤ H ├ - └───┘└───────────────┘└───┘└────────────────┘└───┘└───┘ + """Return the following circuit + + .. parsed-literal:: + ┌───┐┌───────────────┐ ┌────────────────┐┌───┐ + q_0: ┤ H ├┤1 ├─────┤1 ├┤ H ├───── + ├───┤│ Rzx(theta/2) │┌───┐│ Rzx(-theta/2) │├───┤┌───┐ + q_1: ┤ H ├┤0 ├┤ X ├┤0 ├┤ X ├┤ H ├ + └───┘└───────────────┘└───┘└────────────────┘└───┘└───┘ """ reverse_rzx_dag = DAGCircuit() qr = QuantumRegister(2) diff --git a/qiskit/transpiler/passes/optimization/template_matching/template_substitution.py b/qiskit/transpiler/passes/optimization/template_matching/template_substitution.py index 3390abd6c0c8..c1cbd26190ed 100644 --- a/qiskit/transpiler/passes/optimization/template_matching/template_substitution.py +++ b/qiskit/transpiler/passes/optimization/template_matching/template_substitution.py @@ -455,19 +455,25 @@ def _attempt_bind(self, template_sublist, circuit_sublist): i.e. attempts to solve for a valid parameter assignment. template_sublist and circuit_sublist match up to the assignment of the parameters. For example the template - ┌───────────┐ ┌────────┐ - q_0: ┤ P(-1.0*β) ├──■────────────■──┤0 ├ - ├───────────┤┌─┴─┐┌──────┐┌─┴─┐│ CZ(β) │ - q_1: ┤ P(-1.0*β) ├┤ X ├┤ P(β) ├┤ X ├┤1 ├ - └───────────┘└───┘└──────┘└───┘└────────┘ + + .. parsed-literal:: + ┌───────────┐ ┌────────┐ + q_0: ┤ P(-1.0*β) ├──■────────────■──┤0 ├ + ├───────────┤┌─┴─┐┌──────┐┌─┴─┐│ CZ(β) │ + q_1: ┤ P(-1.0*β) ├┤ X ├┤ P(β) ├┤ X ├┤1 ├ + └───────────┘└───┘└──────┘└───┘└────────┘ + should only maximally match once in the circuit - ┌───────┐ - q_0: ┤ P(-2) ├──■────────────■──────────────────────────── - ├───────┤┌─┴─┐┌──────┐┌─┴─┐┌──────┐ - q_1: ┤ P(-2) ├┤ X ├┤ P(2) ├┤ X ├┤ P(3) ├──■────────────■── - └┬──────┤└───┘└──────┘└───┘└──────┘┌─┴─┐┌──────┐┌─┴─┐ - q_2: ─┤ P(3) ├──────────────────────────┤ X ├┤ P(3) ├┤ X ├ - └──────┘ └───┘└──────┘└───┘ + + .. parsed-literal:: + ┌───────┐ + q_0: ┤ P(-2) ├──■────────────■──────────────────────────── + ├───────┤┌─┴─┐┌──────┐┌─┴─┐┌──────┐ + q_1: ┤ P(-2) ├┤ X ├┤ P(2) ├┤ X ├┤ P(3) ├──■────────────■── + └┬──────┤└───┘└──────┘└───┘└──────┘┌─┴─┐┌──────┐┌─┴─┐ + q_2: ─┤ P(3) ├──────────────────────────┤ X ├┤ P(3) ├┤ X ├ + └──────┘ └───┘└──────┘└───┘ + However, up until attempt bind is called, the soft matching will have found two matches due to the parameters. The first match can be satisfied with β=2. However, the diff --git a/qiskit/transpiler/passes/utils/merge_adjacent_barriers.py b/qiskit/transpiler/passes/utils/merge_adjacent_barriers.py index 03c9b87c3dff..d92f6615265e 100644 --- a/qiskit/transpiler/passes/utils/merge_adjacent_barriers.py +++ b/qiskit/transpiler/passes/utils/merge_adjacent_barriers.py @@ -40,13 +40,14 @@ class MergeAdjacentBarriers(TransformationPass): i.e, - ░ ░ ░ ░ - q_0: ─░──░─ q_0: ─░──░─ - ░ ░ ░ ░ - q_1: ─░──░─ => q_1: ────░─ - ░ ░ ░ - q_2: ────░─ q_2: ────░─ - ░ + .. parsed-literal:: + ░ ░ ░ ░ + q_0: ─░──░─ q_0: ─░──░─ + ░ ░ ░ ░ + q_1: ─░──░─ => q_1: ────░─ + ░ ░ ░ + q_2: ────░─ q_2: ────░─ + ░ after one iteration of the pass. These two barriers were not merged by the first pass as they are not adjacent in the initial circuit. From 7f4341a24eca0b61af2cb51b5d2c638b226d1381 Mon Sep 17 00:00:00 2001 From: Jintaoyu Date: Fri, 10 Dec 2021 18:55:18 +0800 Subject: [PATCH 15/18] fix a lint problem --- .../passes/optimization/echo_rzx_weyl_decomposition.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qiskit/transpiler/passes/optimization/echo_rzx_weyl_decomposition.py b/qiskit/transpiler/passes/optimization/echo_rzx_weyl_decomposition.py index adbcc4055252..05ce4264ce3e 100644 --- a/qiskit/transpiler/passes/optimization/echo_rzx_weyl_decomposition.py +++ b/qiskit/transpiler/passes/optimization/echo_rzx_weyl_decomposition.py @@ -50,7 +50,7 @@ def _is_native(self, qubit_pair: Tuple) -> bool: @staticmethod def _echo_rzx_dag(theta): """Return the following circuit - + .. parsed-literal:: ┌───────────────┐┌───┐┌────────────────┐┌───┐ q_0: ┤0 ├┤ X ├┤0 ├┤ X ├ From d269a310c11eb373b6b4f10916eae5db5621173e Mon Sep 17 00:00:00 2001 From: Jintaoyu Date: Fri, 10 Dec 2021 22:32:02 +0800 Subject: [PATCH 16/18] Update circuit diagram in test --- .../estimation_problem.py | 4 +- .../library/n_local/pauli_two_design.py | 2 +- qiskit/circuit/quantumcircuit.py | 12 +- .../quantum_initializer/initializer.py | 3 +- ...rap-library-circuits-9b7f7398f3fce8a8.yaml | 4 +- test/python/basicaer/test_qasm_simulator.py | 128 +-- .../circuit/library/test_grover_operator.py | 35 +- test/python/circuit/library/test_nlocal.py | 16 +- .../python/circuit/test_circuit_properties.py | 1009 ++++++++--------- test/python/compiler/test_compiler.py | 46 +- test/python/compiler/test_transpiler.py | 63 +- test/python/dagcircuit/test_dagcircuit.py | 257 ++--- test/python/dagcircuit/test_dagdependency.py | 26 +- test/python/scheduler/test_basic_scheduler.py | 58 +- .../transpiler/test_basis_translator.py | 29 +- test/python/transpiler/test_bip_mapping.py | 100 +- .../transpiler/test_commutation_analysis.py | 27 +- .../test_commutative_cancellation.py | 25 +- .../transpiler/test_consolidate_blocks.py | 67 +- .../test_count_ops_longest_path_pass.py | 11 +- test/python/transpiler/test_count_ops_pass.py | 13 +- .../python/transpiler/test_cx_cancellation.py | 23 +- .../transpiler/test_dag_longest_path_pass.py | 11 +- test/python/transpiler/test_depth_pass.py | 15 +- test/python/transpiler/test_faulty_backend.py | 31 +- test/python/transpiler/test_hoare_opt.py | 21 +- test/python/transpiler/test_lookahead_swap.py | 66 +- .../test_optimize_1q_commutation.py | 60 +- .../transpiler/test_optimize_1q_gates.py | 58 +- test/python/transpiler/test_sabre_layout.py | 54 +- test/python/transpiler/test_unroller.py | 203 ++-- 31 files changed, 1175 insertions(+), 1302 deletions(-) diff --git a/qiskit/algorithms/amplitude_estimators/estimation_problem.py b/qiskit/algorithms/amplitude_estimators/estimation_problem.py index 056fc83687b4..be563614809b 100644 --- a/qiskit/algorithms/amplitude_estimators/estimation_problem.py +++ b/qiskit/algorithms/amplitude_estimators/estimation_problem.py @@ -221,7 +221,7 @@ def _rescale_amplitudes(circuit: QuantumCircuit, scaling_factor: float) -> Quant For example, for a scaling factor of 0.25 this turns this circuit - .. code-block:: + .. parsed-literal:: ┌───┐ state_0: ─────┤ H ├─────────■──── @@ -231,7 +231,7 @@ def _rescale_amplitudes(circuit: QuantumCircuit, scaling_factor: float) -> Quant into - .. code-block:: + .. parsed-literal:: ┌───┐ state_0: ─────┤ H ├─────────■──── diff --git a/qiskit/circuit/library/n_local/pauli_two_design.py b/qiskit/circuit/library/n_local/pauli_two_design.py index efc11bd16d65..34ef1cb05302 100644 --- a/qiskit/circuit/library/n_local/pauli_two_design.py +++ b/qiskit/circuit/library/n_local/pauli_two_design.py @@ -37,7 +37,7 @@ class PauliTwoDesign(TwoLocal): For instance, the circuit could look like this (but note that choosing a different seed yields different Pauli rotations). - .. code-block:: + .. parsed-literal:: ┌─────────┐┌──────────┐ ░ ┌──────────┐ ░ ┌──────────┐ q_0: ┤ RY(π/4) ├┤ RZ(θ[0]) ├─■─────░─┤ RY(θ[4]) ├─■─────░──┤ RZ(θ[8]) ├ diff --git a/qiskit/circuit/quantumcircuit.py b/qiskit/circuit/quantumcircuit.py index 3bb8be5ed7d2..6d18cc031ff9 100644 --- a/qiskit/circuit/quantumcircuit.py +++ b/qiskit/circuit/quantumcircuit.py @@ -426,6 +426,7 @@ def reverse_ops(self) -> "QuantumCircuit": input: .. parsed-literal:: + ┌───┐ q_0: ┤ H ├─────■────── └───┘┌────┴─────┐ @@ -434,6 +435,7 @@ def reverse_ops(self) -> "QuantumCircuit": output: .. parsed-literal:: + ┌───┐ q_0: ─────■──────┤ H ├ ┌────┴─────┐└───┘ @@ -468,6 +470,7 @@ def reverse_bits(self) -> "QuantumCircuit": input: .. parsed-literal:: + ┌───┐ q_0: ┤ H ├─────■────── └───┘┌────┴─────┐ @@ -476,6 +479,7 @@ def reverse_bits(self) -> "QuantumCircuit": output: .. parsed-literal:: + ┌──────────┐ q_0: ─────┤ RX(1.57) ├ ┌───┐└────┬─────┘ @@ -516,14 +520,16 @@ def inverse(self) -> "QuantumCircuit": input: .. parsed-literal:: - ┌───┐ + + ┌───┐ q_0: ┤ H ├─────■────── - └───┘┌────┴─────┐ + └───┘┌────┴─────┐ q_1: ─────┤ RX(1.57) ├ - └──────────┘ + └──────────┘ output: .. parsed-literal:: + ┌───┐ q_0: ──────■──────┤ H ├ ┌─────┴─────┐└───┘ diff --git a/qiskit/extensions/quantum_initializer/initializer.py b/qiskit/extensions/quantum_initializer/initializer.py index 398485c3c748..594135c5971f 100644 --- a/qiskit/extensions/quantum_initializer/initializer.py +++ b/qiskit/extensions/quantum_initializer/initializer.py @@ -425,13 +425,13 @@ def initialize(self, params, qubits=None): output: .. parsed-literal:: + ┌──────────────────┐ q_0: ┤0 ├ │ initialize(0,1) │ q_1: ┤1 ├ └──────────────────┘ - Initialize two qubits from an array of complex amplitudes .. jupyter-execute:: @@ -444,6 +444,7 @@ def initialize(self, params, qubits=None): output: .. parsed-literal:: + ┌────────────────────────────────────┐ q_0: ┤0 ├ │ initialize(0,0.70711,-0.70711j,0) │ diff --git a/releasenotes/notes/0.18/wrap-library-circuits-9b7f7398f3fce8a8.yaml b/releasenotes/notes/0.18/wrap-library-circuits-9b7f7398f3fce8a8.yaml index 7a1b06653cce..15126bca3495 100644 --- a/releasenotes/notes/0.18/wrap-library-circuits-9b7f7398f3fce8a8.yaml +++ b/releasenotes/notes/0.18/wrap-library-circuits-9b7f7398f3fce8a8.yaml @@ -16,7 +16,7 @@ upgrade: before looked like - .. code-block:: + .. parsed-literal:: ┌───┐ q_0: ────────────────────■────────■───────┤ H ├─X─ @@ -28,7 +28,7 @@ upgrade: and now looks like - .. code-block:: + .. parsed-literal:: ┌──────┐ q_0: ┤0 ├ diff --git a/test/python/basicaer/test_qasm_simulator.py b/test/python/basicaer/test_qasm_simulator.py index b0ef864ca419..52941e210306 100644 --- a/test/python/basicaer/test_qasm_simulator.py +++ b/test/python/basicaer/test_qasm_simulator.py @@ -114,29 +114,25 @@ def test_measure_sampler_single_qubit(self): self.assertEqual(counts, target) def test_measure_sampler_partial_qubit(self): - """Test measure sampler if single-qubit is measured. - - (circuit) - - ░ ░ ░ ┌─┐ ░ - qr_0: ──────░─────░─────░─┤M├─░──── - ┌───┐ ░ ░ ┌─┐ ░ └╥┘ ░ - qr_1: ┤ X ├─░─────░─┤M├─░──╫──░──── - └───┘ ░ ░ └╥┘ ░ ║ ░ - qr_2: ──────░─────░──╫──░──╫──░──── - ┌───┐ ░ ┌─┐ ░ ║ ░ ║ ░ ┌─┐ - qr_3: ┤ X ├─░─┤M├─░──╫──░──╫──░─┤M├ - └───┘ ░ └╥┘ ░ ║ ░ ║ ░ └╥┘ - qr_4: ──────░──╫──░──╫──░──╫──░──╫─ - ░ ║ ░ ║ ░ ║ ░ ║ - cr: 4/═════════╩═════╩═════╩═════╩═ - 1 0 2 3 - """ + """Test measure sampler if single-qubit is measured.""" shots = 100 num_qubits = 5 qr = QuantumRegister(num_qubits, "qr") cr = ClassicalRegister(4, "cr") + # ░ ░ ░ ┌─┐ ░ + # qr_0: ──────░─────░─────░─┤M├─░──── + # ┌───┐ ░ ░ ┌─┐ ░ └╥┘ ░ + # qr_1: ┤ X ├─░─────░─┤M├─░──╫──░──── + # └───┘ ░ ░ └╥┘ ░ ║ ░ + # qr_2: ──────░─────░──╫──░──╫──░──── + # ┌───┐ ░ ┌─┐ ░ ║ ░ ║ ░ ┌─┐ + # qr_3: ┤ X ├─░─┤M├─░──╫──░──╫──░─┤M├ + # └───┘ ░ └╥┘ ░ ║ ░ ║ ░ └╥┘ + # qr_4: ──────░──╫──░──╫──░──╫──░──╫─ + # ░ ║ ░ ║ ░ ║ ░ ║ + # cr: 4/═════════╩═════╩═════╩═════╩═ + # 1 0 2 3 circuit = QuantumCircuit(qr, cr) circuit.x(qr[3]) circuit.x(qr[1]) @@ -231,22 +227,18 @@ def test_if_statement(self): def test_bit_cif_crossaffect(self): """Test if bits in a classical register other than - the single conditional bit affect the conditioned operation. - - (circuit) - - ┌───┐ ┌─┐ - q0_0: ────────┤ H ├──────────┤M├ - ┌───┐ └─╥─┘ ┌─┐ └╥┘ - q0_1: ┤ X ├─────╫──────┤M├────╫─ - ├───┤ ║ └╥┘┌─┐ ║ - q0_2: ┤ X ├─────╫───────╫─┤M├─╫─ - └───┘┌────╨─────┐ ║ └╥┘ ║ - c0: 3/═════╡ c0_0=0x1 ╞═╩══╩══╬═ - └──────────┘ 1 2 ║ - c1: 1/════════════════════════╩═ - 0 - """ + the single conditional bit affect the conditioned operation.""" + # ┌───┐ ┌─┐ + # q0_0: ────────┤ H ├──────────┤M├ + # ┌───┐ └─╥─┘ ┌─┐ └╥┘ + # q0_1: ┤ X ├─────╫──────┤M├────╫─ + # ├───┤ ║ └╥┘┌─┐ ║ + # q0_2: ┤ X ├─────╫───────╫─┤M├─╫─ + # └───┘┌────╨─────┐ ║ └╥┘ ║ + # c0: 3/═════╡ c0_0=0x1 ╞═╩══╩══╬═ + # └──────────┘ 1 2 ║ + # c1: 1/════════════════════════╩═ + # 0 shots = 100 qr = QuantumRegister(3) cr = ClassicalRegister(3) @@ -263,25 +255,21 @@ def test_bit_cif_crossaffect(self): self.assertEqual(result, target) def test_teleport(self): - """Test teleportation as in tutorials - - (circuit) - - ┌─────────┐ ┌───┐ ░ ┌─┐ - qr_0: ┤ Ry(π/4) ├───────■──┤ H ├─░─┤M├──────────────────── - └──┬───┬──┘ ┌─┴─┐└───┘ ░ └╥┘┌─┐ - qr_1: ───┤ H ├─────■──┤ X ├──────░──╫─┤M├───────────────── - └───┘ ┌─┴─┐└───┘ ░ ║ └╥┘ ┌───┐ ┌───┐ ┌─┐ - qr_2: ───────────┤ X ├───────────░──╫──╫──┤ Z ├──┤ X ├─┤M├ - └───┘ ░ ║ ║ └─╥─┘ └─╥─┘ └╥┘ - ║ ║ ┌──╨──┐ ║ ║ - cr0: 1/═════════════════════════════╩══╬═╡ 0x1 ╞═══╬════╬═ - 0 ║ └─────┘┌──╨──┐ ║ - cr1: 1/════════════════════════════════╩════════╡ 0x1 ╞═╬═ - 0 └─────┘ ║ - cr2: 1/═════════════════════════════════════════════════╩═ - 0 - """ + """Test teleportation as in tutorials""" + # ┌─────────┐ ┌───┐ ░ ┌─┐ + # qr_0: ┤ Ry(π/4) ├───────■──┤ H ├─░─┤M├──────────────────── + # └──┬───┬──┘ ┌─┴─┐└───┘ ░ └╥┘┌─┐ + # qr_1: ───┤ H ├─────■──┤ X ├──────░──╫─┤M├───────────────── + # └───┘ ┌─┴─┐└───┘ ░ ║ └╥┘ ┌───┐ ┌───┐ ┌─┐ + # qr_2: ───────────┤ X ├───────────░──╫──╫──┤ Z ├──┤ X ├─┤M├ + # └───┘ ░ ║ ║ └─╥─┘ └─╥─┘ └╥┘ + # ║ ║ ┌──╨──┐ ║ ║ + # cr0: 1/═════════════════════════════╩══╬═╡ 0x1 ╞═══╬════╬═ + # 0 ║ └─────┘┌──╨──┐ ║ + # cr1: 1/════════════════════════════════╩════════╡ 0x1 ╞═╬═ + # 0 └─────┘ ║ + # cr2: 1/═════════════════════════════════════════════════╩═ + # 0 self.log.info("test_teleport") pi = np.pi shots = 2000 @@ -326,25 +314,21 @@ def test_teleport(self): self.assertLess(error, 0.05) def test_memory(self): - """Test memory. - - (circ) - - ┌───┐ ┌─┐ - qr_0: ┤ H ├──■─────┤M├─── - └───┘┌─┴─┐ └╥┘┌─┐ - qr_1: ─────┤ X ├────╫─┤M├ - └┬─┬┘ ║ └╥┘ - qr_2: ──────┤M├─────╫──╫─ - ┌───┐ └╥┘ ┌─┐ ║ ║ - qr_3: ┤ X ├──╫──┤M├─╫──╫─ - └───┘ ║ └╥┘ ║ ║ - cr0: 2/══════╬═══╬══╩══╩═ - ║ ║ 0 1 - ║ ║ - cr1: 2/══════╩═══╩═══════ - 0 1 - """ + """Test memory.""" + # ┌───┐ ┌─┐ + # qr_0: ┤ H ├──■─────┤M├─── + # └───┘┌─┴─┐ └╥┘┌─┐ + # qr_1: ─────┤ X ├────╫─┤M├ + # └┬─┬┘ ║ └╥┘ + # qr_2: ──────┤M├─────╫──╫─ + # ┌───┐ └╥┘ ┌─┐ ║ ║ + # qr_3: ┤ X ├──╫──┤M├─╫──╫─ + # └───┘ ║ └╥┘ ║ ║ + # cr0: 2/══════╬═══╬══╩══╩═ + # ║ ║ 0 1 + # ║ ║ + # cr1: 2/══════╩═══╩═══════ + # 0 1 qr = QuantumRegister(4, "qr") cr0 = ClassicalRegister(2, "cr0") cr1 = ClassicalRegister(2, "cr1") diff --git a/test/python/circuit/library/test_grover_operator.py b/test/python/circuit/library/test_grover_operator.py index e11398fe02c8..7ec85a5b7036 100644 --- a/test/python/circuit/library/test_grover_operator.py +++ b/test/python/circuit/library/test_grover_operator.py @@ -128,25 +128,22 @@ def test_custom_zero_reflection(self): self.assertEqual(expected, grover_op.decompose()) def test_num_mcx_ancillas(self): - """Test the number of ancilla bits for the mcx gate in zero_reflection. - - (oracle) - - q_0: ──■────────────────────── - │ - q_1: ──■────────────────────── - │ - q_2: ──┼────■───────────────── - │ │ - q_3: ──┼────■───────────────── - ┌─┴─┐ │ - q_4: ┤ X ├──┼────■──────────── - └───┘┌─┴─┐ │ - q_5: ─────┤ X ├──■──────────── - ┌───┐├───┤┌─┴─┐┌───┐┌───┐ - q_6: ┤ X ├┤ H ├┤ X ├┤ H ├┤ X ├ - └───┘└───┘└───┘└───┘└───┘ - """ + """Test the number of ancilla bits for the mcx gate in zero_reflection.""" + # + # q_0: ──■────────────────────── + # │ + # q_1: ──■────────────────────── + # │ + # q_2: ──┼────■───────────────── + # │ │ + # q_3: ──┼────■───────────────── + # ┌─┴─┐ │ + # q_4: ┤ X ├──┼────■──────────── + # └───┘┌─┴─┐ │ + # q_5: ─────┤ X ├──■──────────── + # ┌───┐├───┤┌─┴─┐┌───┐┌───┐ + # q_6: ┤ X ├┤ H ├┤ X ├┤ H ├┤ X ├ + # └───┘└───┘└───┘└───┘└───┘ oracle = QuantumCircuit(7) oracle.x(6) oracle.h(6) diff --git a/test/python/circuit/library/test_nlocal.py b/test/python/circuit/library/test_nlocal.py index 38b0b83f7b04..82180f69c133 100644 --- a/test/python/circuit/library/test_nlocal.py +++ b/test/python/circuit/library/test_nlocal.py @@ -422,16 +422,12 @@ def test_entanglement_by_list(self): self.assertCircuitEqual(nlocal, circuit) def test_initial_state_as_circuit_object(self): - """Test setting `initial_state` to `QuantumCircuit` object - - (ref) - - ┌───┐ ┌───┐ - q_0: ──■──┤ X ├───────■──┤ X ├ - ┌─┴─┐├───┤┌───┐┌─┴─┐├───┤ - q_1: ┤ X ├┤ H ├┤ X ├┤ X ├┤ X ├ - └───┘└───┘└───┘└───┘└───┘ - """ + """Test setting `initial_state` to `QuantumCircuit` object""" + # ┌───┐ ┌───┐ + # q_0: ──■──┤ X ├───────■──┤ X ├ + # ┌─┴─┐├───┤┌───┐┌─┴─┐├───┤ + # q_1: ┤ X ├┤ H ├┤ X ├┤ X ├┤ X ├ + # └───┘└───┘└───┘└───┘└───┘ ref = QuantumCircuit(2) ref.cx(0, 1) ref.x(0) diff --git a/test/python/circuit/test_circuit_properties.py b/test/python/circuit/test_circuit_properties.py index e9faa050adc1..c4355f2eee05 100644 --- a/test/python/circuit/test_circuit_properties.py +++ b/test/python/circuit/test_circuit_properties.py @@ -79,22 +79,21 @@ def test_circuit_depth_meas_only(self): self.assertEqual(qc.depth(), 1) def test_circuit_depth_barrier(self): - """Make sure barriers do not add to depth - - ┌───┐ ░ ┌─┐ - q_0: ┤ H ├──■──────────────────░─┤M├──────────── - ├───┤┌─┴─┐ ░ └╥┘┌─┐ - q_1: ┤ H ├┤ X ├──■─────────────░──╫─┤M├───────── - ├───┤└───┘ │ ┌───┐ ░ ║ └╥┘┌─┐ - q_2: ┤ H ├───────┼──┤ X ├──■───░──╫──╫─┤M├────── - ├───┤ │ └─┬─┘┌─┴─┐ ░ ║ ║ └╥┘┌─┐ - q_3: ┤ H ├───────┼────┼──┤ X ├─░──╫──╫──╫─┤M├─── - ├───┤ ┌─┴─┐ │ └───┘ ░ ║ ║ ║ └╥┘┌─┐ - q_4: ┤ H ├─────┤ X ├──■────────░──╫──╫──╫──╫─┤M├ - └───┘ └───┘ ░ ║ ║ ║ ║ └╥┘ - c: 5/═════════════════════════════╩══╩══╩══╩══╩═ - 0 1 2 3 4 - """ + """Make sure barriers do not add to depth""" + + # ┌───┐ ░ ┌─┐ + # q_0: ┤ H ├──■──────────────────░─┤M├──────────── + # ├───┤┌─┴─┐ ░ └╥┘┌─┐ + # q_1: ┤ H ├┤ X ├──■─────────────░──╫─┤M├───────── + # ├───┤└───┘ │ ┌───┐ ░ ║ └╥┘┌─┐ + # q_2: ┤ H ├───────┼──┤ X ├──■───░──╫──╫─┤M├────── + # ├───┤ │ └─┬─┘┌─┴─┐ ░ ║ ║ └╥┘┌─┐ + # q_3: ┤ H ├───────┼────┼──┤ X ├─░──╫──╫──╫─┤M├─── + # ├───┤ ┌─┴─┐ │ └───┘ ░ ║ ║ ║ └╥┘┌─┐ + # q_4: ┤ H ├─────┤ X ├──■────────░──╫──╫──╫──╫─┤M├ + # └───┘ └───┘ ░ ║ ║ ║ ║ └╥┘ + # c: 5/═════════════════════════════╩══╩══╩══╩══╩═ + # 0 1 2 3 4 q = QuantumRegister(5, "q") c = ClassicalRegister(5, "c") qc = QuantumCircuit(q, c) @@ -112,21 +111,20 @@ def test_circuit_depth_barrier(self): self.assertEqual(qc.depth(), 6) def test_circuit_depth_simple(self): - """Test depth for simple circuit - ┌───┐ - q_0: ┤ H ├──■──────────────────── - └───┘ │ ┌───┐┌─┐ - q_1: ───────┼────────────┤ X ├┤M├ - ┌───┐ │ ┌───┐┌───┐└─┬─┘└╥┘ - q_2: ┤ X ├──┼──┤ X ├┤ X ├──┼───╫─ - └───┘ │ └───┘└───┘ │ ║ - q_3: ───────┼──────────────┼───╫─ - ┌─┴─┐┌───┐ │ ║ - q_4: ─────┤ X ├┤ X ├───────■───╫─ - └───┘└───┘ ║ - c: 1/══════════════════════════╩═ - 0 - """ + """Test depth for simple circuit""" + # ┌───┐ + # q_0: ┤ H ├──■──────────────────── + # └───┘ │ ┌───┐┌─┐ + # q_1: ───────┼────────────┤ X ├┤M├ + # ┌───┐ │ ┌───┐┌───┐└─┬─┘└╥┘ + # q_2: ┤ X ├──┼──┤ X ├┤ X ├──┼───╫─ + # └───┘ │ └───┘└───┘ │ ║ + # q_3: ───────┼──────────────┼───╫─ + # ┌─┴─┐┌───┐ │ ║ + # q_4: ─────┤ X ├┤ X ├───────■───╫─ + # └───┘└───┘ ║ + # c: 1/══════════════════════════╩═ + # 0 q = QuantumRegister(5, "q") c = ClassicalRegister(1, "c") qc = QuantumCircuit(q, c) @@ -141,21 +139,19 @@ def test_circuit_depth_simple(self): self.assertEqual(qc.depth(), 5) def test_circuit_depth_multi_reg(self): - """Test depth for multiple registers - - ┌───┐ - q1_0: ┤ H ├──■───────────────── - ├───┤┌─┴─┐ - q1_1: ┤ H ├┤ X ├──■──────────── - ├───┤└───┘ │ ┌───┐ - q1_2: ┤ H ├───────┼──┤ X ├──■── - ├───┤ │ └─┬─┘┌─┴─┐ - q2_0: ┤ H ├───────┼────┼──┤ X ├ - ├───┤ ┌─┴─┐ │ └───┘ - q2_1: ┤ H ├─────┤ X ├──■─────── - └───┘ └───┘ - c: 5/═════════════════════════ - """ + """Test depth for multiple registers""" + + # ┌───┐ + # q1_0: ┤ H ├──■───────────────── + # ├───┤┌─┴─┐ + # q1_1: ┤ H ├┤ X ├──■──────────── + # ├───┤└───┘ │ ┌───┐ + # q1_2: ┤ H ├───────┼──┤ X ├──■── + # ├───┤ │ └─┬─┘┌─┴─┐ + # q2_0: ┤ H ├───────┼────┼──┤ X ├ + # ├───┤ ┌─┴─┐ │ └───┘ + # q2_1: ┤ H ├─────┤ X ├──■─────── + # └───┘ └───┘ q1 = QuantumRegister(3, "q1") q2 = QuantumRegister(2, "q2") c = ClassicalRegister(5, "c") @@ -172,21 +168,19 @@ def test_circuit_depth_multi_reg(self): self.assertEqual(qc.depth(), 5) def test_circuit_depth_3q_gate(self): - """Test depth for 3q gate - - ┌───┐ - q1_0: ┤ H ├──■────■───────────────── - ├───┤ │ ┌─┴─┐ - q1_1: ┤ H ├──┼──┤ X ├──■──────────── - ├───┤ │ └───┘ │ ┌───┐ - q1_2: ┤ H ├──┼─────────┼──┤ X ├──■── - ├───┤┌─┴─┐ │ └─┬─┘┌─┴─┐ - q2_0: ┤ H ├┤ X ├───────┼────┼──┤ X ├ - ├───┤└─┬─┘ ┌─┴─┐ │ └───┘ - q2_1: ┤ H ├──■───────┤ X ├──■─────── - └───┘ └───┘ - c: 5/══════════════════════════════ - """ + """Test depth for 3q gate""" + + # ┌───┐ + # q1_0: ┤ H ├──■────■───────────────── + # ├───┤ │ ┌─┴─┐ + # q1_1: ┤ H ├──┼──┤ X ├──■──────────── + # ├───┤ │ └───┘ │ ┌───┐ + # q1_2: ┤ H ├──┼─────────┼──┤ X ├──■── + # ├───┤┌─┴─┐ │ └─┬─┘┌─┴─┐ + # q2_0: ┤ H ├┤ X ├───────┼────┼──┤ X ├ + # ├───┤└─┬─┘ ┌─┴─┐ │ └───┘ + # q2_1: ┤ H ├──■───────┤ X ├──■─────── + # └───┘ └───┘ q1 = QuantumRegister(3, "q1") q2 = QuantumRegister(2, "q2") c = ClassicalRegister(5, "c") @@ -204,21 +198,20 @@ def test_circuit_depth_3q_gate(self): self.assertEqual(qc.depth(), 6) def test_circuit_depth_conditionals1(self): - """Test circuit depth for conditional gates #1. - - ┌───┐ ┌─┐ - q_0: ┤ H ├──■──┤M├───────────────── - ├───┤┌─┴─┐└╥┘┌─┐ - q_1: ┤ H ├┤ X ├─╫─┤M├────────────── - ├───┤└───┘ ║ └╥┘ ┌───┐ - q_2: ┤ H ├──■───╫──╫──┤ H ├──────── - ├───┤┌─┴─┐ ║ ║ └─╥─┘ ┌───┐ - q_3: ┤ H ├┤ X ├─╫──╫────╫────┤ H ├─ - └───┘└───┘ ║ ║ ║ └─╥─┘ - ║ ║ ┌──╨──┐┌──╨──┐ - c: 4/═══════════╩══╩═╡ 0x2 ╞╡ 0x4 ╞ - 0 1 └─────┘└─────┘ - """ + """Test circuit depth for conditional gates #1.""" + + # ┌───┐ ┌─┐ + # q_0: ┤ H ├──■──┤M├───────────────── + # ├───┤┌─┴─┐└╥┘┌─┐ + # q_1: ┤ H ├┤ X ├─╫─┤M├────────────── + # ├───┤└───┘ ║ └╥┘ ┌───┐ + # q_2: ┤ H ├──■───╫──╫──┤ H ├──────── + # ├───┤┌─┴─┐ ║ ║ └─╥─┘ ┌───┐ + # q_3: ┤ H ├┤ X ├─╫──╫────╫────┤ H ├─ + # └───┘└───┘ ║ ║ ║ └─╥─┘ + # ║ ║ ┌──╨──┐┌──╨──┐ + # c: 4/═══════════╩══╩═╡ 0x2 ╞╡ 0x4 ╞ + # 0 1 └─────┘└─────┘ size = 4 q = QuantumRegister(size, "q") c = ClassicalRegister(size, "c") @@ -237,21 +230,20 @@ def test_circuit_depth_conditionals1(self): self.assertEqual(qc.depth(), 5) def test_circuit_depth_conditionals2(self): - """Test circuit depth for conditional gates #2. - - ┌───┐ ┌─┐┌─┐ - q_0: ┤ H ├──■──┤M├┤M├────────────── - ├───┤┌─┴─┐└╥┘└╥┘ - q_1: ┤ H ├┤ X ├─╫──╫─────────────── - ├───┤└───┘ ║ ║ ┌───┐ - q_2: ┤ H ├──■───╫──╫──┤ H ├──────── - ├───┤┌─┴─┐ ║ ║ └─╥─┘ ┌───┐ - q_3: ┤ H ├┤ X ├─╫──╫────╫────┤ H ├─ - └───┘└───┘ ║ ║ ║ └─╥─┘ - ║ ║ ┌──╨──┐┌──╨──┐ - c: 4/═══════════╩══╩═╡ 0x2 ╞╡ 0x4 ╞ - 0 0 └─────┘└─────┘ - """ + """Test circuit depth for conditional gates #2.""" + + # ┌───┐ ┌─┐┌─┐ + # q_0: ┤ H ├──■──┤M├┤M├────────────── + # ├───┤┌─┴─┐└╥┘└╥┘ + # q_1: ┤ H ├┤ X ├─╫──╫─────────────── + # ├───┤└───┘ ║ ║ ┌───┐ + # q_2: ┤ H ├──■───╫──╫──┤ H ├──────── + # ├───┤┌─┴─┐ ║ ║ └─╥─┘ ┌───┐ + # q_3: ┤ H ├┤ X ├─╫──╫────╫────┤ H ├─ + # └───┘└───┘ ║ ║ ║ └─╥─┘ + # ║ ║ ┌──╨──┐┌──╨──┐ + # c: 4/═══════════╩══╩═╡ 0x2 ╞╡ 0x4 ╞ + # 0 0 └─────┘└─────┘ size = 4 q = QuantumRegister(size, "q") c = ClassicalRegister(size, "c") @@ -270,21 +262,20 @@ def test_circuit_depth_conditionals2(self): self.assertEqual(qc.depth(), 6) def test_circuit_depth_conditionals3(self): - """Test circuit depth for conditional gates #3. - - ┌───┐┌─┐ - q_0: ┤ H ├┤M├───■──────────── - ├───┤└╥┘ │ ┌─┐ - q_1: ┤ H ├─╫────┼───┤M├────── - ├───┤ ║ │ └╥┘┌─┐ - q_2: ┤ H ├─╫────┼────╫─┤M├─── - ├───┤ ║ ┌─┴─┐ ║ └╥┘┌─┐ - q_3: ┤ H ├─╫──┤ X ├──╫──╫─┤M├ - └───┘ ║ └─╥─┘ ║ ║ └╥┘ - ║ ┌──╨──┐ ║ ║ ║ - c: 4/══════╩═╡ 0x2 ╞═╩══╩══╩═ - 0 └─────┘ 1 2 3 - """ + """Test circuit depth for conditional gates #3.""" + + # ┌───┐┌─┐ + # q_0: ┤ H ├┤M├───■──────────── + # ├───┤└╥┘ │ ┌─┐ + # q_1: ┤ H ├─╫────┼───┤M├────── + # ├───┤ ║ │ └╥┘┌─┐ + # q_2: ┤ H ├─╫────┼────╫─┤M├─── + # ├───┤ ║ ┌─┴─┐ ║ └╥┘┌─┐ + # q_3: ┤ H ├─╫──┤ X ├──╫──╫─┤M├ + # └───┘ ║ └─╥─┘ ║ ║ └╥┘ + # ║ ┌──╨──┐ ║ ║ ║ + # c: 4/══════╩═╡ 0x2 ╞═╩══╩══╩═ + # 0 └─────┘ 1 2 3 size = 4 q = QuantumRegister(size, "q") c = ClassicalRegister(size, "c") @@ -303,21 +294,20 @@ def test_circuit_depth_conditionals3(self): self.assertEqual(qc.depth(), 4) def test_circuit_depth_bit_conditionals1(self): - """Test circuit depth for single bit conditional gates #1. - - ┌───┐┌─┐ - q_0: ┤ H ├┤M├───────────────────────── - ├───┤└╥┘ ┌───┐ - q_1: ┤ H ├─╫───────┤ H ├────────────── - ├───┤ ║ ┌─┐ └─╥─┘ - q_2: ┤ H ├─╫─┤M├─────╫──────────────── - ├───┤ ║ └╥┘ ║ ┌───┐ - q_3: ┤ H ├─╫──╫──────╫────────┤ H ├─── - └───┘ ║ ║ ║ └─╥─┘ - ║ ║ ┌────╨────┐┌────╨────┐ - c: 4/══════╩══╩═╡ c_0=0x1 ╞╡ c_2=0x0 ╞ - 0 2 └─────────┘└─────────┘ - """ + """Test circuit depth for single bit conditional gates #1.""" + + # ┌───┐┌─┐ + # q_0: ┤ H ├┤M├───────────────────────── + # ├───┤└╥┘ ┌───┐ + # q_1: ┤ H ├─╫───────┤ H ├────────────── + # ├───┤ ║ ┌─┐ └─╥─┘ + # q_2: ┤ H ├─╫─┤M├─────╫──────────────── + # ├───┤ ║ └╥┘ ║ ┌───┐ + # q_3: ┤ H ├─╫──╫──────╫────────┤ H ├─── + # └───┘ ║ ║ ║ └─╥─┘ + # ║ ║ ┌────╨────┐┌────╨────┐ + # c: 4/══════╩══╩═╡ c_0=0x1 ╞╡ c_2=0x0 ╞ + # 0 2 └─────────┘└─────────┘ size = 4 q = QuantumRegister(size, "q") c = ClassicalRegister(size, "c") @@ -334,33 +324,32 @@ def test_circuit_depth_bit_conditionals1(self): self.assertEqual(qc.depth(), 3) def test_circuit_depth_bit_conditionals2(self): - """Test circuit depth for single bit conditional gates #2. - - ┌───┐┌─┐ » - q_0: ┤ H ├┤M├──────────────────────────────■─────────────────────■─────» - ├───┤└╥┘ ┌───┐ ┌─┴─┐ │ » - q_1: ┤ H ├─╫───────┤ H ├─────────────────┤ X ├───────────────────┼─────» - ├───┤ ║ ┌─┐ └─╥─┘ └─╥─┘ ┌─┴─┐ » - q_2: ┤ H ├─╫─┤M├─────╫─────────────────────╫──────────■────────┤ H ├───» - ├───┤ ║ └╥┘ ║ ┌───┐ ║ ┌─┴─┐ └─╥─┘ » - q_3: ┤ H ├─╫──╫──────╫────────┤ H ├────────╫────────┤ X ├────────╫─────» - └───┘ ║ ║ ║ └─╥─┘ ║ └─╥─┘ ║ » - ║ ║ ┌────╨────┐┌────╨────┐┌────╨────┐┌────╨────┐┌────╨────┐» - c: 4/══════╩══╩═╡ c_1=0x1 ╞╡ c_3=0x1 ╞╡ c_0=0x0 ╞╡ c_2=0x0 ╞╡ c_1=0x1 ╞» - 0 2 └─────────┘└─────────┘└─────────┘└─────────┘└─────────┘» - « - «q_0: ─────────── - « - «q_1: ─────■───── - « │ - «q_2: ─────┼───── - « ┌─┴─┐ - «q_3: ───┤ H ├─── - « └─╥─┘ - « ┌────╨────┐ - «c: 4/╡ c_3=0x1 ╞ - « └─────────┘ - """ + """Test circuit depth for single bit conditional gates #2.""" + + # ┌───┐┌─┐ » + # q_0: ┤ H ├┤M├──────────────────────────────■─────────────────────■─────» + # ├───┤└╥┘ ┌───┐ ┌─┴─┐ │ » + # q_1: ┤ H ├─╫───────┤ H ├─────────────────┤ X ├───────────────────┼─────» + # ├───┤ ║ ┌─┐ └─╥─┘ └─╥─┘ ┌─┴─┐ » + # q_2: ┤ H ├─╫─┤M├─────╫─────────────────────╫──────────■────────┤ H ├───» + # ├───┤ ║ └╥┘ ║ ┌───┐ ║ ┌─┴─┐ └─╥─┘ » + # q_3: ┤ H ├─╫──╫──────╫────────┤ H ├────────╫────────┤ X ├────────╫─────» + # └───┘ ║ ║ ║ └─╥─┘ ║ └─╥─┘ ║ » + # ║ ║ ┌────╨────┐┌────╨────┐┌────╨────┐┌────╨────┐┌────╨────┐» + # c: 4/══════╩══╩═╡ c_1=0x1 ╞╡ c_3=0x1 ╞╡ c_0=0x0 ╞╡ c_2=0x0 ╞╡ c_1=0x1 ╞» + # 0 2 └─────────┘└─────────┘└─────────┘└─────────┘└─────────┘» + # « + # «q_0: ─────────── + # « + # «q_1: ─────■───── + # « │ + # «q_2: ─────┼───── + # « ┌─┴─┐ + # «q_3: ───┤ H ├─── + # « └─╥─┘ + # « ┌────╨────┐ + # «c: 4/╡ c_3=0x1 ╞ + # « └─────────┘ size = 4 q = QuantumRegister(size, "q") c = ClassicalRegister(size, "c") @@ -381,21 +370,20 @@ def test_circuit_depth_bit_conditionals2(self): self.assertEqual(qc.depth(), 4) def test_circuit_depth_bit_conditionals3(self): - """Test circuit depth for single bit conditional gates #3. - - ┌───┐┌─┐ - q_0: ┤ H ├┤M├────────────────────────────────────── - ├───┤└╥┘ ┌───┐ ┌─┐ - q_1: ┤ H ├─╫────┤ H ├─────────────────────┤M├────── - ├───┤ ║ └─╥─┘ ┌───┐ └╥┘┌─┐ - q_2: ┤ H ├─╫──────╫──────┤ H ├─────────────╫─┤M├─── - ├───┤ ║ ║ └─╥─┘ ┌───┐ ║ └╥┘┌─┐ - q_3: ┤ H ├─╫──────╫────────╫──────┤ H ├────╫──╫─┤M├ - └───┘ ║ ║ ║ └─╥─┘ ║ ║ └╥┘ - ║ ┌────╨────┐┌──╨──┐┌────╨────┐ ║ ║ ║ - c: 4/══════╩═╡ c_0=0x1 ╞╡ 0x2 ╞╡ c_3=0x1 ╞═╩══╩══╩═ - 0 └─────────┘└─────┘└─────────┘ 1 2 3 - """ + """Test circuit depth for single bit conditional gates #3.""" + + # ┌───┐┌─┐ + # q_0: ┤ H ├┤M├────────────────────────────────────── + # ├───┤└╥┘ ┌───┐ ┌─┐ + # q_1: ┤ H ├─╫────┤ H ├─────────────────────┤M├────── + # ├───┤ ║ └─╥─┘ ┌───┐ └╥┘┌─┐ + # q_2: ┤ H ├─╫──────╫──────┤ H ├─────────────╫─┤M├─── + # ├───┤ ║ ║ └─╥─┘ ┌───┐ ║ └╥┘┌─┐ + # q_3: ┤ H ├─╫──────╫────────╫──────┤ H ├────╫──╫─┤M├ + # └───┘ ║ ║ ║ └─╥─┘ ║ ║ └╥┘ + # ║ ┌────╨────┐┌──╨──┐┌────╨────┐ ║ ║ ║ + # c: 4/══════╩═╡ c_0=0x1 ╞╡ 0x2 ╞╡ c_3=0x1 ╞═╩══╩══╩═ + # 0 └─────────┘└─────┘└─────────┘ 1 2 3 size = 4 q = QuantumRegister(size, "q") c = ClassicalRegister(size, "c") @@ -415,20 +403,19 @@ def test_circuit_depth_bit_conditionals3(self): self.assertEqual(qc.depth(), 6) def test_circuit_depth_measurements1(self): - """Test circuit depth for measurements #1. - - ┌───┐┌─┐ - q_0: ┤ H ├┤M├───────── - ├───┤└╥┘┌─┐ - q_1: ┤ H ├─╫─┤M├────── - ├───┤ ║ └╥┘┌─┐ - q_2: ┤ H ├─╫──╫─┤M├─── - ├───┤ ║ ║ └╥┘┌─┐ - q_3: ┤ H ├─╫──╫──╫─┤M├ - └───┘ ║ ║ ║ └╥┘ - c: 4/══════╩══╩══╩══╩═ - 0 1 2 3 - """ + """Test circuit depth for measurements #1.""" + + # ┌───┐┌─┐ + # q_0: ┤ H ├┤M├───────── + # ├───┤└╥┘┌─┐ + # q_1: ┤ H ├─╫─┤M├────── + # ├───┤ ║ └╥┘┌─┐ + # q_2: ┤ H ├─╫──╫─┤M├─── + # ├───┤ ║ ║ └╥┘┌─┐ + # q_3: ┤ H ├─╫──╫──╫─┤M├ + # └───┘ ║ ║ ║ └╥┘ + # c: 4/══════╩══╩══╩══╩═ + # 0 1 2 3 size = 4 q = QuantumRegister(size, "q") c = ClassicalRegister(size, "c") @@ -445,20 +432,19 @@ def test_circuit_depth_measurements1(self): self.assertEqual(qc.depth(), 2) def test_circuit_depth_measurements2(self): - """Test circuit depth for measurements #2. - - ┌───┐┌─┐┌─┐┌─┐┌─┐ - q_0: ┤ H ├┤M├┤M├┤M├┤M├ - ├───┤└╥┘└╥┘└╥┘└╥┘ - q_1: ┤ H ├─╫──╫──╫──╫─ - ├───┤ ║ ║ ║ ║ - q_2: ┤ H ├─╫──╫──╫──╫─ - ├───┤ ║ ║ ║ ║ - q_3: ┤ H ├─╫──╫──╫──╫─ - └───┘ ║ ║ ║ ║ - c: 4/══════╩══╩══╩══╩═ - 0 1 2 3 - """ + """Test circuit depth for measurements #2.""" + + # ┌───┐┌─┐┌─┐┌─┐┌─┐ + # q_0: ┤ H ├┤M├┤M├┤M├┤M├ + # ├───┤└╥┘└╥┘└╥┘└╥┘ + # q_1: ┤ H ├─╫──╫──╫──╫─ + # ├───┤ ║ ║ ║ ║ + # q_2: ┤ H ├─╫──╫──╫──╫─ + # ├───┤ ║ ║ ║ ║ + # q_3: ┤ H ├─╫──╫──╫──╫─ + # └───┘ ║ ║ ║ ║ + # c: 4/══════╩══╩══╩══╩═ + # 0 1 2 3 size = 4 q = QuantumRegister(size, "q") c = ClassicalRegister(size, "c") @@ -475,20 +461,19 @@ def test_circuit_depth_measurements2(self): self.assertEqual(qc.depth(), 5) def test_circuit_depth_measurements3(self): - """Test circuit depth for measurements #3. - - ┌───┐┌─┐ - q_0: ┤ H ├┤M├───────── - ├───┤└╥┘┌─┐ - q_1: ┤ H ├─╫─┤M├────── - ├───┤ ║ └╥┘┌─┐ - q_2: ┤ H ├─╫──╫─┤M├─── - ├───┤ ║ ║ └╥┘┌─┐ - q_3: ┤ H ├─╫──╫──╫─┤M├ - └───┘ ║ ║ ║ └╥┘ - c: 4/══════╩══╩══╩══╩═ - 0 0 0 0 - """ + """Test circuit depth for measurements #3.""" + + # ┌───┐┌─┐ + # q_0: ┤ H ├┤M├───────── + # ├───┤└╥┘┌─┐ + # q_1: ┤ H ├─╫─┤M├────── + # ├───┤ ║ └╥┘┌─┐ + # q_2: ┤ H ├─╫──╫─┤M├─── + # ├───┤ ║ ║ └╥┘┌─┐ + # q_3: ┤ H ├─╫──╫──╫─┤M├ + # └───┘ ║ ║ ║ └╥┘ + # c: 4/══════╩══╩══╩══╩═ + # 0 0 0 0 size = 4 q = QuantumRegister(size, "q") c = ClassicalRegister(size, "c") @@ -505,19 +490,17 @@ def test_circuit_depth_measurements3(self): self.assertEqual(qc.depth(), 5) def test_circuit_depth_barriers1(self): - """Test circuit depth for barriers #1. - - ┌───┐ ░ - q_0: ┤ H ├──■───░─────────── - └───┘┌─┴─┐ ░ - q_1: ─────┤ X ├─░─────────── - └───┘ ░ ┌───┐ - q_2: ───────────░─┤ H ├──■── - ░ └───┘┌─┴─┐ - q_3: ───────────░──────┤ X ├ - ░ └───┘ - c: 4/═══════════════════════ - """ + """Test circuit depth for barriers #1.""" + + # ┌───┐ ░ + # q_0: ┤ H ├──■───░─────────── + # └───┘┌─┴─┐ ░ + # q_1: ─────┤ X ├─░─────────── + # └───┘ ░ ┌───┐ + # q_2: ───────────░─┤ H ├──■── + # ░ └───┘┌─┴─┐ + # q_3: ───────────░──────┤ X ├ + # ░ └───┘ q = QuantumRegister(4, "q") c = ClassicalRegister(4, "c") circ = QuantumCircuit(q, c) @@ -529,19 +512,17 @@ def test_circuit_depth_barriers1(self): self.assertEqual(circ.depth(), 4) def test_circuit_depth_barriers2(self): - """Test circuit depth for barriers #2. - - ┌───┐ ░ ░ ░ - q_0: ┤ H ├─░───■───░───────░────── - └───┘ ░ ┌─┴─┐ ░ ░ - q_1: ──────░─┤ X ├─░───────░────── - ░ └───┘ ░ ┌───┐ ░ - q_2: ──────░───────░─┤ H ├─░───■── - ░ ░ └───┘ ░ ┌─┴─┐ - q_3: ──────░───────░───────░─┤ X ├ - ░ ░ ░ └───┘ - c: 4/═════════════════════════════ - """ + """Test circuit depth for barriers #2.""" + + # ┌───┐ ░ ░ ░ + # q_0: ┤ H ├─░───■───░───────░────── + # └───┘ ░ ┌─┴─┐ ░ ░ + # q_1: ──────░─┤ X ├─░───────░────── + # ░ └───┘ ░ ┌───┐ ░ + # q_2: ──────░───────░─┤ H ├─░───■── + # ░ ░ └───┘ ░ ┌─┴─┐ + # q_3: ──────░───────░───────░─┤ X ├ + # ░ ░ ░ └───┘ q = QuantumRegister(4, "q") c = ClassicalRegister(4, "c") circ = QuantumCircuit(q, c) @@ -555,19 +536,17 @@ def test_circuit_depth_barriers2(self): self.assertEqual(circ.depth(), 4) def test_circuit_depth_barriers3(self): - """Test circuit depth for barriers #3. - - ┌───┐ ░ ░ ░ ░ ░ - q_0: ┤ H ├─░───■───░──░──░───────░────── - └───┘ ░ ┌─┴─┐ ░ ░ ░ ░ - q_1: ──────░─┤ X ├─░──░──░───────░────── - ░ └───┘ ░ ░ ░ ┌───┐ ░ - q_2: ──────░───────░──░──░─┤ H ├─░───■── - ░ ░ ░ ░ └───┘ ░ ┌─┴─┐ - q_3: ──────░───────░──░──░───────░─┤ X ├ - ░ ░ ░ ░ ░ └───┘ - c: 4/═══════════════════════════════════ - """ + """Test circuit depth for barriers #3.""" + + # ┌───┐ ░ ░ ░ ░ ░ + # q_0: ┤ H ├─░───■───░──░──░───────░────── + # └───┘ ░ ┌─┴─┐ ░ ░ ░ ░ + # q_1: ──────░─┤ X ├─░──░──░───────░────── + # ░ └───┘ ░ ░ ░ ┌───┐ ░ + # q_2: ──────░───────░──░──░─┤ H ├─░───■── + # ░ ░ ░ ░ └───┘ ░ ┌─┴─┐ + # q_3: ──────░───────░──░──░───────░─┤ X ├ + # ░ ░ ░ ░ ░ └───┘ q = QuantumRegister(4, "q") c = ClassicalRegister(4, "c") circ = QuantumCircuit(q, c) @@ -583,19 +562,17 @@ def test_circuit_depth_barriers3(self): self.assertEqual(circ.depth(), 4) def test_circuit_depth_snap1(self): - """Test circuit depth for snapshots #1. - - ┌───┐ ░ - q_0: ┤ H ├──■───░─────────── - └───┘┌─┴─┐ ░ - q_1: ─────┤ X ├─░─────────── - └───┘ ░ ┌───┐ - q_2: ───────────░─┤ H ├──■── - ░ └───┘┌─┴─┐ - q_3: ───────────░──────┤ X ├ - ░ └───┘ - c: 4/═══════════════════════ - """ + """Test circuit depth for snapshots #1.""" + + # ┌───┐ ░ + # q_0: ┤ H ├──■───░─────────── + # └───┘┌─┴─┐ ░ + # q_1: ─────┤ X ├─░─────────── + # └───┘ ░ ┌───┐ + # q_2: ───────────░─┤ H ├──■── + # ░ └───┘┌─┴─┐ + # q_3: ───────────░──────┤ X ├ + # ░ └───┘ q = QuantumRegister(4, "q") c = ClassicalRegister(4, "c") circ = QuantumCircuit(q, c) @@ -607,19 +584,17 @@ def test_circuit_depth_snap1(self): self.assertEqual(circ.depth(), 4) def test_circuit_depth_snap2(self): - """Test circuit depth for snapshots #2. - - ┌───┐ ░ ░ ░ - q_0: ┤ H ├─░───■───░───────░────── - └───┘ ░ ┌─┴─┐ ░ ░ - q_1: ──────░─┤ X ├─░───────░────── - ░ └───┘ ░ ┌───┐ ░ - q_2: ──────░───────░─┤ H ├─░───■── - ░ ░ └───┘ ░ ┌─┴─┐ - q_3: ──────░───────░───────░─┤ X ├ - ░ ░ ░ └───┘ - c: 4/═════════════════════════════ - """ + """Test circuit depth for snapshots #2.""" + + # ┌───┐ ░ ░ ░ + # q_0: ┤ H ├─░───■───░───────░────── + # └───┘ ░ ┌─┴─┐ ░ ░ + # q_1: ──────░─┤ X ├─░───────░────── + # ░ └───┘ ░ ┌───┐ ░ + # q_2: ──────░───────░─┤ H ├─░───■── + # ░ ░ └───┘ ░ ┌─┴─┐ + # q_3: ──────░───────░───────░─┤ X ├ + # ░ ░ ░ └───┘ q = QuantumRegister(4, "q") c = ClassicalRegister(4, "c") circ = QuantumCircuit(q, c) @@ -633,19 +608,17 @@ def test_circuit_depth_snap2(self): self.assertEqual(circ.depth(), 4) def test_circuit_depth_snap3(self): - """Test circuit depth for snapshots #3. - - ┌───┐ ░ ░ - q_0: ┤ H ├──■───░──░─────────── - └───┘┌─┴─┐ ░ ░ - q_1: ─────┤ X ├─░──░─────────── - └───┘ ░ ░ ┌───┐ - q_2: ───────────░──░─┤ H ├──■── - ░ ░ └───┘┌─┴─┐ - q_3: ───────────░──░──────┤ X ├ - ░ ░ └───┘ - c: 4/══════════════════════════ - """ + """Test circuit depth for snapshots #3.""" + + # ┌───┐ ░ ░ + # q_0: ┤ H ├──■───░──░─────────── + # └───┘┌─┴─┐ ░ ░ + # q_1: ─────┤ X ├─░──░─────────── + # └───┘ ░ ░ ┌───┐ + # q_2: ───────────░──░─┤ H ├──■── + # ░ ░ └───┘┌─┴─┐ + # q_3: ───────────░──░──────┤ X ├ + # ░ ░ └───┘ q = QuantumRegister(4, "q") c = ClassicalRegister(4, "c") circ = QuantumCircuit(q, c) @@ -658,20 +631,19 @@ def test_circuit_depth_snap3(self): self.assertEqual(circ.depth(), 4) def test_circuit_depth_2qubit(self): - """Test finding depth of two-qubit gates only. - - ┌───┐ - q_0: ┤ H ├──■─────────────────── - └───┘┌─┴─┐┌─────────┐ ┌─┐ - q_1: ─────┤ X ├┤ Rz(0.1) ├─■─┤M├ - ┌───┐└───┘└─────────┘ │ └╥┘ - q_2: ┤ H ├──■──────────────┼──╫─ - └───┘┌─┴─┐ │ ║ - q_3: ─────┤ X ├────────────■──╫─ - └───┘ ║ - c: 1/═════════════════════════╩═ - 0 - """ + """Test finding depth of two-qubit gates only.""" + + # ┌───┐ + # q_0: ┤ H ├──■─────────────────── + # └───┘┌─┴─┐┌─────────┐ ┌─┐ + # q_1: ─────┤ X ├┤ Rz(0.1) ├─■─┤M├ + # ┌───┐└───┘└─────────┘ │ └╥┘ + # q_2: ┤ H ├──■──────────────┼──╫─ + # └───┘┌─┴─┐ │ ║ + # q_3: ─────┤ X ├────────────■──╫─ + # └───┘ ║ + # c: 1/═════════════════════════╩═ + # 0 circ = QuantumCircuit(4, 1) circ.h(0) circ.cx(0, 1) @@ -683,20 +655,19 @@ def test_circuit_depth_2qubit(self): self.assertEqual(circ.depth(lambda x: x[0].num_qubits == 2), 2) def test_circuit_depth_multiqubit_or_conditional(self): - """Test finding depth of multi-qubit or conditional gates. - - ┌───┐ ┌───┐ - q_0: ┤ H ├──■───────────────────────────┤ X ├─── - └───┘ │ ┌─────────┐ ┌─┐ └─╥─┘ - q_1: ───────■──┤ Rz(0.1) ├──────■─┤M├─────╫───── - ┌─┴─┐└──┬───┬──┘ │ └╥┘ ║ - q_2: ─────┤ X ├───┤ H ├─────■───┼──╫──────╫───── - └───┘ └───┘ ┌─┴─┐ │ ║ ║ - q_3: ─────────────────────┤ X ├─■──╫──────╫───── - └───┘ ║ ┌────╨────┐ - c: 1/══════════════════════════════╩═╡ c_0 = T ╞ - 0 └─────────┘ - """ + """Test finding depth of multi-qubit or conditional gates.""" + + # ┌───┐ ┌───┐ + # q_0: ┤ H ├──■───────────────────────────┤ X ├─── + # └───┘ │ ┌─────────┐ ┌─┐ └─╥─┘ + # q_1: ───────■──┤ Rz(0.1) ├──────■─┤M├─────╫───── + # ┌─┴─┐└──┬───┬──┘ │ └╥┘ ║ + # q_2: ─────┤ X ├───┤ H ├─────■───┼──╫──────╫───── + # └───┘ └───┘ ┌─┴─┐ │ ║ ║ + # q_3: ─────────────────────┤ X ├─■──╫──────╫───── + # └───┘ ║ ┌────╨────┐ + # c: 1/══════════════════════════════╩═╡ c_0 = T ╞ + # 0 └─────────┘ circ = QuantumCircuit(4, 1) circ.h(0) circ.ccx(0, 1, 2) @@ -711,20 +682,19 @@ def test_circuit_depth_multiqubit_or_conditional(self): ) def test_circuit_depth_first_qubit(self): - """Test finding depth of gates touching q0 only. - - ┌───┐ ┌───┐ - q_0: ┤ H ├──■─────┤ T ├───────── - └───┘┌─┴─┐┌──┴───┴──┐ ┌─┐ - q_1: ─────┤ X ├┤ Rz(0.1) ├─■─┤M├ - ┌───┐└───┘└─────────┘ │ └╥┘ - q_2: ┤ H ├──■──────────────┼──╫─ - └───┘┌─┴─┐ │ ║ - q_3: ─────┤ X ├────────────■──╫─ - └───┘ ║ - c: 1/═════════════════════════╩═ - 0 - """ + """Test finding depth of gates touching q0 only.""" + + # ┌───┐ ┌───┐ + # q_0: ┤ H ├──■─────┤ T ├───────── + # └───┘┌─┴─┐┌──┴───┴──┐ ┌─┐ + # q_1: ─────┤ X ├┤ Rz(0.1) ├─■─┤M├ + # ┌───┐└───┘└─────────┘ │ └╥┘ + # q_2: ┤ H ├──■──────────────┼──╫─ + # └───┘┌─┴─┐ │ ║ + # q_3: ─────┤ X ├────────────■──╫─ + # └───┘ ║ + # c: 1/═════════════════════════╩═ + # 0 circ = QuantumCircuit(4, 1) circ.h(0) circ.cx(0, 1) @@ -799,24 +769,23 @@ def test_circuit_count_ops(self): self.assertEqual(expected, result) def test_circuit_nonlocal_gates(self): - """Test num_nonlocal_gates. - - ┌───┐ ┌────────┐ - q_0: ┤ H ├───────────────────┤0 ├ - ├───┤ ┌───┐ │ │ - q_1: ┤ H ├───┤ X ├─────────■─┤ ├ - ├───┤ └───┘ │ │ │ - q_2: ┤ H ├─────■───────────X─┤ Iswap ├ - ├───┤ │ ┌───┐ │ │ │ - q_3: ┤ H ├─────┼─────┤ Z ├─X─┤ ├ - ├───┤┌────┴────┐├───┤ │ │ - q_4: ┤ H ├┤ Ry(0.1) ├┤ Z ├───┤1 ├ - ├───┤└──┬───┬──┘└───┘ └───╥────┘ - q_5: ┤ H ├───┤ Z ├───────────────╫───── - └───┘ └───┘ ┌──╨──┐ - c: 2/═════════════════════════╡ 0x2 ╞══ - └─────┘ - """ + """Test num_nonlocal_gates.""" + + # ┌───┐ ┌────────┐ + # q_0: ┤ H ├───────────────────┤0 ├ + # ├───┤ ┌───┐ │ │ + # q_1: ┤ H ├───┤ X ├─────────■─┤ ├ + # ├───┤ └───┘ │ │ │ + # q_2: ┤ H ├─────■───────────X─┤ Iswap ├ + # ├───┤ │ ┌───┐ │ │ │ + # q_3: ┤ H ├─────┼─────┤ Z ├─X─┤ ├ + # ├───┤┌────┴────┐├───┤ │ │ + # q_4: ┤ H ├┤ Ry(0.1) ├┤ Z ├───┤1 ├ + # ├───┤└──┬───┬──┘└───┘ └───╥────┘ + # q_5: ┤ H ├───┤ Z ├───────────────╫───── + # └───┘ └───┘ ┌──╨──┐ + # c: 2/═════════════════════════╡ 0x2 ╞══ + # └─────┘ q = QuantumRegister(6, "q") c = ClassicalRegister(2, "c") qc = QuantumCircuit(q, c) @@ -848,20 +817,19 @@ def test_circuit_connected_components_empty(self): self.assertEqual(7, qc.num_connected_components()) def test_circuit_connected_components_multi_reg(self): - """Test tensor factors works over multi registers - - ┌───┐ - q1_0: ┤ H ├──■───────────────── - ├───┤┌─┴─┐ - q1_1: ┤ H ├┤ X ├──■──────────── - ├───┤└───┘ │ ┌───┐ - q1_2: ┤ H ├───────┼──┤ X ├──■── - ├───┤ │ └─┬─┘┌─┴─┐ - q2_0: ┤ H ├───────┼────┼──┤ X ├ - ├───┤ ┌─┴─┐ │ └───┘ - q2_1: ┤ H ├─────┤ X ├──■─────── - └───┘ └───┘ - """ + """Test tensor factors works over multi registers""" + + # ┌───┐ + # q1_0: ┤ H ├──■───────────────── + # ├───┤┌─┴─┐ + # q1_1: ┤ H ├┤ X ├──■──────────── + # ├───┤└───┘ │ ┌───┐ + # q1_2: ┤ H ├───────┼──┤ X ├──■── + # ├───┤ │ └─┬─┘┌─┴─┐ + # q2_0: ┤ H ├───────┼────┼──┤ X ├ + # ├───┤ ┌─┴─┐ │ └───┘ + # q2_1: ┤ H ├─────┤ X ├──■─────── + # └───┘ └───┘ q1 = QuantumRegister(3, "q1") q2 = QuantumRegister(2, "q2") qc = QuantumCircuit(q1, q2) @@ -877,19 +845,18 @@ def test_circuit_connected_components_multi_reg(self): self.assertEqual(qc.num_connected_components(), 1) def test_circuit_connected_components_multi_reg2(self): - """Test tensor factors works over multi registers #2. - - q1_0: ──■──────────── - │ - q1_1: ──┼─────────■── - │ ┌───┐ │ - q1_2: ──┼──┤ X ├──┼── - │ └─┬─┘┌─┴─┐ - q2_0: ──┼────■──┤ X ├ - ┌─┴─┐ └───┘ - q2_1: ┤ X ├────────── - └───┘ - """ + """Test tensor factors works over multi registers #2.""" + + # q1_0: ──■──────────── + # │ + # q1_1: ──┼─────────■── + # │ ┌───┐ │ + # q1_2: ──┼──┤ X ├──┼── + # │ └─┬─┘┌─┴─┐ + # q2_0: ──┼────■──┤ X ├ + # ┌─┴─┐ └───┘ + # q2_1: ┤ X ├────────── + # └───┘ q1 = QuantumRegister(3, "q1") q2 = QuantumRegister(2, "q2") qc = QuantumCircuit(q1, q2) @@ -899,29 +866,28 @@ def test_circuit_connected_components_multi_reg2(self): self.assertEqual(qc.num_connected_components(), 2) def test_circuit_connected_components_disconnected(self): - """Test tensor factors works with 2q subspaces. - - q1_0: ──■────────────────────── - │ - q1_1: ──┼────■───────────────── - │ │ - q1_2: ──┼────┼────■──────────── - │ │ │ - q1_3: ──┼────┼────┼────■─────── - │ │ │ │ - q1_4: ──┼────┼────┼────┼────■── - │ │ │ │ ┌─┴─┐ - q2_0: ──┼────┼────┼────┼──┤ X ├ - │ │ │ ┌─┴─┐└───┘ - q2_1: ──┼────┼────┼──┤ X ├───── - │ │ ┌─┴─┐└───┘ - q2_2: ──┼────┼──┤ X ├────────── - │ ┌─┴─┐└───┘ - q2_3: ──┼──┤ X ├─────────────── - ┌─┴─┐└───┘ - q2_4: ┤ X ├──────────────────── - └───┘ - """ + """Test tensor factors works with 2q subspaces.""" + + # q1_0: ──■────────────────────── + # │ + # q1_1: ──┼────■───────────────── + # │ │ + # q1_2: ──┼────┼────■──────────── + # │ │ │ + # q1_3: ──┼────┼────┼────■─────── + # │ │ │ │ + # q1_4: ──┼────┼────┼────┼────■── + # │ │ │ │ ┌─┴─┐ + # q2_0: ──┼────┼────┼────┼──┤ X ├ + # │ │ │ ┌─┴─┐└───┘ + # q2_1: ──┼────┼────┼──┤ X ├───── + # │ │ ┌─┴─┐└───┘ + # q2_2: ──┼────┼──┤ X ├────────── + # │ ┌─┴─┐└───┘ + # q2_3: ──┼──┤ X ├─────────────── + # ┌─┴─┐└───┘ + # q2_4: ┤ X ├──────────────────── + # └───┘ q1 = QuantumRegister(5, "q1") q2 = QuantumRegister(5, "q2") qc = QuantumCircuit(q1, q2) @@ -933,20 +899,19 @@ def test_circuit_connected_components_disconnected(self): self.assertEqual(qc.num_connected_components(), 5) def test_circuit_connected_components_with_clbits(self): - """Test tensor components with classical register. - - ┌───┐┌─┐ - q_0: ┤ H ├┤M├───────── - ├───┤└╥┘┌─┐ - q_1: ┤ H ├─╫─┤M├────── - ├───┤ ║ └╥┘┌─┐ - q_2: ┤ H ├─╫──╫─┤M├─── - ├───┤ ║ ║ └╥┘┌─┐ - q_3: ┤ H ├─╫──╫──╫─┤M├ - └───┘ ║ ║ ║ └╥┘ - c: 4/══════╩══╩══╩══╩═ - 0 1 2 3 - """ + """Test tensor components with classical register.""" + + # ┌───┐┌─┐ + # q_0: ┤ H ├┤M├───────── + # ├───┤└╥┘┌─┐ + # q_1: ┤ H ├─╫─┤M├────── + # ├───┤ ║ └╥┘┌─┐ + # q_2: ┤ H ├─╫──╫─┤M├─── + # ├───┤ ║ ║ └╥┘┌─┐ + # q_3: ┤ H ├─╫──╫──╫─┤M├ + # └───┘ ║ ║ ║ └╥┘ + # c: 4/══════╩══╩══╩══╩═ + # 0 1 2 3 size = 4 q = QuantumRegister(size, "q") c = ClassicalRegister(size, "c") @@ -962,21 +927,20 @@ def test_circuit_connected_components_with_clbits(self): self.assertEqual(qc.num_connected_components(), 4) def test_circuit_connected_components_with_cond(self): - """Test tensor components with one conditional gate. - - ┌───┐┌─┐ - q_0: ┤ H ├┤M├───■──────────── - ├───┤└╥┘ │ ┌─┐ - q_1: ┤ H ├─╫────┼───┤M├────── - ├───┤ ║ │ └╥┘┌─┐ - q_2: ┤ H ├─╫────┼────╫─┤M├─── - ├───┤ ║ ┌─┴─┐ ║ └╥┘┌─┐ - q_3: ┤ H ├─╫──┤ X ├──╫──╫─┤M├ - └───┘ ║ └─╥─┘ ║ ║ └╥┘ - ║ ┌──╨──┐ ║ ║ ║ - c: 4/══════╩═╡ 0x2 ╞═╩══╩══╩═ - 0 └─────┘ 1 2 3 - """ + """Test tensor components with one conditional gate.""" + + # ┌───┐┌─┐ + # q_0: ┤ H ├┤M├───■──────────── + # ├───┤└╥┘ │ ┌─┐ + # q_1: ┤ H ├─╫────┼───┤M├────── + # ├───┤ ║ │ └╥┘┌─┐ + # q_2: ┤ H ├─╫────┼────╫─┤M├─── + # ├───┤ ║ ┌─┴─┐ ║ └╥┘┌─┐ + # q_3: ┤ H ├─╫──┤ X ├──╫──╫─┤M├ + # └───┘ ║ └─╥─┘ ║ ║ └╥┘ + # ║ ┌──╨──┐ ║ ║ ║ + # c: 4/══════╩═╡ 0x2 ╞═╩══╩══╩═ + # 0 └─────┘ 1 2 3 size = 4 q = QuantumRegister(size, "q") c = ClassicalRegister(size, "c") @@ -993,20 +957,19 @@ def test_circuit_connected_components_with_cond(self): self.assertEqual(qc.num_connected_components(), 1) def test_circuit_connected_components_with_cond2(self): - """Test tensor components with two conditional gates. - - ┌───┐ ┌───┐ - q_0: ┤ H ├─┤ H ├──────── - ├───┤ └─╥─┘ - q_1: ┤ H ├───╫──────■─── - ├───┤ ║ ┌─┴─┐ - q_2: ┤ H ├───╫────┤ X ├─ - ├───┤ ║ └─╥─┘ - q_3: ┤ H ├───╫──────╫─── - └───┘┌──╨──┐┌──╨──┐ - c: 8/═════╡ 0x0 ╞╡ 0x4 ╞ - └─────┘└─────┘ - """ + """Test tensor components with two conditional gates.""" + + # ┌───┐ ┌───┐ + # q_0: ┤ H ├─┤ H ├──────── + # ├───┤ └─╥─┘ + # q_1: ┤ H ├───╫──────■─── + # ├───┤ ║ ┌─┴─┐ + # q_2: ┤ H ├───╫────┤ X ├─ + # ├───┤ ║ └─╥─┘ + # q_3: ┤ H ├───╫──────╫─── + # └───┘┌──╨──┐┌──╨──┐ + # c: 8/═════╡ 0x0 ╞╡ 0x4 ╞ + # └─────┘└─────┘ size = 4 q = QuantumRegister(size, "q") c = ClassicalRegister(2 * size, "c") @@ -1020,21 +983,20 @@ def test_circuit_connected_components_with_cond2(self): self.assertEqual(qc.num_connected_components(), 2) def test_circuit_connected_components_with_cond3(self): - """Test tensor components with three conditional gates and measurements. - - ┌───┐┌─┐ ┌───┐ - q0_0: ┤ H ├┤M├─┤ H ├────────────────── - ├───┤└╥┘ └─╥─┘ - q0_1: ┤ H ├─╫────╫──────■───────────── - ├───┤ ║ ║ ┌─┴─┐ ┌─┐ - q0_2: ┤ H ├─╫────╫────┤ X ├─┤M├─────── - ├───┤ ║ ║ └─╥─┘ └╥┘ ┌───┐ - q0_3: ┤ H ├─╫────╫──────╫────╫──┤ X ├─ - └───┘ ║ ║ ║ ║ └─╥─┘ - ║ ┌──╨──┐┌──╨──┐ ║ ┌──╨──┐ - c0: 4/══════╩═╡ 0x0 ╞╡ 0x1 ╞═╩═╡ 0x2 ╞ - 0 └─────┘└─────┘ 2 └─────┘ - """ + """Test tensor components with three conditional gates and measurements.""" + + # ┌───┐┌─┐ ┌───┐ + # q0_0: ┤ H ├┤M├─┤ H ├────────────────── + # ├───┤└╥┘ └─╥─┘ + # q0_1: ┤ H ├─╫────╫──────■───────────── + # ├───┤ ║ ║ ┌─┴─┐ ┌─┐ + # q0_2: ┤ H ├─╫────╫────┤ X ├─┤M├─────── + # ├───┤ ║ ║ └─╥─┘ └╥┘ ┌───┐ + # q0_3: ┤ H ├─╫────╫──────╫────╫──┤ X ├─ + # └───┘ ║ ║ ║ ║ └─╥─┘ + # ║ ┌──╨──┐┌──╨──┐ ║ ┌──╨──┐ + # c0: 4/══════╩═╡ 0x0 ╞╡ 0x1 ╞═╩═╡ 0x2 ╞ + # 0 └─────┘└─────┘ 2 └─────┘ size = 4 q = QuantumRegister(size) c = ClassicalRegister(size) @@ -1051,21 +1013,20 @@ def test_circuit_connected_components_with_cond3(self): self.assertEqual(qc.num_connected_components(), 1) def test_circuit_connected_components_with_bit_cond(self): - """Test tensor components with one single bit conditional gate. - - ┌───┐┌─┐ - q_0: ┤ H ├┤M├───────────■──────── - ├───┤└╥┘┌─┐ │ - q_1: ┤ H ├─╫─┤M├────────┼──────── - ├───┤ ║ └╥┘┌─┐ │ - q_2: ┤ H ├─╫──╫─┤M├─────┼──────── - ├───┤ ║ ║ └╥┘ ┌─┴─┐ ┌─┐ - q_3: ┤ H ├─╫──╫──╫────┤ X ├───┤M├ - └───┘ ║ ║ ║ └─╥─┘ └╥┘ - ║ ║ ║ ┌────╨────┐ ║ - c: 4/══════╩══╩══╩═╡ c_0=0x1 ╞═╩═ - 0 1 2 └─────────┘ 3 - """ + """Test tensor components with one single bit conditional gate.""" + + # ┌───┐┌─┐ + # q_0: ┤ H ├┤M├───────────■──────── + # ├───┤└╥┘┌─┐ │ + # q_1: ┤ H ├─╫─┤M├────────┼──────── + # ├───┤ ║ └╥┘┌─┐ │ + # q_2: ┤ H ├─╫──╫─┤M├─────┼──────── + # ├───┤ ║ ║ └╥┘ ┌─┴─┐ ┌─┐ + # q_3: ┤ H ├─╫──╫──╫────┤ X ├───┤M├ + # └───┘ ║ ║ ║ └─╥─┘ └╥┘ + # ║ ║ ║ ┌────╨────┐ ║ + # c: 4/══════╩══╩══╩═╡ c_0=0x1 ╞═╩═ + # 0 1 2 └─────────┘ 3 size = 4 q = QuantumRegister(size, "q") c = ClassicalRegister(size, "c") @@ -1082,20 +1043,19 @@ def test_circuit_connected_components_with_bit_cond(self): self.assertEqual(qc.num_connected_components(), 3) def test_circuit_connected_components_with_bit_cond2(self): - """Test tensor components with two bit conditional gates. - - ┌───┐ ┌───┐ ┌───┐ - q_0: ┤ H ├───┤ H ├─────────────────┤ X ├─── - ├───┤ └─╥─┘ └─┬─┘ - q_1: ┤ H ├─────╫─────────────────────■───── - ├───┤ ║ ║ - q_2: ┤ H ├─────╫──────────■──────────╫───── - ├───┤ ║ │ ║ - q_3: ┤ H ├─────╫──────────■──────────╫───── - └───┘┌────╨────┐┌────╨────┐┌────╨────┐ - c: 6/═════╡ c_1=0x1 ╞╡ c_0=0x1 ╞╡ c_4=0x0 ╞ - └─────────┘└─────────┘└─────────┘ - """ + """Test tensor components with two bit conditional gates.""" + + # ┌───┐ ┌───┐ ┌───┐ + # q_0: ┤ H ├───┤ H ├─────────────────┤ X ├─── + # ├───┤ └─╥─┘ └─┬─┘ + # q_1: ┤ H ├─────╫─────────────────────■───── + # ├───┤ ║ ║ + # q_2: ┤ H ├─────╫──────────■──────────╫───── + # ├───┤ ║ │ ║ + # q_3: ┤ H ├─────╫──────────■──────────╫───── + # └───┘┌────╨────┐┌────╨────┐┌────╨────┐ + # c: 6/═════╡ c_1=0x1 ╞╡ c_0=0x1 ╞╡ c_4=0x0 ╞ + # └─────────┘└─────────┘└─────────┘ size = 4 q = QuantumRegister(size, "q") c = ClassicalRegister(size + 2, "c") @@ -1110,21 +1070,20 @@ def test_circuit_connected_components_with_bit_cond2(self): self.assertEqual(qc.num_connected_components(), 5) def test_circuit_connected_components_with_bit_cond3(self): - """Test tensor components with register and bit conditional gates. - - ┌───┐ ┌───┐ - q0_0: ┤ H ├───┤ H ├─────────────────────── - ├───┤ └─╥─┘ - q0_1: ┤ H ├─────╫─────────■─────────────── - ├───┤ ║ ┌─┴─┐ - q0_2: ┤ H ├─────╫───────┤ X ├───────────── - ├───┤ ║ └─╥─┘ ┌───┐ - q0_3: ┤ H ├─────╫─────────╫──────┤ X ├──── - └───┘ ║ ║ └─╥─┘ - ┌────╨─────┐┌──╨──┐┌────╨─────┐ - c0: 4/═════╡ c0_0=0x1 ╞╡ 0x1 ╞╡ c0_2=0x1 ╞ - └──────────┘└─────┘└──────────┘ - """ + """Test tensor components with register and bit conditional gates.""" + + # ┌───┐ ┌───┐ + # q0_0: ┤ H ├───┤ H ├─────────────────────── + # ├───┤ └─╥─┘ + # q0_1: ┤ H ├─────╫─────────■─────────────── + # ├───┤ ║ ┌─┴─┐ + # q0_2: ┤ H ├─────╫───────┤ X ├───────────── + # ├───┤ ║ └─╥─┘ ┌───┐ + # q0_3: ┤ H ├─────╫─────────╫──────┤ X ├──── + # └───┘ ║ ║ └─╥─┘ + # ┌────╨─────┐┌──╨──┐┌────╨─────┐ + # c0: 4/═════╡ c0_0=0x1 ╞╡ 0x1 ╞╡ c0_2=0x1 ╞ + # └──────────┘└─────┘└──────────┘ size = 4 q = QuantumRegister(size) c = ClassicalRegister(size) @@ -1155,21 +1114,20 @@ def test_circuit_unitary_factors2(self): self.assertEqual(qc.num_unitary_factors(), 4) def test_circuit_unitary_factors3(self): - """Test unitary factors measurements and conditionals. - - ┌───┐ ┌─┐ - q_0: ┤ H ├────────■──────────■────■──────────■──┤M├─── - ├───┤ │ │ │ ┌─┐ │ └╥┘ - q_1: ┤ H ├──■─────┼─────■────┼────┼──┤M├─────┼───╫──── - ├───┤┌─┴─┐ │ ┌─┴─┐ │ │ └╥┘┌─┐ │ ║ - q_2: ┤ H ├┤ X ├───┼───┤ X ├──┼────┼───╫─┤M├──┼───╫──── - ├───┤└───┘ ┌─┴─┐ └───┘┌─┴─┐┌─┴─┐ ║ └╥┘┌─┴─┐ ║ ┌─┐ - q_3: ┤ H ├──────┤ X ├──────┤ X ├┤ X ├─╫──╫─┤ X ├─╫─┤M├ - └───┘ └─╥─┘ └───┘└───┘ ║ ║ └───┘ ║ └╥┘ - ┌──╨──┐ ║ ║ ║ ║ - c: 4/══════════╡ 0x2 ╞════════════════╩══╩═══════╩══╩═ - └─────┘ 1 2 0 3 - """ + """Test unitary factors measurements and conditionals.""" + + # ┌───┐ ┌─┐ + # q_0: ┤ H ├────────■──────────■────■──────────■──┤M├─── + # ├───┤ │ │ │ ┌─┐ │ └╥┘ + # q_1: ┤ H ├──■─────┼─────■────┼────┼──┤M├─────┼───╫──── + # ├───┤┌─┴─┐ │ ┌─┴─┐ │ │ └╥┘┌─┐ │ ║ + # q_2: ┤ H ├┤ X ├───┼───┤ X ├──┼────┼───╫─┤M├──┼───╫──── + # ├───┤└───┘ ┌─┴─┐ └───┘┌─┴─┐┌─┴─┐ ║ └╥┘┌─┴─┐ ║ ┌─┐ + # q_3: ┤ H ├──────┤ X ├──────┤ X ├┤ X ├─╫──╫─┤ X ├─╫─┤M├ + # └───┘ └─╥─┘ └───┘└───┘ ║ ║ └───┘ ║ └╥┘ + # ┌──╨──┐ ║ ║ ║ ║ + # c: 4/══════════╡ 0x2 ╞════════════════╩══╩═══════╩══╩═ + # └─────┘ 1 2 0 3 size = 4 q = QuantumRegister(size, "q") c = ClassicalRegister(size, "c") @@ -1191,22 +1149,21 @@ def test_circuit_unitary_factors3(self): self.assertEqual(qc.num_unitary_factors(), 2) def test_circuit_unitary_factors4(self): - """Test unitary factors measurements go to same cbit. - - ┌───┐┌─┐ - q_0: ┤ H ├┤M├───────── - ├───┤└╥┘┌─┐ - q_1: ┤ H ├─╫─┤M├────── - ├───┤ ║ └╥┘┌─┐ - q_2: ┤ H ├─╫──╫─┤M├─── - ├───┤ ║ ║ └╥┘┌─┐ - q_3: ┤ H ├─╫──╫──╫─┤M├ - └───┘ ║ ║ ║ └╥┘ - q_4: ──────╫──╫──╫──╫─ - ║ ║ ║ ║ - c: 5/══════╩══╩══╩══╩═ - 0 0 0 0 - """ + """Test unitary factors measurements go to same cbit.""" + + # ┌───┐┌─┐ + # q_0: ┤ H ├┤M├───────── + # ├───┤└╥┘┌─┐ + # q_1: ┤ H ├─╫─┤M├────── + # ├───┤ ║ └╥┘┌─┐ + # q_2: ┤ H ├─╫──╫─┤M├─── + # ├───┤ ║ ║ └╥┘┌─┐ + # q_3: ┤ H ├─╫──╫──╫─┤M├ + # └───┘ ║ ║ ║ └╥┘ + # q_4: ──────╫──╫──╫──╫─ + # ║ ║ ║ ║ + # c: 5/══════╩══╩══╩══╩═ + # 0 0 0 0 size = 5 q = QuantumRegister(size, "q") c = ClassicalRegister(size, "c") diff --git a/test/python/compiler/test_compiler.py b/test/python/compiler/test_compiler.py index d602fffcf627..6218270a5cb8 100644 --- a/test/python/compiler/test_compiler.py +++ b/test/python/compiler/test_compiler.py @@ -272,19 +272,18 @@ def test_mapper_overoptimization(self): The mapper should not change the semantics of the input. An overoptimization introduced issue #81: https://github.com/Qiskit/qiskit-terra/issues/81 - - ┌───┐ ┌─┐ - q0_0: ┤ X ├──■───────┤M├─────────── - ├───┤┌─┴─┐┌───┐└╥┘ ┌─┐ - q0_1: ┤ Y ├┤ X ├┤ S ├─╫───■──┤M├─── - ├───┤└───┘├───┤ ║ ┌─┴─┐└╥┘┌─┐ - q0_2: ┤ Z ├──■──┤ T ├─╫─┤ X ├─╫─┤M├ - └───┘┌─┴─┐├───┤ ║ └┬─┬┘ ║ └╥┘ - q0_3: ─────┤ X ├┤ H ├─╫──┤M├──╫──╫─ - └───┘└───┘ ║ └╥┘ ║ ║ - c0: 4/════════════════╩═══╩═══╩══╩═ - 0 3 1 2 """ + # ┌───┐ ┌─┐ + # q0_0: ┤ X ├──■───────┤M├─────────── + # ├───┤┌─┴─┐┌───┐└╥┘ ┌─┐ + # q0_1: ┤ Y ├┤ X ├┤ S ├─╫───■──┤M├─── + # ├───┤└───┘├───┤ ║ ┌─┴─┐└╥┘┌─┐ + # q0_2: ┤ Z ├──■──┤ T ├─╫─┤ X ├─╫─┤M├ + # └───┘┌─┴─┐├───┤ ║ └┬─┬┘ ║ └╥┘ + # q0_3: ─────┤ X ├┤ H ├─╫──┤M├──╫──╫─ + # └───┘└───┘ ║ └╥┘ ║ ║ + # c0: 4/════════════════╩═══╩═══╩══╩═ + # 0 3 1 2 qr = QuantumRegister(4) cr = ClassicalRegister(4) circ = QuantumCircuit(qr, cr) @@ -400,19 +399,18 @@ def test_math_domain_error(self): The math library operates over floats and introduces floating point errors that should be avoided. See: https://github.com/Qiskit/qiskit-terra/issues/111 - - ┌───┐┌───┐ ┌─┐ - q0_0: ┤ Y ├┤ X ├─────┤M├───────────────────── - └───┘└─┬─┘ └╥┘ ┌─┐ - q0_1: ───────■────────╫─────────────■──┤M├─── - ┌───┐┌───┐┌───┐ ║ ┌───┐┌───┐┌─┴─┐└╥┘┌─┐ - q0_2: ┤ Z ├┤ H ├┤ Y ├─╫─┤ T ├┤ Z ├┤ X ├─╫─┤M├ - └┬─┬┘└───┘└───┘ ║ └───┘└───┘└───┘ ║ └╥┘ - q0_3: ─┤M├────────────╫─────────────────╫──╫─ - └╥┘ ║ ║ ║ - c0: 4/══╩═════════════╩═════════════════╩══╩═ - 3 0 1 2 """ + # ┌───┐┌───┐ ┌─┐ + # q0_0: ┤ Y ├┤ X ├─────┤M├───────────────────── + # └───┘└─┬─┘ └╥┘ ┌─┐ + # q0_1: ───────■────────╫─────────────■──┤M├─── + # ┌───┐┌───┐┌───┐ ║ ┌───┐┌───┐┌─┴─┐└╥┘┌─┐ + # q0_2: ┤ Z ├┤ H ├┤ Y ├─╫─┤ T ├┤ Z ├┤ X ├─╫─┤M├ + # └┬─┬┘└───┘└───┘ ║ └───┘└───┘└───┘ ║ └╥┘ + # q0_3: ─┤M├────────────╫─────────────────╫──╫─ + # └╥┘ ║ ║ ║ + # c0: 4/══╩═════════════╩═════════════════╩══╩═ + # 3 0 1 2 qr = QuantumRegister(4) cr = ClassicalRegister(4) circ = QuantumCircuit(qr, cr) diff --git a/test/python/compiler/test_transpiler.py b/test/python/compiler/test_transpiler.py index fd28705a17e6..118c80da16bd 100644 --- a/test/python/compiler/test_transpiler.py +++ b/test/python/compiler/test_transpiler.py @@ -105,15 +105,17 @@ def test_transpile_non_adjacent_layout(self): """Transpile pipeline can handle manual layout on non-adjacent qubits. circuit: - ┌───┐ - qr_0: ┤ H ├──■──────────── -> 1 - └───┘┌─┴─┐ - qr_1: ─────┤ X ├──■─────── -> 2 - └───┘┌─┴─┐ - qr_2: ──────────┤ X ├──■── -> 3 - └───┘┌─┴─┐ - qr_3: ───────────────┤ X ├ -> 5 - └───┘ + .. parsed-literal:: + + ┌───┐ + qr_0: ┤ H ├──■──────────── -> 1 + └───┘┌─┴─┐ + qr_1: ─────┤ X ├──■─────── -> 2 + └───┘┌─┴─┐ + qr_2: ──────────┤ X ├──■── -> 3 + └───┘┌─┴─┐ + qr_3: ───────────────┤ X ├ -> 5 + └───┘ device: 0 - 1 - 2 - 3 - 4 - 5 - 6 @@ -208,21 +210,23 @@ def test_already_mapped_via_layout(self): See: https://github.com/Qiskit/qiskit-terra/issues/2036 circuit: - ┌───┐ ┌───┐ ░ ┌─┐ - qn_0: ┤ H ├──■────────────■──┤ H ├─░─┤M├─── -> 9 - └───┘ │ │ └───┘ ░ └╥┘ - qn_1: ───────┼────────────┼────────░──╫──── -> 6 - │ │ ░ ║ - qn_2: ───────┼────────────┼────────░──╫──── -> 5 - │ │ ░ ║ - qn_3: ───────┼────────────┼────────░──╫──── -> 0 - │ │ ░ ║ - qn_4: ───────┼────────────┼────────░──╫──── -> 1 - ┌───┐┌─┴─┐┌──────┐┌─┴─┐┌───┐ ░ ║ ┌─┐ - qn_5: ┤ H ├┤ X ├┤ P(2) ├┤ X ├┤ H ├─░──╫─┤M├ -> 4 - └───┘└───┘└──────┘└───┘└───┘ ░ ║ └╥┘ - cn: 2/════════════════════════════════╩══╩═ - 0 1 + .. parsed-literal:: + + ┌───┐ ┌───┐ ░ ┌─┐ + qn_0: ┤ H ├──■────────────■──┤ H ├─░─┤M├─── -> 9 + └───┘ │ │ └───┘ ░ └╥┘ + qn_1: ───────┼────────────┼────────░──╫──── -> 6 + │ │ ░ ║ + qn_2: ───────┼────────────┼────────░──╫──── -> 5 + │ │ ░ ║ + qn_3: ───────┼────────────┼────────░──╫──── -> 0 + │ │ ░ ║ + qn_4: ───────┼────────────┼────────░──╫──── -> 1 + ┌───┐┌─┴─┐┌──────┐┌─┴─┐┌───┐ ░ ║ ┌─┐ + qn_5: ┤ H ├┤ X ├┤ P(2) ├┤ X ├┤ H ├─░──╫─┤M├ -> 4 + └───┘└───┘└──────┘└───┘└───┘ ░ ║ └╥┘ + cn: 2/════════════════════════════════╩══╩═ + 0 1 device: 0 -- 1 -- 2 -- 3 -- 4 @@ -656,13 +660,12 @@ def test_do_not_run_gatedirection_with_symmetric_cm(self): def test_optimize_to_nothing(self): """Optimize gates up to fixed point in the default pipeline See https://github.com/Qiskit/qiskit-terra/issues/2035 - - ┌───┐ ┌───┐┌───┐┌───┐ ┌───┐ - q0_0: ┤ H ├──■──┤ X ├┤ Y ├┤ Z ├──■──┤ H ├──■────■── - └───┘┌─┴─┐└───┘└───┘└───┘┌─┴─┐└───┘┌─┴─┐┌─┴─┐ - q0_1: ─────┤ X ├───────────────┤ X ├─────┤ X ├┤ X ├ - └───┘ └───┘ └───┘└───┘ """ + # ┌───┐ ┌───┐┌───┐┌───┐ ┌───┐ + # q0_0: ┤ H ├──■──┤ X ├┤ Y ├┤ Z ├──■──┤ H ├──■────■── + # └───┘┌─┴─┐└───┘└───┘└───┘┌─┴─┐└───┘┌─┴─┐┌─┴─┐ + # q0_1: ─────┤ X ├───────────────┤ X ├─────┤ X ├┤ X ├ + # └───┘ └───┘ └───┘└───┘ qr = QuantumRegister(2) circ = QuantumCircuit(qr) circ.h(qr[0]) diff --git a/test/python/dagcircuit/test_dagcircuit.py b/test/python/dagcircuit/test_dagcircuit.py index 55406c865d60..db63566a3fa4 100644 --- a/test/python/dagcircuit/test_dagcircuit.py +++ b/test/python/dagcircuit/test_dagcircuit.py @@ -844,6 +844,8 @@ def test_dag_nodes_on_wire_multiple_successors(self): Test that if an DAGOpNode has multiple successors in the DAG along one wire, they are all retrieved in order. This could be the case for a circuit such as + .. parsed-literal:: + q0_0: |0>──■─────────■── ┌─┴─┐┌───┐┌─┴─┐ q0_1: |0>┤ X ├┤ H ├┤ X ├ @@ -1135,20 +1137,18 @@ class TestCircuitProperties(QiskitTestCase): """DAGCircuit properties test.""" def setUp(self): - """ - ┌───┐ ┌───┐ - q0_0: ┤ H ├────────────────┤ X ├────────── - └───┘ └─┬─┘ ┌───┐ - q0_1: ───────────────────────┼───────┤ H ├ - ┌───┐ │ ┌───┐└─┬─┘ - q0_2: ──■───────┤ H ├────────┼──┤ T ├──■── - ┌─┴─┐┌────┴───┴─────┐ │ └───┘ - q0_3: ┤ X ├┤ U(0,0.1,0.2) ├──┼──────────── - └───┘└──────────────┘ │ - q1_0: ───────────────────────■──────────── - │ - q1_1: ───────────────────────■──────────── - """ + # ┌───┐ ┌───┐ + # q0_0: ┤ H ├────────────────┤ X ├────────── + # └───┘ └─┬─┘ ┌───┐ + # q0_1: ───────────────────────┼───────┤ H ├ + # ┌───┐ │ ┌───┐└─┬─┘ + # q0_2: ──■───────┤ H ├────────┼──┤ T ├──■── + # ┌─┴─┐┌────┴───┴─────┐ │ └───┘ + # q0_3: ┤ X ├┤ U(0,0.1,0.2) ├──┼──────────── + # └───┘└──────────────┘ │ + # q1_0: ───────────────────────■──────────── + # │ + # q1_1: ───────────────────────■──────────── super().setUp() qr1 = QuantumRegister(4) qr2 = QuantumRegister(2) @@ -1213,20 +1213,18 @@ class TestDagEquivalence(QiskitTestCase): """DAGCircuit equivalence check.""" def setUp(self): - """ - ┌───┐ ┌───┐ - qr1_0: ┤ H ├────────────────┤ X ├────────── - └───┘ └─┬─┘ ┌───┐ - qr1_1: ───────────────────────┼───────┤ H ├ - ┌───┐ │ ┌───┐└─┬─┘ - qr1_2: ──■───────┤ H ├────────┼──┤ T ├──■── - ┌─┴─┐┌────┴───┴─────┐ │ └───┘ - qr1_3: ┤ X ├┤ U(0,0.1,0.2) ├──┼──────────── - └───┘└──────────────┘ │ - qr2_0: ───────────────────────■──────────── - │ - qr2_1: ───────────────────────■──────────── - """ + # ┌───┐ ┌───┐ + # qr1_0: ┤ H ├────────────────┤ X ├────────── + # └───┘ └─┬─┘ ┌───┐ + # qr1_1: ───────────────────────┼───────┤ H ├ + # ┌───┐ │ ┌───┐└─┬─┘ + # qr1_2: ──■───────┤ H ├────────┼──┤ T ├──■── + # ┌─┴─┐┌────┴───┴─────┐ │ └───┘ + # qr1_3: ┤ X ├┤ U(0,0.1,0.2) ├──┼──────────── + # └───┘└──────────────┘ │ + # qr2_0: ───────────────────────■──────────── + # │ + # qr2_1: ───────────────────────■──────────── super().setUp() self.qr1 = QuantumRegister(4, "qr1") self.qr2 = QuantumRegister(2, "qr2") @@ -1241,21 +1239,19 @@ def setUp(self): self.dag1 = circuit_to_dag(circ1) def test_dag_eq(self): - """DAG equivalence check: True. - - ┌───┐ ┌───┐ - qr1_0: ┤ H ├────────────────┤ X ├────────── - └───┘ └─┬─┘ ┌───┐ - qr1_1: ───────────────────────┼───────┤ H ├ - ┌───┐ │ ┌───┐└─┬─┘ - qr1_2: ──■───────┤ H ├────────┼──┤ T ├──■── - ┌─┴─┐┌────┴───┴─────┐ │ └───┘ - qr1_3: ┤ X ├┤ U(0,0.1,0.2) ├──┼──────────── - └───┘└──────────────┘ │ - qr2_0: ───────────────────────■──────────── - │ - qr2_1: ───────────────────────■──────────── - """ + """DAG equivalence check: True.""" + # ┌───┐ ┌───┐ + # qr1_0: ┤ H ├────────────────┤ X ├────────── + # └───┘ └─┬─┘ ┌───┐ + # qr1_1: ───────────────────────┼───────┤ H ├ + # ┌───┐ │ ┌───┐└─┬─┘ + # qr1_2: ──■───────┤ H ├────────┼──┤ T ├──■── + # ┌─┴─┐┌────┴───┴─────┐ │ └───┘ + # qr1_3: ┤ X ├┤ U(0,0.1,0.2) ├──┼──────────── + # └───┘└──────────────┘ │ + # qr2_0: ───────────────────────■──────────── + # │ + # qr2_1: ───────────────────────■──────────── circ2 = QuantumCircuit(self.qr1, self.qr2) circ2.cx(self.qr1[2], self.qr1[3]) circ2.u(0.0, 0.1, 0.2, self.qr1[3]) @@ -1269,21 +1265,19 @@ def test_dag_eq(self): self.assertEqual(self.dag1, dag2) def test_dag_neq_topology(self): - """DAG equivalence check: False. Different topology. - - ┌───┐ ┌───┐ - qr1_0: ┤ H ├───────■─────────────┤ X ├ - └───┘ ┌─┴─┐ └─┬─┘ - qr1_1: ──────────┤ H ├─────────────┼── - ├───┤ ┌───┐ │ - qr1_2: ──■───────┤ H ├──────┤ T ├──┼── - ┌─┴─┐┌────┴───┴─────┐└───┘ │ - qr1_3: ┤ X ├┤ U(0,0.1,0.2) ├───────┼── - └───┘└──────────────┘ │ - qr2_0: ────────────────────────────■── - │ - qr2_1: ────────────────────────────■── - """ + """DAG equivalence check: False. Different topology.""" + # ┌───┐ ┌───┐ + # qr1_0: ┤ H ├───────■─────────────┤ X ├ + # └───┘ ┌─┴─┐ └─┬─┘ + # qr1_1: ──────────┤ H ├─────────────┼── + # ├───┤ ┌───┐ │ + # qr1_2: ──■───────┤ H ├──────┤ T ├──┼── + # ┌─┴─┐┌────┴───┴─────┐└───┘ │ + # qr1_3: ┤ X ├┤ U(0,0.1,0.2) ├───────┼── + # └───┘└──────────────┘ │ + # qr2_0: ────────────────────────────■── + # │ + # qr2_1: ────────────────────────────■── circ2 = QuantumCircuit(self.qr1, self.qr2) circ2.cx(self.qr1[2], self.qr1[3]) circ2.u(0.0, 0.1, 0.2, self.qr1[3]) @@ -1297,21 +1291,19 @@ def test_dag_neq_topology(self): self.assertNotEqual(self.dag1, dag2) def test_dag_neq_same_topology(self): - """DAG equivalence check: False. Same topology. - - ┌───┐ ┌───┐ - qr1_0: ┤ H ├────────────────┤ X ├────────── - └───┘ └─┬─┘ ┌───┐ - qr1_1: ───────────────────────┼───────┤ X ├ - ┌───┐ │ ┌───┐└─┬─┘ - qr1_2: ──■───────┤ H ├────────┼──┤ T ├──■── - ┌─┴─┐┌────┴───┴─────┐ │ └───┘ - qr1_3: ┤ X ├┤ U(0,0.1,0.2) ├──┼──────────── - └───┘└──────────────┘ │ - qr2_0: ───────────────────────■──────────── - │ - qr2_1: ───────────────────────■──────────── - """ + """DAG equivalence check: False. Same topology.""" + # ┌───┐ ┌───┐ + # qr1_0: ┤ H ├────────────────┤ X ├────────── + # └───┘ └─┬─┘ ┌───┐ + # qr1_1: ───────────────────────┼───────┤ X ├ + # ┌───┐ │ ┌───┐└─┬─┘ + # qr1_2: ──■───────┤ H ├────────┼──┤ T ├──■── + # ┌─┴─┐┌────┴───┴─────┐ │ └───┘ + # qr1_3: ┤ X ├┤ U(0,0.1,0.2) ├──┼──────────── + # └───┘└──────────────┘ │ + # qr2_0: ───────────────────────■──────────── + # │ + # qr2_1: ───────────────────────■──────────── circ2 = QuantumCircuit(self.qr1, self.qr2) circ2.cx(self.qr1[2], self.qr1[3]) circ2.u(0.0, 0.1, 0.2, self.qr1[3]) @@ -1601,20 +1593,18 @@ class TestDagProperties(QiskitTestCase): """Test the DAG properties.""" def setUp(self): - """ - ┌───┐ ┌───┐ - q0_0: ┤ H ├────────────────┤ X ├────────── - └───┘ └─┬─┘ ┌───┐ - q0_1: ───────────────────────┼───────┤ H ├ - ┌───┐ │ ┌───┐└─┬─┘ - q0_2: ──■───────┤ H ├────────┼──┤ T ├──■── - ┌─┴─┐┌────┴───┴─────┐ │ └───┘ - q0_3: ┤ X ├┤ U(0,0.1,0.2) ├──┼──────────── - └───┘└──────────────┘ │ - q1_0: ───────────────────────■──────────── - │ - q1_1: ───────────────────────■──────────── - """ + # ┌───┐ ┌───┐ + # q0_0: ┤ H ├────────────────┤ X ├────────── + # └───┘ └─┬─┘ ┌───┐ + # q0_1: ───────────────────────┼───────┤ H ├ + # ┌───┐ │ ┌───┐└─┬─┘ + # q0_2: ──■───────┤ H ├────────┼──┤ T ├──■── + # ┌─┴─┐┌────┴───┴─────┐ │ └───┘ + # q0_3: ┤ X ├┤ U(0,0.1,0.2) ├──┼──────────── + # └───┘└──────────────┘ │ + # q1_0: ───────────────────────■──────────── + # │ + # q1_1: ───────────────────────■──────────── super().setUp() qr1 = QuantumRegister(4) qr2 = QuantumRegister(2) @@ -1670,21 +1660,18 @@ def test_dag_idle_wires(self): self.assertEqual(len(wires), 1) def test_dag_depth1(self): - """Test DAG depth #1 - - ┌───┐ - q1_0: ┤ H ├──■────■───────────────── - ├───┤ │ ┌─┴─┐ - q1_1: ┤ H ├──┼──┤ X ├──■──────────── - ├───┤ │ └───┘ │ ┌───┐ - q1_2: ┤ H ├──┼─────────┼──┤ X ├──■── - ├───┤┌─┴─┐ │ └─┬─┘┌─┴─┐ - q2_0: ┤ H ├┤ X ├───────┼────┼──┤ X ├ - ├───┤└─┬─┘ ┌─┴─┐ │ └───┘ - q2_1: ┤ H ├──■───────┤ X ├──■─────── - └───┘ └───┘ - c: 5/══════════════════════════════ - """ + """Test DAG depth #1""" + # ┌───┐ + # q1_0: ┤ H ├──■────■───────────────── + # ├───┤ │ ┌─┴─┐ + # q1_1: ┤ H ├──┼──┤ X ├──■──────────── + # ├───┤ │ └───┘ │ ┌───┐ + # q1_2: ┤ H ├──┼─────────┼──┤ X ├──■── + # ├───┤┌─┴─┐ │ └─┬─┘┌─┴─┐ + # q2_0: ┤ H ├┤ X ├───────┼────┼──┤ X ├ + # ├───┤└─┬─┘ ┌─┴─┐ │ └───┘ + # q2_1: ┤ H ├──■───────┤ X ├──■─────── + # └───┘ └───┘ qr1 = QuantumRegister(3, "q1") qr2 = QuantumRegister(2, "q2") c = ClassicalRegister(5, "c") @@ -1703,22 +1690,21 @@ def test_dag_depth1(self): self.assertEqual(dag.depth(), 6) def test_dag_depth2(self): - """Test barrier increases DAG depth - - ┌───┐ ░ - q_0: ┤ H ├──■──────────────────░──── - └───┘ │ ┌───┐ ░ ┌─┐ - q_1: ───────┼────────────┤ X ├─░─┤M├ - ┌───┐ │ ┌───┐┌───┐└─┬─┘ ░ └╥┘ - q_2: ┤ X ├──┼──┤ X ├┤ X ├──┼───░──╫─ - └───┘ │ └───┘└───┘ │ ░ ║ - q_3: ───────┼──────────────┼───░──╫─ - ┌─┴─┐┌───┐ │ ░ ║ - q_4: ─────┤ X ├┤ X ├───────■───░──╫─ - └───┘└───┘ ░ ║ - c: 1/═════════════════════════════╩═ - 0 - """ + """Test barrier increases DAG depth""" + + # ┌───┐ ░ + # q_0: ┤ H ├──■──────────────────░──── + # └───┘ │ ┌───┐ ░ ┌─┐ + # q_1: ───────┼────────────┤ X ├─░─┤M├ + # ┌───┐ │ ┌───┐┌───┐└─┬─┘ ░ └╥┘ + # q_2: ┤ X ├──┼──┤ X ├┤ X ├──┼───░──╫─ + # └───┘ │ └───┘└───┘ │ ░ ║ + # q_3: ───────┼──────────────┼───░──╫─ + # ┌─┴─┐┌───┐ │ ░ ║ + # q_4: ─────┤ X ├┤ X ├───────■───░──╫─ + # └───┘└───┘ ░ ║ + # c: 1/═════════════════════════════╩═ + # 0 q = QuantumRegister(5, "q") c = ClassicalRegister(1, "c") qc = QuantumCircuit(q, c) @@ -1735,24 +1721,23 @@ def test_dag_depth2(self): self.assertEqual(dag.depth(), 6) def test_dag_depth3(self): - """Test DAG depth for silly circuit. - - ┌───┐ ░ ░ ┌─┐ - q_0: ┤ H ├──■────░────░───────┤M├───── - └───┘┌─┴─┐ ░ ░ └╥┘ - q_1: ─────┤ X ├──■─────────────╫────── - └───┘┌─┴─┐ ║ - q_2: ──────────┤ X ├──■────────╫────── - └───┘┌─┴─┐ ║ - q_3: ───────────────┤ X ├──■───╫────── - └───┘┌─┴─┐ ║ - q_4: ────────────────────┤ X ├─╫───■── - └───┘ ║ ┌─┴─┐ - q_5: ──────────────────────────╫─┤ X ├ - ║ └───┘ - c: 1/══════════════════════════╩══════ - 0 - """ + """Test DAG depth for silly circuit.""" + + # ┌───┐ ░ ░ ┌─┐ + # q_0: ┤ H ├──■────░────░───────┤M├───── + # └───┘┌─┴─┐ ░ ░ └╥┘ + # q_1: ─────┤ X ├──■─────────────╫────── + # └───┘┌─┴─┐ ║ + # q_2: ──────────┤ X ├──■────────╫────── + # └───┘┌─┴─┐ ║ + # q_3: ───────────────┤ X ├──■───╫────── + # └───┘┌─┴─┐ ║ + # q_4: ────────────────────┤ X ├─╫───■── + # └───┘ ║ ┌─┴─┐ + # q_5: ──────────────────────────╫─┤ X ├ + # ║ └───┘ + # c: 1/══════════════════════════╩══════ + # 0 q = QuantumRegister(6, "q") c = ClassicalRegister(1, "c") qc = QuantumCircuit(q, c) diff --git a/test/python/dagcircuit/test_dagdependency.py b/test/python/dagcircuit/test_dagdependency.py index d4d414a9b6d6..1daa0e9aa561 100644 --- a/test/python/dagcircuit/test_dagdependency.py +++ b/test/python/dagcircuit/test_dagdependency.py @@ -244,20 +244,18 @@ class TestDagProperties(QiskitTestCase): """Test the DAG properties.""" def setUp(self): - """ - ┌───┐ ┌───┐ - q0_0: ┤ H ├────────────────┤ X ├────────── - └───┘ └─┬─┘ ┌───┐ - q0_1: ───────────────────────┼───────┤ H ├ - ┌───┐ │ ┌───┐└─┬─┘ - q0_2: ──■───────┤ H ├────────┼──┤ T ├──■── - ┌─┴─┐┌────┴───┴─────┐ │ └───┘ - q0_3: ┤ X ├┤ U(0,0.1,0.2) ├──┼──────────── - └───┘└──────────────┘ │ - q1_0: ───────────────────────■──────────── - │ - q1_1: ───────────────────────■──────────── - """ + # ┌───┐ ┌───┐ + # q0_0: ┤ H ├────────────────┤ X ├────────── + # └───┘ └─┬─┘ ┌───┐ + # q0_1: ───────────────────────┼───────┤ H ├ + # ┌───┐ │ ┌───┐└─┬─┘ + # q0_2: ──■───────┤ H ├────────┼──┤ T ├──■── + # ┌─┴─┐┌────┴───┴─────┐ │ └───┘ + # q0_3: ┤ X ├┤ U(0,0.1,0.2) ├──┼──────────── + # └───┘└──────────────┘ │ + # q1_0: ───────────────────────■──────────── + # │ + # q1_1: ───────────────────────■──────────── super().setUp() qr1 = QuantumRegister(4) qr2 = QuantumRegister(2) diff --git a/test/python/scheduler/test_basic_scheduler.py b/test/python/scheduler/test_basic_scheduler.py index fa3b3bf8750c..03a2b67d1c71 100644 --- a/test/python/scheduler/test_basic_scheduler.py +++ b/test/python/scheduler/test_basic_scheduler.py @@ -50,16 +50,15 @@ def test_unavailable_defaults(self): self.assertRaises(QiskitError, lambda: schedule(qc, backend)) def test_alap_pass(self): - """Test ALAP scheduling. - - ┌───────────────┐ ░ ┌─┐ - q0_0: ┤ U2(3.14,1.57) ├────────────────────░───■──┤M├─── - └┬──────────────┤ ░ ┌──────────────┐ ░ ┌─┴─┐└╥┘┌─┐ - q0_1: ─┤ U2(0.5,0.25) ├─░─┤ U2(0.5,0.25) ├─░─┤ X ├─╫─┤M├ - └──────────────┘ ░ └──────────────┘ ░ └───┘ ║ └╥┘ - c0: 2/═════════════════════════════════════════════╩══╩═ - 0 1 - """ + """Test ALAP scheduling.""" + + # ┌───────────────┐ ░ ┌─┐ + # q0_0: ┤ U2(3.14,1.57) ├────────────────────░───■──┤M├─── + # └┬──────────────┤ ░ ┌──────────────┐ ░ ┌─┴─┐└╥┘┌─┐ + # q0_1: ─┤ U2(0.5,0.25) ├─░─┤ U2(0.5,0.25) ├─░─┤ X ├─╫─┤M├ + # └──────────────┘ ░ └──────────────┘ ░ └───┘ ║ └╥┘ + # c0: 2/═════════════════════════════════════════════╩══╩═ + # 0 1 q = QuantumRegister(2) c = ClassicalRegister(2) qc = QuantumCircuit(q, c) @@ -127,16 +126,15 @@ def test_alap_aligns_end(self): ) def test_asap_pass(self): - """Test ASAP scheduling. - - ┌───────────────┐ ░ ┌─┐ - q0_0: ┤ U2(3.14,1.57) ├────────────────────░───■──┤M├─── - └┬──────────────┤ ░ ┌──────────────┐ ░ ┌─┴─┐└╥┘┌─┐ - q0_1: ─┤ U2(0.5,0.25) ├─░─┤ U2(0.5,0.25) ├─░─┤ X ├─╫─┤M├ - └──────────────┘ ░ └──────────────┘ ░ └───┘ ║ └╥┘ - c0: 2/═════════════════════════════════════════════╩══╩═ - 0 1 - """ + """Test ASAP scheduling.""" + + # ┌───────────────┐ ░ ┌─┐ + # q0_0: ┤ U2(3.14,1.57) ├────────────────────░───■──┤M├─── + # └┬──────────────┤ ░ ┌──────────────┐ ░ ┌─┴─┐└╥┘┌─┐ + # q0_1: ─┤ U2(0.5,0.25) ├─░─┤ U2(0.5,0.25) ├─░─┤ X ├─╫─┤M├ + # └──────────────┘ ░ └──────────────┘ ░ └───┘ ║ └╥┘ + # c0: 2/═════════════════════════════════════════════╩══╩═ + # 0 1 q = QuantumRegister(2) c = ClassicalRegister(2) qc = QuantumCircuit(q, c) @@ -226,17 +224,15 @@ def test_measure_combined(self): self.assertEqual(sched.instructions, expected.instructions) def test_3q_schedule(self): - """Test a schedule that was recommended by David McKay :D - - ┌─────────────────┐ - q0_0: ─────────■─────────┤ U3(3.14,1.57,0) ├──────────────────────── - ┌─┴─┐ └┬───────────────┬┘ - q0_1: ───────┤ X ├────────┤ U2(3.14,1.57) ├───■───────────────────── - ┌──────┴───┴──────┐ └───────────────┘ ┌─┴─┐┌─────────────────┐ - q0_2: ┤ U2(0.778,0.122) ├───────────────────┤ X ├┤ U2(0.778,0.122) ├ - └─────────────────┘ └───┘└─────────────────┘ - c0: 3/══════════════════════════════════════════════════════════════ - """ + """Test a schedule that was recommended by David McKay :D""" + + # ┌─────────────────┐ + # q0_0: ─────────■─────────┤ U3(3.14,1.57,0) ├──────────────────────── + # ┌─┴─┐ └┬───────────────┬┘ + # q0_1: ───────┤ X ├────────┤ U2(3.14,1.57) ├───■───────────────────── + # ┌──────┴───┴──────┐ └───────────────┘ ┌─┴─┐┌─────────────────┐ + # q0_2: ┤ U2(0.778,0.122) ├───────────────────┤ X ├┤ U2(0.778,0.122) ├ + # └─────────────────┘ └───┘└─────────────────┘ backend = FakeOpenPulse3Q() inst_map = backend.defaults().instruction_schedule_map q = QuantumRegister(3) diff --git a/test/python/transpiler/test_basis_translator.py b/test/python/transpiler/test_basis_translator.py index 403c0fa163cc..cb3e10d22107 100644 --- a/test/python/transpiler/test_basis_translator.py +++ b/test/python/transpiler/test_basis_translator.py @@ -421,21 +421,20 @@ def test_unroll_toffoli(self): self.assertIn(node.name, ["h", "t", "tdg", "cx"]) def test_unroll_1q_chain_conditional(self): - """Test unroll chain of 1-qubit gates interrupted by conditional. - - ┌───┐┌─────┐┌───┐┌───┐┌─────────┐┌─────────┐┌─────────┐┌─┐ ┌───┐ ┌───┐ » - qr: ┤ H ├┤ Tdg ├┤ Z ├┤ T ├┤ Ry(0.5) ├┤ Rz(0.3) ├┤ Rx(0.1) ├┤M├─┤ X ├──┤ Y ├─» - └───┘└─────┘└───┘└───┘└─────────┘└─────────┘└─────────┘└╥┘ └─╥─┘ └─╥─┘ » - ║ ┌──╨──┐┌──╨──┐» - cr: 1/══════════════════════════════════════════════════════╩═╡ 0x1 ╞╡ 0x1 ╞» - 0 └─────┘└─────┘» - « ┌───┐ - « qr: ─┤ Z ├─ - « └─╥─┘ - « ┌──╨──┐ - «cr: 1/╡ 0x1 ╞ - « └─────┘ - """ + """Test unroll chain of 1-qubit gates interrupted by conditional.""" + + # ┌───┐┌─────┐┌───┐┌───┐┌─────────┐┌─────────┐┌─────────┐┌─┐ ┌───┐ ┌───┐ » + # qr: ┤ H ├┤ Tdg ├┤ Z ├┤ T ├┤ Ry(0.5) ├┤ Rz(0.3) ├┤ Rx(0.1) ├┤M├─┤ X ├──┤ Y ├─» + # └───┘└─────┘└───┘└───┘└─────────┘└─────────┘└─────────┘└╥┘ └─╥─┘ └─╥─┘ » + # ║ ┌──╨──┐┌──╨──┐» + # cr: 1/══════════════════════════════════════════════════════╩═╡ 0x1 ╞╡ 0x1 ╞» + # 0 └─────┘└─────┘» + # « ┌───┐ + # « qr: ─┤ Z ├─ + # « └─╥─┘ + # « ┌──╨──┐ + # «cr: 1/╡ 0x1 ╞ + # « └─────┘ qr = QuantumRegister(1, "qr") cr = ClassicalRegister(1, "cr") circuit = QuantumCircuit(qr, cr) diff --git a/test/python/transpiler/test_bip_mapping.py b/test/python/transpiler/test_bip_mapping.py index 9fdb436b44b6..77f0fc60af00 100644 --- a/test/python/transpiler/test_bip_mapping.py +++ b/test/python/transpiler/test_bip_mapping.py @@ -192,23 +192,22 @@ def test_unmappable_cnots_in_a_layer(self): self.assertEqual(circuit, actual) def test_multi_cregs(self): - """Test for multiple ClassicalRegisters. - - ┌───┐ ░ ┌─┐ - qr_0: ──■────────────┤ X ├─░─┤M├───────── - ┌─┴─┐ ┌───┐└─┬─┘ ░ └╥┘┌─┐ - qr_1: ┤ X ├──■──┤ H ├──■───░──╫─┤M├────── - └───┘┌─┴─┐└───┘ ░ ║ └╥┘┌─┐ - qr_2: ──■──┤ X ├───────────░──╫──╫─┤M├─── - ┌─┴─┐└───┘ ░ ║ ║ └╥┘┌─┐ - qr_3: ┤ X ├────────────────░──╫──╫──╫─┤M├ - └───┘ ░ ║ ║ ║ └╥┘ - c: 2/════════════════════════╩══╬══╩══╬═ - 0 ║ 1 ║ - ║ ║ - d: 2/═══════════════════════════╩═════╩═ - 0 1 - """ + """Test for multiple ClassicalRegisters.""" + + # ┌───┐ ░ ┌─┐ + # qr_0: ──■────────────┤ X ├─░─┤M├───────── + # ┌─┴─┐ ┌───┐└─┬─┘ ░ └╥┘┌─┐ + # qr_1: ┤ X ├──■──┤ H ├──■───░──╫─┤M├────── + # └───┘┌─┴─┐└───┘ ░ ║ └╥┘┌─┐ + # qr_2: ──■──┤ X ├───────────░──╫──╫─┤M├─── + # ┌─┴─┐└───┘ ░ ║ ║ └╥┘┌─┐ + # qr_3: ┤ X ├────────────────░──╫──╫──╫─┤M├ + # └───┘ ░ ║ ║ ║ └╥┘ + # c: 2/════════════════════════╩══╬══╩══╬═ + # 0 ║ 1 ║ + # ║ ║ + # d: 2/═══════════════════════════╩═════╩═ + # 0 1 qr = QuantumRegister(4, "qr") cr1 = ClassicalRegister(2, "c") cr2 = ClassicalRegister(2, "d") @@ -233,18 +232,17 @@ def test_multi_cregs(self): self.assertTrue(property_set["is_swap_mapped"]) def test_swaps_in_dummy_steps(self): - """Test the case when swaps are inserted in dummy steps. - - ┌───┐ ░ ░ - q_0: ──■──┤ H ├─░───■────────░───■─────── - ┌─┴─┐├───┤ ░ │ ░ │ - q_1: ┤ X ├┤ H ├─░───┼────■───░───┼────■── - └───┘├───┤ ░ │ ┌─┴─┐ ░ ┌─┴─┐ │ - q_2: ──■──┤ H ├─░───┼──┤ X ├─░─┤ X ├──┼── - ┌─┴─┐├───┤ ░ ┌─┴─┐└───┘ ░ └───┘┌─┴─┐ - q_3: ┤ X ├┤ H ├─░─┤ X ├──────░──────┤ X ├ - └───┘└───┘ ░ └───┘ ░ └───┘ - """ + """Test the case when swaps are inserted in dummy steps.""" + + # ┌───┐ ░ ░ + # q_0: ──■──┤ H ├─░───■────────░───■─────── + # ┌─┴─┐├───┤ ░ │ ░ │ + # q_1: ┤ X ├┤ H ├─░───┼────■───░───┼────■── + # └───┘├───┤ ░ │ ┌─┴─┐ ░ ┌─┴─┐ │ + # q_2: ──■──┤ H ├─░───┼──┤ X ├─░─┤ X ├──┼── + # ┌─┴─┐├───┤ ░ ┌─┴─┐└───┘ ░ └───┘┌─┴─┐ + # q_3: ┤ X ├┤ H ├─░─┤ X ├──────░──────┤ X ├ + # └───┘└───┘ ░ └───┘ ░ └───┘ circuit = QuantumCircuit(4) circuit.cx(0, 1) circuit.cx(2, 3) @@ -271,17 +269,16 @@ def test_swaps_in_dummy_steps(self): self.assertFalse(isinstance(inst, SwapGate)) def test_different_number_of_virtual_and_physical_qubits(self): - """Test the case when number of virtual and physical qubits are different. - - q_0: ──■────■─────── - ┌─┴─┐ │ - q_1: ┤ X ├──┼────■── - └───┘ │ ┌─┴─┐ - q_2: ──■────┼──┤ X ├ - ┌─┴─┐┌─┴─┐└───┘ - q_3: ┤ X ├┤ X ├───── - └───┘└───┘ - """ + """Test the case when number of virtual and physical qubits are different.""" + + # q_0: ──■────■─────── + # ┌─┴─┐ │ + # q_1: ┤ X ├──┼────■── + # └───┘ │ ┌─┴─┐ + # q_2: ──■────┼──┤ X ├ + # ┌─┴─┐┌─┴─┐└───┘ + # q_3: ┤ X ├┤ X ├───── + # └───┘└───┘ circuit = QuantumCircuit(4) circuit.cx(0, 1) circuit.cx(2, 3) @@ -321,18 +318,17 @@ def test_unconnected_qubit_subset(self): BIPMapping(coupling, qubit_subset=[0, 1, 2])(circuit) def test_objective_function(self): - """Test if ``objective`` functions priorities metrics correctly. - - ┌──────┐┌──────┐ ┌──────┐ - q_0: ┤0 ├┤0 ├─────┤0 ├ - │ Dcx ││ │ │ Dcx │ - q_1: ┤1 ├┤ Dcx ├──■──┤1 ├ - └──────┘│ │ │ └──────┘ - q_2: ───■────┤1 ├──┼─────■──── - ┌─┴─┐ └──────┘┌─┴─┐ ┌─┴─┐ - q_3: ─┤ X ├──────────┤ X ├─┤ X ├── - └───┘ └───┘ └───┘ - """ + """Test if ``objective`` functions priorities metrics correctly.""" + + # ┌──────┐┌──────┐ ┌──────┐ + # q_0: ┤0 ├┤0 ├─────┤0 ├ + # │ Dcx ││ │ │ Dcx │ + # q_1: ┤1 ├┤ Dcx ├──■──┤1 ├ + # └──────┘│ │ │ └──────┘ + # q_2: ───■────┤1 ├──┼─────■──── + # ┌─┴─┐ └──────┘┌─┴─┐ ┌─┴─┐ + # q_3: ─┤ X ├──────────┤ X ├─┤ X ├── + # └───┘ └───┘ └───┘ qc = QuantumCircuit(4) qc.dcx(0, 1) qc.cx(2, 3) diff --git a/test/python/transpiler/test_commutation_analysis.py b/test/python/transpiler/test_commutation_analysis.py index 4772b4b96d8f..7253bcb81693 100644 --- a/test/python/transpiler/test_commutation_analysis.py +++ b/test/python/transpiler/test_commutation_analysis.py @@ -258,20 +258,19 @@ def test_jordan_wigner_type_circuit(self): self.assertCommutationSet(self.pset["commutation_set"], expected) def test_all_commute_circuit(self): - """Test circuit with that all commute - - ┌───┐ - qr_0: ──■──┤ Z ├──■──────────── - ┌─┴─┐├───┤┌─┴─┐┌───┐ - qr_1: ┤ X ├┤ X ├┤ X ├┤ X ├───── - └───┘└─┬─┘└───┘└─┬─┘ - qr_2: ───────■────■────■────■── - ┌───┐ ┌─┴─┐┌───┐┌─┴─┐ - qr_3: ┤ X ├─────┤ X ├┤ X ├┤ X ├ - └─┬─┘┌───┐└───┘└─┬─┘└───┘ - qr_4: ──■──┤ Z ├───────■─────── - └───┘ - """ + """Test circuit with that all commute""" + + # ┌───┐ + # qr_0: ──■──┤ Z ├──■──────────── + # ┌─┴─┐├───┤┌─┴─┐┌───┐ + # qr_1: ┤ X ├┤ X ├┤ X ├┤ X ├───── + # └───┘└─┬─┘└───┘└─┬─┘ + # qr_2: ───────■────■────■────■── + # ┌───┐ ┌─┴─┐┌───┐┌─┴─┐ + # qr_3: ┤ X ├─────┤ X ├┤ X ├┤ X ├ + # └─┬─┘┌───┐└───┘└─┬─┘└───┘ + # qr_4: ──■──┤ Z ├───────■─────── + # └───┘ qr = QuantumRegister(5, "qr") circuit = QuantumCircuit(qr) circuit.cx(qr[0], qr[1]) diff --git a/test/python/transpiler/test_commutative_cancellation.py b/test/python/transpiler/test_commutative_cancellation.py index a124348dd4bb..86e166ffded9 100644 --- a/test/python/transpiler/test_commutative_cancellation.py +++ b/test/python/transpiler/test_commutative_cancellation.py @@ -517,19 +517,18 @@ def test_cnot_cascade1(self): self.assertEqual(expected, new_circuit) def test_conditional_gates_dont_commute(self): - """Conditional gates do not commute and do not cancel - - ┌───┐┌─┐ - q_0: ┤ H ├┤M├───────────── - └───┘└╥┘ ┌─┐ - q_1: ──■───╫────■───┤M├─── - ┌─┴─┐ ║ ┌─┴─┐ └╥┘┌─┐ - q_2: ┤ X ├─╫──┤ X ├──╫─┤M├ - └───┘ ║ └─╥─┘ ║ └╥┘ - ║ ┌──╨──┐ ║ ║ - c: 2/══════╩═╡ 0x0 ╞═╩══╩═ - 0 └─────┘ 0 1 - """ + """Conditional gates do not commute and do not cancel""" + + # ┌───┐┌─┐ + # q_0: ┤ H ├┤M├───────────── + # └───┘└╥┘ ┌─┐ + # q_1: ──■───╫────■───┤M├─── + # ┌─┴─┐ ║ ┌─┴─┐ └╥┘┌─┐ + # q_2: ┤ X ├─╫──┤ X ├──╫─┤M├ + # └───┘ ║ └─╥─┘ ║ └╥┘ + # ║ ┌──╨──┐ ║ ║ + # c: 2/══════╩═╡ 0x0 ╞═╩══╩═ + # 0 └─────┘ 0 1 circuit = QuantumCircuit(3, 2) circuit.h(0) circuit.measure(0, 0) diff --git a/test/python/transpiler/test_consolidate_blocks.py b/test/python/transpiler/test_consolidate_blocks.py index c6ba7229e361..1eaf9d310a96 100644 --- a/test/python/transpiler/test_consolidate_blocks.py +++ b/test/python/transpiler/test_consolidate_blocks.py @@ -101,15 +101,14 @@ def test_topological_order_preserved(self): self.assertEqual(new_topo_ops[1].qargs, [qr[0], qr[1]]) def test_3q_blocks(self): - """blocks of more than 2 qubits work. - - ┌────────┐ - qr_0: ──────┤ P(0.5) ├────────────■── - ┌─────┴────────┴────┐┌───┐┌─┴─┐ - qr_1: ┤ U(1.5708,0.2,0.6) ├┤ X ├┤ X ├ - └───────────────────┘└─┬─┘└───┘ - qr_2: ───────────────────────■─────── - """ + """blocks of more than 2 qubits work.""" + + # ┌────────┐ + # qr_0: ──────┤ P(0.5) ├────────────■── + # ┌─────┴────────┴────┐┌───┐┌─┴─┐ + # qr_1: ┤ U(1.5708,0.2,0.6) ├┤ X ├┤ X ├ + # └───────────────────┘└─┬─┘└───┘ + # qr_2: ───────────────────────■─────── qr = QuantumRegister(3, "qr") qc = QuantumCircuit(qr) qc.p(0.5, qr[0]) @@ -128,14 +127,13 @@ def test_3q_blocks(self): self.assertAlmostEqual(fidelity, 1.0, places=7) def test_block_spanning_two_regs(self): - """blocks spanning wires on different quantum registers work. + """blocks spanning wires on different quantum registers work.""" - ┌────────┐ - qr0: ──────┤ P(0.5) ├───────■── - ┌─────┴────────┴────┐┌─┴─┐ - qr1: ┤ U(1.5708,0.2,0.6) ├┤ X ├ - └───────────────────┘└───┘ - """ + # ┌────────┐ + # qr0: ──────┤ P(0.5) ├───────■── + # ┌─────┴────────┴────┐┌─┴─┐ + # qr1: ┤ U(1.5708,0.2,0.6) ├┤ X ├ + # └───────────────────┘└───┘ qr0 = QuantumRegister(1, "qr0") qr1 = QuantumRegister(1, "qr1") qc = QuantumCircuit(qr0, qr1) @@ -183,14 +181,13 @@ def test_node_added_before_block(self): first node in the block was seen. blocks = [['id', 'cx', 'id']] - - ┌────┐┌───┐ - q_0: |0>┤ Id ├┤ X ├────── - └┬─┬─┘└─┬─┘┌────┐ - q_1: |0>─┤M├────■──┤ Id ├ - └╥┘ └────┘ - c_0: 0 ══╩══════════════ """ + # ┌────┐┌───┐ + # q_0: |0>┤ Id ├┤ X ├────── + # └┬─┬─┘└─┬─┘┌────┐ + # q_1: |0>─┤M├────■──┤ Id ├ + # └╥┘ └────┘ + # c_0: 0 ══╩══════════════ qc = QuantumCircuit(2, 1) qc.i(0) qc.measure(1, 0) @@ -210,13 +207,12 @@ def test_node_added_before_block(self): def test_consolidate_blocks_big(self): """Test ConsolidateBlocks with U2() https://github.com/Qiskit/qiskit-terra/issues/3637#issuecomment-612954865 - - ┌────────────────┐ ┌───┐ - q_0: ┤ U2(-804.15,pi) ├──■──┤ X ├ - ├────────────────┤┌─┴─┐└─┬─┘ - q_1: ┤ U2(-6433.2,pi) ├┤ X ├──■── - └────────────────┘└───┘ """ + # ┌────────────────┐ ┌───┐ + # q_0: ┤ U2(-804.15,pi) ├──■──┤ X ├ + # ├────────────────┤┌─┴─┐└─┬─┘ + # q_1: ┤ U2(-6433.2,pi) ├┤ X ├──■── + # └────────────────┘└───┘ circuit = QuantumCircuit(2) circuit.append(U2Gate(-804.15, np.pi), [0]) circuit.append(U2Gate(-6433.2, np.pi), [1]) @@ -298,14 +294,13 @@ def test_node_middle_of_blocks(self): self.assertEqual(qc, qc1) def test_overlapping_block_and_run(self): - """Test that an overlapping block and run only consolidate once + """Test that an overlapping block and run only consolidate once""" - ┌───┐┌───┐┌─────┐ - q_0: ┤ H ├┤ T ├┤ Sdg ├──■──────────────────────── - └───┘└───┘└─────┘┌─┴─┐┌───┐┌─────┐┌───┐┌───┐ - q_1: ─────────────────┤ X ├┤ T ├┤ Sdg ├┤ Z ├┤ I ├ - └───┘└───┘└─────┘└───┘└───┘ - """ + # ┌───┐┌───┐┌─────┐ + # q_0: ┤ H ├┤ T ├┤ Sdg ├──■──────────────────────── + # └───┘└───┘└─────┘┌─┴─┐┌───┐┌─────┐┌───┐┌───┐ + # q_1: ─────────────────┤ X ├┤ T ├┤ Sdg ├┤ Z ├┤ I ├ + # └───┘└───┘└─────┘└───┘└───┘ qc = QuantumCircuit(2) qc.h(0) qc.t(0) diff --git a/test/python/transpiler/test_count_ops_longest_path_pass.py b/test/python/transpiler/test_count_ops_longest_path_pass.py index 37de6eac708b..2354788d0424 100644 --- a/test/python/transpiler/test_count_ops_longest_path_pass.py +++ b/test/python/transpiler/test_count_ops_longest_path_pass.py @@ -36,13 +36,12 @@ def test_empty_dag(self): def test_just_qubits(self): """A dag with 9 operations (3 CXs, 2Xs, 2Ys and 2 Hs) on the longest path - - ┌───┐┌───┐┌───┐ - q0_0: ──■──┤ X ├┤ Y ├┤ H ├──■───────────────────■── - ┌─┴─┐└───┘└───┘└───┘┌─┴─┐┌───┐┌───┐┌───┐┌─┴─┐ - q0_1: ┤ X ├───────────────┤ X ├┤ X ├┤ Y ├┤ H ├┤ X ├ - └───┘ └───┘└───┘└───┘└───┘└───┘ """ + # ┌───┐┌───┐┌───┐ + # q0_0: ──■──┤ X ├┤ Y ├┤ H ├──■───────────────────■── + # ┌─┴─┐└───┘└───┘└───┘┌─┴─┐┌───┐┌───┐┌───┐┌─┴─┐ + # q0_1: ┤ X ├───────────────┤ X ├┤ X ├┤ Y ├┤ H ├┤ X ├ + # └───┘ └───┘└───┘└───┘└───┘└───┘ qr = QuantumRegister(2) circuit = QuantumCircuit(qr) circuit.cx(qr[0], qr[1]) diff --git a/test/python/transpiler/test_count_ops_pass.py b/test/python/transpiler/test_count_ops_pass.py index 76033dd4ac54..ed8c9091d63a 100644 --- a/test/python/transpiler/test_count_ops_pass.py +++ b/test/python/transpiler/test_count_ops_pass.py @@ -34,14 +34,13 @@ def test_empty_dag(self): self.assertDictEqual(pass_.property_set["count_ops"], {}) def test_just_qubits(self): - """A dag with 8 operations (6 CXs and 2 Hs) + """A dag with 8 operations (6 CXs and 2 Hs)""" - ┌───┐ ┌───┐┌───┐ - q0_0: ┤ H ├──■────■────■────■──┤ X ├┤ X ├ - ├───┤┌─┴─┐┌─┴─┐┌─┴─┐┌─┴─┐└─┬─┘└─┬─┘ - q0_1: ┤ H ├┤ X ├┤ X ├┤ X ├┤ X ├──■────■── - └───┘└───┘└───┘└───┘└───┘ - """ + # ┌───┐ ┌───┐┌───┐ + # q0_0: ┤ H ├──■────■────■────■──┤ X ├┤ X ├ + # ├───┤┌─┴─┐┌─┴─┐┌─┴─┐┌─┴─┐└─┬─┘└─┬─┘ + # q0_1: ┤ H ├┤ X ├┤ X ├┤ X ├┤ X ├──■────■── + # └───┘└───┘└───┘└───┘└───┘ qr = QuantumRegister(2) circuit = QuantumCircuit(qr) circuit.h(qr[0]) diff --git a/test/python/transpiler/test_cx_cancellation.py b/test/python/transpiler/test_cx_cancellation.py index 129d86a41bfe..6a9e10ab60b7 100644 --- a/test/python/transpiler/test_cx_cancellation.py +++ b/test/python/transpiler/test_cx_cancellation.py @@ -69,18 +69,17 @@ def test_pass_cx_cancellation_intermixed_ops(self): self.assertEqual(out_circuit, expected) def test_pass_cx_cancellation_chained_cx(self): - """Include a test were not all operations can be cancelled. - - ┌───┐ - q0_0: ┤ H ├──■─────────■─────── - ├───┤┌─┴─┐ ┌─┴─┐ - q0_1: ┤ H ├┤ X ├──■──┤ X ├───── - └───┘└───┘┌─┴─┐└───┘ - q0_2: ──────────┤ X ├──■────■── - └───┘┌─┴─┐┌─┴─┐ - q0_3: ───────────────┤ X ├┤ X ├ - └───┘└───┘ - """ + """Include a test were not all operations can be cancelled.""" + + # ┌───┐ + # q0_0: ┤ H ├──■─────────■─────── + # ├───┤┌─┴─┐ ┌─┴─┐ + # q0_1: ┤ H ├┤ X ├──■──┤ X ├───── + # └───┘└───┘┌─┴─┐└───┘ + # q0_2: ──────────┤ X ├──■────■── + # └───┘┌─┴─┐┌─┴─┐ + # q0_3: ───────────────┤ X ├┤ X ├ + # └───┘└───┘ qr = QuantumRegister(4) circuit = QuantumCircuit(qr) circuit.h(qr[0]) diff --git a/test/python/transpiler/test_dag_longest_path_pass.py b/test/python/transpiler/test_dag_longest_path_pass.py index ac07fe4041fd..36ebb154cd5c 100644 --- a/test/python/transpiler/test_dag_longest_path_pass.py +++ b/test/python/transpiler/test_dag_longest_path_pass.py @@ -34,13 +34,12 @@ def test_empty_dag_true(self): def test_nonempty_dag_false(self): """Test the dag longest path non-empty dag. path length = 11 = 9 ops + 2 qubits at start and end of path - - ┌───┐┌───┐┌───┐ - q0_0: ──■──┤ X ├┤ Y ├┤ H ├──■───────────────────■── - ┌─┴─┐└───┘└───┘└───┘┌─┴─┐┌───┐┌───┐┌───┐┌─┴─┐ - q0_1: ┤ X ├───────────────┤ X ├┤ X ├┤ Y ├┤ H ├┤ X ├ - └───┘ └───┘└───┘└───┘└───┘└───┘ """ + # ┌───┐┌───┐┌───┐ + # q0_0: ──■──┤ X ├┤ Y ├┤ H ├──■───────────────────■── + # ┌─┴─┐└───┘└───┘└───┘┌─┴─┐┌───┐┌───┐┌───┐┌─┴─┐ + # q0_1: ┤ X ├───────────────┤ X ├┤ X ├┤ Y ├┤ H ├┤ X ├ + # └───┘ └───┘└───┘└───┘└───┘└───┘ qr = QuantumRegister(2) circuit = QuantumCircuit(qr) circuit.cx(qr[0], qr[1]) diff --git a/test/python/transpiler/test_depth_pass.py b/test/python/transpiler/test_depth_pass.py index 0f37950e624c..75f258df73ec 100644 --- a/test/python/transpiler/test_depth_pass.py +++ b/test/python/transpiler/test_depth_pass.py @@ -34,14 +34,13 @@ def test_empty_dag(self): self.assertEqual(pass_.property_set["depth"], 0) def test_just_qubits(self): - """A dag with 8 operations and no classic bits - - ┌───┐ ┌───┐┌───┐ - q0_0: ┤ H ├──■────■────■────■──┤ X ├┤ X ├ - ├───┤┌─┴─┐┌─┴─┐┌─┴─┐┌─┴─┐└─┬─┘└─┬─┘ - q0_1: ┤ H ├┤ X ├┤ X ├┤ X ├┤ X ├──■────■── - └───┘└───┘└───┘└───┘└───┘ - """ + """A dag with 8 operations and no classic bits""" + + # ┌───┐ ┌───┐┌───┐ + # q0_0: ┤ H ├──■────■────■────■──┤ X ├┤ X ├ + # ├───┤┌─┴─┐┌─┴─┐┌─┴─┐┌─┴─┐└─┬─┘└─┬─┘ + # q0_1: ┤ H ├┤ X ├┤ X ├┤ X ├┤ X ├──■────■── + # └───┘└───┘└───┘└───┘└───┘ qr = QuantumRegister(2) circuit = QuantumCircuit(qr) circuit.h(qr[0]) diff --git a/test/python/transpiler/test_faulty_backend.py b/test/python/transpiler/test_faulty_backend.py index 0137ba241b6d..80fed1716d01 100644 --- a/test/python/transpiler/test_faulty_backend.py +++ b/test/python/transpiler/test_faulty_backend.py @@ -254,22 +254,21 @@ def test_level(self, level): @data(0, 1, 2) # TODO: add 3 once https://github.com/Qiskit/qiskit-terra/issues/6406 is fixed def test_layout_level(self, level): - """Test level {level} with a faulty CX(Q1, Q3) with a working initial layout - - ┌───┐ ┌───┐ ░ ┌─┐ - qr_0: ┤ H ├──■──┤ X ├───────────────────────────────░─┤M├──────────── - ├───┤┌─┴─┐└─┬─┘ ┌───┐ ┌───┐ ░ └╥┘┌─┐ - qr_1: ┤ H ├┤ X ├──■────■──┤ X ├──■──┤ X ├───────────░──╫─┤M├───────── - ├───┤└───┘ ┌─┴─┐└─┬─┘ │ └─┬─┘ ░ ║ └╥┘┌─┐ - qr_2: ┤ H ├──────────┤ X ├──■────┼────┼─────────────░──╫──╫─┤M├────── - └───┘ └───┘ ┌─┴─┐ │ ┌───┐ ░ ║ ║ └╥┘┌─┐ - qr_3: ─────────────────────────┤ X ├──■────■──┤ X ├─░──╫──╫──╫─┤M├─── - └───┘ ┌─┴─┐└─┬─┘ ░ ║ ║ ║ └╥┘┌─┐ - qr_4: ───────────────────────────────────┤ X ├──■───░──╫──╫──╫──╫─┤M├ - └───┘ ░ ║ ║ ║ ║ └╥┘ - meas: 5/═══════════════════════════════════════════════╩══╩══╩══╩══╩═ - 0 1 2 3 4 - """ + """Test level {level} with a faulty CX(Q1, Q3) with a working initial layout""" + + # ┌───┐ ┌───┐ ░ ┌─┐ + # qr_0: ┤ H ├──■──┤ X ├───────────────────────────────░─┤M├──────────── + # ├───┤┌─┴─┐└─┬─┘ ┌───┐ ┌───┐ ░ └╥┘┌─┐ + # qr_1: ┤ H ├┤ X ├──■────■──┤ X ├──■──┤ X ├───────────░──╫─┤M├───────── + # ├───┤└───┘ ┌─┴─┐└─┬─┘ │ └─┬─┘ ░ ║ └╥┘┌─┐ + # qr_2: ┤ H ├──────────┤ X ├──■────┼────┼─────────────░──╫──╫─┤M├────── + # └───┘ └───┘ ┌─┴─┐ │ ┌───┐ ░ ║ ║ └╥┘┌─┐ + # qr_3: ─────────────────────────┤ X ├──■────■──┤ X ├─░──╫──╫──╫─┤M├─── + # └───┘ ┌─┴─┐└─┬─┘ ░ ║ ║ ║ └╥┘┌─┐ + # qr_4: ───────────────────────────────────┤ X ├──■───░──╫──╫──╫──╫─┤M├ + # └───┘ ░ ║ ║ ║ ║ └╥┘ + # meas: 5/═══════════════════════════════════════════════╩══╩══╩══╩══╩═ + # 0 1 2 3 4 circuit = QuantumCircuit(QuantumRegister(5, "qr")) circuit.h(range(3)) circuit.cx(0, 1) diff --git a/test/python/transpiler/test_hoare_opt.py b/test/python/transpiler/test_hoare_opt.py index e5fd9f166e14..82c05ad26ea7 100644 --- a/test/python/transpiler/test_hoare_opt.py +++ b/test/python/transpiler/test_hoare_opt.py @@ -30,7 +30,8 @@ class TestHoareOptimizer(QiskitTestCase): def test_phasegate_removal(self): """Should remove the phase on a classical state, - but not on a superposition state.""" + but not on a superposition state. + """ # ┌───┐ # q_0: ┤ Z ├────── @@ -60,7 +61,8 @@ def test_phasegate_removal(self): def test_cswap_removal(self): """Should remove Fredkin gates because the optimizer - can deduce the targets are in the same state""" + can deduce the targets are in the same state + """ # ┌───┐┌───┐ ┌───┐ ┌───┐ ┌───┐ # q_0: ┤ X ├┤ X ├──■──┤ X ├──■──┤ X ├──■────■──┤ X ├───────────────────────────────── @@ -165,7 +167,8 @@ def test_cswap_removal(self): def test_lnn_cnot_removal(self): """Should remove some cnots from swaps introduced because of linear nearest architecture. Only uses - single-gate optimization techniques.""" + single-gate optimization techniques. + """ # ┌───┐ ┌───┐ » # q_0: ┤ H ├──■──┤ X ├──■────────────────────────────────────────────────────» @@ -230,7 +233,8 @@ def test_lnn_cnot_removal(self): def test_lnncnot_advanced_removal(self): """Should remove all cnots from swaps introduced because of linear nearest architecture. This time - using multi-gate optimization techniques.""" + using multi-gate optimization techniques. + """ # ┌───┐ ┌───┐ » # q_0: ┤ H ├──■──┤ X ├──■────────────────────────────────────────────────────» @@ -311,7 +315,8 @@ def test_successive_identity_removal(self): def test_targetsuccessive_identity_removal(self): """Should remove pair of controlled target successive which are the inverse of each other, if they can be - identified to be executed as a unit (either both or none).""" + identified to be executed as a unit (either both or none). + """ # ┌───┐ ┌───┐┌───┐ # q_0: ┤ H ├──■──┤ X ├┤ X ├──■── @@ -354,7 +359,8 @@ def test_targetsuccessive_identity_removal(self): def test_targetsuccessive_identity_advanced_removal(self): """Should remove target successive identity gates with DIFFERENT sets of control qubits. - In this case CCCX(4,5,6,7) & CCX(5,6,7).""" + In this case CCCX(4,5,6,7) & CCX(5,6,7). + """ # ┌───┐┌───┐ » # q_0: ┤ H ├┤ X ├───────■─────────────────────────────■───────────────────■──» @@ -621,7 +627,8 @@ def test_is_identity(self): def test_multiple_pass(self): """Verify that multiple pass can be run - with the same Hoare instance.""" + with the same Hoare instance. + """ # ┌───┐┌───┐ # q_0:─┤ H ├┤ Z ├─ diff --git a/test/python/transpiler/test_lookahead_swap.py b/test/python/transpiler/test_lookahead_swap.py index 65b8fb8aefe7..f7a0fe9388d1 100644 --- a/test/python/transpiler/test_lookahead_swap.py +++ b/test/python/transpiler/test_lookahead_swap.py @@ -157,41 +157,39 @@ def test_lookahead_swap_higher_depth_width_is_better(self): Increasing the tree width and depth is expected to yield a better (or same) quality circuit, in the form of fewer SWAPs. - - q_0: ──■───────────────────■───────────────────────────────────────────────» - ┌─┴─┐ │ ┌───┐ » - q_1: ┤ X ├──■──────────────┼─────────────────┤ X ├─────────────────────────» - └───┘┌─┴─┐ │ └─┬─┘┌───┐ ┌───┐ » - q_2: ─────┤ X ├──■─────────┼───────────────────┼──┤ X ├──────────┤ X ├──■──» - └───┘┌─┴─┐ ┌─┴─┐ │ └─┬─┘ ┌───┐└─┬─┘ │ » - q_3: ──────────┤ X ├──■──┤ X ├─────────────────┼────┼────■──┤ X ├──┼────┼──» - └───┘┌─┴─┐└───┘ ┌───┐ │ │ │ └─┬─┘ │ │ » - q_4: ───────────────┤ X ├──■────────────┤ X ├──┼────■────┼────┼────┼────┼──» - └───┘┌─┴─┐ └─┬─┘ │ │ │ │ │ » - q_5: ────────────────────┤ X ├──■─────────┼────┼─────────┼────■────┼────┼──» - └───┘┌─┴─┐ │ │ │ │ │ » - q_6: ─────────────────────────┤ X ├──■────■────┼─────────┼─────────■────┼──» - └───┘┌─┴─┐ │ ┌─┴─┐ ┌─┴─┐» - q_7: ──────────────────────────────┤ X ├───────■───────┤ X ├──────────┤ X ├» - └───┘ └───┘ └───┘» - «q_0: ──■─────── - « │ - «q_1: ──┼─────── - « │ - «q_2: ──┼─────── - « │ - «q_3: ──┼─────── - « │ - «q_4: ──┼─────── - « │ - «q_5: ──┼────■── - « ┌─┴─┐ │ - «q_6: ┤ X ├──┼── - « └───┘┌─┴─┐ - «q_7: ─────┤ X ├ - « └───┘ """ - + # q_0: ──■───────────────────■───────────────────────────────────────────────» + # ┌─┴─┐ │ ┌───┐ » + # q_1: ┤ X ├──■──────────────┼─────────────────┤ X ├─────────────────────────» + # └───┘┌─┴─┐ │ └─┬─┘┌───┐ ┌───┐ » + # q_2: ─────┤ X ├──■─────────┼───────────────────┼──┤ X ├──────────┤ X ├──■──» + # └───┘┌─┴─┐ ┌─┴─┐ │ └─┬─┘ ┌───┐└─┬─┘ │ » + # q_3: ──────────┤ X ├──■──┤ X ├─────────────────┼────┼────■──┤ X ├──┼────┼──» + # └───┘┌─┴─┐└───┘ ┌───┐ │ │ │ └─┬─┘ │ │ » + # q_4: ───────────────┤ X ├──■────────────┤ X ├──┼────■────┼────┼────┼────┼──» + # └───┘┌─┴─┐ └─┬─┘ │ │ │ │ │ » + # q_5: ────────────────────┤ X ├──■─────────┼────┼─────────┼────■────┼────┼──» + # └───┘┌─┴─┐ │ │ │ │ │ » + # q_6: ─────────────────────────┤ X ├──■────■────┼─────────┼─────────■────┼──» + # └───┘┌─┴─┐ │ ┌─┴─┐ ┌─┴─┐» + # q_7: ──────────────────────────────┤ X ├───────■───────┤ X ├──────────┤ X ├» + # └───┘ └───┘ └───┘» + # «q_0: ──■─────── + # « │ + # «q_1: ──┼─────── + # « │ + # «q_2: ──┼─────── + # « │ + # «q_3: ──┼─────── + # « │ + # «q_4: ──┼─────── + # « │ + # «q_5: ──┼────■── + # « ┌─┴─┐ │ + # «q_6: ┤ X ├──┼── + # « └───┘┌─┴─┐ + # «q_7: ─────┤ X ├ + # « └───┘ qr = QuantumRegister(8, name="q") circuit = QuantumCircuit(qr) circuit.cx(qr[0], qr[1]) diff --git a/test/python/transpiler/test_optimize_1q_commutation.py b/test/python/transpiler/test_optimize_1q_commutation.py index 9daa51c0dd31..2a01e5593907 100644 --- a/test/python/transpiler/test_optimize_1q_commutation.py +++ b/test/python/transpiler/test_optimize_1q_commutation.py @@ -34,12 +34,11 @@ class TestOptimize1qSimpleCommutation(QiskitTestCase): def test_successor_commutation(self): """ Check that Optimize1qGatesSimpleCommutation correctly moves 1Q gates later. - - q_0: ────────■───────────────────────── - ┌────┐┌─┴─┐┌───────┐┌────┐┌──────┐ - q_1: ┤ √X ├┤ X ├┤ P(-π) ├┤ √X ├┤ P(π) ├ - └────┘└───┘└───────┘└────┘└──────┘ """ + # q_0: ────────■───────────────────────── + # ┌────┐┌─┴─┐┌───────┐┌────┐┌──────┐ + # q_1: ┤ √X ├┤ X ├┤ P(-π) ├┤ √X ├┤ P(π) ├ + # └────┘└───┘└───────┘└────┘└──────┘ qc = QuantumCircuit(2) qc.sx(1) qc.cx(0, 1) @@ -58,12 +57,11 @@ def test_successor_commutation(self): def test_predecessor_commutation(self): """ Check that Optimize1qGatesSimpleCommutation correctly moves 1Q gates earlier. - - q_0: ─────────────────────────■──────── - ┌───────┐┌────┐┌──────┐┌─┴─┐┌────┐ - q_1: ┤ P(-π) ├┤ √X ├┤ P(π) ├┤ X ├┤ √X ├ - └───────┘└────┘└──────┘└───┘└────┘ """ + # q_0: ─────────────────────────■──────── + # ┌───────┐┌────┐┌──────┐┌─┴─┐┌────┐ + # q_1: ┤ P(-π) ├┤ √X ├┤ P(π) ├┤ X ├┤ √X ├ + # └───────┘└────┘└──────┘└───┘└────┘ qc = QuantumCircuit(2) qc.p(-np.pi, 1) qc.sx(1) @@ -82,13 +80,12 @@ def test_predecessor_commutation(self): def test_elaborate_commutation(self): """ Check that Optimize1qGatesSimpleCommutation can perform several steps without fumbling. - - ┌────────┐┌────┐┌────────┐ ┌────────┐┌────┐┌────────┐ - q_0: ┤ P(π/8) ├┤ √X ├┤ P(π/7) ├──■──┤ P(π/7) ├┤ √X ├┤ P(π/8) ├ - ├────────┤├────┤└────────┘┌─┴─┐├───────┬┘├────┤├───────┬┘ - q_1: ┤ P(π/4) ├┤ √X ├──────────┤ X ├┤ P(-π) ├─┤ √X ├┤ P(-π) ├─ - └────────┘└────┘ └───┘└───────┘ └────┘└───────┘ """ + # ┌────────┐┌────┐┌────────┐ ┌────────┐┌────┐┌────────┐ + # q_0: ┤ P(π/8) ├┤ √X ├┤ P(π/7) ├──■──┤ P(π/7) ├┤ √X ├┤ P(π/8) ├ + # ├────────┤├────┤└────────┘┌─┴─┐├───────┬┘├────┤├───────┬┘ + # q_1: ┤ P(π/4) ├┤ √X ├──────────┤ X ├┤ P(-π) ├─┤ √X ├┤ P(-π) ├─ + # └────────┘└────┘ └───┘└───────┘ └────┘└───────┘ qc = QuantumCircuit(2) qc.p(np.pi / 8, 0) @@ -136,23 +133,22 @@ def test_midcircuit_double_commutation(self): """ Check that Optimize1qGatesSimpleCommutation can push gates forward and backward out of a run in the middle of a circuit. - - ┌──────────┐┌────┐┌───────────┐┌────┐┌───────────┐┌───┐┌────┐┌──────────┐» - q_0: ─┤ Rz(2.15) ├┤ √X ├┤ Rz(-2.75) ├┤ √X ├┤ Rz(0.255) ├┤ X ├┤ √X ├┤ Rz(1.03) ├» - ┌┴──────────┤├────┤├───────────┤├────┤└┬──────────┤└─┬─┘├────┤├──────────┤» - q_1: ┤ Rz(0.138) ├┤ √X ├┤ Rz(-2.87) ├┤ √X ├─┤ Rz(-2.1) ├──■──┤ √X ├┤ Rz(1.45) ├» - └───────────┘└────┘└───────────┘└────┘ └──────────┘ └────┘└──────────┘» - « ┌────┐ ┌───┐ ┌──────────┐ ┌────┐┌───────────┐┌────┐» - «q_0: ┤ √X ├────────────┤ X ├─┤ Rz(2.01) ├─┤ √X ├┤ Rz(-1.62) ├┤ √X ├» - « ├────┤┌──────────┐└─┬─┘┌┴──────────┴┐├────┤├───────────┤├────┤» - «q_1: ┤ √X ├┤ Rz(1.33) ├──■──┤ Rz(-0.732) ├┤ √X ├┤ Rz(-2.65) ├┤ √X ├» - « └────┘└──────────┘ └────────────┘└────┘└───────────┘└────┘» - « ┌───────────┐ - «q_0: ┤ Rz(-1.16) ├ - « └┬──────────┤ - «q_1: ─┤ Rz(2.17) ├ - « └──────────┘ """ + # ┌──────────┐┌────┐┌───────────┐┌────┐┌───────────┐┌───┐┌────┐┌──────────┐» + # q_0: ─┤ Rz(2.15) ├┤ √X ├┤ Rz(-2.75) ├┤ √X ├┤ Rz(0.255) ├┤ X ├┤ √X ├┤ Rz(1.03) ├» + # ┌┴──────────┤├────┤├───────────┤├────┤└┬──────────┤└─┬─┘├────┤├──────────┤» + # q_1: ┤ Rz(0.138) ├┤ √X ├┤ Rz(-2.87) ├┤ √X ├─┤ Rz(-2.1) ├──■──┤ √X ├┤ Rz(1.45) ├» + # └───────────┘└────┘└───────────┘└────┘ └──────────┘ └────┘└──────────┘» + # « ┌────┐ ┌───┐ ┌──────────┐ ┌────┐┌───────────┐┌────┐» + # «q_0: ┤ √X ├────────────┤ X ├─┤ Rz(2.01) ├─┤ √X ├┤ Rz(-1.62) ├┤ √X ├» + # « ├────┤┌──────────┐└─┬─┘┌┴──────────┴┐├────┤├───────────┤├────┤» + # «q_1: ┤ √X ├┤ Rz(1.33) ├──■──┤ Rz(-0.732) ├┤ √X ├┤ Rz(-2.65) ├┤ √X ├» + # « └────┘└──────────┘ └────────────┘└────┘└───────────┘└────┘» + # « ┌───────────┐ + # «q_0: ┤ Rz(-1.16) ├ + # « └┬──────────┤ + # «q_1: ─┤ Rz(2.17) ├ + # « └──────────┘ qc = QuantumCircuit(2) qc.rz(2.15, 0) # this block will get modified by resynthesis diff --git a/test/python/transpiler/test_optimize_1q_gates.py b/test/python/transpiler/test_optimize_1q_gates.py index 1fd37cc4abba..88611e1d913d 100644 --- a/test/python/transpiler/test_optimize_1q_gates.py +++ b/test/python/transpiler/test_optimize_1q_gates.py @@ -67,22 +67,21 @@ def test_optimize_1q_gates_collapse_identity_equivalent(self): """test optimize_1q_gates removes u1(2*pi) rotations. See: https://github.com/Qiskit/qiskit-terra/issues/159 - - ┌───┐┌───┐┌────────┐┌───┐┌─────────┐┌───────┐┌─────────┐┌───┐ ┌─┐» - qr_0: ┤ H ├┤ X ├┤ U1(2π) ├┤ X ├┤ U1(π/2) ├┤ U1(π) ├┤ U1(π/2) ├┤ X ├─────────┤M├» - └───┘└─┬─┘└────────┘└─┬─┘└─────────┘└───────┘└─────────┘└─┬─┘┌───────┐└╥┘» - qr_1: ───────■──────────────■───────────────────────────────────■──┤ U1(π) ├─╫─» - └───────┘ ║ » - cr: 2/═══════════════════════════════════════════════════════════════════════╩═» - 0 » - « - «qr_0: ──────────── - « ┌───────┐┌─┐ - «qr_1: ┤ U1(π) ├┤M├ - « └───────┘└╥┘ - «cr: 2/══════════╩═ - « 1 """ + # ┌───┐┌───┐┌────────┐┌───┐┌─────────┐┌───────┐┌─────────┐┌───┐ ┌─┐» + # qr_0: ┤ H ├┤ X ├┤ U1(2π) ├┤ X ├┤ U1(π/2) ├┤ U1(π) ├┤ U1(π/2) ├┤ X ├─────────┤M├» + # └───┘└─┬─┘└────────┘└─┬─┘└─────────┘└───────┘└─────────┘└─┬─┘┌───────┐└╥┘» + # qr_1: ───────■──────────────■───────────────────────────────────■──┤ U1(π) ├─╫─» + # └───────┘ ║ » + # cr: 2/═══════════════════════════════════════════════════════════════════════╩═» + # 0 » + # « + # «qr_0: ──────────── + # « ┌───────┐┌─┐ + # «qr_1: ┤ U1(π) ├┤M├ + # « └───────┘└╥┘ + # «cr: 2/══════════╩═ + # « 1 qr = QuantumRegister(2, "qr") cr = ClassicalRegister(2, "cr") qc = QuantumCircuit(qr, cr) @@ -109,22 +108,21 @@ def test_optimize_1q_gates_collapse_identity_equivalent_phase_gate(self): """test optimize_1q_gates removes u1(2*pi) rotations. See: https://github.com/Qiskit/qiskit-terra/issues/159 - - ┌───┐┌───┐┌───────┐┌───┐┌────────┐┌──────┐┌────────┐┌───┐ ┌─┐» - qr_0: ┤ H ├┤ X ├┤ P(2π) ├┤ X ├┤ P(π/2) ├┤ P(π) ├┤ P(π/2) ├┤ X ├────────┤M├» - └───┘└─┬─┘└───────┘└─┬─┘└────────┘└──────┘└────────┘└─┬─┘┌──────┐└╥┘» - qr_1: ───────■─────────────■────────────────────────────────■──┤ P(π) ├─╫─» - └──────┘ ║ » - cr: 2/══════════════════════════════════════════════════════════════════╩═» - 0 » - « - «qr_0: ─────────── - « ┌──────┐┌─┐ - «qr_1: ┤ P(π) ├┤M├ - « └──────┘└╥┘ - «cr: 2/═════════╩═ - « 1 """ + # ┌───┐┌───┐┌───────┐┌───┐┌────────┐┌──────┐┌────────┐┌───┐ ┌─┐» + # qr_0: ┤ H ├┤ X ├┤ P(2π) ├┤ X ├┤ P(π/2) ├┤ P(π) ├┤ P(π/2) ├┤ X ├────────┤M├» + # └───┘└─┬─┘└───────┘└─┬─┘└────────┘└──────┘└────────┘└─┬─┘┌──────┐└╥┘» + # qr_1: ───────■─────────────■────────────────────────────────■──┤ P(π) ├─╫─» + # └──────┘ ║ » + # cr: 2/══════════════════════════════════════════════════════════════════╩═» + # 0 » + # « + # «qr_0: ─────────── + # « ┌──────┐┌─┐ + # «qr_1: ┤ P(π) ├┤M├ + # « └──────┘└╥┘ + # «cr: 2/═════════╩═ + # « 1 qr = QuantumRegister(2, "qr") cr = ClassicalRegister(2, "cr") qc = QuantumCircuit(qr, cr) diff --git a/test/python/transpiler/test_sabre_layout.py b/test/python/transpiler/test_sabre_layout.py index f45dea5e9bac..2c0d57f25df5 100644 --- a/test/python/transpiler/test_sabre_layout.py +++ b/test/python/transpiler/test_sabre_layout.py @@ -30,20 +30,17 @@ def setUp(self): self.cmap20 = FakeAlmaden().configuration().coupling_map def test_5q_circuit_20q_coupling(self): - """Test finds layout for 5q circuit on 20q device. - - ┌───┐ - q_0: ──■───────┤ X ├─────────────── - │ └─┬─┘┌───┐ - q_1: ──┼────■────┼──┤ X ├───────■── - ┌─┴─┐ │ │ ├───┤┌───┐┌─┴─┐ - q_2: ┤ X ├──┼────┼──┤ X ├┤ X ├┤ X ├ - └───┘┌─┴─┐ │ └───┘└─┬─┘└───┘ - q_3: ─────┤ X ├──■─────────┼─────── - └───┘ │ - q_4: ──────────────────────■─────── - - """ + """Test finds layout for 5q circuit on 20q device.""" + # ┌───┐ + # q_0: ──■───────┤ X ├─────────────── + # │ └─┬─┘┌───┐ + # q_1: ──┼────■────┼──┤ X ├───────■── + # ┌─┴─┐ │ │ ├───┤┌───┐┌─┴─┐ + # q_2: ┤ X ├──┼────┼──┤ X ├┤ X ├┤ X ├ + # └───┘┌─┴─┐ │ └───┘└─┬─┘└───┘ + # q_3: ─────┤ X ├──■─────────┼─────── + # └───┘ │ + # q_4: ──────────────────────■─────── qr = QuantumRegister(5, "q") circuit = QuantumCircuit(qr) circuit.cx(qr[0], qr[2]) @@ -66,22 +63,19 @@ def test_5q_circuit_20q_coupling(self): self.assertEqual(layout[qr[4]], 13) def test_6q_circuit_20q_coupling(self): - """Test finds layout for 6q circuit on 20q device. - - ┌───┐┌───┐┌───┐┌───┐┌───┐ - q0_0: ┤ X ├┤ X ├┤ X ├┤ X ├┤ X ├ - └─┬─┘└─┬─┘└─┬─┘└─┬─┘└─┬─┘ - q0_1: ──┼────■────┼────┼────┼── - │ ┌───┐ │ │ │ - q0_2: ──┼──┤ X ├──┼────■────┼── - │ └───┘ │ │ - q1_0: ──■─────────┼─────────┼── - ┌───┐ │ │ - q1_1: ─────┤ X ├──┼─────────■── - └───┘ │ - q1_2: ────────────■──────────── - - """ + """Test finds layout for 6q circuit on 20q device.""" + # ┌───┐┌───┐┌───┐┌───┐┌───┐ + # q0_0: ┤ X ├┤ X ├┤ X ├┤ X ├┤ X ├ + # └─┬─┘└─┬─┘└─┬─┘└─┬─┘└─┬─┘ + # q0_1: ──┼────■────┼────┼────┼── + # │ ┌───┐ │ │ │ + # q0_2: ──┼──┤ X ├──┼────■────┼── + # │ └───┘ │ │ + # q1_0: ──■─────────┼─────────┼── + # ┌───┐ │ │ + # q1_1: ─────┤ X ├──┼─────────■── + # └───┘ │ + # q1_2: ────────────■──────────── qr0 = QuantumRegister(3, "q0") qr1 = QuantumRegister(3, "q1") circuit = QuantumCircuit(qr0, qr1) diff --git a/test/python/transpiler/test_unroller.py b/test/python/transpiler/test_unroller.py index b8bb28df30ea..d083d8437112 100644 --- a/test/python/transpiler/test_unroller.py +++ b/test/python/transpiler/test_unroller.py @@ -317,13 +317,11 @@ def compare_dags(self): self.assertEqual(unrolled_dag, ref_dag) def test_unroll_crx(self): - """test unroll crx - - qr_1: ─────■───── qr_1: ─────────────────■─────────────────────■───────────────────── - ┌────┴────┐ = ┌─────────────┐┌─┴─┐┌───────────────┐┌─┴─┐┌─────────────────┐ - qr_2: ┤ Rx(0.5) ├ qr_2: ┤ U3(0,0,π/2) ├┤ X ├┤ U3(-0.25,0,0) ├┤ X ├┤ U3(0.25,-π/2,0) ├ - └─────────┘ └─────────────┘└───┘└───────────────┘└───┘└─────────────────┘ - """ + """test unroll crx""" + # qr_1: ─────■───── qr_1: ─────────────────■─────────────────────■───────────────────── + # ┌────┴────┐ = ┌─────────────┐┌─┴─┐┌───────────────┐┌─┴─┐┌─────────────────┐ + # qr_2: ┤ Rx(0.5) ├ qr_2: ┤ U3(0,0,π/2) ├┤ X ├┤ U3(-0.25,0,0) ├┤ X ├┤ U3(0.25,-π/2,0) ├ + # └─────────┘ └─────────────┘└───┘└───────────────┘└───┘└─────────────────┘ self.circuit.crx(0.5, 1, 2) self.ref_circuit.append(U3Gate(0, 0, pi / 2), [2]) self.ref_circuit.cx(1, 2) @@ -333,13 +331,11 @@ def test_unroll_crx(self): self.compare_dags() def test_unroll_cry(self): - """test unroll cry - - qr_1: ─────■───── qr_1: ──────────────────■─────────────────────■── - ┌────┴────┐ = ┌──────────────┐┌─┴─┐┌───────────────┐┌─┴─┐ - qr_2: ┤ Ry(0.5) ├ qr_2: ┤ U3(0.25,0,0) ├┤ X ├┤ U3(-0.25,0,0) ├┤ X ├ - └─────────┘ └──────────────┘└───┘└───────────────┘└───┘ - """ + """test unroll cry""" + # qr_1: ─────■───── qr_1: ──────────────────■─────────────────────■── + # ┌────┴────┐ = ┌──────────────┐┌─┴─┐┌───────────────┐┌─┴─┐ + # qr_2: ┤ Ry(0.5) ├ qr_2: ┤ U3(0.25,0,0) ├┤ X ├┤ U3(-0.25,0,0) ├┤ X ├ + # └─────────┘ └──────────────┘└───┘└───────────────┘└───┘ self.circuit.cry(0.5, 1, 2) self.ref_circuit.append(U3Gate(0.25, 0, 0), [2]) self.ref_circuit.cx(1, 2) @@ -348,22 +344,21 @@ def test_unroll_cry(self): self.compare_dags() def test_unroll_ccx(self): - """test unroll ccx - - qr_0: ──■── qr_0: ──────────────────────────────────────■──────────────────────» - │ │ » - qr_1: ──■── = qr_1: ─────────────────■────────────────────┼───────────────────■──» - ┌─┴─┐ ┌─────────────┐┌─┴─┐┌──────────────┐┌─┴─┐┌─────────────┐┌─┴─┐» - qr_2: ┤ X ├ qr_2: ┤ U3(π/2,0,π) ├┤ X ├┤ U3(0,0,-π/4) ├┤ X ├┤ U3(0,0,π/4) ├┤ X ├» - └───┘ └─────────────┘└───┘└──────────────┘└───┘└─────────────┘└───┘» - « ┌─────────────┐ - «qr_0: ──────────────────■─────────■───────┤ U3(0,0,π/4) ├───■── - « ┌─────────────┐ │ ┌─┴─┐ ├─────────────┴┐┌─┴─┐ - «qr_1: ┤ U3(0,0,π/4) ├───┼───────┤ X ├─────┤ U3(0,0,-π/4) ├┤ X ├ - « ├─────────────┴┐┌─┴─┐┌────┴───┴────┐├─────────────┬┘└───┘ - «qr_2: ┤ U3(0,0,-π/4) ├┤ X ├┤ U3(0,0,π/4) ├┤ U3(π/2,0,π) ├────── - « └──────────────┘└───┘└─────────────┘└─────────────┘ - """ + """test unroll ccx""" + + # qr_0: ──■── qr_0: ──────────────────────────────────────■──────────────────────» + # │ │ » + # qr_1: ──■── = qr_1: ─────────────────■────────────────────┼───────────────────■──» + # ┌─┴─┐ ┌─────────────┐┌─┴─┐┌──────────────┐┌─┴─┐┌─────────────┐┌─┴─┐» + # qr_2: ┤ X ├ qr_2: ┤ U3(π/2,0,π) ├┤ X ├┤ U3(0,0,-π/4) ├┤ X ├┤ U3(0,0,π/4) ├┤ X ├» + # └───┘ └─────────────┘└───┘└──────────────┘└───┘└─────────────┘└───┘» + # « ┌─────────────┐ + # «qr_0: ──────────────────■─────────■───────┤ U3(0,0,π/4) ├───■── + # « ┌─────────────┐ │ ┌─┴─┐ ├─────────────┴┐┌─┴─┐ + # «qr_1: ┤ U3(0,0,π/4) ├───┼───────┤ X ├─────┤ U3(0,0,-π/4) ├┤ X ├ + # « ├─────────────┴┐┌─┴─┐┌────┴───┴────┐├─────────────┬┘└───┘ + # «qr_2: ┤ U3(0,0,-π/4) ├┤ X ├┤ U3(0,0,π/4) ├┤ U3(π/2,0,π) ├────── + # « └──────────────┘└───┘└─────────────┘└─────────────┘ self.circuit.ccx(0, 1, 2) self.ref_circuit.append(U3Gate(pi / 2, 0, pi), [2]) self.ref_circuit.cx(1, 2) @@ -383,18 +378,17 @@ def test_unroll_ccx(self): self.compare_dags() def test_unroll_ch(self): - """test unroll ch - - qr_0: ──■── qr_0: ───────────────────────────────────────────────■──────────────────» - ┌─┴─┐ = ┌─────────────┐┌─────────────┐┌─────────────┐┌─┴─┐┌──────────────┐» - qr_2: ┤ H ├ qr_2: ┤ U3(0,0,π/2) ├┤ U3(π/2,0,π) ├┤ U3(0,0,π/4) ├┤ X ├┤ U3(0,0,-π/4) ├» - └───┘ └─────────────┘└─────────────┘└─────────────┘└───┘└──────────────┘» - « - «qr_0: ─────────────────────────────── - « ┌─────────────┐┌──────────────┐ - «qr_2: ┤ U3(π/2,0,π) ├┤ U3(0,0,-π/2) ├ - « └─────────────┘└──────────────┘ - """ + """test unroll ch""" + + # qr_0: ──■── qr_0: ───────────────────────────────────────────────■──────────────────» + # ┌─┴─┐ = ┌─────────────┐┌─────────────┐┌─────────────┐┌─┴─┐┌──────────────┐» + # qr_2: ┤ H ├ qr_2: ┤ U3(0,0,π/2) ├┤ U3(π/2,0,π) ├┤ U3(0,0,π/4) ├┤ X ├┤ U3(0,0,-π/4) ├» + # └───┘ └─────────────┘└─────────────┘└─────────────┘└───┘└──────────────┘» + # « + # «qr_0: ─────────────────────────────── + # « ┌─────────────┐┌──────────────┐ + # «qr_2: ┤ U3(π/2,0,π) ├┤ U3(0,0,-π/2) ├ + # « └─────────────┘└──────────────┘ self.circuit.ch(0, 2) self.ref_circuit.append(U3Gate(0, 0, pi / 2), [2]) self.ref_circuit.append(U3Gate(pi / 2, 0, pi), [2]) @@ -406,13 +400,12 @@ def test_unroll_ch(self): self.compare_dags() def test_unroll_crz(self): - """test unroll crz + """test unroll crz""" - qr_1: ─────■───── qr_1: ──────────────────■─────────────────────■── - ┌────┴────┐ = ┌──────────────┐┌─┴─┐┌───────────────┐┌─┴─┐ - qr_2: ┤ Rz(0.5) ├ qr_2: ┤ U3(0,0,0.25) ├┤ X ├┤ U3(0,0,-0.25) ├┤ X ├ - └─────────┘ └──────────────┘└───┘└───────────────┘└───┘ - """ + # qr_1: ─────■───── qr_1: ──────────────────■─────────────────────■── + # ┌────┴────┐ = ┌──────────────┐┌─┴─┐┌───────────────┐┌─┴─┐ + # qr_2: ┤ Rz(0.5) ├ qr_2: ┤ U3(0,0,0.25) ├┤ X ├┤ U3(0,0,-0.25) ├┤ X ├ + # └─────────┘ └──────────────┘└───┘└───────────────┘└───┘ self.circuit.crz(0.5, 1, 2) self.ref_circuit.append(U3Gate(0, 0, 0.25), [2]) self.ref_circuit.cx(1, 2) @@ -420,23 +413,21 @@ def test_unroll_crz(self): self.ref_circuit.cx(1, 2) def test_unroll_cswap(self): - """test unroll cswap - - ┌───┐ » - qr_0: ─X─ qr_0: ┤ X ├─────────────────■────────────────────────────────────────■──» - │ └─┬─┘ │ │ » - qr_1: ─■─ = qr_1: ──┼───────────────────┼────────────────────■───────────────────┼──» - │ │ ┌─────────────┐┌─┴─┐┌──────────────┐┌─┴─┐┌─────────────┐┌─┴─┐» - qr_2: ─X─ qr_2: ──■──┤ U3(π/2,0,π) ├┤ X ├┤ U3(0,0,-π/4) ├┤ X ├┤ U3(0,0,π/4) ├┤ X ├» - └─────────────┘└───┘└──────────────┘└───┘└─────────────┘└───┘» - « ┌─────────────┐ ┌───┐ ┌──────────────┐┌───┐┌───┐ - «qr_0: ┤ U3(0,0,π/4) ├───────────┤ X ├─────┤ U3(0,0,-π/4) ├┤ X ├┤ X ├ - « └─────────────┘ └─┬─┘ ├─────────────┬┘└─┬─┘└─┬─┘ - «qr_1: ──────────────────■─────────■───────┤ U3(0,0,π/4) ├───■────┼── - « ┌──────────────┐┌─┴─┐┌─────────────┐├─────────────┤ │ - «qr_2: ┤ U3(0,0,-π/4) ├┤ X ├┤ U3(0,0,π/4) ├┤ U3(π/2,0,π) ├────────■── - « └──────────────┘└───┘└─────────────┘└─────────────┘ - """ + """test unroll cswap""" + # ┌───┐ » + # qr_0: ─X─ qr_0: ┤ X ├─────────────────■────────────────────────────────────────■──» + # │ └─┬─┘ │ │ » + # qr_1: ─■─ = qr_1: ──┼───────────────────┼────────────────────■───────────────────┼──» + # │ │ ┌─────────────┐┌─┴─┐┌──────────────┐┌─┴─┐┌─────────────┐┌─┴─┐» + # qr_2: ─X─ qr_2: ──■──┤ U3(π/2,0,π) ├┤ X ├┤ U3(0,0,-π/4) ├┤ X ├┤ U3(0,0,π/4) ├┤ X ├» + # └─────────────┘└───┘└──────────────┘└───┘└─────────────┘└───┘» + # « ┌─────────────┐ ┌───┐ ┌──────────────┐┌───┐┌───┐ + # «qr_0: ┤ U3(0,0,π/4) ├───────────┤ X ├─────┤ U3(0,0,-π/4) ├┤ X ├┤ X ├ + # « └─────────────┘ └─┬─┘ ├─────────────┬┘└─┬─┘└─┬─┘ + # «qr_1: ──────────────────■─────────■───────┤ U3(0,0,π/4) ├───■────┼── + # « ┌──────────────┐┌─┴─┐┌─────────────┐├─────────────┤ │ + # «qr_2: ┤ U3(0,0,-π/4) ├┤ X ├┤ U3(0,0,π/4) ├┤ U3(π/2,0,π) ├────────■── + # « └──────────────┘└───┘└─────────────┘└─────────────┘ self.circuit.cswap(1, 0, 2) self.ref_circuit.cx(2, 0) self.ref_circuit.append(U3Gate(pi / 2, 0, pi), [2]) @@ -458,14 +449,12 @@ def test_unroll_cswap(self): self.compare_dags() def test_unroll_cu1(self): - """test unroll cu1 - - ┌──────────────┐ - qr_0: ─■──────── qr_0: ┤ U3(0,0,0.05) ├──■─────────────────────■────────────────── - │U1(0.1) = └──────────────┘┌─┴─┐┌───────────────┐┌─┴─┐┌──────────────┐ - qr_2: ─■──────── qr_2: ────────────────┤ X ├┤ U3(0,0,-0.05) ├┤ X ├┤ U3(0,0,0.05) ├ - └───┘└───────────────┘└───┘└──────────────┘ - """ + """test unroll cu1""" + # ┌──────────────┐ + # qr_0: ─■──────── qr_0: ┤ U3(0,0,0.05) ├──■─────────────────────■────────────────── + # │U1(0.1) = └──────────────┘┌─┴─┐┌───────────────┐┌─┴─┐┌──────────────┐ + # qr_2: ─■──────── qr_2: ────────────────┤ X ├┤ U3(0,0,-0.05) ├┤ X ├┤ U3(0,0,0.05) ├ + # └───┘└───────────────┘└───┘└──────────────┘ self.circuit.append(CU1Gate(0.1), [0, 2]) self.ref_circuit.append(U3Gate(0, 0, 0.05), [0]) self.ref_circuit.cx(0, 2) @@ -475,14 +464,12 @@ def test_unroll_cu1(self): self.compare_dags() def test_unroll_cu3(self): - """test unroll cu3 - - ┌──────────────┐ - qr_1: ────────■──────── qr_1: ─┤ U3(0,0,0.05) ├──■────────────────────────■─────────────────── - ┌───────┴───────┐ = ┌┴──────────────┤┌─┴─┐┌──────────────────┐┌─┴─┐┌───────────────┐ - qr_2: ┤ U3(0.2,0.1,0) ├ qr_2: ┤ U3(0,0,-0.05) ├┤ X ├┤ U3(-0.1,0,-0.05) ├┤ X ├┤ U3(0.1,0.1,0) ├ - └───────────────┘ └───────────────┘└───┘└──────────────────┘└───┘└───────────────┘ - """ + """test unroll cu3""" + # ┌──────────────┐ + # qr_1: ────────■──────── qr_1: ─┤ U3(0,0,0.05) ├──■────────────────────────■─────────────────── + # ┌───────┴───────┐ = ┌┴──────────────┤┌─┴─┐┌──────────────────┐┌─┴─┐┌───────────────┐ + # qr_2: ┤ U3(0.2,0.1,0) ├ qr_2: ┤ U3(0,0,-0.05) ├┤ X ├┤ U3(-0.1,0,-0.05) ├┤ X ├┤ U3(0.1,0.1,0) ├ + # └───────────────┘ └───────────────┘└───┘└──────────────────┘└───┘└───────────────┘ self.circuit.append(CU3Gate(0.2, 0.1, 0.0), [1, 2]) self.ref_circuit.append(U3Gate(0, 0, 0.05), [1]) self.ref_circuit.append(U3Gate(0, 0, -0.05), [2]) @@ -499,13 +486,11 @@ def test_unroll_cx(self): self.compare_dags() def test_unroll_cy(self): - """test unroll cy - - qr_1: ──■── qr_1: ──────────────────■───────────────── - ┌─┴─┐ = ┌──────────────┐┌─┴─┐┌─────────────┐ - qr_2: ┤ Y ├ qr_2: ┤ U3(0,0,-π/2) ├┤ X ├┤ U3(0,0,π/2) ├ - └───┘ └──────────────┘└───┘└─────────────┘ - """ + """test unroll cy""" + # qr_1: ──■── qr_1: ──────────────────■───────────────── + # ┌─┴─┐ = ┌──────────────┐┌─┴─┐┌─────────────┐ + # qr_2: ┤ Y ├ qr_2: ┤ U3(0,0,-π/2) ├┤ X ├┤ U3(0,0,π/2) ├ + # └───┘ └──────────────┘└───┘└─────────────┘ self.circuit.cy(1, 2) self.ref_circuit.append(U3Gate(0, 0, -pi / 2), [2]) self.ref_circuit.cx(1, 2) @@ -513,14 +498,11 @@ def test_unroll_cy(self): self.compare_dags() def test_unroll_cz(self): - """test unroll cz - - ┌─────────────┐┌───┐┌─────────────┐ - qr_0: ─■─ qr_0: ┤ U3(π/2,0,π) ├┤ X ├┤ U3(π/2,0,π) ├ - │ = └─────────────┘└─┬─┘└─────────────┘ - qr_2: ─■─ qr_2: ─────────────────■───────────────── - - """ + """test unroll cz""" + # ┌─────────────┐┌───┐┌─────────────┐ + # qr_0: ─■─ qr_0: ┤ U3(π/2,0,π) ├┤ X ├┤ U3(π/2,0,π) ├ + # │ = └─────────────┘└─┬─┘└─────────────┘ + # qr_2: ─■─ qr_2: ─────────────────■───────────────── self.circuit.cz(2, 0) self.ref_circuit.append(U3Gate(pi / 2, 0, pi), [0]) self.ref_circuit.cx(2, 0) @@ -559,15 +541,12 @@ def test_unroll_rz(self): self.compare_dags() def test_unroll_rzz(self): - """test unroll rzz - - global phase: 5.9832 - ┌───┐┌─────────────┐┌───┐ - qr_0: ─■──────── qr_0: ┤ X ├┤ U3(0,0,0.6) ├┤ X ├ - │ZZ(0.6) = └─┬─┘└─────────────┘└─┬─┘ - qr_1: ─■──────── qr_1: ──■───────────────────■── - - """ + """test unroll rzz""" + # global phase: 5.9832 + # ┌───┐┌─────────────┐┌───┐ + # qr_0: ─■──────── qr_0: ┤ X ├┤ U3(0,0,0.6) ├┤ X ├ + # │ZZ(0.6) = └─┬─┘└─────────────┘└─┬─┘ + # qr_1: ─■──────── qr_1: ──■───────────────────■── self.circuit.rzz(0.6, 1, 0) self.ref_circuit.global_phase = -1 * 0.6 / 2 self.ref_circuit.cx(1, 0) @@ -588,14 +567,12 @@ def test_unroll_sdg(self): self.compare_dags() def test_unroll_swap(self): - """test unroll swap - - ┌───┐ - qr_1: ─X─ qr_1: ──■──┤ X ├──■── - │ = ┌─┴─┐└─┬─┘┌─┴─┐ - qr_2: ─X─ qr_2: ┤ X ├──■──┤ X ├ - └───┘ └───┘ - """ + """test unroll swap""" + # ┌───┐ + # qr_1: ─X─ qr_1: ──■──┤ X ├──■── + # │ = ┌─┴─┐└─┬─┘┌─┴─┐ + # qr_2: ─X─ qr_2: ┤ X ├──■──┤ X ├ + # └───┘ └───┘ self.circuit.swap(1, 2) self.ref_circuit.cx(1, 2) self.ref_circuit.cx(2, 1) From 76a5c46435ce9a5a16868349d5aecc8fbd4a1885 Mon Sep 17 00:00:00 2001 From: Jintaoyu Date: Sat, 11 Dec 2021 10:11:15 +0800 Subject: [PATCH 17/18] Fix a lint problem --- test/python/transpiler/test_unroller.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/python/transpiler/test_unroller.py b/test/python/transpiler/test_unroller.py index d083d8437112..80f1ebde746f 100644 --- a/test/python/transpiler/test_unroller.py +++ b/test/python/transpiler/test_unroller.py @@ -465,11 +465,11 @@ def test_unroll_cu1(self): def test_unroll_cu3(self): """test unroll cu3""" - # ┌──────────────┐ - # qr_1: ────────■──────── qr_1: ─┤ U3(0,0,0.05) ├──■────────────────────────■─────────────────── - # ┌───────┴───────┐ = ┌┴──────────────┤┌─┴─┐┌──────────────────┐┌─┴─┐┌───────────────┐ - # qr_2: ┤ U3(0.2,0.1,0) ├ qr_2: ┤ U3(0,0,-0.05) ├┤ X ├┤ U3(-0.1,0,-0.05) ├┤ X ├┤ U3(0.1,0.1,0) ├ - # └───────────────┘ └───────────────┘└───┘└──────────────────┘└───┘└───────────────┘ + # ┌──────────────┐ + # q_1: ────────■──────── q_1: ─┤ U3(0,0,0.05) ├──■────────────────────────■─────────────────── + # ┌───────┴───────┐ = ┌┴──────────────┤┌─┴─┐┌──────────────────┐┌─┴─┐┌───────────────┐ + # q_2: ┤ U3(0.2,0.1,0) ├ q_2: ┤ U3(0,0,-0.05) ├┤ X ├┤ U3(-0.1,0,-0.05) ├┤ X ├┤ U3(0.1,0.1,0) ├ + # └───────────────┘ └───────────────┘└───┘└──────────────────┘└───┘└───────────────┘ self.circuit.append(CU3Gate(0.2, 0.1, 0.0), [1, 2]) self.ref_circuit.append(U3Gate(0, 0, 0.05), [1]) self.ref_circuit.append(U3Gate(0, 0, -0.05), [2]) From 8d921bb19cee0e9c292a4b63542580f247393da1 Mon Sep 17 00:00:00 2001 From: Jintaoyu Date: Sat, 11 Dec 2021 21:07:12 +0800 Subject: [PATCH 18/18] Add blank lines before and after parsed-literal --- qiskit/circuit/quantumcircuit.py | 8 +++++++- qiskit/extensions/quantum_initializer/initializer.py | 3 +++ .../passes/optimization/echo_rzx_weyl_decomposition.py | 2 ++ .../template_matching/template_substitution.py | 2 ++ .../notes/0.14/0.14.0-release-19557dcd9d5af6e3.yaml | 1 + test/python/compiler/test_transpiler.py | 2 ++ 6 files changed, 17 insertions(+), 1 deletion(-) diff --git a/qiskit/circuit/quantumcircuit.py b/qiskit/circuit/quantumcircuit.py index a67e02260b1a..ac4aa5183fef 100644 --- a/qiskit/circuit/quantumcircuit.py +++ b/qiskit/circuit/quantumcircuit.py @@ -425,6 +425,7 @@ def reverse_ops(self) -> "QuantumCircuit": Examples: input: + .. parsed-literal:: ┌───┐ @@ -434,6 +435,7 @@ def reverse_ops(self) -> "QuantumCircuit": └──────────┘ output: + .. parsed-literal:: ┌───┐ @@ -469,6 +471,7 @@ def reverse_bits(self) -> "QuantumCircuit": Examples: input: + .. parsed-literal:: ┌───┐ @@ -478,6 +481,7 @@ def reverse_bits(self) -> "QuantumCircuit": └──────────┘ output: + .. parsed-literal:: ┌──────────┐ @@ -519,15 +523,17 @@ def inverse(self) -> "QuantumCircuit": Examples: input: + .. parsed-literal:: ┌───┐ q_0: ┤ H ├─────■────── └───┘┌────┴─────┐ q_1: ─────┤ RX(1.57) ├ - └──────────┘ + └──────────┘ output: + .. parsed-literal:: ┌───┐ diff --git a/qiskit/extensions/quantum_initializer/initializer.py b/qiskit/extensions/quantum_initializer/initializer.py index b9a4878af3aa..62dad242b624 100644 --- a/qiskit/extensions/quantum_initializer/initializer.py +++ b/qiskit/extensions/quantum_initializer/initializer.py @@ -404,6 +404,7 @@ def initialize(self, params, qubits=None): circuit.draw() output: + .. parsed-literal:: ┌──────────────────────────────┐ @@ -426,6 +427,7 @@ def initialize(self, params, qubits=None): circuit.draw() output: + .. parsed-literal:: ┌──────────────────┐ @@ -445,6 +447,7 @@ def initialize(self, params, qubits=None): circuit.draw() output: + .. parsed-literal:: ┌────────────────────────────────────┐ diff --git a/qiskit/transpiler/passes/optimization/echo_rzx_weyl_decomposition.py b/qiskit/transpiler/passes/optimization/echo_rzx_weyl_decomposition.py index 979817c97d79..5d55796df668 100644 --- a/qiskit/transpiler/passes/optimization/echo_rzx_weyl_decomposition.py +++ b/qiskit/transpiler/passes/optimization/echo_rzx_weyl_decomposition.py @@ -54,6 +54,7 @@ def _echo_rzx_dag(theta): """Return the following circuit .. parsed-literal:: + ┌───────────────┐┌───┐┌────────────────┐┌───┐ q_0: ┤0 ├┤ X ├┤0 ├┤ X ├ │ Rzx(theta/2) │└───┘│ Rzx(-theta/2) │└───┘ @@ -74,6 +75,7 @@ def _reverse_echo_rzx_dag(theta): """Return the following circuit .. parsed-literal:: + ┌───┐┌───────────────┐ ┌────────────────┐┌───┐ q_0: ┤ H ├┤1 ├─────┤1 ├┤ H ├───── ├───┤│ Rzx(theta/2) │┌───┐│ Rzx(-theta/2) │├───┤┌───┐ diff --git a/qiskit/transpiler/passes/optimization/template_matching/template_substitution.py b/qiskit/transpiler/passes/optimization/template_matching/template_substitution.py index c1cbd26190ed..640e6c45e2ec 100644 --- a/qiskit/transpiler/passes/optimization/template_matching/template_substitution.py +++ b/qiskit/transpiler/passes/optimization/template_matching/template_substitution.py @@ -457,6 +457,7 @@ def _attempt_bind(self, template_sublist, circuit_sublist): assignment of the parameters. For example the template .. parsed-literal:: + ┌───────────┐ ┌────────┐ q_0: ┤ P(-1.0*β) ├──■────────────■──┤0 ├ ├───────────┤┌─┴─┐┌──────┐┌─┴─┐│ CZ(β) │ @@ -466,6 +467,7 @@ def _attempt_bind(self, template_sublist, circuit_sublist): should only maximally match once in the circuit .. parsed-literal:: + ┌───────┐ q_0: ┤ P(-2) ├──■────────────■──────────────────────────── ├───────┤┌─┴─┐┌──────┐┌─┴─┐┌──────┐ diff --git a/releasenotes/notes/0.14/0.14.0-release-19557dcd9d5af6e3.yaml b/releasenotes/notes/0.14/0.14.0-release-19557dcd9d5af6e3.yaml index 0462bbf1996c..fbe0e38c0b30 100644 --- a/releasenotes/notes/0.14/0.14.0-release-19557dcd9d5af6e3.yaml +++ b/releasenotes/notes/0.14/0.14.0-release-19557dcd9d5af6e3.yaml @@ -52,6 +52,7 @@ prelude: | >>> lhs.compose(rhs, qubits=[3, 2], inplace=True) .. parsed-literal:: + ┌───┐ ┌─────┐ ┌───┐ lqr_1_0: ───┤ H ├─── rqr_0: ──■──┤ Tdg ├ lqr_1_0: ───┤ H ├─────────────── ├───┤ ┌─┴─┐└─────┘ ├───┤ diff --git a/test/python/compiler/test_transpiler.py b/test/python/compiler/test_transpiler.py index 118c80da16bd..39525af4ab86 100644 --- a/test/python/compiler/test_transpiler.py +++ b/test/python/compiler/test_transpiler.py @@ -105,6 +105,7 @@ def test_transpile_non_adjacent_layout(self): """Transpile pipeline can handle manual layout on non-adjacent qubits. circuit: + .. parsed-literal:: ┌───┐ @@ -210,6 +211,7 @@ def test_already_mapped_via_layout(self): See: https://github.com/Qiskit/qiskit-terra/issues/2036 circuit: + .. parsed-literal:: ┌───┐ ┌───┐ ░ ┌─┐