-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Labels
area/pauliskind/bug-reportSomething doesn't seem to work.Something doesn't seem to work.kind/design-issueA conversation around designA conversation around designtriage/acceptedA consensus emerged that this bug report, feature request, or other action should be worked onA consensus emerged that this bug report, feature request, or other action should be worked ontriage/discussNeeds decision / discussion, bring these up during Cirq CynqueNeeds decision / discussion, bring these up during Cirq Cynque
Description
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):
- 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.
- Change it so that PauliString and GateOperation[X/Y/ZPowGate] are not comparable, so both even and odd exponents return False.
- Allow e.g.
(X**2==PauliString()) == True
. This would run into transitivity issues because we'd also need(Y**2==PauliString()) == True
etc., butX**2 != Y**2
. If we were to go with this option, we would likely need to create a universalIdentity
equality value, and have all "identity" ops be equal. On the surface, that actually seems kind of nice, an easy way to checkif op==cirq.I
generically, but note it would implycirq.I(q1) == cirq.I(q2)
for q1 != q2, which seems wrong. - 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 ifx == PauliString(x)
butx**3 != PauliString(x)
, that could lead to problems. - Leave things as-is.
Tell us the version of Cirq where this happens
1.6.1
Metadata
Metadata
Assignees
Labels
area/pauliskind/bug-reportSomething doesn't seem to work.Something doesn't seem to work.kind/design-issueA conversation around designA conversation around designtriage/acceptedA consensus emerged that this bug report, feature request, or other action should be worked onA consensus emerged that this bug report, feature request, or other action should be worked ontriage/discussNeeds decision / discussion, bring these up during Cirq CynqueNeeds decision / discussion, bring these up during Cirq Cynque