Skip to content

Commit

Permalink
change: Add test to check classical indices used in measurement are p…
Browse files Browse the repository at this point in the history
…reserved between Circuit and OpenQASM Translations. (#1013)
  • Loading branch information
Altanali authored Jun 26, 2024
1 parent 785d251 commit eeb7630
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
package_dir={"": "src"},
install_requires=[
"amazon-braket-schemas>=1.21.3",
"amazon-braket-default-simulator>=1.21.4",
"amazon-braket-default-simulator>=1.25.0",
"oqpy~=0.3.5",
"backoff",
"boltons",
Expand Down
29 changes: 29 additions & 0 deletions test/unit_tests/braket/circuits/test_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3610,3 +3610,32 @@ def test_circuit_with_global_phase():
"b[0] = measure $0;",
]
)


def test_from_ir_round_trip_transformation_with_targeted_measurements():
circuit = (
Circuit()
.h(0)
.cnot(0, 1)
.add_instruction(Instruction(Measure(index=2), 1))
.add_instruction(Instruction(Measure(index=1), 2))
.add_instruction(Instruction(Measure(index=0), 0))
)
ir = OpenQasmProgram(
source="\n".join(
[
"OPENQASM 3.0;",
"bit[3] b;",
"qubit[3] q;",
"h q[0];",
"cnot q[0], q[1];",
"b[2] = measure q[1];",
"b[1] = measure q[2];",
"b[0] = measure q[0];",
]
),
inputs={},
)

assert Circuit.from_ir(ir) == Circuit.from_ir(circuit.to_ir("OPENQASM"))
assert circuit.to_ir("OPENQASM") == Circuit.from_ir(ir).to_ir("OPENQASM")

0 comments on commit eeb7630

Please sign in to comment.