Repository navigation
The decomposition solver uses a generalized Dijkstra's algorithm - #3334
Merged
Merged
Conversation
kipawaa
marked this pull request as ready for review
October 15, 2026 13:59
HelioXv022
pushed a commit
to HelioXv022/pennylane
that referenced
this pull request
Oct 22, 2026
…PennyLaneAI#10350) **Context:** We added `PPR_2/4/8` as frontend versions of Pauli product rotations and have quite a few decompositions using them already. The remaining translation of gates to PPRs currently is done in the Catalyst pass `to_ppr`. However, given that this is mere decomposition, we'd rather have it happen as part of `qp.decompose` to leverage graph solution quality. **Description of the Change:** Add most remaining decompositions that are part of `to_ppr` to the decomposition rule set. The only types of rule skipped for now are - the ones translating continuous-angle operations with static-valued angles to discrete PPR counterparts. This is not a task handled very well by the graph (because the resources differ very strongly depending on information that is not available at graph construction/solution time), so we leave this type of translation to well-designed discretization passes that leverage special angles into cheap gate sequences. - measurement translations (MidMeasure -> PPM). This is not needed because it is a simple lowering step, and it would lead to complications due to the interaction between measurement return values and the graph system. side note: as usual, touching decompositions led to some expected (doc)test outputs changing (tie-break is not stable against such changes). **Benefits:** More decomposition happens within `qp.decompose`. **Possible Drawbacks:** Some more (very short) cycles in the decomposition graph, but that's not really a problem because the solver needs to handle those anyways. It is noteworthy that we had some edge case of suboptimal solutions with the current solver, which will be remedied by PennyLaneAI/catalyst#3334. This is not blocking, though (did not find any regression in test suite, nor in a set of 20 cycle-constructing examples). **Related GitHub Issues:** Made with AI
maliasadi
reviewed
Oct 23, 2026
maliasadi
reviewed
Oct 23, 2026
maliasadi
reviewed
Oct 23, 2026
kipawaa
force-pushed
the
decomp/solver-knuth-rework
branch
from
October 26, 2026 14:43
c80393a to
627c67e
Compare
Co-authored-by: Ali Asadi <10773383+maliasadi@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3334 +/- ##
==========================================
+ Coverage 95.98% 96.21% +0.23%
==========================================
Files 176 176
Lines 21203 21583 +380
Branches 2142 2160 +18
==========================================
+ Hits 20351 20766 +415
+ Misses 660 631 -29
+ Partials 192 186 -6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
paul0403
reviewed
Oct 26, 2026
paul0403
approved these changes
Oct 27, 2026
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 current decomposition solver uses a DFS search, which is fast and efficient but fails to guarantee optimality, and struggles to handle cyclic decompositions without simply ignoring the rules involved in them.
Description of the Change:
The decomposition solver uses a generalization of Dijkstra's algorithm for hypergraphs.
Performance was measured with respect to the DFS implementation on graphs of up to 500 rules, 10s-100s of gate types, and is generally ~5-10% faster than the DFS implementation. The exception is on highly cyclic graphs, where the DFS solver incorrectly avoids rules previously labelled as cycles.
Benefits:
Guarantees an optimal solution and handles cyclic rules natively.
Possible Drawbacks:
Cannot handle negative/NaN weights in the graph.
Related GitHub Issues:
[sc-133667]
Primarily generated using LLMs. Reviewed and validated by @kipawaa