6
$\begingroup$

I've been asking and answering some questions recently and have been drawing my own circuits (in PowerPoint), that aren't always aligned or have too thick/too thin weights on the lines/etc. I compare my circuits to others in other questions/answers, and many others render beautifully. I've not yet learned any other tools to draw them, but I know I should.

Where are people drawing such lovely circuits that always render correctly?

I know there was a similar question asked here but what is the specific practice that people are using?

Some are nice clips from Mike & Ike that still render well, but some others that come directly to mind are:

I recently revised an answer with a PowerPoint circuit to a Quirk clip, which comes out a lot better, but it's still a clip and might not resize correctly.

@DaftWullie's circuits are always quite nice. He indicates he draws them with his Quantikz LaTeX package - learning that doesn't seem so intimidating.

$\endgroup$
4
4
$\begingroup$

I wasn't sure whether this question was about generating the circuits, or including the circuits in a post in a way that renders exactly the source circuit (e.g. vector graphics). I have no idea about the latter, but here is a way I've found to generate nice circuit diagrams quickly using QCircuit as a backend.


  1. Compose the circuit in python using the cirq package, e.g.
>>> import cirq
>>> q0, q1 = cirq.LineQubit.range(2)
>>> circuit = cirq.Circuit(cirq.CNOT(q0, q1), cirq.rz(q1), cirq.CNOT(q0, q1))
  1. Use cirq's contributed function cirq.contrib.circuit_to_latex_using_qcircuit
>>> print(cirq.contrib.circuit_to_latex_using_qcircuit(circuit))
\Qcircuit @R=1em @C=0.75em {
 \\
 &\lstick{\text{0}}& \qw&\control \qw    &                          \qw&\control \qw    &\qw\\
 &\lstick{\text{1}}& \qw&\targ    \qw\qwx&\gate{\text{Rz(0.392pi)}} \qw&\targ    \qw\qwx&\qw\\
 \\
}
  1. Copy and paste this into a tex file with \usepackage{qcircuit} and make a few adjustments to the qcircuit code as you see fit (e.g. remove the "0.392pi" filler angle from the above). I keep an overleaf file around exclusively for this process.

  2. Zoom in on the compiled pdf and screenclip the circuit.

  3. Copy the screenclip into the SE post to generate an imgur url, but then embed this url with an html img tag, e.g. <img src="https://i.stack.imgur.com/jskNF.png" width="350" />. This lets you control the size of the displayed circuit; if you choose a width close to the original screenclip width you should get a mostly clean outcome.

  4. Center the image. I've found only one of the answers from this post to work: Shift the image right by 4 pixels at a time using &nbsp; I would love know if there is a better way to do this.

                           ;                  


The instructions look long but generating and including the image above took about 3 minutes.

For steps 1-2 there is probably an equivalent approach in qiskit or other popular circuit simulation libraries, I just am most familiar with cirq.

$\endgroup$
1
$\begingroup$

Here is a small tutorial to a specific latex package to design quantum circuits : Qcircuit tutorial and quickref

You can find a complete documentation of the package here

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .