Open gideonuchehara opened 3 weeks ago
@glassnotes
Thanks for opening this issue @gideonuchehara . Hopefully I am understanding the problem correctly, but I think I understand what's happening.
In optimized_go_qnode
, you are expecting the match for the first half of the template temp_go
to be replaced by the second half of temp_go
?
I think the problem is that replacing four cnots with a different four cnots doesn't actually optimize the circuit at all. We only replace the match if it results in a reduction in the size of the circuit.
If we update `go_circuit to have one additional CNOT:
dev = qml.device('default.qubit', wires=4)
@qml.qnode(device=dev)
def go_circuit():
qml.CNOT([1, 2])
qml.CNOT([0, 1])
qml.CNOT([2, 3])
qml.CNOT([1, 2])
qml.CNOT([2, 3])
return qml.expval(qml.PauliZ(0)@qml.PauliZ(1)@qml.PauliZ(2)@qml.PauliZ(3))
The optimized circuit optimized_go_qnode = pattern_matching_optimization(go_circuit, pattern_tapes=[temp_go])
does end up with a circuit with three cnots.
Note that the template should not contain any measurements, and that pennylane now has a new syntax for applying transforms to qnodes.
Expected behavior
The above quantum tape is a matching template for the circuit below
The expected behaviour is that the result of applying
pattern_matching_optimization
togo_circuit()
should betemp_go
.Actual behavior
The actual behaviour is that applying
pattern_matching_optimization
togo_circuit()
does not return thetemp_go
, instead it returns the original circuitgo_circuit()
.Additional information
No response
Source code
Tracebacks
No response
System information
Existing GitHub issues