🐛 Enforce terminal measurements in Base QIR - #2449
Conversation
Reject gates on measured qubits before moving measurements to the final block. Track static and register aliases while allowing later gates on independent qubits. Assisted-by: GPT-6 via Codex
Assisted-by: GPT-6 via Codex
Keep the static measurement-order helper outside the anonymous namespace without changing its internal linkage or behavior. Assisted-by: GPT-6 via Codex
burgholzer
left a comment
There was a problem hiding this comment.
LGTM in principle. One quick comment on the scope here that could potentially be simplified.
Feel free to resolve, then merge
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Keep constant-index register aliases, which Base lowering already accepts. Remove runtime-index alias tracking and its test and docs from this static-qubit ordering fix. Assisted-by: GPT-6 via Codex
Assisted-by: GPT-6 via Codex
|
Important Approval pendingCodeRabbit has no unresolved comments, but it has not reviewed the latest commit. Use the checkbox below to review the latest commit. CodeRabbit will approve the changes if it finds no blocking issues.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Preserve quantum instruction order until canonical qubit pointers are checked, then move measurements into the Base measurement block. Resolve repeated register loads once during lowering and reject unresolved or out-of-bounds indices and mixed allocation modes. Reject repeated Base measurements while retaining Adaptive support and QCO measurements whose qubits are inserted into a freed tensor. Assisted-by: GPT-6 via Codex
burgholzer
left a comment
There was a problem hiding this comment.
Cleaned this up a little. Should be good to go now ![]()
🤖 AI text below 🤖
Description
Base QIR lowering moved measurements behind all gates, so
measure q; x q;becamex q; measure q;. Lowering now preserves instruction order, checks canonical qubit pointers in one forward scan, and moves measurements only after validation succeeds. It rejects gates, measured controls, and repeated measurements on an already measured qubit, as required by the Base profile. Gates on independent qubits remain supported.Repeated loads of a constant register element reuse the same qubit pointer. Unresolved register references, runtime or out-of-bounds indices, and mixed static/allocation modes are rejected during resource lowering. QC and QCO use the same validation path; a measured QCO qubit can be inserted into a QTensor and then freed. Adaptive measurement behavior is unchanged.
Addresses the Base-profile ordering finding in #2287.
Local validation: 136 Base conversion tests, 152 Adaptive conversion tests, and 165 compiler tests passed with LLVM/MLIR 23.1.0.
uvx nox -s lintanduvx nox -s cpp-lint -- 80abe20f444d231e91e06df3deba5ff665ab3f55passed; the C++ check covers every line of all three changed C++ source/test files with clang-tidy 23.1.1. Hosted CI must validate the new head.GPT-6 via Codex assisted the implementation, tests, and PR text.
Checklist
If PR contains AI-assisted content:
🤖 *AI text below* 🤖(titles are exempt).