Say, I have a list of operations which are pennylane gates, can I create a circuit from it?
I tried:
import pennylane as qml
operations=[qml.Hadamard(wires=2),qml.PauliX(wires=[2]),qml.PauliX(wires=[3]),qml.CNOT(wires=[1, 2])]
def circuit():
operations[0]
for op in operations:
op
qml.Hadamard(wires=[3])
return qml.expval(qml.PauliZ(0))
dev=qml.device('default.qubit',wires=4)
circuit=qml.QNode(circuit, dev)
print(qml.draw(circuit)())
This seems not to work. Only the Hadamard on wire 3 is drawn. I do not understand what difference it makes whether I write the gate directly into the circuit or first in a list and then insert it into the circuit.
Is there another way to do this?