Cirq icon indicating copy to clipboard operation
Cirq copied to clipboard

Make CircuitDiagramInfo also support LaTeX

Open kevinsung opened this issue 6 years ago • 7 comments

Often gates in LaTeX look something like R_{z}(\theta). I think there are three parts of this: the main letter R, the subscript z, and the angle \theta which will be in rads, not half-turns.

Another thing is that when possible, people like to draw two-qubit gates as a single box with two lines going into it and the description of the gate in the center of the box. Using the qcircuit functionality in contrib, two-qubit gates always look like two separate boxes connected by a line.

It would be cool to take care of this stuff automatically.

kevinsung avatar Jul 06 '18 18:07 kevinsung

The difficulty with putting a single box around a multi-qubit gate is that the parameters of the relevant qcircuit command use absolute positions rather than relative ones. I'm not sure how to best address that, but in any case a necessary intermediary step is preventing the vertical lines from being drawn; see #538.

bryano avatar Jul 06 '18 18:07 bryano

We don't need to stick to qcircuit; perhaps qpic might be more suitable. I haven't tried it out though.

kevinsung avatar Jul 06 '18 18:07 kevinsung

qcircuit does seem quite restrictive (e.g. there's also no way to color individual parts of the circuit), so I'm definitely open to alternatives. It would be great to decide ASAP though, because my generalized swap network code is based on qcircuit.

bryano avatar Jul 06 '18 18:07 bryano

Craig also mentioned (#516) the possibility of svgwrite. That seems powerful enough and it would enable fine-grained control, but at the cost of having to build all the quantum-computing primitives from scratch.

bryano avatar Jul 06 '18 18:07 bryano

You should definitely submit the algorithmic part of your generalized swap network code separately from any LaTeX diagramming code.

kevinsung avatar Jul 06 '18 20:07 kevinsung

Gates can control their LaTeX output in somewhat finer detail by implementing QCircuitDiagrammableGate and returning latex strings for the wire symbols. But I agree that the support is very weak at the moment.

I think several changes are needed to make this work well:

  1. Create an easy way to say "hey, if this subset of qubits is together in the right order, you can use a box with this text in it".
  2. Give QCircuitDiagrammableGate much more control over what gets output. For example, control over what goes on the intermediate qubits between targeted qubits.
  3. Have proper support of this functionality for all the basic gates as an example.

Ideally I would like all of the diagram functionality to have some common core, especially around e.g. what should be boxed or not.

Strilanc avatar Jul 08 '18 05:07 Strilanc

The code to produce qcircuit LaTeX currently uses the circuit info object. It does output code that has single boxes for multiqubit gates.

I think the question that remains here is whether there should be a way to specify gates as @kevinsung suggested, i.e. should the information that is returned by gates include an explicit LaTeX version R_z(\theta).

I'm going to title this to reflect that. Please let me know if I've misidentified this issue.

dabacon avatar Apr 29 '20 23:04 dabacon

Adding better latex support for diagrams using QPIC is currently tracked in https://github.com/quantumlib/Cirq/issues/5895

Closing this as a duplicate

tanujkhattar avatar Feb 02 '24 08:02 tanujkhattar