# Do we want a package for drawing quantum circuits enabled?

In the comments to the question How to draw quantum circuits?, there's a comment saying: "Maybe we could request the devs to add a LaTeX package to draw quantum circuits"

I've just discovered that this may be possible.

While what (if anything) is implemented will presumably be up to the developers (and I could imagine they would like properties such as being as simple as possible to implement and minimal effect on loading times), the first step in the process is to ask here:

Do we want to submit a request to the SE developers to add a package that allows native drawing of quantum circuits?

While it doesn't necessarily have to be implemented in MathJax (as pointed out in the comments in the above question, User Experience uses mockups), as an example, some $\LaTeX$ packages include:

• Q-circuit
• TikZ
• qasm2circ

For reference, a (by no means exhaustive) list of questions and answers that have used a quantum circuit are:

• I'd recommend NOT TikZ, as it is honestly quite a pain, but I would find Q-circuit or some similar package very very useful.
– Auden Young Mod
Apr 24, 2018 at 0:37
• Mithrandir24601, I removed the multiple polling-style answers you posted in favor of an open discussion. If you have thoughts on the issue yourself, please please feel free to post it as an answer. But it is generally better to let everyone have a voice in meta to express their own opinions rather pre-posting all sides of the conversation yourself. It's not difficult to infer what the community wants from the conversation while allowing for the possibility that there's an issue we have not considered. Polling is generally not a good substitute for discussion. Apr 24, 2018 at 1:11
• I'm not sure there would be much of a time benefit when creating the diagram (as contrasted with the time benefits of mathjax vs uploading an image). But the idea of being to edit a broken diagram is compelling. Apr 24, 2018 at 1:48
• @RobertCartaino OK, I'll keep that in mind, thanks for letting me know. Is there anything you'd be able to add in terms of what the devs may/may not be willing to do/consider?
– Mithrandir24601 Mod
Apr 24, 2018 at 7:47
• So it would be possible to have "Mockups" for quantum circuits? That would be great, but I don't understand how would they work. Would you still use latex via some package to write the circuits or would it be a graphical interface?
– glS Mod
Apr 24, 2018 at 8:48
• @heather: I empathise (but do not sympathise...) with you about TiKZ. It is not the easiest tool to use. But these days, I use nothing else. In particular, I find both the syntax and the output of Qcircuit unattractive (the wires don't always connect to the edges of the boxes, for example; and that's even setting aside the fact that it likely won't work as well on the web as on my desktop ten years ago). Apr 24, 2018 at 8:49
• @Mithrandir24601 I don't know yet what enabling (or building) this feature entails, so step one is to have this conversation to help gauge what the cost-benefit is to this site (and network?). And I say this with absolutely no direct insight—but I suspect if there isn't some metaphorical "switch" to make this happen, the dev team may not be in a position to integrate a feature which may only (marginally) benefit one site. But continue the conversation; if a simple solution is available or this becomes a game-changing feature, the changes may justify the costs of getting this done 🤞. Apr 24, 2018 at 13:39
• There's an answer about QCircuit / XYJax / Xy-Pic for @Nat 's Tutorial: How to use TeX/MathJax? question. It mentions that the Stacks website has QCircuit working with MathJax and shows an example of how it would appear.
– Rob
Apr 24, 2018 at 16:49
• Shouldn't this be tagged as [feature-request]? Apr 24, 2018 at 17:35
• @MEE The reason I hadn't tagged it as such is because I'm asking people here if we want a way to draw quantum circuits before actually requesting such a feature. I also don't know what we want to request - an extension to mathjax (which one?), or something different? We've actually already got a feature request, only it's a request asking how to draw quantum circuits, as opposed to asking for something letting us draw quantum circuits, so I'm slightly confused about how things should work in this case, so I'll keep you updated here.
– Mithrandir24601 Mod
Apr 24, 2018 at 18:52
• @Mithrandir24601 ok thanks. That seems to be understandable for me(e) Apr 24, 2018 at 19:09
• @NieldeBeaudrap I think the most painful part of TikZ would be the time required to render it (see e.g. this old comment). Be aware that 'merely' MathJax is already quite heavy for the pages to load. I'd imagine that using TikZ would be far too costly. Apr 25, 2018 at 10:17
• @Discretelizard: I actually agree (see e.g. my 'answer' below). Both the slowness and the complexity of TiKZ are symptoms of the fact that it is a much, much bigger hammer than you need, in principle, to represent quantum circuits. Having said that, it's my hammer of choice in my written work for a reason. I wanted to present a counterpoint to say that Qcircuit is not necessarily ideal either, for all the problems a straight-up MathJax realisation of TiKZ would have. Apr 25, 2018 at 11:34
• For my part, I'd value having QCircuit, and possibly tikz, available. The couple of quantum circuits I've already posted in answers were done in QCircuit, compiled and then uploaded. I'd much rather do it directly. On the other hand, tikz is a far more flexible package that lets you do all sorts of other things as well, which could be useful at some point (but I would use a lot less; that's simply an issue of what one is used to using). Apr 26, 2018 at 1:39

# Desiderata for a circuit drawing package

Assuming that we are seriously entertaining (as opposed to 'committed to') having a circuit-drawing package, here are the things I personally would want from it.

1. Fast — meaning that it should not take over four seconds to produce output for a circuit on e.g. four qubits and eight gates. This is likely to be a barrier, considering how fast MathJax is on SE sites, but I don't want to wait ten seconds for a diagram to load if a well-written equation would have done the job just as well.

2. High-quality output — meaning that it should rarely produce an output with graphical hiccups which would make me wish that they had used a different tool (such as a pen, graph paper, and a smartphone).

3. Clean input syntax — the main point of having it compile from a text source online is easy editing. That should mean that the input syntax should be not just "okay" or "functional", but actually motivated first and foremost by depicting a sequence of operations on qubits or quantum registers.

4. Flexible — it should be easy to denote custom gates ad hoc.

5. SWAP gates representable either as interactions or wire -swaps — not exactly essential, but I'll be honest, I would like it to be possible.

For example, in my experience, TIKZ falls very badly afoul of #3 and is bad at #1; Qcircuit — when I last used it, some time ago — fell afoul of #1 and #2, and wasn't great at #3. I have no experience at all with qasm2circ: it seems to excel at #3, but as it uses xypic.sty as a back end (just as Qcircuit does), I'm wary that it may exhibit the same flaws as Qcircuit for #1 and #2. (If it uses Qcircuit as an intermediary, it may even do more poorly at #1 than Qcircuit.)

It is not clear what the best solution is, but for what it's worth, the above criteria are what I would consider important.