amazon-braket-sdk-python icon indicating copy to clipboard operation
amazon-braket-sdk-python copied to clipboard

Going to and from Braket Circuits and OpenQASM via to_ir and from_ir yields incorrect indexing in classical bit registers during measurements.

Open Altanali opened this issue 1 year ago • 0 comments

Describe the bug When taking an OpenQASM program, creating a Circuit via the Circuit.from_ir method, and then translated back to OpenQASM via the Circuit.to_ir method, indices used in classical registers during qubit measurement are all set to 0, even if the indices in the original OpenQASM code were non-zero.

To reproduce Example:

program = """
OPENQASM 3.0;
input float alpha;

bit[2] b;
qubit[2] q;

h q[0];
h q[1];
rx(alpha) q[0];
rx(alpha) q[1];
b[0] = measure q[0];
b[1] = measure q[1];
"""

circuit = Circuit.from_ir(program)
openqasm_str = circuit.to_ir(IRType.OpenQASM).source
print(openqasm_str)

Expected behavior The indices used in the classical registers in the translated output should match the indices in the original openqasm program (even if the classical register name is changed). In this example, we should see

b[0] = measure q[0];
b[1] = measure q[1];

However, the output from running this code yields

b[0] = measure q[0];
b[0] = measure q[1];

Screenshots or logs Print out from running snippet in example:

OPENQASM 3.0;
input float alpha;
bit[2] b;
qubit[2] q;
h q[0];
h q[1];
rx(alpha) q[0];
rx(alpha) q[1];
b[0] = measure q[0];
b[0] = measure q[1];

System information A description of your system. Please provide:

  • Amazon Braket Python SDK version: 1.8.0 (commit 1c46ca7f18f68b963ba06edf7bb719258e838a16)
  • Amazon Braket Python Schemas version:
  • Amazon Braket Python Default Simulator version:
  • Python version: 3.12.0

Additional context Add any other context about the problem here.

Altanali avatar Jun 19 '24 23:06 Altanali