Skip to content

🐛 Fix and simplify QCO decomposition - #2478

Open
simon1hofmann wants to merge 2 commits into
mainfrom
codex/decomposition-audit-fixes
Open

🐛 Fix and simplify QCO decomposition#2478
simon1hofmann wants to merge 2 commits into
mainfrom
codex/decomposition-audit-fixes

Conversation

@simon1hofmann

@simon1hofmann simon1hofmann commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

🤖 AI text below 🤖

Description

Fix decomposition and fusion on valid QCO IR, and remove repeated work without adding pass-local IR verification or relaxing numerical tolerances.

  • Count all participating qubits in single-qubit fusion, including controlled global phases.
  • Make numerical Weyl failure recoverable: optional fusion leaves the affected run unchanged, while required native synthesis reports failure before emitting its replacement.
  • Run optional generic two-qubit fusion only for unrestricted targets or targets with a usable two-qubit synthesis basis. Already-native CX-only and U+DCX programs remain compilable.
  • Preserve small rotations with stable quaternion-to-Euler extraction. Use sparse ZYZ products and direct RX/RY-to-R synthesis without combining input half angles or changing phase accounting.
  • Reuse embedded matrix kernels and cache pending one-qubit matrices. Flatten SP22 planning and remove unreachable HP24 alternatives, identity maps, and redundant basis-count selection work.
  • Retain semantic, phase, wire-order, and gate-cost regressions while removing redundant test scaffolding.

Updated against main at 4c5e45855, including #2464 and the target-environment API. Its centralized modifier-matrix handling is retained unchanged at the getters; this PR optimizes the shared composer while preserving full-width, idle-target, zero-target, ordered-yield, and width-limit behavior. The duplicate getter fix was dropped. The update keeps the parameterless target pass factories and adapts the affected regression tests to the typed target environment. Numerical-failure documentation remains in the pass definition.

C++ API note: decomposeUnitary2QWeyl now returns an optional result. TwoQubitWeylDecomposition::tryCreate provides the recoverable path; create retains its success-required contract. Related decomposition work in #2467 and #2468 is not duplicated.

No new dependencies. Detailed audit notes and standalone experimental probes are excluded from the PR.

Validation

  • Release rebuild with LLVM/MLIR 23.1.0: 1,374 tests passed across decomposition (242), native synthesis (52), optimizations (197), QCO IR (512), QCO utilities (190), and compiler (181).
  • uvx nox -s lint: passed.
  • Whole-file uvx nox -s cpp-lint: passed across all 15 changed C++ implementation/test files, with zero findings.
  • mlir-doc generation: passed.
  • Historical implementation validation: the Python reference script ran all 18 cases. Independent probes confirmed zero SWAP error and a small-angle error reduction from approximately 7.1e-9 to 2.5e-17 before integration with main; the native regression suites were rerun for this update. The standalone probes were not rerun.

Local clang-tidy is 23.0.0git, not CI's 23.1.1. Hosted CI must rerun on the updated head. Local coverage, Python binding tests, and a full Sphinx build were not rerun for this update; results from the previous head are not claimed for the new commit.

Checklist

  • The pull request only contains commits that are focused and relevant to this change.
  • I have added appropriate tests that cover the new/changed functionality.
  • I have updated the documentation to reflect these changes.
  • Changelog entries: not applicable to this unreleased v4 functionality, per repository policy.
  • Upgrade guide: no standalone entry for unreleased functionality; the C++ API contract is documented in its header.
  • The changes follow the project's style guidelines and introduce no new warnings in local checks.
  • The changes are fully tested and pass the CI checks. Local checks passed; hosted CI pending.
  • I have reviewed my own code changes. Independent agent review completed; personal human review remains to be confirmed.

AI assistance: Codex assisted with the audit, implementation, tests, independent review, and PR preparation. A human must review the contribution before accepting or merging it.

  • Any agent that created, edited, or submitted GitHub content was explicitly authorized for that scope, as required by the AI Usage Guidelines.
  • Every agent-authored or agent-edited public text body begins with the visible disclosure 🤖 *AI text below* 🤖 (titles are exempt).
  • I have disclosed AI assistance in the PR description.
  • I confirm that I have personally reviewed and understood all AI-generated content, and accept full responsibility for it.

Keep single-qubit fusion, numerical Weyl failure, native-target synthesis,
and small rotations correct on valid QCO IR.

Reuse embedded matrix kernels, cache pending matrices, and reduce
multi-controlled planning and runtime rotation arithmetic. Retain the
modifier-matrix contract already merged in #2464.

Preserve phase, numerical tolerances, supported widths, and gate-cost
contracts with semantic regressions.

Assisted-by: Codex
@simon1hofmann simon1hofmann added refactor Anything related to code refactoring fix Fix for something that isn't working c++ Anything related to C++ code MLIR Anything related to MLIR skip-changelog Changes that do not need to show up in the changelog labels Sep 8, 2026
@codecov

codecov Bot commented Sep 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.88372% with 11 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
.../lib/Dialect/QCO/Transforms/Decomposition/Weyl.cpp 84.4% 7 Missing ⚠️
mlir/lib/Dialect/QCO/IR/QCOUtils.cpp 85.7% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

@mergify mergify Bot added the conflict label Sep 8, 2026
burgholzer added a commit that referenced this pull request Sep 8, 2026
Preserve small interactions with stable beta extraction and use the
analytic prefix instead of searching equivalent basis gates. Reuse
matrix reconstruction and attach fixed-basis local factors directly.

Repair native operand orientation without requiring a synthesis basis.
Skip generic CX/CZ-cost fusion for this target to avoid increasing native
gate counts, and document the per-unitary optimality limit.

Leave the shared decomposition failure and fusion work to #2478.

Assisted-by: GPT-6 via Codex
Keep the typed target environment and generated pass factories from main. Adapt the affected regression tests and preserve the numerical failure contract in the pass definition.

Assisted-by: Codex
burgholzer added a commit that referenced this pull request Sep 8, 2026
Preserve small interactions with stable beta extraction and use the
analytic prefix instead of searching equivalent basis gates. Reuse
matrix reconstruction and attach fixed-basis local factors directly.

Repair native operand orientation without requiring a synthesis basis.
Skip generic CX/CZ-cost fusion for this target to avoid increasing native
gate counts, and document the per-unitary optimality limit.

Leave the shared decomposition failure and fusion work to #2478.

Assisted-by: GPT-6 via Codex
@mergify mergify Bot added the conflict label Sep 8, 2026
burgholzer added a commit that referenced this pull request Sep 9, 2026
* ✨ Add optimal square-root iSWAP synthesis

Synthesize numeric two-qubit blocks with zero to three square-root iSWAP gates and expose the fixed gate as a compiler target capability.

Assisted-by: GPT-6 via Codex

* 📝 Remove unnecessary synthesis documentation

Remove the added guide and glossary sections and modification comments.

Assisted-by: GPT-6 via Codex

* ♻️ Fold square-root iSWAP tests into Weyl tests

Keep two-qubit Weyl synthesis coverage in the existing test file.

Assisted-by: GPT-6 via Codex

* 📝 Simplify square-root iSWAP reference comment

Keep the equation reference next to the interleaving rotations.

Assisted-by: GPT-6 via Codex

* ♻️ Simplify square-root iSWAP synthesis details

Inline the margin calculation, shorten comments, and format the gate matrix by row.

Assisted-by: GPT-6 via Codex

* ♻️ Use the explicit Weyl decomposition type

Remove the KAK alias from square-root iSWAP synthesis.

Assisted-by: GPT-6 via Codex

* 🎨 Format the square-root iSWAP test matrix

Keep each matrix row on a separate line with row comments.

Assisted-by: GPT-6 via Codex

* ♻️ Keep Python coverage focused on bindings

Move the target enum check into the existing MLIR tests and leave gate-count and synthesis correctness coverage to C++.

Assisted-by: GPT-6 via Codex

* 🧪 Remove redundant Python target enum test

Assisted-by: GPT-6 via Codex

* 📝 Fold sqrt(iSWAP) into synthesis changelog

Assisted-by: GPT-6 via Codex

* 📝 Preserve existing changelog wording

Assisted-by: GPT-6 via Codex

* 🐛 Include parameter utilities in compiler target

Assisted-by: GPT-6 via Codex

* 🐛 Qualify complex type in Weyl tests

Assisted-by: GPT-6 via Codex

* 🐛 Stabilize sqrt(iSWAP) synthesis near CNOT

Use a rationalized half-angle formula to avoid cancellation near zero rotations. Resolve the clang-tidy diagnostics in synthesis and its tests.

Assisted-by: GPT-6 via Codex

* 🎨 Add trailing comma in placement test

Assisted-by: GPT-6 via Codex

* 🐛 Fix and simplify square-root iSWAP synthesis

Preserve small interactions with stable beta extraction and use the
analytic prefix instead of searching equivalent basis gates. Reuse
matrix reconstruction and attach fixed-basis local factors directly.

Repair native operand orientation without requiring a synthesis basis.
Skip generic CX/CZ-cost fusion for this target to avoid increasing native
gate counts, and document the per-unitary optimality limit.

Leave the shared decomposition failure and fusion work to #2478.

Assisted-by: GPT-6 via Codex

* 📝 Remove unnecessary square-root iSWAP guide section

* 🐍 Align the Python SQRTISWAP enum spelling

Assisted-by: GPT-6 via Codex

* 🎨 Wrap the combined synthesis changelog entry

Assisted-by: GPT-6 via Codex

---------

Co-authored-by: Lukas Burgholzer <burgholzer@me.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Anything related to C++ code conflict fix Fix for something that isn't working MLIR Anything related to MLIR refactor Anything related to code refactoring skip-changelog Changes that do not need to show up in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant