Cirq
Cirq copied to clipboard
Make CircuitDiagramInfo also support LaTeX
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.
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.
We don't need to stick to qcircuit; perhaps qpic might be more suitable. I haven't tried it out though.
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.
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.
You should definitely submit the algorithmic part of your generalized swap network code separately from any LaTeX diagramming code.
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:
- 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".
- Give
QCircuitDiagrammableGate
much more control over what gets output. For example, control over what goes on the intermediate qubits between targeted qubits. - 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.
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.
Adding better latex support for diagrams using QPIC is currently tracked in https://github.com/quantumlib/Cirq/issues/5895
Closing this as a duplicate