✨ Support fixed-width classical registers across formats - #2297
✨ Support fixed-width classical registers across formats#2297simon1hofmann wants to merge 9 commits into
Conversation
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
1823237 to
d487c05
Compare
d487c05 to
8916c83
Compare
|
@coderabbitai full review |
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Team Run ID: 📒 Files selected for processing (8)
Included review availability: Your plan provides up to 2 included reviews per hour; 0 remain after this review. 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.
📝 SummarySummary by CodeRabbit
WalkthroughThe OpenQASM frontend now parses sized ChangesBit-register cast support
Estimated code review effort: 3 (Moderate) | ~25 minutes Merge Risk: ⚪ Minimal · up to This PR adds validated, width-bounded OpenQASM integer casts within the existing frontend and verification flow; no actionable merge-blocking risk remains beyond normal checks and review. Suggested reviewers: Sequence Diagram(s)sequenceDiagram
participant OpenQASMParser
participant OpenQASMSemantics
participant OpenQASMToQCEmitter
participant QCIR
OpenQASMParser->>OpenQASMSemantics: Parse int or uint bit-register cast
OpenQASMSemantics->>OpenQASMToQCEmitter: Lower to BitVectorCast
OpenQASMToQCEmitter->>QCIR: Pack and extend cast value
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Linked Issues checkExplanation The changes satisfy issue Full details: Docstring CoverageExplanation Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 39 functions across 7 files. (1 skipped: 1 unsupported.) Full details: Description checkExplanation The description includes a detailed summary, motivation, issue reference, implementation scope, limitations, validation results, AI disclosure, and a completed checklist. It satisfies the required template. 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 |
|
@coderabbitai full review |
|
|
@coderabbitai full review |
✅ Action performedFull review finished. |
8916c83 to
4d5c6a1
Compare
c5032c4 to
ab336c6
Compare
ab336c6 to
fda9242
Compare
|
Also made this one a fair bit more general and hopefully usable. |
bbd9777 to
fc5a2b3
Compare
Use arith::CmpIPredicate across CBit, OpenQASM, Qiskit, and DD evaluation. Restrict cbit.cmp to the six unsigned predicates and reuse MLIR's evaluator where possible. Assisted-by: Codex Signed-off-by: Lukas Burgholzer <burgholzer@me.com>
Parse sized int and uint casts from initialized bit registers and lower their little-endian representation through the existing QC bit-vector path. Preserve signedness, integer promotions, and clear width diagnostics. Assisted-by: GPT-5.6 Sol via Codex Signed-off-by: Simon Hofmann <simon.t.hofmann@tum.de>
Represent whole-register snapshots and writes with cbit.read and cbit.write. Reuse fixed-width integer operations for bitwise expressions across OpenQASM and Qiskit. Preserve signed comparison semantics with sign-bit biasing. Reject exports when a target cannot preserve snapshot or type semantics. Assisted-by: GPT-5.6 Sol via Codex Signed-off-by: Lukas Burgholzer <burgholzer@me.com>
Classify whole-register reads and writes in Adaptive QIR returned-register analysis. Reject forwarded returned writes before lowering. Reuse the indexed OpenQASM snapshot validation and update parent tests to MLIR comparison predicates. Assisted-by: GPT-5.6 Sol via Codex Signed-off-by: Lukas Burgholzer <burgholzer@me.com>
Import and export bit, indexed-register, and atomic whole-register Store instructions. Preserve signed comparisons through an exact Qiskit boundary encoding. Delete generic comparison reconstruction and share CBit decomposition between MemRef and Adaptive QIR lowering. Assisted-by: GPT-5.6 Sol via Codex Signed-off-by: Lukas Burgholzer <burgholzer@me.com>
fc5a2b3 to
7bc22a4
Compare
burgholzer
left a comment
There was a problem hiding this comment.
Alright, this has become a bit of a monster. But I still think this is quite useful and expands the capabilities of the OpenQASM and Qiskit support.
Maybe you could run it through a sanity check on your side (maybe that finds a few simplifications)?
This is good to go from my side.
I went through the changes and they look quite good to me. Also ran it through ponytail again, but that did not flag any over engineering or possible simplifications. Just three findings regarding correctness, see comments. |
Thanks! I added a few replies. I'll hand that back to Codex, iterate once, then likely merge this. It feels ready 😌 |
Keep CBit for storage and use arith for exact-width integer computation. Share zero-filling shift and integer intrinsic lowering across formats. Extend OpenQASM and Qiskit expressions and legalize integers up to 64 bits for jeff. Preserve wide constant comparisons and array snapshot semantics. Reject register-valued QIR calls and fix simulator alias invalidation. Validate with 912 Python tests, 3828 C++ tests and one QDMI skip, plus computed-comparison regressions, documentation, stubs, and lint. Assisted-by: Codex Signed-off-by: Lukas Burgholzer <burgholzer@me.com>
Remove redundant Qiskit expression paths, dead OpenQASM state, and private CBit and QIR wrappers. Consolidate the classical expression design record. Preserve measurement snapshots, exact-width integer semantics, and jeff branch effects. Reject unsupported array snapshots and add regressions for the confirmed translation failures. Validate with 3,069 MLIR tests and 394 Python translation tests, plus general lint, C++ lint, and stub regeneration. Assisted-by: Codex
Gate Qiskit round trips on the supported adapter versions, including explicit candidate builds. Keep simulator, OpenQASM, and jeff checks active when minimum-dependency jobs install Qiskit 1.1.0. Validate all 140 interchange tests with Qiskit 1.1.0 and 2.5.2, plus general lint. Assisted-by: Codex
burgholzer
left a comment
There was a problem hiding this comment.
Alright, I took this for another spin after your comments. I repeatedly tried to cut the complexity from this PR. However, this is as far as I got. To be fair, I think this works quite will now.
If you are happy with it as well, then let's get it in.
🤖 AI text below 🤖
Description
Preserve fixed-width classical-register semantics across OpenQASM and Qiskit without reconstructing bit-load graphs in each exporter.
cbit.readandcbit.writefor whole-register snapshots and atomic updates. Keepcbit.cmpas the compact register-versus-constant operation for signed and unsigned predicates.int[N]casts use signed two's-complement ordering; direct bit-register anduint[N]comparisons use unsigned ordering.Storefor Clbits, indexed ClassicalRegisters, and whole ClassicalRegisters, including nested control flow.Runtime shift distances must be unsigned and less than the register width. Constant overshifts fold to zero. Qiskit expressions remain limited to 64 bits. Standalone Qiskit variables remain outside the CBit register model.
jeff supports arbitrary-width
cbit.cmpthrough per-bit array reads and Boolean logic. Generalcbit.readandcbit.writeremain rejected because jeff has neither arbitrary-width integer casts nor logical right shift; promoting values would require incomplete logical-width emulation. QIR Base rejects the same general whole-register forms, while Adaptive QIR lowers internal values.Fixes #2289
Validation
main.uv run --no-sync pytest -q test/python/test_mlir_qiskit_translation.py: 253 tests passed.uvx nox -s stubsuvx nox -s lintuvx nox -s cpp-lintgit diff --check7bc22a446.Codex assisted with implementation, simplification, independent review, validation, and this description under human direction.
Checklist
If PR contains AI-assisted content:
🤖 *AI text below* 🤖(titles are exempt).