-
Notifications
You must be signed in to change notification settings - Fork 1k
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
PauliSum reorders the qubits, possibly in a non-deterministic way #6630
Comments
…iterating on a PauliSum elements
Adding some pointers: Each term of the Suggested fix: |
cirq-sync: it makes sense to maintain the original qubit order. to do this we need to keep track of the original qubit order and use it when computing the unitary or decomposition |
Description of the issue
When retrieving the terms of a
PauliSum
, the resultingPauliString
may have their qubits reordered compared to what was their original order when added to the sum.What is happening behind the scenes is that the Pauli string
cirq.DensePauliString('XY').on(q0, q1)
is added to the PauliSum, but may be turned into acirq.DensePauliString('YX').on(q1, q0)
when retrieving the first term of the sum. They represent the same operation indeed, but do not have the same representation and unitary.As a result, everything based on
PauliSum
produces consistent results at the circuit level, butx
andPauliSum() + x
are not guaranteed to be equivalent at the representation and unitary level. In addition,PauliSum() + x
might have an inconsistent representation over several calls.How to reproduce the issue
Output
Output in Colab
Cirq version
Observed on
1.5.0.dev
with python3.11.9 (main, Apr 6 2024, 17:59:24) [GCC 9.4.0]
in a dev environement. Non-deterministic behavior.Observed on
1.5.0.dev20240531223815
with python3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0]
running in Colab. Deterministic behavior, but qubit order consistently swapped in the string repr and unitary.The text was updated successfully, but these errors were encountered: