| 1 |
# yquant |
| 2 |
Typesetting quantum circuits in a human-readable language |
| 3 |
|
| 4 |
yquant is a LaTeX package that allows to quickly draw quantum circuits. It bridges the gap between the two groups of packages that already exist: those that use a logic-oriented custom language, which is then translated into TeX by means of an external program; and the pure TeX versions that mainly provide some macros to allow for an easier input. |
| 5 |
yquant is a pure-LaTeX solution - i.e., it requires no external program - that introduces a logic oriented language and thus brings the best of both worlds together. |
| 6 |
It builds on and interacts with TiKZ, which brings an enourmous flexibility for customization of individual circuit. |
| 7 |
|
| 8 |
Important features in the latest updates (for a much more complete list, see the documentation): |
| 9 |
- Support for comfortably enclosing or embracing region in a circuit (since 0.9) |
| 10 |
- Support for `\intertext` in groups (since 0.8) |
| 11 |
- Support for [corner-like gates](https://arxiv.org/abs/1709.06648) by allowing for controlled `init` and `discard` gates (since 0.8) |
| 12 |
- Support for custom attributes in custom gates and boxes, making them effectively parameteric (since 0.8) |
| 13 |
- Support for vertical circuit layout (since 0.7) |
| 14 |
- Support for a simplified drawing pipeline (since 0.7) |
| 15 |
- Support the `beamer` package (since 0.6) |
| 16 |
- New `text` gate, which replaces the common `[draw=none] box` situation (since 0.6) |
| 17 |
- Integration of all qpic examples in the manual, showcasing some very advanced circuits (since 0.6) |
| 18 |
- Simple interface for circuit equations, no more `subcircuit` hassling (since 0.5) |
| 19 |
- Measurement outputs can now directly control other gates, i.e., with a vertical classical line emanating from the measurement (since 0.4) |
| 20 |
- Automatically adjust vertical positions of wires also for multi-register gates (since 0.4-alpha) |
| 21 |
- Vertical alignment actually works for subcircuits (since 0.4-alpha) |
| 22 |
- Directly support circuits written in the `qasm` language (since 0.3) |
| 23 |
- Simple declaration of custom gates (since 0.2.1) |
| 24 |
- Support for subcircuits, though vertical alignment may be messed up (since 0.2) |
| 25 |
- Load circuits from files (since 0.2) |
| 26 |
- Native support for non-contiguous multi-qubit gates (since 0.1.2) |
| 27 |
- Extensive user-friendly support for register name ranges, lists (since 0.1.1) |
| 28 |
|
| 29 |
A detailed reference with lots of examples is provided in the PDF version of this Readme. We will sketch some basic usage. |
| 30 |
|
| 31 |
The arXiv runs on version 0.7.4 (TeXLive 2023) and 0.7.5 (TeXLive 2025) - you may download the latest version from the releases section and include it in your submission. |
| 32 |
|
| 33 |
Support the development: |
| 34 |
- [](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=UTR3MRBYJ825A&source=url) |
| 35 |
|
| 36 |
## Examples |
| 37 |
Many more examples and explanations can be found in the [PDF version](https://github.com/projekter/yquant/blob/master/doc/latex/yquant/yquant-doc.pdf) of this Readme. |
| 38 |
Only the interesting part is shown here; `\usepackage[compat=0.6]{yquant}` is required for every example and `\usepackage{braket}` where the bra/ket notation is used. |
| 39 |
|
| 40 |
### Simple teleportation circuit |
| 41 |
 |
| 42 |
```LaTeX |
| 43 |
\begin{tikzpicture} |
| 44 |
\begin{yquant} |
| 45 |
qubit {$\ket{\reg_{\idx}}$} q[3]; |
| 46 |
|
| 47 |
h q[1]; |
| 48 |
cnot q[2] | q[1]; |
| 49 |
cnot q[1] | q[0]; |
| 50 |
h q[0]; |
| 51 |
measure q[0-1]; |
| 52 |
|
| 53 |
z q[2] | q[1]; |
| 54 |
x q[2] | q[0]; |
| 55 |
\end{yquant} |
| 56 |
\end{tikzpicture} |
| 57 |
``` |
| 58 |
|
| 59 |
### Three-qubit phase estimation circuit with QFT and controlled-U |
| 60 |
 |
| 61 |
```LaTeX |
| 62 |
\begin{tikzpicture} |
| 63 |
\begin{yquant} |
| 64 |
qubit {$\ket{j_{\idx}} = \ket0$} j[3]; |
| 65 |
qubit {$\ket{s_{\idx}}$} s[2]; |
| 66 |
|
| 67 |
h j; |
| 68 |
box {$U^4$} (s) | j[0]; |
| 69 |
box {$U^2$} (s) | j[1]; |
| 70 |
box {$U$} (s) | j[2]; |
| 71 |
h j[0]; |
| 72 |
box {$S$} j[1] | j[0]; |
| 73 |
h j[1]; |
| 74 |
box {$T$} j[2] | j[0]; |
| 75 |
box {$S$} j[2] | j[1]; |
| 76 |
h j[2]; |
| 77 |
measure j; |
| 78 |
\end{yquant} |
| 79 |
\end{tikzpicture} |
| 80 |
``` |
| 81 |
|
| 82 |
### Three-qubit FT QEC circuit with syndrome measurement |
| 83 |
 |
| 84 |
```LaTeX |
| 85 |
\begin{tikzpicture} |
| 86 |
\begin{yquant} |
| 87 |
qubit {$\ket{q_{\idx}}$} q[3]; |
| 88 |
qubit {$\ket{s_{\idx}} = \ket0$} s[2]; |
| 89 |
cbit {$c_{\idx} = 0$} c[2]; |
| 90 |
|
| 91 |
h s[0]; |
| 92 |
cnot s[1] | s[0]; |
| 93 |
cnot s[0] | q[0]; |
| 94 |
cnot s[1] | q[1]; |
| 95 |
cnot s[1] | s[0]; |
| 96 |
h s[0]; |
| 97 |
measure s; |
| 98 |
cnot c[0] | s[0]; |
| 99 |
cnot c[1] | s[1]; |
| 100 |
discard s; |
| 101 |
|
| 102 |
init {$\ket0$} s; |
| 103 |
h s[0]; |
| 104 |
cnot s[1] | s[0]; |
| 105 |
cnot s[0] | q[1]; |
| 106 |
cnot s[1] | q[2]; |
| 107 |
cnot s[1] | s[0]; |
| 108 |
h s[0]; |
| 109 |
measure s; |
| 110 |
|
| 111 |
box {Process\\Syndrome} (s, c); |
| 112 |
box {$\mathcal R$} (q) | s, c; |
| 113 |
\end{yquant} |
| 114 |
\end{tikzpicture} |
| 115 |
``` |
| 116 |
|
| 117 |
### Error correction |
| 118 |
 |
| 119 |
```LaTeX |
| 120 |
% \usetikzlibrary{quotes} |
| 121 |
\begin{tikzpicture} |
| 122 |
\begin{yquant} |
| 123 |
qubit {} msg[3]; |
| 124 |
|
| 125 |
\encloseall["Syndrome Measurement"]{ |
| 126 |
qubit {$\ket0$} syndrome[3]; |
| 127 |
|
| 128 |
cnot syndrome[0] | msg[0]; |
| 129 |
cnot syndrome[0] | msg[1]; |
| 130 |
cnot syndrome[1] | msg[1]; |
| 131 |
cnot syndrome[1] | msg[2]; |
| 132 |
cnot syndrome[2] | msg[0]; |
| 133 |
cnot syndrome[2] | msg[2]; |
| 134 |
[shape=yquant-rectangle, rounded corners=.45em] |
| 135 |
dmeter {$M_{\symbol{\numexpr`a+\idx}}$} syndrome; |
| 136 |
} |
| 137 |
|
| 138 |
["Recovery"] |
| 139 |
box {$\mathcal R$} (msg) | syndrome; |
| 140 |
discard syndrome; |
| 141 |
\end{yquant} |
| 142 |
\end{tikzpicture} |
| 143 |
``` |
| 144 |
|
| 145 |
### Lots of controls |
| 146 |
 |
| 147 |
```LaTeX |
| 148 |
\begin{tikzpicture} |
| 149 |
\begin{yquant*} |
| 150 |
zz (a[0, 2]); |
| 151 |
cnot a[1] ~ a[0]; |
| 152 |
zz (a[2, 3]); |
| 153 |
h a[3] | a[0] ~ a[1]; |
| 154 |
measure a[2, 3]; |
| 155 |
box {$U$} (a[0, 1]) | a[3] ~ a[2]; |
| 156 |
discard a[2, 3]; |
| 157 |
\end{yquant*} |
| 158 |
\end{tikzpicture} |
| 159 |
``` |
| 160 |
|
| 161 |
### Circuit equations |
| 162 |
 |
| 163 |
```LaTeX |
| 164 |
% \useyquantlanguage{groups} |
| 165 |
\begin{tikzpicture} |
| 166 |
\begin{yquantgroup} |
| 167 |
\registers{ |
| 168 |
qubit {} q[2]; |
| 169 |
} |
| 170 |
\circuit{ |
| 171 |
h -; |
| 172 |
cnot q[1] | q[0]; |
| 173 |
h -; |
| 174 |
} |
| 175 |
\equals |
| 176 |
\circuit{ |
| 177 |
cnot q[0] | q[1]; |
| 178 |
} |
| 179 |
\end{yquantgroup} |
| 180 |
\end{tikzpicture} |
| 181 |
``` |