Cirq icon indicating copy to clipboard operation
Cirq copied to clipboard

Print subcircuits out-of-line

Open 95-martin-orion opened this issue 4 years ago • 4 comments

Is your feature request related to a use case or problem? Please describe.

In #3580, a circuit containing CircuitOperations 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

CircuitOperations 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

95-martin-orion avatar Dec 11 '20 17:12 95-martin-orion

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?

balopat avatar Dec 16 '20 17:12 balopat

Child of #3235

95-martin-orion avatar Dec 18 '20 00:12 95-martin-orion

Do you think this would benefit from something like the fix for: https://github.com/quantumlib/Cirq/issues/3184

thanacles avatar Nov 28 '21 01:11 thanacles

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 a Circuit: no exponential explosion like MatrixGate.
  • At the same time, a CircuitOperation can be much more complex than a MatrixGate; omitting the subcircuit potentially obscures many moments of a circuit in its diagram.

95-martin-orion avatar Nov 29 '21 17:11 95-martin-orion