🎨 Retain register name - #2014
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
@coderabbitai full review |
✅ Action performedFull review finished. |
|
Warning Review limit reached
Next review available in: 9 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughSummary by CodeRabbit
WalkthroughThe change preserves quantum-register names across QC and QCO allocation, conversion, and translation paths. Named allocations store ChangesQuantum register name propagation
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant SourceRegister
participant Translation
participant AllocationBuilder
participant Conversion
participant OpenQASM3
SourceRegister->>Translation: provide register name
Translation->>AllocationBuilder: allocate register with name
AllocationBuilder->>AllocationBuilder: validate uniqueness
AllocationBuilder-->>Translation: return allocation with name attribute
Conversion->>Conversion: copy name attribute
OpenQASM3->>Conversion: read stored register name
Conversion-->>OpenQASM3: emit named register
Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
✨ Simplify code
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 |
burgholzer
left a comment
There was a problem hiding this comment.
This looks like a great start.
Just a few quick side comments:
- does the OpenQASM importer already do this? Feels like it should also preserve the name.
- is this attribute retained across dialect conversions? Ideally, it would propagate through the QCO conversion and lead to a nice OpenQASM roundtrip. (Maybe this is already handled though)
- is there anything to do for QIR emission? (Both on classical and quantum registers)
- is there anything to do for the OpenQASM emission?
denialhaag
left a comment
There was a problem hiding this comment.
Thanks a lot for getting this started, @simon1hofmann! 🙂
Below, you can find two things that jumped out to me. In addition to that, I agree with @burgholzer's comment above. I would expect some changes in the OpenQASM translations and the QIR conversions to be necessary. 🤔
You're right, these should be added as well. Concerning QIR emission, |
I think you are right; register names only make sense for classical registers in the context of output recording. 🤔 |
yeah. for QIR emission, quantum registers do not really matter 👍🏼 |
|
@coderabbitai review |
❌ Action failedReview failed.
|
|
@coderabbitai full review |
✅ Action performedFull review finished. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@mlir/unittests/Dialect/QC/Translation/test_openqasm3_emission.cpp`:
- Around line 530-545: Extend ReusesQuantumRegisterNames with an invalid stored
register name, then require strict OpenQASM parsing of the emitted result.
Assert the output does not declare the invalid name while preserving the
existing valid-name assertion.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: ce584dc3-5254-4e6c-aed3-fda634cf5aca
📒 Files selected for processing (18)
CHANGELOG.mdmlir/include/mlir/Dialect/QC/Builder/QCProgramBuilder.hmlir/include/mlir/Dialect/QCO/Builder/QCOProgramBuilder.hmlir/include/mlir/Dialect/Utils/Utils.hmlir/lib/Conversion/QCOToQC/QCOToQC.cppmlir/lib/Conversion/QCToQCO/QCToQCO.cppmlir/lib/Dialect/QC/Builder/QCProgramBuilder.cppmlir/lib/Dialect/QC/Translation/OpenQASMToQCEmitter.cppmlir/lib/Dialect/QC/Translation/TranslateQCToOpenQASM3.cppmlir/lib/Dialect/QC/Translation/TranslateQuantumComputationToQC.cppmlir/lib/Dialect/QCO/Builder/QCOProgramBuilder.cppmlir/unittests/Conversion/QCOToQC/test_qco_to_qc.cppmlir/unittests/Conversion/QCToQCO/test_qc_to_qco.cppmlir/unittests/Dialect/QC/IR/test_qc_ir.cppmlir/unittests/Dialect/QC/Translation/test_openqasm3_emission.cppmlir/unittests/Dialect/QC/Translation/test_qasm3_translation.cppmlir/unittests/Dialect/QC/Translation/test_quantum_computation_translation.cppmlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp
|
@coderabbitai review |
|
denialhaag
left a comment
There was a problem hiding this comment.
This looks really clean to me now! I have three more comments, but I'll already now to not blcok the PR further. I'll leave the final say to @burgholzer. 😌
| /// Attribute used to retain a source-level quantum-register name. | ||
| inline constexpr llvm::StringLiteral QUANTUM_REGISTER_NAME_ATTR = | ||
| "mqt.quantum_register_name"; |
There was a problem hiding this comment.
This applies to quite a few places, but I think we should generally go with qubit register instead of quantum register. 🤔
| /// Attribute used to retain a source-level quantum-register name. | |
| inline constexpr llvm::StringLiteral QUANTUM_REGISTER_NAME_ATTR = | |
| "mqt.quantum_register_name"; | |
| /// Attribute used to retain a source-level qubit-register name. | |
| inline constexpr llvm::StringLiteral QUBIT_REGISTER_NAME_ATTR = | |
| "mqt.qubit_register_name"; |
| /// Track non-empty source-level quantum register names. | ||
| llvm::StringSet<> quantumRegisterNames; |
There was a problem hiding this comment.
Also here, for example.
| /// Track non-empty source-level quantum register names. | |
| llvm::StringSet<> quantumRegisterNames; | |
| /// Track non-empty source-level qubit-register names. | |
| llvm::StringSet<> qubitRegisterNames; |
| } | ||
|
|
||
| )mlir"; |
There was a problem hiding this comment.
| } | |
| )mlir"; | |
| } | |
| )mlir"; |
🤖 AI text below 🤖
Description
This PR retains source-level quantum-register names when translating a
QuantumComputationto the QC dialect.The register name is attached to the generated
memref.allocusing the newmqt.quantum_register_namestring attribute, matching the existing handling of classical-register names.Fixes #1616.
Checklist
If PR contains AI-assisted content:
🤖 *AI text below* 🤖(titles are exempt).