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.
```bash
File "/Users/xxx/identity_gate_cirq.py", line 11, in
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:
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.
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
Cirq version You can get the cirq version by printing
cirq.__version__
. From the command line: