Skip to content
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

cirq.MutablePauliString supports identity gates but cirq.PauliString doesn't, which leads to inconsistencies #5572

Closed
tanujkhattar opened this issue Jun 22, 2022 · 6 comments · Fixed by #5621
Assignees
Labels
area/gates area/paulis kind/bug-report Something doesn't seem to work. triage/discuss Needs decision / discussion, bring these up during Cirq Cynque

Comments

@tanujkhattar
Copy link
Collaborator

Description of the issue
cirq.MutablePauliString seems to support identity gates (for example: when passed in pauli_int_dict parameter). The type annotations on on methods like .values() and .items() also have a Union[Pauli, IdentityGate].

This is bad because cirq.PauliString does not support identity gates and hence this leads to inconsistencies between the mutable vs the non-mutable version.

How to reproduce the issue

>>> q = cirq.LineQubit.range(3)
>>> mps = cirq.MutablePauliString(pauli_int_dict={q[0] : 0, q[1] : 1, q[2] : 2})
>>> [*mps.values()]
[cirq.I, cirq.X, cirq.Y]
>>> [*eval(repr(mps)).values()]
[cirq.X, cirq.Y]

Cirq version
0.15dev

@tanujkhattar tanujkhattar added kind/bug-report Something doesn't seem to work. time/before-1.0 labels Jun 22, 2022
@tanujkhattar tanujkhattar changed the title cirq.MutablePauliString supports identity gates but cirq.PauliString doesn't cirq.MutablePauliString supports identity gates but cirq.PauliString doesn't, which leads to inconsistencies Jun 22, 2022
@tanujkhattar
Copy link
Collaborator Author

Also, I see that cirq.MutablePauliString is not an operation; and uses the underlying .frozen() version (i.e. a PauliString) when comparing two instances of MutablePauliString.

@tanujkhattar tanujkhattar added the triage/discuss Needs decision / discussion, bring these up during Cirq Cynque label Jun 22, 2022
@Strilanc
Copy link
Contributor

Operations are hashable, mutable things aren't hashable, so a mutable thing can't be an operation.

No strong opinion on keeping or removing the identities but my default expectation would be that they were removed. Do some tests fail if they're removed?

@dabacon
Copy link
Collaborator

dabacon commented Jun 24, 2022

I don't remember why we had a mutable version of PauliString. Was it just convenience?

@tanujkhattar
Copy link
Collaborator Author

Also, since it's not an operation, can we make it a private class?

@vtomole
Copy link
Collaborator

vtomole commented Jun 24, 2022

@tanujkhattar It used to be private: #3299

@vtomole
Copy link
Collaborator

vtomole commented Jun 24, 2022

@dabacon

Was it just convenience?

Looks like it was for performance reasons: Add private _MutablePauliString type for aggregating products efficiently - #2232

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/gates area/paulis kind/bug-report Something doesn't seem to work. triage/discuss Needs decision / discussion, bring these up during Cirq Cynque
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants