Skip to content

Support decomposition of Controlled ops to GraphSolver#3003

Open
maliasadi wants to merge 7 commits into
mainfrom
graph-solver/ctrl-op
Open

Support decomposition of Controlled ops to GraphSolver#3003
maliasadi wants to merge 7 commits into
mainfrom
graph-solver/ctrl-op

Conversation

@maliasadi

@maliasadi maliasadi commented Jul 9, 2026

Copy link
Copy Markdown
Member

Context:
The decomposition graph solver could not decompose Controlled ops. This PR adds this support to the graph solver to handle them, mirroring the two decomposition families used by PL:

  1. Decompose C(Op) directly: Rules registered against the controlled operator itself: e.g. a dedicated CRX rule, C(SWAP), C(PhaseShift), etc. in PL. These were already supported by the graph. A RuleNode whose output has numControlWires > 0 is registered and solved like any other rule; so no new logic was needed to the solver; they just need to be provided as rules. I'll take care of this in a follow-up PR to integrate the support with the graph-decomposition pass.

  2. Decompose Op, then control each produced gate: From each base rule Op, the graph builder should synthesize C(Op) with the same k control wires applied to every produced gate and the same multiplicities. I assumed that only the cost of controlling each produced gate matters here; the actual control-each-gate wrapping happens in the follow-up PR when integrating with the pass.

Both pathways coexist in the graph, and the solver picks the cheapest decomp pathway! :)

Unlike the adjoint case #3001, there is no build-time short-circuit that suppresses one pathway in general; both are always added and left to compete. The one exception mirrors PL's control-specific special cases (e.g. GlobalPhase, ChangeOpBasis): controlling their decomposition is not semantically valid, so I added a static method to the graph to suppress them (isCtrlRuleRequired) and they must be decomposed by a dedicated controlled rule. Since the graph reasons about resource cost and not the semantics of rules, this suppression is required to keep the solver from picking a cheap but invalid controlled decomposition.

Benefits:

  • Supporting C(Op) decomposition and resource estimation
  • Composes with existing operator identity (numControlWires is matched exactly, like adjoint), so multi-controlled operators is also supported in the graph.

Possible Drawbacks:

  • For circuits with many Ctrl ops, the graph grows as we add synthesized controlled rules for each C(Op) and track them across multiple decomp pathways.
  • I'm using explicit rules for the special ops (GlobalPhase, ...), and the suppression list is currently hard-coded. This can be revisited later after integration with the graph-decomposition pass.
  • `control_values are not supported yet. This can be added later.

Related GitHub Issues:
[sc-122044]

@maliasadi maliasadi changed the title Graph solver/ctrl op Support decomposition of Controlled ops to GraphSolver Jul 9, 2026
@maliasadi maliasadi requested review from astralcai and kipawaa July 9, 2026 16:09
@codecov

codecov Bot commented Jul 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.96%. Comparing base (c30fe9a) to head (64d9ea8).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3003   +/-   ##
=======================================
  Coverage   96.96%   96.96%           
=======================================
  Files         167      167           
  Lines       19346    19346           
  Branches     1801     1801           
=======================================
  Hits        18758    18758           
  Misses        433      433           
  Partials      155      155           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@maliasadi maliasadi added this to the delightning milestone Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant