-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Labels
area/paulisgood first issueThis issue can be resolved by someone who is not familiar with the codebase. A good starting issue.This issue can be resolved by someone who is not familiar with the codebase. A good starting issue.kind/bug-reportSomething doesn't seem to work.Something doesn't seem to work.
Description
Describe the issue
DensePauliString (DPS) is designed to accept multiplication by pauli-like gates on linequbits, using the linequibit index as the string index in the DPS. However there's no bounds check, so it crashes if the linequbit index is greater than the DPS string. It also fails on multi-qubit pauli gates like parity gates, which causes associativity problems where they shouldn't exist.
Explain how to reproduce the bug or problem
import cirq
q0, q1, q2 = cirq.LineQubit.range(3)
dps0 = cirq.DensePauliString('x')
dps2 = cirq.DensePauliString('iix')
x0 = cirq.X(q0)
x1 = cirq.X(q1)
x2 = cirq.X(q2)
print(repr(dps0 * dps2)) # cirq.DensePauliString('XIX', coefficient=(1+0j))
print(repr(x0 * dps2)) # cirq.DensePauliString('XIX', coefficient=(1+0j))
print(repr(dps0 * x2)) # index 2 is out of bounds for axis 0 with size 1
print(repr(x0 * (x1 * dps2))) # cirq.DensePauliString('XXX', coefficient=(1+0j))
print(repr(x1 * dps2 * x0)) # cirq.DensePauliString('XXX', coefficient=(1+0j))
print(repr(x0 * x1 * dps2)) # unsupported operand type(s) for *: 'PauliString' and 'DensePauliString'
xx01 = cirq.XX(q0, q1)
print(repr(xx01 * dps2)) # unsupported operand type(s) for *: 'GateOperation' and 'DensePauliString'
Similar issues occur in the _commutes_
protocol on DPS.
Metadata
Metadata
Assignees
Labels
area/paulisgood first issueThis issue can be resolved by someone who is not familiar with the codebase. A good starting issue.This issue can be resolved by someone who is not familiar with the codebase. A good starting issue.kind/bug-reportSomething doesn't seem to work.Something doesn't seem to work.