summaryrefslogtreecommitdiff
path: root/graphics/pgf/contrib/yquant/README.md
blob: e8f39e3df0c588bd38ec897af325e735d0632e2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# yquant
Typesetting quantum circuits in a human-readable language

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.
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.
It builds on and interacts with TiKZ, which brings an enourmous flexibility for customization of individual circuit.

A detailed reference with lots of examples is provided in the PDF version of this Readme. We will sketch some basic usage.

Now yquant also understands circuits written in the qasm language and provides a simple interface for circuit equations!

Support the development:
- [![PayPal](https://img.shields.io/badge/donate-via%20PayPal-blue.svg?style=flat)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=UTR3MRBYJ825A&source=url)
- ![Bitcoin](https://img.shields.io/badge/donate-BTC-blue.svg?style=flat) 3KBFpoJuA4eSPLGXEf3jicqaV1czhK36fH
- ![Ethereum](https://img.shields.io/badge/donate-ETH-blue.svg?style=flat) 0xE0F774221290b1E41ea62c2dd9af5dbD3df7c685

## Examples
Many more examples and explanations can be found in the [PDF version](doc/latex/yquant/yquant-doc.pdf) of this Readme.

### Simple teleportation circuit
![ex-01.png](markdown/ex-01.png)
```LaTeX
\begin{tikzpicture}
  \begin{yquant}
    qubit {$\ket{\reg_{\idx}}$} q[3];

    h q[1];
    cnot q[2] | q[1];
    cnot q[1] | q[0];
    h q[0];
    measure q[0-1];

    z q[2] | q[1];
    x q[2] | q[0];
  \end{yquant}
\end{tikzpicture}
```

### Three-qubit phase estimation circuit with QFT and controlled-U
![ex-02.png](markdown/ex-02.png)
```LaTeX
\begin{tikzpicture}
  \begin{yquant}
    qubit {$\ket{j_{\idx}} = \ket0$} j[3];
    qubit {$\ket{s_{\idx}}$} s[2];

    h j;
    box {$U^4$} (s) | j[0];
    box {$U^2$} (s) | j[1];
    box {$U$} (s) | j[2];
    h j[0];
    box {$S$} j[1] | j[0];
    h j[1];
    box {$T$} j[2] | j[0];
    box {$S$} j[2] | j[1];
    h j[2];
    measure j;
  \end{yquant}
\end{tikzpicture}
```

### Three-qubit FT QEC circuit with syndrome measurement
![ex-03.png](markdown/ex-03.png)
```LaTeX
\begin{tikzpicture}
  \begin{yquant}
    qubit {$\ket{q_{\idx}}$} q[3];
    qubit {$\ket{s_{\idx}} = \ket0$} s[2];
    cbit {$c_{\idx} = 0$} c[2];

    h s[0];
    cnot s[1] | s[0];
    cnot s[0] | q[0];
    cnot s[1] | q[1];
    cnot s[1] | s[0];
    h s[0];
    measure s;
    cnot c[0] | s[0];
    cnot c[1] | s[1];
    discard s;

    init {$\ket0$} s;
    h s[0];
    cnot s[1] | s[0];
    cnot s[0] | q[1];
    cnot s[1] | q[2];
    cnot s[1] | s[0];
    h s[0];
    measure s;

    box {Process\\Syndrome} (s, c);
    box {$\mathcal R$} (q) | s, c;
  \end{yquant}
\end{tikzpicture}
```

### Error correction
![ex-04.png](markdown/ex-04.png)
```LaTeX
% \usetikzlibrary{quotes}
\begin{tikzpicture}
  \begin{yquant}
    qubit {} msg[3];
    nobit syndrome[3];

    [this subcircuit box style={dashed, "Syndrome Measurement"}]
    subcircuit {
       qubit {} msg[3];
       [out]
       qubit {$\ket0$} syndrome[3];

       cnot syndrome[0] | msg[0];
       cnot syndrome[0] | msg[1];
       cnot syndrome[1] | msg[1];
       cnot syndrome[1] | msg[2];
       cnot syndrome[2] | msg[0];
       cnot syndrome[2] | msg[2];

       dmeter {$M_{\symbol{\numexpr`a+\idx}}$} syndrome;
    } (msg[-2], syndrome[-2]);

    ["Recovery"]
    box {$\mathcal R$} (msg) | syndrome;
    discard syndrome;
  \end{yquant}
\end{tikzpicture}
```

### Lots of controls
![ex-05.png](markdown/ex-05.png)
```LaTeX
\begin{tikzpicture}
   \begin{yquant*}
      zz (a[0, 2]);
      cnot a[1] ~ a[0];
      zz (a[2, 3]);
      h a[3] | a[0] ~ a[1];
      measure a[2, 3];
      box {$U$} (a[0, 1]) | a[3] ~ a[2];
      discard a[2, 3];
   \end{yquant*}
\end{tikzpicture}
```

### Circuit equations
![ex-06.png](markdown/ex-06.png)
```LaTeX
% \useyquantlanguage{groups}
\begin{tikzpicture}
   \begin{yquantgroup}
      \registers{
         qubit {} q[2];
      }
      \circuit{
         h -;
         cnot q[1] | q[0];
         h -;
      }
      \equals
      \circuit{
         cnot q[0] | q[1];
      }
   \end{yquantgroup}
\end{tikzpicture}
```