diff --git a/src/braket/circuits/braket_program_context.py b/src/braket/circuits/braket_program_context.py index a17864ed4..852dfba80 100644 --- a/src/braket/circuits/braket_program_context.py +++ b/src/braket/circuits/braket_program_context.py @@ -167,5 +167,6 @@ def add_measure(self, target: tuple[int]) -> None: Args: target (tuple[int]): the target qubits to be measured. """ - instruction = Instruction(Measure(), list(target)) - self._circuit.add_instruction(instruction) + for index, qubit in enumerate(target): + instruction = Instruction(Measure(index=index), qubit) + self._circuit.add_instruction(instruction) diff --git a/test/unit_tests/braket/circuits/test_circuit.py b/test/unit_tests/braket/circuits/test_circuit.py index 7680f9b4f..51752e3d4 100644 --- a/test/unit_tests/braket/circuits/test_circuit.py +++ b/test/unit_tests/braket/circuits/test_circuit.py @@ -811,6 +811,48 @@ def test_from_ir_with_measure(): assert Circuit.from_ir(source=ir.source, inputs=ir.inputs) == expected_circ +def test_from_ir_with_single_measure(): + ir = OpenQasmProgram( + source="\n".join( + [ + "OPENQASM 3.0;", + "bit[2] b;", + "qubit[2] q;", + "h q[0];", + "cnot q[0], q[1];", + "b = measure q;", + ] + ), + inputs={}, + ) + expected_circ = Circuit().h(0).cnot(0, 1).measure(0).measure(1) + assert Circuit.from_ir(source=ir.source, inputs=ir.inputs) == expected_circ + + +def test_from_ir_round_trip_transformation(): + circuit = Circuit().h(0).cnot(0, 1).measure(0).measure(1) + ir = OpenQasmProgram( + source="\n".join( + [ + "OPENQASM 3.0;", + "bit[2] b;", + "qubit[2] q;", + "h q[0];", + "cnot q[0], q[1];", + "b[0] = measure q[0];", + "b[1] = measure q[1];", + ] + ), + inputs={}, + ) + new_ir = circuit.to_ir("OPENQASM") + new_circuit = Circuit.from_ir(new_ir) + + assert new_ir == ir + assert Circuit.from_ir(source=ir.source, inputs=ir.inputs) == circuit + assert new_circuit == circuit + + def test_add_with_instruction_with_default(cnot_instr): circ = Circuit().add(cnot_instr) assert circ == Circuit().add_instruction(cnot_instr)