Skip to content

♻️ Remove CircuitOptimizer - #2262

Merged
simon1hofmann merged 10 commits into
mainfrom
codex/2088-prune-circuit-optimizer
Aug 27, 2026
Merged

♻️ Remove CircuitOptimizer#2262
simon1hofmann merged 10 commits into
mainfrom
codex/2088-prune-circuit-optimizer

Conversation

@simon1hofmann

@simon1hofmann simon1hofmann commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

🤖 AI text below 🤖

Description

Remove the standalone qc::CircuitOptimizer API and MQT::CoreCircuitOptimizer library:

  • move circuit flattening and final-measurement removal to QuantumComputation member methods in MQT::CoreIR;
  • move single-qubit gate fusion to its two production owners, QCEC and QMAP;
  • remove the optimizer header, CMake target, sources, tests, installed export, and wheel dependency;
  • move the retained behavioral tests into CoreIR and add empty-circuit member-contract coverage; and
  • document every migration in the changelog and upgrade guide.

This implements the ownership split proposed in review while avoiding a separately distributed library for three functions.

Fixes #2088

Downstream drafts and release sequence

The downstream projects remain pinned to Core 3.9.x, so these PRs stay in draft until Core v4 is released. After the release, each project can update its Core pin, revalidate, and merge its migration:

Validation

  • warning-clean static release build with WARNINGS_AS_ERRORS=ON
  • fresh warning-clean shared package build (272/272 targets)
  • 298/298 CoreIR tests
  • 51/51 DDSIM QDMI-device tests
  • static and shared installs contain the member declarations and no optimizer header, library, or exported CMake target
  • minimal out-of-tree MQT::CoreIR consumer compiled, linked, and ran against both installs
  • QCEC: 20/20 focused optimizer and 573/573 full C++ tests
  • QMAP: 9/9 focused fusion, 41/41 QMapDS, and 11/11 NASP tests
  • QuSAT: 11/11 full C++ tests
  • DDSIM: 28/28 affected and 116/116 non-stochastic tests
  • Debugger: 149/149 full C++ tests
  • full uvx nox -s lint and git diff --check

AI assistance

Codex materially assisted with the organization-wide consumer census, implementation, tests, cross-repository validation, independent review, and this pull request description. A human must review and understand the changes before merge.

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. Local and downstream validation passes; CI is pending.
  • 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.

@simon1hofmann simon1hofmann added refactor Anything related to code refactoring major Major version update Core Anything related to the Core library and IR c++ Anything related to C++ code labels Aug 26, 2026
Resolve #2088 after moving domain-specific behavior to its owning repositories.

Assisted-by: GPT-5.6 via Codex
@simon1hofmann
simon1hofmann force-pushed the codex/2088-prune-circuit-optimizer branch from b53423a to 287e176 Compare August 26, 2026 16:28
@codecov

codecov Bot commented Aug 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.49541% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/ir/CircuitOptimization.cpp 94.4% 6 Missing ⚠️

📢 Thoughts on this report? Let us know!

@simon1hofmann simon1hofmann self-assigned this Aug 26, 2026
@simon1hofmann simon1hofmann added this to the MQT Core milestone Aug 26, 2026
@mergify mergify Bot added the conflict label Aug 26, 2026
@burgholzer

Copy link
Copy Markdown
Member

Just out of interest: how many users are there of the methods that are still here?
Or, right to the point, how bad would it be if we completely removed this and copied the implementation of the relevant methods into the respective libraries?

@simon1hofmann

Copy link
Copy Markdown
Contributor Author

🤖 AI text below 🤖

I reran the production-use census across the current companion PR heads plus DDSIM and the Debugger:

Method Production repositories Direct production calls
singleQubitGateFusion QCEC, QMAP 5
removeFinalMeasurements Core, QCEC, QMAP, DDSIM 11
flattenOperations QMAP, DDSIM, Debugger 7

This covers MQT production consumers; it does not count unknown external consumers.

A complete removal would therefore turn the three shared implementations into nine repository-local method copies across five production repositories:

  • gate fusion in QCEC and QMAP;
  • final-measurement removal in Core, QCEC, QMAP, and DDSIM;
  • flattening in QMAP, DDSIM, and Debugger.

QuSAT has no production use after munich-quantum-toolkit/qusat#512, but its tests still use flattening and would need adjustment. The retained implementation is a 303-line source file backed by 16 focused tests.

Based on that, my inclination would be to keep the reduced three-method target: every remaining method is genuinely shared, and duplicating removeFinalMeasurements four times in particular seems like a maintenance regression. singleQubitGateFusion is the closest borderline case, with two consuming repositories.

Would you still prefer us to remove the target completely and localize all three implementations?

@burgholzer

Copy link
Copy Markdown
Member

Hm. I do not quite like the fact that this is another shared library that needs to be distributed and appropriately handled downstream. So I'd have a slight preference for trying to remove it.

How about the following proposal

  • move the single-qubit gate fusion to QCEC and QMAP
  • turn flattening and final-measurement removal into member methods of the QuantumComputation class so that they are directly part of the MQT::CoreIR library and do not need to be placed separately

Would that make sense?

@mergify mergify Bot added the conflict label Aug 27, 2026
@simon1hofmann

Copy link
Copy Markdown
Contributor Author

🤖 AI text below 🤖

Yes, that split makes sense, and it is now implemented:

  • flattenOperations and removeFinalMeasurements are QuantumComputation member methods in MQT::CoreIR;
  • single-qubit gate fusion is owned and tested independently by QCEC and QMAP; and
  • the CircuitOptimizer header, library, CMake target, installed export, tests, and wheel dependency are removed from Core.

I re-audited every MQT repository and found no additional production consumers. Core passes 298/298 IR tests and 51/51 QDMI-device tests, warning-clean static/shared builds and installs, and out-of-tree MQT::CoreIR consumers in both modes.

The coordinated downstream migrations are open as drafts and will remain pinned to Core 3.9 until Core v4 is released:

@mergify mergify Bot removed the conflict label Aug 27, 2026

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

Nice! Let's get this in as soon as CI is green here!

simon1hofmann and others added 5 commits August 27, 2026 13:31
Assisted-by: GPT-5.6 via Codex
Use the Doxygen and fixed-width type conventions introduced on main. Clarify the generated-header migration note and record the new C++ lint workflow.

Assisted-by: GPT-5.6 via Codex
@simon1hofmann
simon1hofmann enabled auto-merge (squash) August 27, 2026 15:23
@simon1hofmann
simon1hofmann merged commit 036dd9b into main Aug 27, 2026
26 checks passed
@simon1hofmann
simon1hofmann deleted the codex/2088-prune-circuit-optimizer branch August 27, 2026 15:41
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 Core Anything related to the Core library and IR major Major version update refactor Anything related to code refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

♻️ Reduce the public CircuitOptimizer API to shared transformations

2 participants