Support decomposition of Controlled ops to GraphSolver#3003
Open
maliasadi wants to merge 7 commits into
Open
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
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. ARuleNodewhose output hasnumControlWires > 0is 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.Decompose
Op, then control each produced gate: From each base rule Op, the graph builder should synthesizeC(Op)with the samekcontrol 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:
C(Op)decomposition and resource estimationnumControlWiresis matched exactly, likeadjoint), so multi-controlled operators is also supported in the graph.Possible Drawbacks:
Ctrlops, the graph grows as we add synthesized controlled rules for eachC(Op)and track them across multiple decomp pathways.GlobalPhase, ...), and the suppression list is currently hard-coded. This can be revisited later after integration with the graph-decomposition pass.Related GitHub Issues:
[sc-122044]