🐛 Verify modifier bodies at the dialect boundary - #2319
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Measurement lifting could erase or move effectful support operations across a measurement. Refuse these rewrites when modifier bodies are not memory-effect free while retaining optimization for pure classical support computations. Assisted-by: GPT-5.6 via Codex
df1ffbc to
c933b52
Compare
There was a problem hiding this comment.
That's an edge case I didn't think about, but I also have some concerns about it.
In particular, I'm not very convinced by the example test case. I assume the @observe function should represent a function that contains a measurement. But it's not really reasonable to invert a measurement.
In fact, I would say the contents of an qco.inv modifier should always be unitary. That means the only way to have actual memory effects in there is to have a gphase operation, because that adds a global phase with no targeted qubits (but actually, in that case, I don't even know if the inv modifier allows 0 target qubits.
Similarly, qco.ctrl also only makes sense for unitaries.
What are your thoughts on that?
Thanks a lot for the review, you're right, the func.call example is invalid modifier content. I will retarget this PR to reject unknown/effectful non-unitary operations in both modifier verifiers while permitting pure classical support and UnitaryOpInterface operations. The audit produced a lot of edge cases that are quite hypothetical. |
Apply the review fix on the current verifier and test infrastructure. Assisted-by: GPT-5.6 via Codex
Reject effectful, non-speculatable, and qubit-carrying non-unitary operations in QC and QCO modifier bodies while retaining pure classical support and all UnitaryOpInterface operations. Reject unrepresentable controlled global phases before mutating the QIR conversion state, and let measurement lifting rely on verified IR. Assisted-by: GPT-5.6 via Codex
Keep the shared recursive qubit-type predicate, but inline the helpers that each had a single caller into the QC and QCO modifier verification paths. Assisted-by: GPT-5.6 via Codex
There was a problem hiding this comment.
Hi @simon1hofmann, thanks for the update! Looks quite reasonable, I think it's good to make these verifications in advance.
I do have some minor concerns on the correctness/completeness of the implementation though, but I'm not 100% sure on any of them.
Assisted-by: GPT-5.6 via Codex # Conflicts: # mlir/lib/Dialect/QC/IR/Modifiers/ModifierUtils.cpp # mlir/lib/Dialect/QCO/IR/Modifiers/ModifierUtils.cpp # mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp
Exercise the control-reordering guard separately from the phase-erasure guard so either unsafe rewrite causes the regression to fail. Assisted-by: GPT-5.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 |
🤖 AI text below 🤖
Description
Reject invalid operations at the QC and QCO modifier boundary instead of adding pass-local guardrails to measurement lifting.
Modifier bodies may contain operations implementing
UnitaryOpInterfaceand pure, speculatable, qubit-free classical support computations. Effectful or unknown operations, register access, and non-unitary operations carrying qubits are rejected by the dialect verifiers. Measurement lifting can consequently assume valid IR and no longer needs its redundant memory-effect checks.The QIR conversion also rejects controlled global phases before mutating or inlining the control region. This preserves the existing diagnostic for valid multi-block classical computations that produce a non-hoistable phase angle.
Part of #2255.
Validation
nox -s lintChecklist
skip-changeloglabel is applied.If PR contains AI-assisted content:
🤖 *AI text below* 🤖(titles are exempt).