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