Cirq
Cirq copied to clipboard
Print subcircuits out-of-line
Is your feature request related to a use case or problem? Please describe.
In #3580, a circuit containing CircuitOperation
s will print those operations inline. This can make the diagram much larger in the best case, and impossible to read in more complex situations.
Describe the solution you'd like
CircuitOperation
s should be printed outside the circuit, with an identifier replacing them inline. Example:
a, b, c = cirq.LineQubit.range(2)
op = cirq.CircuitOperation(cirq.FrozenCircuit(
cirq.H(a), cirq.CZ(a, b), cirq.H(a)
))
circuit = cirq.Circuit(
cirq.X(a), cirq.H(b), cirq.X(c),
op.with_qubits(c, a),
)
print(circuit)
# output
circuit body:
0 --X--[ (1) subcircuit ]--
|
1 --H--+-------------------
|
2 --X--[ (0) subcircuit ]--
subcircuit:
0 --H--@--H--
|
1 -----@-----
Some way to explicitly name FrozenCircuits would be useful for this.
What is the urgency from your perspective for this issue? Is it blocking important work?
P2 - we should do it in the next couple of quarters
I don't think I agree with always putting CircuitOperation out of line. I could see how the inline diagram can be useful in smaller cases. Maybe we could control the behavior by a flag on CircuitOperation itself?
Child of #3235
Do you think this would benefit from something like the fix for: https://github.com/quantumlib/Cirq/issues/3184
It could, but without an out-of-line copy of the subcircuit the value is limited compared to MatrixGate
:
- The contents of a
CircuitOperation
is just aCircuit
: no exponential explosion likeMatrixGate
. - At the same time, a
CircuitOperation
can be much more complex than aMatrixGate
; omitting the subcircuit potentially obscures many moments of a circuit in its diagram.