Deprecates `PauliOp.commutes`
See original GitHub issueWhat is the expected enhancement?
Only PauliOp has commutes method among all OperatorBase.
I notice that there are some problems with PauliOp.commutes thanks to Qiskit/qiskit-aqua#1415.
PauliOp.commuteschecks qubit-wise commutation because it was originally introduced forAbelianGrouper. The method name looks misleading. Note thatAbelianGrouperdoes not use it anymore and no other Aqua module use it.PauliOp.commutestakesOperatorBaseas argument, but, it always returnsFalseifOperatorBaseis notPauliOp. It does not check commutation with other operators. It causes the following behavior.
from qiskit.aqua.operators import X
print(X.commutes(X))
print(X.commutes(X.to_matrix_op()))
output
True
False
The second output False is not expected because X.to_matrix_op() is essentially equal to X.
It would be good to deprecate PauliOp.commutes because of the following reasons.
- No other Aqua module uses it.
- The method name and the behavior do not match now (qubit-wise commutation).
- It checks commutation with only PauliOp and it always returns False with other operators without checking commutation.
Overall, I think
PauliOp.commutesis misleading.
If users want to check commutation of Pauli operators, they can do it by using the primitives as follows.
from qiskit.aqua.operators import X, Z
a = X^X
b = Z^Z
print(a.primitive * b.primitive == b.primitive * a.primitive)
output
True
~~or using https://github.com/Qiskit/qiskit-terra/pull/5299.~~ (see https://github.com/Qiskit/qiskit-aqua/issues/1416#issuecomment-723728545)
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Deprecates `PauliOp.commutes` · Issue #5727 - GitHub
PauliOp.commutes checks qubit-wise commutation because it was originally introduced for AbelianGrouper . The method name looks misleading. Note ...
Read more >PauliOp — Qiskit 0.32.1 documentation
commutes. Returns whether self commutes with other_op. ; compose. Return Operator Composition between self and other (linear algebra-style: A@B(x) = A(B(x))), ...
Read more >Expected outcome of adding two PauliOp
What further confuses me is that the deprecated version of PauliOp actually results in the expected operator. Running this code:
Read more >qiskit-terra Changelog - PyUp.io
deprecate qiskit.pulse.utils.deprecated_functionality in favor of ... Grouping commuting Pauli strings in quantum_info (6690)
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Yes, it makes sense to delete it. Because I used
PauliOp.commutesfor unit tests of test_abelian_grouper.py (this is the only use case ofPauliOp.commutesin Qiskit), I need to replace it. I ask Hamamura-san to deletePauliOp.commutesand update test_abelian_grouper.py as part of #5537 because it introducescommutatorfunction and related to this issue. https://github.com/Qiskit/qiskit-terra/blob/f53a4b0bd1c951b6b1ccc3c8c33eec6e9cf3288e/test/python/opflow/test_abelian_grouper.py#L50 https://github.com/Qiskit/qiskit-terra/blob/f53a4b0bd1c951b6b1ccc3c8c33eec6e9cf3288e/test/python/opflow/test_abelian_grouper.py#L92+1
Sorry, my
is_commutativeis not for this purpose. (I made a mistake in the previous issue) To check the commutativity of Pauli,PauliTable.commutesis useful.(note that PauliTable will be deprecated.)