Rule lowering depends on operator order in circuit
Maintainers usually reply within 1 day
@kipawaa is already working on this.
Since Nov 4, 2026.
Assessment
This issue has not been assessed yet.
Description
Observation
With the graph_decomposition decomposer, whether a circuit compiles can depend on the operator ordering in the circuit.
Less severely, but still problematically, the decomposition result can have reduced quality depending on the operator ordering.
Cause
An operator (node) that is pruned due to a control wire increasing cycle is cached as invalid, so that later visits to that node will not explore it again, even though in a different context, i.e. not as part of such a problematic cycle.
This caching "side effect" means that if the valid usage of the operator (node) comes first, we're fine, but if it follows the invalid usage as part of a cycle, the decomposition may fail (or produce worse outcomes if this causes worse decompositions to be chosen)
The PL graph decomposer has the same problem: https://github.com/PennyLaneAI/pennylane/issues/10424, which is fixed in https://github.com/PennyLaneAI/pennylane/pull/10423.
Minimal example
Only providing resources, no rule bodies because this is about graph construction.
import pennylane as qp
from pennylane.decomposition import add_decomps, local_decomps, register_resources
from pennylane.typing import Wire
from catalyst import qjit
from catalyst.passes import graph_decomposition
class B(qp.core.Operator2):
def __init__(self, wires):
super().__init__(wires=wires)
class X(qp.core.Operator2):
def __init__(self, wires):
super().__init__(wires=wires)
class Y(qp.core.Operator2):
def __init__(self, wires):
super().__init__(wires=wires)
@register_resources({})
def b_to_nothing(wires):
del wires
@register_resources({X(Wire[1]): 1})
def cb_to_x(base, **_):
del base
@register_resources({qp.ctrl(B(Wire[1]), control=[Wire[2], Wire[3]]): 1})
def x_to_ccb(wires):
del wires
@register_resources({X(Wire[1]): 1})
def y_to_x(wires):
del wires
def compile_circuit(controlled_b_first):
with local_decomps():
add_decomps(B, b_to_nothing)
add_decomps("C(B)", cb_to_x)
add_decomps(X, x_to_ccb)
add_decomps(Y, y_to_x)
@qjit(capture=True, target="mlir")
@graph_decomposition(gate_set={qp.Z: 1})
@qp.qnode(qp.device("null.qubit", wires=2))
def circuit():
if controlled_b_first:
qp.ctrl(B(0), control=1)
Y(0)
else:
Y(0)
qp.ctrl(B(0), control=1)
return qp.state()
return qp.specs(circuit, level="all")().resources
compile_circuit(controlled_b_first=False) # compiles
compile_circuit(controlled_b_first=True) # fails
Technical cause (AI analysis)
In walk_reachable_decomp_rule_sets (frontend/catalyst/decomposition/decomposition_rules.py), whether a child gets pruned depends on the path taken (path_control_counts). But processed_states is keyed only by (base_id, modifier state) and shared across all paths:
previous_states = processed_states.setdefault(request.base_id, set())
missing_states = demanded_states - previous_states
if not missing_states:
continue
...
if increases_control_cycle:
continue
With C(B) first, the walk reaches X through C(B). On that path B already has one control, so X's child 2C(B) is pruned and X is marked as processed. The visit to X through Y, where nothing would be pruned, is then skipped. 2C(B) is never given rules, and X's only rule becomes unusable.
The roots are recorded in the order their operators first appear in the circuit (DecompositionScope.roots), so reordering independent gates changes the result. The C++ solver itself doesn't depend on order; it just receives an incomplete rule set. If X had a costlier fallback rule, the result would be a worse decomposition rather than an error.
Possible fix
Following PennyLane #10423: don't treat an operator state as fully explored when one of its children was pruned. For example, record the pruned children for each (base_id, state), and on a revisit through a different path, check them again against the new path instead of skipping the operator.
- Dominant language
- Python
- Stars
- 234
- Forks
- 84
- Avg merge
- 3d 11h
- Merged PRs (30d)
- 78
Getting set up
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from PennyLaneAI/catalyst
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
PennyLaneAI/catalyst#3489 ·
Maintainers usually reply within 1 day
-
Fix platform tag for macOS wheelsMay be free again @sarehaskari17 claimed this 107 days ago, and no pull request is open. OpenCI/Build enhancement good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
PennyLaneAI/catalyst#2907 · 2 comments ·
Maintainers usually reply within 1 day
-
The docs page for `CompileOptions` is missing a description for the `target` attributePossibly taken @daxsh2803 claimed this 68 days ago. Opendocumentation
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
PennyLaneAI/catalyst#2653 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 3/5 1-2 days Newbie friendliness 68/100
PennyLaneAI/catalyst#3550 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 57/100
PennyLaneAI/catalyst#3497 ·
Maintainers usually reply within 1 day
All issues in PennyLaneAI/catalyst
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
521xueweihan/HelloGitHub#4729 ·
-
auto-reported bug
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
needs-triage type:bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
pollen-robotics/reachy_mini_conversation_app#631 ·
Maintainers usually reply within 7 days
-
stix-atlas.json: the same relationship id is used for several different mitigates relationshipsOpen
Difficulty 2/5 1-3 hours Newbie friendliness 76/100