✨ Enhance QCOProgramBuilder with tracked qubit and tensor structures - #2017
✨ Enhance QCOProgramBuilder with tracked qubit and tensor structures#2017simon1hofmann wants to merge 7 commits into
Conversation
- Introduced `Qubit` and `Tensor` structs to encapsulate SSA values along with their register information. - Updated methods `allocQubit` and `staticQubit` to return `Qubit` instances instead of raw `Value`. - Modified internal tracking of valid qubits and tensors to utilize `DenseSet` for improved management. - Enhanced unit tests to validate the new structures and their integration within the builder. * Updated CHANGELOG to reflect changes related to PR #2017.
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. |
📝 WalkthroughSummary by CodeRabbit
Walkthrough
ChangesQCO tracking refactor
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related PRs
Suggested labels: Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches✨ 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 |
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/include/mlir/Dialect/QCO/Builder/QCOProgramBuilder.h`:
- Around line 173-206: Add Doxygen documentation to the public Qubit and Tensor
constructors, implicit Value conversion operators, getType(), and both
getDefiningOp() overloads. Describe the conversion direction and state that
getDefiningOp() may return a null operation when the value has no defining
operation; document both the non-templated and templated accessors consistently.
🪄 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: 5bd9e4b3-942b-45fa-9da5-145c0f5b89bb
📒 Files selected for processing (5)
CHANGELOG.mdmlir/include/mlir/Dialect/QCO/Builder/QCOProgramBuilder.hmlir/lib/Dialect/QCO/Builder/QCOProgramBuilder.cppmlir/unittests/Dialect/QCO/IR/test_qco_ir.cppmlir/unittests/Dialect/QCO/Transforms/Optimizations/test_qco_measurement_lifting.cpp
|
@coderabbitai review |
✅ Action performedReview 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/include/mlir/Dialect/QCO/Builder/QCOProgramBuilder.h`:
- Around line 179-180: Make the Qubit(Value, int64_t, Value) constructor
explicit to prevent implicit Value-to-Qubit conversions from discarding regId
and regIndex. Preserve explicit assignment-from-Value behavior only in
intentional metadata-reset paths such as updateQubitTracking.
🪄 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: 43432451-ea74-41ed-b509-2ea0de49393d
📒 Files selected for processing (1)
mlir/include/mlir/Dialect/QCO/Builder/QCOProgramBuilder.h
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
mlir/lib/Dialect/QCO/Builder/QCOProgramBuilder.cpp (1)
242-250: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win🤖 AI text below 🤖
Validate the tensor before dereferencing
find.
checkQubitTypechecks the tensor type, but it does not verify tracking membership. If an untracked tensor reachesprepareInitArg,validTensors.find(initArg)returnsend(), and->regIddereferences an invalid iterator. CallvalidateTensorValue(initArg)before the lookup.Suggested fix
if (isa<QubitType>(initArg.getType())) { return initArg; } + validateTensorValue(initArg); const auto regId = validTensors.find(initArg)->regId;🤖 Prompt for 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. In `@mlir/lib/Dialect/QCO/Builder/QCOProgramBuilder.cpp` around lines 242 - 250, In prepareInitArg, validate initArg with validateTensorValue before dereferencing the validTensors.find(initArg) result. Preserve the existing register-ID lookup and initialization flow after validation.
🤖 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.
Outside diff comments:
In `@mlir/lib/Dialect/QCO/Builder/QCOProgramBuilder.cpp`:
- Around line 242-250: In prepareInitArg, validate initArg with
validateTensorValue before dereferencing the validTensors.find(initArg) result.
Preserve the existing register-ID lookup and initialization flow after
validation.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 0d14e32f-eae8-465c-8518-24546e21887d
📒 Files selected for processing (3)
mlir/include/mlir/Dialect/QCO/Builder/QCOProgramBuilder.hmlir/lib/Dialect/QCO/Builder/QCOProgramBuilder.cppmlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp
…ntracked tensor initialization
denialhaag
left a comment
There was a problem hiding this comment.
Apart from the two small comments below, this LGTM! Thanks for the improvements to the QCOProgramBuilder, @simon1hofmann! 🙂
Co-authored-by: Daniel Haag <121057143+denialhaag@users.noreply.github.com> Signed-off-by: simon1hofmann <119581649+simon1hofmann@users.noreply.github.com>
🤖 AI text below 🤖
Description
DenseMap<Value, QubitInfo/TensorInfo>withDenseSet<Qubit/Tensor>keyed on the SSAValue, keeping register metadata on the handle itself.Qubithandles fromallocQubit()/staticQubit()(implicitly convertible toValue); add smallgetType()/getDefiningOp()forwards so common call sites stay ergonomic.Value/ValueRange.Fixes #1628
Checklist
If PR contains AI-assisted content:
🤖 *AI text below* 🤖(titles are exempt).