catalyst icon indicating copy to clipboard operation
catalyst copied to clipboard

Duplicate gates with higher-order gate functions in structured programs

Open dime10 opened this issue 4 months ago • 0 comments

The normal mechanism in PennyLane that "un-queues" a gate when supplied to a HOF like qml.adjoint does not work when the original and modified gate appear in different program scopes, such as across control flow segments. The reason is that Catalyst using different tapes for each section.

import pennylane as qml

@qml.qjit
@qml.qnode(qml.device("lightning.qubit", wires=1))
def circuit(b: bool):
    g = qml.H(0)

    @qml.cond(b)
    def apply():
        qml.adjoint(g)
    apply()

    return qml.state()

print(circuit(1))  # should not read [1, 0]

dime10 avatar Jul 16 '25 19:07 dime10