Skip to content

Support Adjoint symbolic rules in graph-decomposition - #3204

Merged
maliasadi merged 16 commits into
mainfrom
decomp/fix_sym_rules
Sep 14, 2026
Merged

maliasadi merged 16 commits into
mainfrom
decomp/fix_sym_rules

Conversation

@maliasadi

@maliasadi maliasadi commented Sep 9, 2026

Copy link
Copy Markdown
Member

Context:
This PR adds support for the rules PL registers with the symbolic operator's arguments, i.e. self_adjoint(base), adjoint_rotation(base), and others rather than the base op's (*params, wires). Now, rules registered for Adjoint(Op) against the base op's parameters keep working:

import pennylane as qp
from catalyst.passes import graph_decomposition

class MyOp(qp.core.Operator2):
    def __init__(self, wires):
        super().__init__(wires=wires)


@qp.register_resources({qp.Hadamard: 1})
def my_op_decomp(wires):
    qp.Hadamard(wires=wires)


qp.add_decomps(MyOp, my_op_decomp)

@qp.register_resources({qp.Hadamard: 1})
def self_adjoint(base):
    """Decompose a symbolic operator to its base."""
    qp.apply(base)


qp.add_decomps("Adjoint(Hadamard)", self_adjoint)


@qp.qjit(target="mlir", capture=True)
@graph_decomposition(gate_set=["H"])
@qp.qnode(qp.device("lightning.qubit", wires=1))
def circuit(x: float):
    qp.adjoint(MyOp(0))
    return qp.expval(qp.Z(0))


# print(circuit.mlir)
print(qp.specs(circuit, level="all-mlir")(0.0))

Description of the Change:

Benefits:

Possible Drawbacks:

Related GitHub Issues:
[sc-130029]

@codecov

codecov Bot commented Sep 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.73418% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 95.63%. Comparing base (c6aa156) to head (546c55d).

Files with missing lines Patch % Lines
...tend/catalyst/decomposition/decomposition_rules.py 98.73% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3204   +/-   ##
=======================================
  Coverage   95.63%   95.63%           
=======================================
  Files         177      177           
  Lines       20893    20947   +54     
  Branches     2105     2112    +7     
=======================================
+ Hits        19980    20033   +53     
  Misses        725      725           
- Partials      188      189    +1     

☔ 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 requested review from dime10 and kipawaa September 10, 2026 18:19
Comment thread frontend/catalyst/decomposition/decomposition_rules.py Outdated
Comment thread frontend/catalyst/decomposition/decomposition_rules.py Outdated
Comment thread frontend/catalyst/decomposition/decomposition_rules.py Outdated
Comment thread frontend/catalyst/decomposition/decomposition_rules.py
Comment thread frontend/catalyst/decomposition/decomposition_rules.py Outdated
Comment thread frontend/catalyst/decomposition/decomposition_rules.py
Comment thread frontend/catalyst/decomposition/decomposition_rules.py

@astralcai astralcai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It took me a while to understand the overall structure of this decomposition_rule.py module, but everything finally makes sense to me.

Comment thread frontend/catalyst/decomposition/decomposition_rules.py Outdated
Comment thread frontend/catalyst/decomposition/decomposition_rules.py
@maliasadi
maliasadi merged commit 397b2ce into main Sep 14, 2026
38 checks passed
@maliasadi
maliasadi deleted the decomp/fix_sym_rules branch September 14, 2026 21:23
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