Skip to content

✨ Synthesize two-qubit blocks in the native basis - #2537

Open
burgholzer wants to merge 2 commits into
mainfrom
codex/initial-placement
Open

✨ Synthesize two-qubit blocks in the native basis#2537
burgholzer wants to merge 2 commits into
mainfrom
codex/initial-placement

Conversation

@burgholzer

@burgholzer burgholzer commented Sep 11, 2026

Copy link
Copy Markdown
Member

🤖 AI text below 🤖

Description

Both compile_for_target and synthesize_for_target now resynthesize constant two-qubit blocks in the selected native basis while preserving cheaper native operations. For example, non-native RZZ(0.3); RXX(0.4) needs two CZ gates together instead of four individually; a native SWAP/RZZ pair stays at two gates when block synthesis would need three. Unrestricted targets also optimize their blocks.

Both pipelines reuse the existing fusion implementation at two stages:

  • Before placement, replace a block only when both its two-qubit IR operation count and native cost decrease. This removes cancelled interactions before routing and keeps compact gate pairs intact. Native support is checked without assigning physical sites.
  • After placement/routing, resynthesize only when native two-qubit cost decreases, using the assigned sites and operand direction. Individual lowering preserves supported native gates and supplies the comparison cost.

Run scanning, Weyl decomposition, phase handling, and emission remain shared. Numerical block failures fall back to individual lowering; the standalone target-independent fusion factory remains available. The selected synthesis basis uses one entangler family and does not search arbitrary native mixtures or calibration costs. No new dependencies or block IR are added.

Validation and measurements

Release CTest: 3,537 passed, with one existing QDMI skip. All 90 Python MLIR tests, whole-file C++ lint, repository lint, and complete executable documentation/internal link checks passed. The final target-synthesis suite passes all 61 tests. Coverage includes full-unitary and phase preservation, pre-routing cancellation, native preservation, reversed connectivity, unrestricted optimization, numerical fallback, and routed measurement results.

Benchpress Small compares upstream main 8d9bcfb03 with this change: 42 circuits across four abstract topologies, five alternating samples per version and case (1,680 successful samples). Both builds use GCC 13.3, LLVM/MLIR 23.1.0, the release preset with LTO disabled, CPU 0 affinity, one routing trial, and seed 42. Targets use the id/sx/x/rz/cz basis with measurement, reset, and global phase. Timing includes the compiler pipeline, QC/QCO conversion, cleanup, and OpenQASM export; file import and target construction are excluded.

Topology Compile time Native two-qubit count Two-qubit depth
All-to-all +0.4% unchanged unchanged
Square +0.2% -2.0% -2.2%
Heavy-hex -0.6% -5.4% -5.9%
Linear -0.4% -4.8% -5.1%

Changes are geometric means of paired ratios, using median compile times; lower is better. Native count improves in 41 cases, ties in 127, and never regresses. Depth improves in 38 of 152 comparable cases and never regresses; structured-control-flow cases have no depth metric. Zero values are excluded only from geometric means. Output hashes and quality metrics are deterministic within each version.

Runtime is broadly unchanged: summed case medians increase 0.86%, and the largest per-case median slowdown is 3.60% (adder_n10, all-to-all, 17.916 to 18.562 ms). Separate long-block probes preserve full matrices, including phase, and reduce 1,024-gate RZZ/RXX synthesis from 2,048 native entanglers to two. These results cover the stated workloads and settings, not a general speedup or global synthesis optimum. The benchmark drivers, exact build metadata, raw measurements, and PNG/PDF plots remain in the local experiment archive.

Codex assisted with implementation, review, validation, and this description.

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.
  • I have added entries to the changelog for any noteworthy additions, changes, fixes, or removals.
  • I have added migration instructions to the upgrade guide (if needed).
  • The changes follow the project's style guidelines and introduce no new warnings.
  • The changes are fully tested and pass the CI checks.
  • I have reviewed my own code changes.

If PR contains AI-assisted content:

  • Any agent that created, edited, or submitted GitHub content was explicitly authorized for that scope, as required by our 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.

@burgholzer burgholzer added enhancement Improvement of existing feature c++ Anything related to C++ code MLIR Anything related to MLIR labels Sep 11, 2026
@burgholzer burgholzer self-assigned this Sep 11, 2026
@burgholzer
burgholzer force-pushed the codex/initial-placement branch from 7337dda to ab5625d Compare September 11, 2026 19:57
@codecov

codecov Bot commented Sep 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.11538% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...QCO/Transforms/NativeSynthesis/TargetSynthesis.cpp 97.0% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

@burgholzer
burgholzer force-pushed the codex/initial-placement branch from ab5625d to a9da95e Compare September 11, 2026 20:30
@burgholzer burgholzer changed the title ✨ Improve structured placement and routing costs ⚡️ Fuse routing SWAPs with two-qubit gates Sep 11, 2026
Resynthesize constant two-wire runs in the shared native-synthesis pass,
so both target APIs compare blocks with native-preserving individual
lowering. Stop cost evaluation once the block is cheaper and retain the
existing direction, phase, and numerical reconstruction constraints.

Optimize unrestricted targets too, preserve cheaper native operations,
and keep standalone target-independent fusion available. Moving fusion
after placement trades some long-block CZ compilation time for correct
native-basis decisions.

Assisted-by: GPT-6 via Codex
@burgholzer burgholzer changed the title ⚡️ Fuse routing SWAPs with two-qubit gates ✨ Synthesize two-qubit blocks in the native basis Sep 11, 2026
@burgholzer
burgholzer force-pushed the codex/initial-placement branch from a9da95e to 1f89f27 Compare September 11, 2026 21:24
Run target-aware fusion before placement in both target pipelines, only
when it reduces the two-qubit operation count and native cost. This removes
cancelled interactions before routing without expanding compact native
blocks. Keep physical-site cost decisions in the later synthesis pass.

Cover cancellation with full-unitary equivalence and preserve compact
native pairs. Document the early and late synthesis contracts.

Assisted-by: GPT-6 via Codex
@burgholzer burgholzer added this to the v4.1.0 - QDMI 1.4 / MQSF milestone Sep 12, 2026
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 enhancement Improvement of existing feature MLIR Anything related to MLIR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant