🚸 Remove One-Tensor Constraint From Mapping Pass#1748
Conversation
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
📝 WalkthroughWalkthroughTensorIterator gains an ChangesTensorIterator and Mapping Pass Multi-AllocOp Support
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
mlir/unittests/Dialect/QTensor/Utils/test_tensoriterator.cpp (1)
148-153:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winAdd a round-trip assertion (rewind then forward) to cover
isFinal_state reset.These additions check sentinel idempotence, but they still miss the regression where
--from sentinel leaves a stale final-state and the next++jumps to sentinel again.Suggested test additions
--it; ASSERT_EQ(it.operation(), tensor0.getDefiningOp()); // qtensor.alloc ASSERT_EQ(it.tensor(), tensor0); + ++it; + ASSERT_EQ(it.operation(), tensor1.getDefiningOp()); // qtensor.extract + ASSERT_EQ(it.tensor(), tensor1); + --it; ASSERT_EQ(it.operation(), tensor0.getDefiningOp()); // qtensor.alloc ASSERT_EQ(it.tensor(), tensor0); @@ --recIt; ASSERT_EQ(recIt.operation(), nullptr); ASSERT_EQ(recIt.tensor(), tensorElse0); + ++recIt; + ASSERT_EQ(recIt.operation(), tensorElse1.getDefiningOp()); // qtensor.extract + ASSERT_EQ(recIt.tensor(), tensorElse1); + --recIt; ASSERT_EQ(recIt.operation(), nullptr); ASSERT_EQ(recIt.tensor(), tensorElse0);Also applies to: 222-223
🤖 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/unittests/Dialect/QTensor/Utils/test_tensoriterator.cpp` around lines 148 - 153, The test currently checks that incrementing an iterator at sentinel is idempotent but misses the regression where decrementing from sentinel leaves the iterator's internal isFinal_ flag stuck; add a round-trip check that does --it then ++it and asserts the iterator does not immediately re-enter std::default_sentinel (use the existing iterator variable it and the ++/-- operators) to verify isFinal_ is reset, and apply the same round-trip assertion at the other similar spot in the test (the block around the other ++it assertion).
🤖 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/lib/Dialect/QCO/Transforms/Mapping/Mapping.cpp`:
- Around line 471-489: The code flattens all qtensor.extract into a single
global wires list and never frees the assigned program indices, so
getComputation()/place() cumulatively count qubits across disjoint tensors;
update the logic to track per-alloc lifetimes and reuse/release prog indices
when the matching qtensor.insert is encountered: iterate allocs from
func.getOps<qtensor::AllocOp>() with TensorIterator/ExtractOp and InsertOp,
maintain a per-alloc active set (or reference-counted mapping) of wires->prog
assignments instead of a single global wires vector, on seeing an InsertOp
remove/release the corresponding prog index(s) so place() and comp->size()
reflect the peak concurrent qubits rather than the sum of all extracts, and
ensure runOnOperation() compares device.nqubits() against the maximum
live-program-qubit count computed this way.
In `@mlir/lib/Dialect/QTensor/Utils/TensorIterator.cpp`:
- Around line 47-51: When marking the iterator as a sentinel (setting
isSentinel_ = true) make sure to clear the terminal flag by resetting isFinal_ =
false so rewinding doesn't leave the iterator in a stale "final" state; update
the places that set isSentinel_ (the increment/advance logic/operator++ and the
corresponding rewind/decrement logic/operator--) to also clear isFinal_ when
transitioning states so a subsequent ++/-- behaves correctly.
---
Outside diff comments:
In `@mlir/unittests/Dialect/QTensor/Utils/test_tensoriterator.cpp`:
- Around line 148-153: The test currently checks that incrementing an iterator
at sentinel is idempotent but misses the regression where decrementing from
sentinel leaves the iterator's internal isFinal_ flag stuck; add a round-trip
check that does --it then ++it and asserts the iterator does not immediately
re-enter std::default_sentinel (use the existing iterator variable it and the
++/-- operators) to verify isFinal_ is reset, and apply the same round-trip
assertion at the other similar spot in the test (the block around the other ++it
assertion).
🪄 Autofix (Beta)
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
Run ID: 955d21bd-c373-467e-8aa8-cef6d20949d1
📒 Files selected for processing (6)
mlir/include/mlir/Dialect/QTensor/Utils/TensorIterator.hmlir/lib/Dialect/QCO/Transforms/CMakeLists.txtmlir/lib/Dialect/QCO/Transforms/Mapping/Mapping.cppmlir/lib/Dialect/QTensor/Utils/TensorIterator.cppmlir/unittests/Dialect/QCO/Transforms/Mapping/test_mapping.cppmlir/unittests/Dialect/QTensor/Utils/test_tensoriterator.cpp
burgholzer
left a comment
There was a problem hiding this comment.
Besides one broken docstring, this looks very clean to me!
Description
This pull request is a follow-up of #1716 and lifts the assumption that the quantum computation consists of a single quantum tensor. By doing so, we support programs such as the
qpeexactones generated by MQT-Bench.Changes
Checklist
If PR contains AI-assisted content:
Assisted-by: [Model Name] via [Tool Name]footer.