Skip to content

⚡ Reduce QCO-to-QC conversion overhead - #2695

Merged
burgholzer merged 5 commits into
mainfrom
codex/qco-conversion-performance
Oct 8, 2026
Merged

burgholzer merged 5 commits into
mainfrom
codex/qco-conversion-performance

Conversation

@simon1hofmann

@simon1hofmann simon1hofmann commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

🤖 AI text below 🤖

Description

Reduce QCO → QC conversion overhead by applying rewrites immediately, releasing replaced operations and SSA uses as conversion progresses. Explicit legality for unchanged classical types avoids unnecessary folding; remove the unused branch conversion pattern and its transform dependency.

Regression coverage checks classical folding and unsupported quantum consumers. Existing target-pipeline tests cover rejection of unstructured control flow.

Benchmarks

Fresh native C++ measurements of 4916b0c1d against the conversion implementation at base 3e8ba8b87. The earlier Mac harness and frozen imports were not available in this workspace; these runs use pinned Benchpress OpenQASM inputs and reconstructed targets on DGX Spark.

Workload / timed scope Runs per variant Baseline PR head Time change
2,000,000 H gates: QCO → QC 3 3.839 s 2.661 s -30.7%
BWT n37 / line: full native compilation 1 277.05 s 269.98 s -2.6%
BWT n37 / line: QCO → QC phase 1 60.30 s 53.24 s -11.7%
QuGAN n395 / heavy-hex: full native compilation 6 6.926 s 7.211 s +4.1%
QuGAN n395 / heavy-hex: QCO → QC phase 6 0.0906 s 0.0852 s -6.0%

Values are medians; BWT has only one pair. All matched output QC hashes and gate counts are identical. QuGAN's full-compilation median increased 4.1% despite its faster conversion phase; full times ranged from 6.28–7.86 s for baseline and 7.04–7.39 s for the PR. These measurements do not establish a general end-to-end speedup.

BWT whole-process peak RSS was 12.18 GiB for baseline and 8.01 GiB for the PR, including untimed import and serialization.

Method: DGX Spark pinned to ten Cortex-X925 cores; Clang 23, -O3, ThinLTO, mold, LLVM/MLIR 23.1.0 with assertions enabled. Both executables use the same harness and common libraries; only the QCO-to-QC implementation differs. Serial fresh processes alternate variant order across pairs. The full timer includes QC copying, QC → QCO, target compilation, and return to QC, including API verification. Import, target setup, output verification, serialization, and hashing are outside the timer.

Inputs and topology recipe: Benchpress b695f30e8. BWT uses a symmetric 37-site line; QuGAN uses a symmetric 409-site heavy-hex graph. Native basis: id, sx, x, rz, cz, measurement, reset. QIR Base payload; seed 42, 10 mapping trials, 1 refinement iteration, lookahead 20. The synthetic case has one dynamic qubit and two million consecutive H gates; its timer includes conversion-boundary verification.

Validation

  • Exact head 4916b0c1d: 158 native conversion tests and 271 compiler tests passed.
  • Repository lint, whole-file C++ lint, and git diff --check passed.
  • Hosted CI passes for this head.

Codex assisted with implementation, review, tests, benchmark reruns, and this description. Human review remains required.

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.
  • 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.

@codecov

codecov Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@simon1hofmann
simon1hofmann added this pull request to stack #2692 October 7, 2026 07:43
@simon1hofmann simon1hofmann changed the title ⚡ Reduce QCO conversion and Release verification overhead ⚡ Reduce QCO-to-QC conversion overhead Oct 7, 2026
@simon1hofmann simon1hofmann self-assigned this Oct 7, 2026
@simon1hofmann simon1hofmann added this to the v4.1.0 - QDMI 1.4 / MQSF milestone Oct 7, 2026
@simon1hofmann simon1hofmann added enhancement Improvement of existing feature c++ Anything related to C++ code MLIR Anything related to MLIR labels Oct 7, 2026
@simon1hofmann
simon1hofmann marked this pull request as ready for review October 7, 2026 08:03
@simon1hofmann
simon1hofmann force-pushed the codex/qco-conversion-performance branch from 416b19c to d87fe7c Compare October 7, 2026 11:43
@mergify mergify Bot added the conflict label Oct 7, 2026
Base automatically changed from codex/target-dead-value-fast-path to main October 7, 2026 15:49
🤖 *AI text below* 🤖

Use no-rollback QCO-to-QC conversion and verify Core-owned Release
pipelines at their boundaries. Keep per-pass verification in Debug and
preserve caller-owned pass-manager settings.

Add negative tests for invalid boundary IR and unsupported conversion.
Focused measurements improve several cases but regress QuGAN; retain
this as an experimental candidate pending broader validation.

Assisted-by: Codex
🤖 *AI text below* 🤖

Keep runOnOperation protected, matching the MLIR pass interface and
resolving the clang-tidy 23 diagnostic on the boundary-verification test.

Assisted-by: Codex
🤖 *AI text below* 🤖

Keep this branch focused on no-rollback QCO-to-QC lowering. Move the
boundary-verification policy and its tests to a separate draft so the
conversion optimization can be reviewed without adopting that tradeoff.

Assisted-by: Codex
@burgholzer

Copy link
Copy Markdown
Member

I'll rebase and review this next 😌

@burgholzer
burgholzer force-pushed the codex/qco-conversion-performance branch from d87fe7c to 3418fc8 Compare October 7, 2026 15:53
@burgholzer burgholzer self-assigned this Oct 7, 2026
@simon1hofmann

Copy link
Copy Markdown
Contributor Author

I'll rebase and review this next 😌

Sounds good. Me and @MatthiasReumann had some further ideas for improving the conversions quite substantially, but would create follow-ups for those.

🤖 *AI text below* 🤖

Treat unrelated operations with legal operand and result types as legal
so no-rollback conversion does not rewrite or fold classical IR. Remove
the ineffective branch conversion pattern and its transform dependency;
quantum branch operands remain unsupported.

Cover classical branches, foldable LLVM comparisons, and rejected quantum
branches. Document the conversion boundary and failure ownership.

Assisted-by: Codex
🤖 *AI text below* 🤖

Remove branch fixtures that implied support for unstructured control
flow, which target compilation already rejects and tests. Keep the
straight-line folding regression and unsupported-consumer failure check.

Drop the added pass documentation and explanatory comment rather than
turning incidental conversion behavior into a public contract.

Assisted-by: Codex

@burgholzer burgholzer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trimmed this down a bit while preserving the main speedup. Let's get this in.

@burgholzer
burgholzer merged commit 82da752 into main Oct 8, 2026
26 checks passed
@burgholzer
burgholzer deleted the codex/qco-conversion-performance branch October 8, 2026 08:44
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.

2 participants