Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Altanali opened this issue Jun 19, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@Altanali
Copy link
Contributor

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 1c46ca7)
  • 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant