✨ Add two-qubit Weyl (KAK) decomposition library#1803
Conversation
…e tolerance checks in existing tests
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughSummary by CodeRabbit
WalkthroughAdds a full two-qubit Weyl decomposition and basis-gate synthesis pipeline to the MLIR QCO dialect. New rotation and i-Pauli matrix primitives are introduced in the Matrix utility layer, ChangesWeyl Two-Qubit Decomposition Pipeline
Sequence Diagram(s)sequenceDiagram
participant Caller
participant decomposeTwoQubitWithBasis
participant TwoQubitWeylDecomposition
participant TwoQubitBasisDecomposer
participant diagonalizeComplexSymmetric
Caller->>decomposeTwoQubitWithBasis: target Matrix4x4, basisMatrix, basisFidelity, numBasisUses
decomposeTwoQubitWithBasis->>TwoQubitBasisDecomposer: create(basisMatrix, basisFidelity)
TwoQubitBasisDecomposer->>TwoQubitWeylDecomposition: create(basisMatrix, basisFidelity)
TwoQubitWeylDecomposition->>diagonalizeComplexSymmetric: M·Mᵀ in magic basis
diagonalizeComplexSymmetric-->>TwoQubitWeylDecomposition: eigenphases → a, b, c
TwoQubitWeylDecomposition-->>TwoQubitBasisDecomposer: basis Weyl decomposition
TwoQubitBasisDecomposer-->>decomposeTwoQubitWithBasis: TwoQubitBasisDecomposer instance
decomposeTwoQubitWithBasis->>TwoQubitWeylDecomposition: create(target, nullopt)
TwoQubitWeylDecomposition-->>decomposeTwoQubitWithBasis: target Weyl decomposition
decomposeTwoQubitWithBasis->>TwoQubitBasisDecomposer: twoQubitDecompose(targetWeyl, numBasisUses)
TwoQubitBasisDecomposer->>TwoQubitBasisDecomposer: score traces 0..3, select best count
TwoQubitBasisDecomposer->>TwoQubitBasisDecomposer: decomp0/1/2/3 → single-qubit factors
TwoQubitBasisDecomposer-->>decomposeTwoQubitWithBasis: optional TwoQubitNativeDecomposition
decomposeTwoQubitWithBasis-->>Caller: optional TwoQubitNativeDecomposition
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 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
🤖 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/Decomposition/Weyl.cpp`:
- Around line 112-118: The hardcoded constants 1.2602066112249388 and
0.22317849046722027 assigned to randA and randB in the if (i == 0) block lack
documentation about their origin and purpose. Add a comment above the if
statement explaining that these are perturbation coefficients specifically
chosen for the first diagonalization attempt, likely derived from a reference
implementation such as Qiskit, to clarify why these specific values are used for
the initial iteration while subsequent iterations use randomly generated values
from the distribution.
In
`@mlir/unittests/Dialect/QCO/Transforms/Decomposition/test_weyl_decomposition.cpp`:
- Around line 189-193: The test fixture classes WeylDecompositionTest and
BasisDecomposerTest are defined at translation unit scope without internal
linkage, triggering a clang-tidy warning. Wrap these class definitions (and any
related helper code that is only used within this test file) in an anonymous
namespace to limit their visibility to internal linkage and resolve the warning.
🪄 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: b251ecb4-6a99-454e-a2b7-dc6a2ce6d4c6
📒 Files selected for processing (9)
mlir/include/mlir/Dialect/QCO/Transforms/Decomposition/Euler.hmlir/include/mlir/Dialect/QCO/Transforms/Decomposition/Weyl.hmlir/include/mlir/Dialect/QCO/Utils/Matrix.hmlir/lib/Dialect/QCO/Transforms/Decomposition/Euler.cppmlir/lib/Dialect/QCO/Transforms/Decomposition/Weyl.cppmlir/lib/Dialect/QCO/Utils/Matrix.cppmlir/unittests/Dialect/QCO/Transforms/Decomposition/CMakeLists.txtmlir/unittests/Dialect/QCO/Transforms/Decomposition/test_euler_decomposition.cppmlir/unittests/Dialect/QCO/Transforms/Decomposition/test_weyl_decomposition.cpp
💤 Files with no reviewable changes (1)
- mlir/unittests/Dialect/QCO/Transforms/Decomposition/test_euler_decomposition.cpp
… behavior in Weyl decomposition diagonalization
|
@coderabbitai review |
✅ Action performedReview finished.
|
Description
Adds a two-qubit Weyl (KAK) decomposition on top of
Matrix4x4. A 4×4 unitary is factored as(K1l ⊗ K1r) · U_canon(a,b,c) · (K2l ⊗ K2r)up to global phase, with optional canonical-gate specialization and basis-gate (CX/CZ) synthesis.This PR is intentionally scoped to the decomposition library + tests. It does not wire an MLIR pass, emit gate sequences, or add
NativeProfile/ fuse-pass integration — those are planned follow-ups.New API (
mlir/Dialect/QCO/Transforms/Decomposition/Weyl.h)TwoQubitWeylDecomposition— KAK decomposition with Weyl-chamber reduction and 10 canonical-gate specializations (identity, SWAP, partial-SWAP ±, controlled, mirror-controlled, fSim variants)TwoQubitBasisDecomposer— decomposes a Weyl result into single-qubit factors + basis-gate count (0–3 uses)Supporting changes
Matrix.h/Matrix.cpp— shared gate matrix factories:rx/ry/rz,iPauliX/Y/Z,rxx/ryy/rzzEuler.h/Euler.cpp— promoteEulerAnglesandanglesFromUnitary()to public API (used by Weyl specialization for controlled / fSim cases)Checklist
If PR contains AI-assisted content:
Assisted-by: [Model Name] via [Tool Name]footer.