Skip to content

The decomposition solver uses a generalized Dijkstra's algorithm - #3334

Merged
kipawaa merged 9 commits into
mainfrom
decomp/solver-knuth-rework
Oct 27, 2026
Merged

kipawaa merged 9 commits into
mainfrom
decomp/solver-knuth-rework

Conversation

@kipawaa

@kipawaa kipawaa commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

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

@kipawaa kipawaa changed the title Decomp/solver knuth rework The decomposition solver uses a generalized Dijkstra's algorithm Oct 14, 2026
@kipawaa
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 maliasadi 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.

Thanks @kipawaa 🤩

Comment thread mlir/unittests/DecompGraphSolver/Test_DecompGraphSolver.cpp
Comment thread mlir/unittests/DecompGraphSolver/Test_DecompGraphSolver.cpp
@kipawaa
kipawaa force-pushed the decomp/solver-knuth-rework branch from c80393a to 627c67e Compare October 26, 2026 14:43
kipawaa and others added 2 commits October 26, 2026 10:45
Co-authored-by: Ali Asadi <10773383+maliasadi@users.noreply.github.com>
@codecov

codecov Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.21%. Comparing base (e6259d4) to head (d43cfc2).
⚠️ Report is 55 commits behind head on main.

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

@kipawaa
kipawaa requested a review from maliasadi October 26, 2026 15:07
Comment thread frontend/test/lit/GraphDecomposition/TestGatesetWeights.mlir
Comment thread mlir/lib/Quantum/Transforms/GraphDecomposition/DecompGraphSolver/DGSolver.cpp Outdated

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

🚅

@kipawaa
kipawaa merged commit 02615a3 into main Oct 27, 2026
38 checks passed
@kipawaa
kipawaa deleted the decomp/solver-knuth-rework branch October 27, 2026 19:04
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.

3 participants