Skip to content

Support Adjoint symbolic rules in graph-decomposition - #3204

Open
maliasadi wants to merge 8 commits into
mainfrom
decomp/fix_sym_rules
Open

Support Adjoint symbolic rules in graph-decomposition#3204
maliasadi wants to merge 8 commits into
mainfrom
decomp/fix_sym_rules

Conversation

@maliasadi

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:

@codecov

codecov Bot commented Sep 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.81633% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.18%. Comparing base (8a6fc50) to head (a723884).

Files with missing lines Patch % Lines
...tend/catalyst/decomposition/decomposition_rules.py 90.81% 6 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3204      +/-   ##
==========================================
- Coverage   95.35%   95.18%   -0.18%     
==========================================
  Files         177      177              
  Lines       20851    20932      +81     
  Branches     2100     2113      +13     
==========================================
+ Hits        19883    19924      +41     
- Misses        764      793      +29     
- Partials      204      215      +11     

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

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.

1 participant