Skip to content

PauliGate and PauliString equality works only on odd exponents #7585

@daxfohl

Description

@daxfohl

Describe the issue

There's an inconsistency in how Pauli ops handle exponentiation and multiplication with respect to equality. While equality holds when the exponent is odd, it doesn't when the exponent is even.

import cirq
x = cirq.X(cirq.LineQubit(0))
print(1 * x == x)  # True
print(x * x == x**2)  # False
print(x * x * x == x**3)  # True
print(x * x * x * x == x**4)  # False
print(x * x * x * x * x == x**5)  # True
print(x * x * x * x * x * x == x**6)  # False
print(x * x * x * x * x * x * x == x**7)  # True

There may not be a way around this. The reason it doesn't hold for even exponents is that x * x evaluates to an empty PauliString(), as PauliString silently drops any identity qubits, whereas x**2 is still an XPowGate on a qubit.

The options I can think of would be (no particular order):

  1. Modify PauliString to retain identity qubits, but I assume there's a reason it was designed the way it is, and/or would be a breaking change.
  2. Change it so that PauliString and GateOperation[X/Y/ZPowGate] are not comparable, so both even and odd exponents return False.
  3. Allow e.g. (X**2==PauliString()) == True. This would run into transitivity issues because we'd also need (Y**2==PauliString()) == True etc., but X**2 != Y**2. If we were to go with this option, we would likely need to create a universal Identity equality value, and have all "identity" ops be equal. On the surface, that actually seems kind of nice, an easy way to check if op==cirq.I generically, but note it would imply cirq.I(q1) == cirq.I(q2) for q1 != q2, which seems wrong.
  4. Change it so that PauliString and GateOperation[X/Y/ZPowGate] are only comparable when the exponent is one. This also causes transitivity problems because x==x**3==x**5==.... So if x == PauliString(x) but x**3 != PauliString(x), that could lead to problems.
  5. Leave things as-is.

Tell us the version of Cirq where this happens

1.6.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/pauliskind/bug-reportSomething doesn't seem to work.kind/design-issueA conversation around designtriage/acceptedA consensus emerged that this bug report, feature request, or other action should be worked ontriage/discussNeeds decision / discussion, bring these up during Cirq Cynque

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions