Skip to content

Cannot print PauliSumExponential of identity gate #5944

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

Closed
lmarti-dev opened this issue Nov 8, 2022 · 3 comments · Fixed by #6880
Closed

Cannot print PauliSumExponential of identity gate #5944

lmarti-dev opened this issue Nov 8, 2022 · 3 comments · Fixed by #6880
Labels
area/gates good first issue This issue can be resolved by someone who is not familiar with the codebase. A good starting issue. kind/bug-report Something doesn't seem to work. no QC knowledge needed Want to contribute to Cirq, but don't know quantum computing? This issue is for you. triage/accepted A consensus emerged that this bug report, feature request, or other action should be worked on

Comments

@lmarti-dev
Copy link

Description of the issue

Exponentiating an identity gate with PauliSumExponential and then printing it raises a ValueError, similar to #5927. I could not tell whether the pull request that fixes the aforementioned issue would fix this one too. Feel free to close this issue if this is the case.

How to reproduce the issue


q = cirq.LineQubit(0)
op = cirq.PauliSumExponential(cirq.I(q))
circ = cirq.Circuit(op)
print(circ)

ValueError: Wanted diagram info from cirq.PauliStringPhasor(((1+0j)*cirq.PauliString()), qubits=(), exponent_neg=-0.31830988618379075, exponent_pos=0.3183098861837907) for []) but got cirq.CircuitDiagramInfo(wire_symbols=(), exponent=-0.6366197723675815, connected=True, exponent_qubit_index=None, auto_exponent_parens=True)

Cirq version
1.0.0

@lmarti-dev lmarti-dev added the kind/bug-report Something doesn't seem to work. label Nov 8, 2022
@viathor viathor added triage/discuss Needs decision / discussion, bring these up during Cirq Cynque area/gates labels Nov 8, 2022
@dstrain115 dstrain115 added good first issue This issue can be resolved by someone who is not familiar with the codebase. A good starting issue. triage/accepted A consensus emerged that this bug report, feature request, or other action should be worked on and removed triage/discuss Needs decision / discussion, bring these up during Cirq Cynque labels Nov 9, 2022
@dstrain115
Copy link
Collaborator

dstrain115 commented Nov 9, 2022

Discussion from cirq cync: This is likely because the exponential of the identity has no operation since the PauliStringPhasor is stripping out identity. This should be accepted. Probably an empty PauliString needs a proper diagram strategy.

Possible cause: "in circuit_diagram_info_protocol there's a if max(1, len(rows)) != len(info.wire_symbols):. That max seems to break things because there's no qubits on this one."

@tanujkhattar tanujkhattar added no QC knowledge needed Want to contribute to Cirq, but don't know quantum computing? This issue is for you. triage/discuss Needs decision / discussion, bring these up during Cirq Cynque and removed good first issue This issue can be resolved by someone who is not familiar with the codebase. A good starting issue. triage/accepted A consensus emerged that this bug report, feature request, or other action should be worked on labels Nov 9, 2022
@dstrain115 dstrain115 added good first issue This issue can be resolved by someone who is not familiar with the codebase. A good starting issue. triage/accepted A consensus emerged that this bug report, feature request, or other action should be worked on and removed triage/discuss Needs decision / discussion, bring these up during Cirq Cynque labels Nov 9, 2022
@daxfohl
Copy link
Collaborator

daxfohl commented Nov 10, 2022

PauliString._circuit_diagram_info_ gets around this by returning NotImplemented if it is empty, which causes the diagramming logic to put the op below the circuit along with global phase and other non-qubit ops. Same strategy would work here.

Though to note, this strategy invokes the str method to display the op, and the PauliStringPhasor.__str__ doesn't match the style of a PSP in the diagram. On the diagram it appears as [I]^0.5 but the str is (I)**0.5. Maybe that's okay? (An empty PauliString just shows a weird isolated I under the diagram).

@taochengfei
Copy link

I'd like to try fixing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/gates good first issue This issue can be resolved by someone who is not familiar with the codebase. A good starting issue. kind/bug-report Something doesn't seem to work. no QC knowledge needed Want to contribute to Cirq, but don't know quantum computing? This issue is for you. triage/accepted A consensus emerged that this bug report, feature request, or other action should be worked on
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

7 participants