Describe the bug
When a program contains mid-circuit measurements (MCM), measurement_counts returns bitstrings padded to the total declared qubit count instead of the size of the classical register that was assigned. An equivalent non-MCM program returns the correctly sized bitstrings, so the issue is specific to the branched MCM execution path.
In the example below, a single qubit is measured into a bit[1] register, but each shot string is two characters wide.
To reproduce
-
Install amazon-braket-default-simulator (reproduced on 1.39.3.dev0 / main) and amazon-braket-sdk.
-
Run the following script:
from braket.devices import LocalSimulator
from braket.ir.openqasm import Program
qasm = """OPENQASM 3.0;
qubit[2] q;
bit[1] b;
x q[0];
b[0] = measure q[0];
x q[0];
b[0] = measure q[0];
x q[0];
b[0] = measure q[0];
"""
res = LocalSimulator().run(Program(source=qasm), shots=100).result()
print(res.measurement_counts)
-
Observe the output:
-
For contrast, run the same shape without MCM and confirm it works correctly:
qasm = """OPENQASM 3.0;
bit[1] b;
qubit[2] q;
h q[1];
b[0] = measure q[1];
"""
Output:
Counter({'1': 56, '0': 44})
Expected behavior
Since b is declared as bit[1] and only one qubit is assigned into it, each shot should produce a 1-bit string. The expected output for the MCM program is:
In general, the width of each measurement string for an MCM program should match the size of the classical register being assigned (i.e., the qubits flowing into b), not the total number of declared qubits.
Describe the bug
When a program contains mid-circuit measurements (MCM),
measurement_countsreturns bitstrings padded to the total declared qubit count instead of the size of the classical register that was assigned. An equivalent non-MCM program returns the correctly sized bitstrings, so the issue is specific to the branched MCM execution path.In the example below, a single qubit is measured into a
bit[1]register, but each shot string is two characters wide.To reproduce
Install
amazon-braket-default-simulator(reproduced on1.39.3.dev0/main) andamazon-braket-sdk.Run the following script:
Observe the output:
For contrast, run the same shape without MCM and confirm it works correctly:
Output:
Expected behavior
Since
bis declared asbit[1]and only one qubit is assigned into it, each shot should produce a 1-bit string. The expected output for the MCM program is:In general, the width of each measurement string for an MCM program should match the size of the classical register being assigned (i.e., the qubits flowing into
b), not the total number of declared qubits.