QASM export changes multi-qubit SympyCondition equality through classical bit order
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 52/100
Research direction
Start by running the reproduction script in the issue and reading the emitted QASM. The two methods involved are MeasurementGate._qasm_, which maps measurement position i to register index i, and SympyCondition._qasm_, which emits the equality constant unchanged. Done means the exported if guard gives the same branch as the source simulation for the [1, 0] / m == 2 case, or the export raises a clear error for that case. Check the maintainers' preferred resolution before writing code.
Written by the indexing model from the issue text.
Description
Problem
Exporting an accepted multi-qubit measurement condition to OpenQASM 2 changes which branch executes. Cirq treats the first measured bit as the most significant bit of the measurement-key integer, while the exporter writes it to classical-register index 0, the least significant bit in OpenQASM 2. The equality constant is emitted unchanged.
Reproduction
import cirq
import sympy
from cirq.contrib.qasm_import import circuit_from_qasm
q0, q1, out = cirq.LineQubit.range(3)
circuit = cirq.Circuit(
cirq.X(q0),
cirq.measure(q0, q1, key="m"),
cirq.X(out).with_classical_controls(sympy.Eq(sympy.Symbol("m"), 2)),
cirq.measure(out, key="out"),
)
text = cirq.qasm(circuit)
print(text)
print("source:", cirq.Simulator().run(circuit).records["out"].tolist())
print("exported:", cirq.Simulator().run(circuit_from_qasm(text)).records["m_out_0"].tolist())
Output includes:
measure q[0] -> m_m[0];
measure q[1] -> m_m[1];
if (m_m==2) x q[2];
source: [[[1]]]
exported: [[[0]]]
The source measurement is [1, 0], so the Cirq condition m == 2 is true and the output should be 1. In the emitted QASM, m_m[0] = 1 and m_m[1] = 0 mean integer 1, making the emitted condition false. This is observable directly from the emitted text using the OpenQASM 2 specification, page 7, which defines index zero as the low-order bit; it does not require assuming general round-trip support.
Expected behavior and checks
The emitted program should preserve the accepted source condition's meaning, or explicitly reject an unsupported case.
I also checked the asymmetric [0, 1] / m == 1 case (source 1, exported 0), and [1, 0] / m == 1 (source 0, exported 1). The all-ones [1, 1] / m == 3 and a single-bit condition are preserved. Separately hand-written QASM with the same register assignments executes according to the specification in the importer, pointing to the export-side mapping.
MeasurementGate._qasm_ assigns measurement position i to register index i; SympyCondition._qasm_ emits the equality constant unchanged. These two source files on current main were inspected on 2026-11-13 and match the installed files. Current main as a whole was not executed.
Related #7624 concerns exporting an imported register condition represented by multiple Cirq keys. This example starts with one native multi-bit measurement and one supported SympyCondition, successfully exports it once, and changes the guard's meaning in that first output.
Environment: Cirq 1.8.0.dev20261111222613, Python 3.12.13, macOS arm64. AI assistance was used to prepare this report; the code above was executed in the stated environment. No patch is included.
- Dominant language
- Python
- Stars
- 5.1k
- Forks
- 1.3k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 48
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from quantumlib/Cirq
-
Potential missed optimization: `drop_diagonal_before_measurement` leaves an identity `PhasedXZGate` that blocks further removalPossibly taken @jangyoujin0917 claimed this 22 days ago. Openarea/gates area/optimization kind/feature-request triage/accepted
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
quantumlib/Cirq#8523 · 1 comment ·
Maintainers usually reply within 1 day
-
`defer_measurements` ignores `BitMaskKeyCondition.index` and changes circuit behaviorMay be free again @Tejendra-06 claimed this 54 days ago, and no pull request is open. Opengood for learning help wanted kind/bug-report skill/experienced triage/accepted triage/wont-fix
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
quantumlib/Cirq#8361 · 8 comments · 1 assignee ·
Maintainers usually reply within 1 day
-
kind/feature-request triage/discuss
quantumlib/Cirq#8598 ·
Maintainers usually reply within 1 day
-
area/docstrings area/google kind/bug-report triage/discuss
Difficulty 1/5 1-3 hours Newbie friendliness 91/100
quantumlib/Cirq#8587 ·
Maintainers usually reply within 1 day
-
kind/bug-report triage/discuss
Difficulty 2/5 1-3 hours Newbie friendliness 57/100
quantumlib/Cirq#8580 ·
Maintainers usually reply within 1 day
Similar issues
-
docs(contributing): the two things that silently block a PRPossibly taken A pull request linked to this issue is open or already merged. Openavailable documentation good first issue
Difficulty 1/5 1-3 hours Newbie friendliness 95/100
Nixitov/Riptide-Native#944 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
JTHCode/secretguard#24 ·
Maintainers usually reply within 1 day
-
area: middleware documentation good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
enhancement good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
good first issue
Difficulty 1/5 Under an hour Newbie friendliness 95/100
omarelshamy25x/shamy-hijri#63 ·
Maintainers usually reply within 1 day