Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] cancel_inverses does not cancel adjoint operators with different wire order that are symmetric on wires #6729

Open
1 task done
mudit2812 opened this issue Dec 17, 2024 · 0 comments
Labels
bug 🐛 Something isn't working

Comments

@mudit2812
Copy link
Contributor

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

pl dev

Existing GitHub issues

  • I have searched existing GitHub issues to make sure the issue does not already exist.
@mudit2812 mudit2812 added the bug 🐛 Something isn't working label Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant