PennyLaneAI / pennylane

PennyLane is a cross-platform Python library for quantum computing, quantum machine learning, and quantum chemistry. Train a quantum computer the same way as a neural network.
https://pennylane.ai
Apache License 2.0
2.35k stars 604 forks source link

[BUG] `qml.prod` incompatible with some `grouping` functionality (likely due to order of ops passed to `qml.prod`) #3210

Open antalszava opened 2 years ago

antalszava commented 2 years ago

Expected behavior

qml.prod works with qml.grouping.utils.are_pauli_words_qwc.

Actual behavior

Incorrect behaviour. Swapping the order of two ops passed to qml.prod changes to correct behaviour (perhaps due to the wire ordering changing).

Additional information

No response

Source code

o1 = qml.PauliZ(1)
o2 = qml.prod(*[qml.PauliZ(1), qml.Identity(0)])
print(qml.grouping.utils.are_pauli_words_qwc([o1, o2]))

o1 = qml.PauliZ(1)
o2 = qml.operation.Tensor(*[qml.PauliZ(1), qml.Identity(0)])
print(qml.grouping.utils.are_pauli_words_qwc([o1, o2]))

False
True

Tracebacks

No response

System information

PL dev

Existing GitHub issues

antalszava commented 2 years ago

Doing

o1 = qml.PauliZ(1)
o2 = qml.prod(*[qml.Identity(0), qml.PauliZ(1)])
print(qml.grouping.utils.are_pauli_words_qwc([o1, o2]))

instead of

o1 = qml.PauliZ(1)
o2 = qml.prod(*[qml.PauliZ(1), qml.Identity(0)])
print(qml.grouping.utils.are_pauli_words_qwc([o1, o2]))

Outputs True (as expected).

timmysilv commented 2 years ago

this will be addressed by the Pauli Word rework

albi3ro commented 1 year ago

Hasn't been addressed by the Pauli word rework, since we haven't gone back and updated the utilities. We will now re-prioritize this issue.