question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Deprecates `PauliOp.commutes`

See original GitHub issue

What 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.

  1. PauliOp.commutes checks qubit-wise commutation because it was originally introduced for AbelianGrouper. The method name looks misleading. Note that AbelianGrouper does not use it anymore and no other Aqua module use it.
  2. PauliOp.commutes takes OperatorBase as argument, but, it always returns False if OperatorBase is not PauliOp. 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.commutes is 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:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
t-imamichicommented, Jan 28, 2021

Yes, it makes sense to delete it. Because I used PauliOp.commutes for unit tests of test_abelian_grouper.py (this is the only use case of PauliOp.commutes in Qiskit), I need to replace it. I ask Hamamura-san to delete PauliOp.commutes and update test_abelian_grouper.py as part of #5537 because it introduces commutator function 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

1reaction
ikkohamcommented, Nov 9, 2020

+1

Sorry, my is_commutative is not for this purpose. (I made a mistake in the previous issue) To check the commutativity of Pauli, PauliTable.commutes is useful.

PauliTable(a.primitive).commutes(b.primitive)

(note that PauliTable will be deprecated.)

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found