Hello,
I am trying to apply a transform to my circuit. When i look at the operations of the transform i see correct gates, but when i draw my circuit, i see the gates applied twice. Here is the code i have:
import pennylane as qml
import pennylane as qml
from typing import Callable, Sequence
from pennylane.tape import QuantumTape
@qml.transform
def convert_cnots(tape: qml.tape.QuantumTape)-> (Sequence[QuantumTape], Callable):
new_ops = []
for op in tape.operations:
if op.name == "CNOT":
new_ops.append( qml.Hadamard(1))
new_ops.append(qml.CZ(wires=[1,0]))
new_ops.append(qml.Hadamard(wires=1))
else:
new_ops.append(op)
tp = QuantumTape(new_ops, tape.measurements, tape.trainable_params)
return [tp], lambda res: res[0]
@qml.qnode(qml.device('default.qubit', wires=2))
@convert_cnots
def circuit():
qml.CNOT(wires=[0, 1])
return qml.expval(qml.PauliZ(0) @ qml.PauliZ(1))
print(qml.draw_mpl(circuit)())
here is the circuit that i get when i draw it. I shouldn’t be getting the H CZ and H twice. What could be causing this?: