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

repr(PauliString) on one qubit doesn't round-trip #2771

Closed
mpharrigan opened this issue Feb 14, 2020 · 7 comments · Fixed by #5444
Closed

repr(PauliString) on one qubit doesn't round-trip #2771

mpharrigan opened this issue Feb 14, 2020 · 7 comments · Fixed by #5444
Assignees
Labels
area/paulis complexity/medium introduces/modifies 3-5 concepts, takes max up to a month for an advanced contributor kind/bug-report Something doesn't seem to work. skill-level/advanced One or more of the areas need a solid understanding. triage/accepted there is consensus amongst maintainers that this is a real bug or a reasonable feature to add

Comments

@mpharrigan
Copy link
Collaborator

In[23]: ps = cirq.Z(q0)*1
In[24]: repr(ps)
Out[24]: 'cirq.Z.on(cirq.LineQubit(0))'
In[26]: type(ps)
Out[26]: cirq.ops.pauli_string.PauliString
In[28]: type(eval(repr(ps)))
Out[28]: cirq.ops.pauli_string.SingleQubitPauliStringGateOperation

and it is no longer a PauliString

@kevinsung
Copy link
Collaborator

ps == eval(repr(ps)) is True though, which is perhaps all that matters.

@mpharrigan
Copy link
Collaborator Author

If you try to include a single-qubit pauli string as part of an object for the json_serialization test it doesn't work because it compares jsonify(ps) == jsonify(eval(repr(ps)))

@cduck
Copy link
Collaborator

cduck commented Feb 14, 2020

Should cirq.testing.assert_equivalent_repr also test repr(val) == repr(eval(repr(val)))?

@Ashalynd
Copy link
Collaborator

AFAIK Python types by themselves aren't expected to be round-trippable.

@Strilanc
Copy link
Contributor

SingleQubitPauliStringGateOperation inherits from PauliString, so it is technically still a pauli string.

@Strilanc Strilanc added kind/bug-report Something doesn't seem to work. triage/discuss Needs decision / discussion, bring these up during Cirq Cynque labels Sep 22, 2020
@balopat balopat added area/paulis triage/accepted there is consensus amongst maintainers that this is a real bug or a reasonable feature to add complexity/medium introduces/modifies 3-5 concepts, takes max up to a month for an advanced contributor skill-level/advanced One or more of the areas need a solid understanding. and removed triage/discuss Needs decision / discussion, bring these up during Cirq Cynque labels Sep 28, 2020
@95-martin-orion
Copy link
Collaborator

Is this still an issue?

@mpharrigan
Copy link
Collaborator Author

the behavior has not changed (I just ran the snippet provided)

@dstrain115 dstrain115 self-assigned this Jun 3, 2022
dstrain115 added a commit to dstrain115/Cirq-1 that referenced this issue Jun 3, 2022
- The repr of pauli strings with coefficient of one
used to truncate the one.
- This is prettier but does not actually repr to the same thing,
ie.  type(eval('cirq.Z.on(cirq.LineQubit(0))')
!=   type(eval('1*cirq.Z.on(cirq.LineQubit(0))')

Fixes: quantumlib#2771
dstrain115 added a commit that referenced this issue Jun 3, 2022
* Update repr of pauli strings

- The repr of pauli strings with coefficient of one
used to truncate the one.
- This is prettier but does not actually repr to the same thing,
ie.  type(eval('cirq.Z.on(cirq.LineQubit(0))')
!=   type(eval('1*cirq.Z.on(cirq.LineQubit(0))')

Fixes: #2771
rht pushed a commit to rht/Cirq that referenced this issue May 1, 2023
* Update repr of pauli strings

- The repr of pauli strings with coefficient of one
used to truncate the one.
- This is prettier but does not actually repr to the same thing,
ie.  type(eval('cirq.Z.on(cirq.LineQubit(0))')
!=   type(eval('1*cirq.Z.on(cirq.LineQubit(0))')

Fixes: quantumlib#2771
harry-phasecraft pushed a commit to PhaseCraft/Cirq that referenced this issue Oct 31, 2024
* Update repr of pauli strings

- The repr of pauli strings with coefficient of one
used to truncate the one.
- This is prettier but does not actually repr to the same thing,
ie.  type(eval('cirq.Z.on(cirq.LineQubit(0))')
!=   type(eval('1*cirq.Z.on(cirq.LineQubit(0))')

Fixes: quantumlib#2771
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/paulis complexity/medium introduces/modifies 3-5 concepts, takes max up to a month for an advanced contributor kind/bug-report Something doesn't seem to work. skill-level/advanced One or more of the areas need a solid understanding. triage/accepted there is consensus amongst maintainers that this is a real bug or a reasonable feature to add
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants