[BUG] cancel_inverses
does not cancel adjoint operators with different wire order that are symmetric on wires
#6729
Labels
bug 🐛
Something isn't working
Expected behavior
If I have an operator and it's adjoint applied next to each other, where they are both applied on the same set of wires, but not in the exact same wire order, I expect them to be cancelled if they are known to be symmetric on all wires.
Actual behavior
Such operators are not cancelled. This is because in
qml.transforms.optimization.cancel_inverses._ops_equal
, we explicitly check for wire equality. Later in the transform, we also check for wire symmetry, but by that point, operators are already no longer being considered for cancellation.Additional information
No response
Source code
import pennylane as qml op = qml.IsingXX(1.5, [0, 1]) tape = qml.tape.QuantumScript( [ qml.IsingXX(1.5, [0, 1]), qml.adjoint(qml.IsingXX(1.5, [1, 0])), ], ) [transformed_tape], _ = qml.transforms.cancel_inverses(tape) print(transformed_tape.circuit) [IsingXX(1.5, wires=[0, 1]), Adjoint(IsingXX(1.5, wires=[1, 0]))] If I update qml.transforms.optimization.cancel_inverses._ops_equal to stop checking for equality, running the same code gives the following output: []
Tracebacks
No response
System information
Existing GitHub issues
The text was updated successfully, but these errors were encountered: