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

IdentityGate Visualization #6768

Open
glanzz opened this issue Oct 15, 2024 · 2 comments
Open

IdentityGate Visualization #6768

glanzz opened this issue Oct 15, 2024 · 2 comments
Labels
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 there is consensus amongst maintainers that this is a real bug or a reasonable feature to add

Comments

@glanzz
Copy link

glanzz commented Oct 15, 2024

Description of the issue
IdentityGate constructor accepts a single parameter which is the number of qubits it acts on.
When the parameter value is set to 0, the circuit works fine until the circuit is printed. Program crashes with an ValueError.

How to reproduce the issue

import cirq as c

idgate = c.IdentityGate(0)


qubit = c.LineQubit(0)
circuit = c.Circuit()
print(idgate())
circuit.append(idgate())

print(circuit)
circuit += c.inverse(circuit)
circuit.append(c.measure_each(qubit))

print(c.Simulator().run(circuit, repetitions=100))
File "/Users/xxx/identity_gate_cirq.py", line 11, in <module>
    print(circuit)
  File "/Users/xxx/cirqenv/lib/python3.11/site-packages/cirq/circuits/circuit.py", line 285, in __str__
    return self.to_text_diagram()
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/xxx/cirqenv/lib/python3.11/site-packages/cirq/circuits/circuit.py", line 1197, in to_text_diagram
    diagram = self.to_text_diagram_drawer(
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/xxx/cirqenv/lib/python3.11/site-packages/cirq/circuits/circuit.py", line 1276, in to_text_diagram_drawer
    _draw_moment_in_diagram(
  File "/Users/xxx/cirqenv/lib/python3.11/site-packages/cirq/circuits/circuit.py", line 2612, in _draw_moment_in_diagram
    _draw_moment_annotations(
  File "/Users/xxx/cirqenv/lib/python3.11/site-packages/cirq/circuits/circuit.py", line 2543, in _draw_moment_annotations
    info = get_circuit_diagram_info(annotation, args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/xxx/cirqenv/lib/python3.11/site-packages/cirq/protocols/circuit_diagram_info_protocol.py", line 345, in _op_info_with_fallback
    raise ValueError(f'Wanted diagram info from {op!r} for {rows!r}) but got {info!r}')
ValueError: Wanted diagram info from cirq.IdentityGate(0)() for []) but got cirq.CircuitDiagramInfo(wire_symbols=(), exponent=1, connected=True, exponent_qubit_index=None, auto_exponent_parens=True)

Cirq version
You can get the cirq version by printing cirq.__version__. From the command line:

Cirq: 1.4.1
@glanzz glanzz added the kind/bug-report Something doesn't seem to work. label Oct 15, 2024
@NoureldinYosri NoureldinYosri added triage/discuss Needs decision / discussion, bring these up during Cirq Cynque triage/accepted there is consensus amongst maintainers that this is a real bug or a reasonable feature to add good first issue This issue can be resolved by someone who is not familiar with the codebase. A good starting issue. no QC knowledge needed Want to contribute to Cirq, but don't know quantum computing? This issue is for you. and removed triage/discuss Needs decision / discussion, bring these up during Cirq Cynque labels Oct 15, 2024
@mhucka
Copy link
Contributor

mhucka commented Oct 16, 2024

Discussed during bit.ly/cirq-cynq today (2024-10-16): probably the solution is to disallow 0 qubit inputs and add validation to IdentityGate, because this is a situation that doesn't make sense physically.

@QuarkBS2
Copy link

QuarkBS2 commented Nov 7, 2024

Hi, I would like to help with this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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 there is consensus amongst maintainers that this is a real bug or a reasonable feature to add
Projects
None yet
Development

No branches or pull requests

4 participants