From e8285fac09b871f0951ae61087880582c38468ed Mon Sep 17 00:00:00 2001 From: Julien Dumazert Date: Mon, 3 Apr 2023 16:53:23 +0200 Subject: [PATCH] Fix handling of cargs in BasicQisVisitor The unit tests in this commit fail without the change made to file src/qiskit_qir/visitor.py. --- src/qiskit_qir/visitor.py | 2 +- tests/test_circuits/__init__.py | 1 + tests/test_circuits/basic_circuits.py | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/qiskit_qir/visitor.py b/src/qiskit_qir/visitor.py index 8152597..c82c6ce 100644 --- a/src/qiskit_qir/visitor.py +++ b/src/qiskit_qir/visitor.py @@ -199,7 +199,7 @@ def process_composite_instruction( ) for (inst, i_qargs, i_cargs) in subcircuit.data: mapped_qbits = [qargs[subcircuit.qubits.index(i)] for i in i_qargs] - mapped_clbits = [cargs[subcircuit.clbits.index] for i in i_cargs] + mapped_clbits = [cargs[subcircuit.clbits.index(i)] for i in i_cargs] _log.debug( f"Processing sub-instruction {inst.name} with mapped qubits {mapped_qbits}" ) diff --git a/tests/test_circuits/__init__.py b/tests/test_circuits/__init__.py index bce674c..e9c91f8 100644 --- a/tests/test_circuits/__init__.py +++ b/tests/test_circuits/__init__.py @@ -12,6 +12,7 @@ "teleport", "unroll", "teleport_with_subroutine", + "measure_x_as_subroutine" ] + random_fixtures noop_tests = ["bernstein_vazirani_with_delay", "ghz_with_delay"] diff --git a/tests/test_circuits/basic_circuits.py b/tests/test_circuits/basic_circuits.py index 063479a..532b53b 100644 --- a/tests/test_circuits/basic_circuits.py +++ b/tests/test_circuits/basic_circuits.py @@ -117,3 +117,18 @@ def ghz_with_delay(): circuit.measure([0, 1, 2], [0, 1, 2]) return circuit + +@pytest.fixture() +def measure_x_as_subroutine(): + measure_x_circuit = QuantumCircuit(1, 1, name='measure_x') + measure_x_circuit.h(0) + measure_x_circuit.measure(0, 0) + measure_x_circuit.h(0) + measure_x_gate = measure_x_circuit.to_instruction() + qq = QuantumRegister(1, name="qq") + cr = ClassicalRegister(1, name="cr") + circuit = QuantumCircuit(qq, cr) + circuit.name = "Qiskit Sample - Measure in the X-basis as a subroutine" + circuit.append(measure_x_gate, [0], [0]) + + return circuit