|
a |
|
b/Code/All Qiskit, PennyLane QML Nov 23/23a Unitary Designs Fid. +.99 kkawchak.ipynb |
|
|
1 |
{ |
|
|
2 |
"cells": [ |
|
|
3 |
{ |
|
|
4 |
"cell_type": "code", |
|
|
5 |
"execution_count": 2, |
|
|
6 |
"metadata": { |
|
|
7 |
"id": "_mDT6fzqwQlp" |
|
|
8 |
}, |
|
|
9 |
"outputs": [], |
|
|
10 |
"source": [ |
|
|
11 |
"# This cell is added by sphinx-gallery\n", |
|
|
12 |
"# It can be customized to whatever you like\n", |
|
|
13 |
"%matplotlib inline\n", |
|
|
14 |
"# !pip install pennylane" |
|
|
15 |
] |
|
|
16 |
}, |
|
|
17 |
{ |
|
|
18 |
"cell_type": "markdown", |
|
|
19 |
"metadata": { |
|
|
20 |
"id": "HmioP9IlwQlq" |
|
|
21 |
}, |
|
|
22 |
"source": [ |
|
|
23 |
"Unitary designs\n", |
|
|
24 |
"===============\n", |
|
|
25 |
"\n", |
|
|
26 |
"::: {.meta}\n", |
|
|
27 |
":property=\\\"og:description\\\": Learn about designs and their uses in\n", |
|
|
28 |
"quantum computing.\n", |
|
|
29 |
"\n", |
|
|
30 |
":property=\\\"og:image\\\": <https://pennylane.ai/qml/_images/fano.png>\n", |
|
|
31 |
":::\n", |
|
|
32 |
"\n", |
|
|
33 |
"::: {.related}\n", |
|
|
34 |
"tutorial\\_haar\\_measure Understanding the Haar measure\n", |
|
|
35 |
":::\n", |
|
|
36 |
"\n", |
|
|
37 |
"*Author: Olivia Di Matteo --- Posted: 07 September 2021. Last updated:\n", |
|
|
38 |
"07 September 2021.*\n", |
|
|
39 |
"\n", |
|
|
40 |
"::: {.note}\n", |
|
|
41 |
"::: {.title}\n", |
|
|
42 |
"Note\n", |
|
|
43 |
":::\n", |
|
|
44 |
"\n", |
|
|
45 |
"This demo is intended to be a sequel to the\n", |
|
|
46 |
"`demo about the Haar measure </demos/tutorial_haar_measure>`{.interpreted-text\n", |
|
|
47 |
"role=\"doc\"}. If you are not familiar with the Haar measure, we recommend\n", |
|
|
48 |
"going through that demo first before exploring this one.\n", |
|
|
49 |
":::\n", |
|
|
50 |
"\n", |
|
|
51 |
"Take a close look at the following mathematical object:\n", |
|
|
52 |
"\n", |
|
|
53 |
"{.align-center\n", |
|
|
54 |
"width=\"30.0%\"}\n", |
|
|
55 |
"\n", |
|
|
56 |
"|\n", |
|
|
57 |
"\n", |
|
|
58 |
"There are many things we can say about it: it consists of seven points\n", |
|
|
59 |
"and seven lines (the circle counts as a line); each line contains three\n", |
|
|
60 |
"points, and each point is contained in three lines. Furthermore, any\n", |
|
|
61 |
"pair of points occur together in exactly one line. This object, called\n", |
|
|
62 |
"the [Fano plane](https://en.wikipedia.org/wiki/Fano_plane), is an\n", |
|
|
63 |
"instance of a mathematical structure called a [projective\n", |
|
|
64 |
"plane](https://en.wikipedia.org/wiki/Projective_plane), which is just\n", |
|
|
65 |
"one example of a [combinatorial\n", |
|
|
66 |
"design](https://en.wikipedia.org/wiki/Combinatorial_design). Designs are\n", |
|
|
67 |
"sets of objects, and groups of those objects, that satisfy certain\n", |
|
|
68 |
"balance properties and symmetries. They have been studied for hundreds\n", |
|
|
69 |
"of years in a huge variety of contexts, from [error correcting\n", |
|
|
70 |
"codes](http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.50.5465),\n", |
|
|
71 |
"to [card\n", |
|
|
72 |
"games](https://homepages.warwick.ac.uk/staff/D.Maclagan/papers/set.pdf),\n", |
|
|
73 |
"and even\n", |
|
|
74 |
"[agriculture](http://www-groups.mcs.st-and.ac.uk/~rab/histLShand.pdf).\n", |
|
|
75 |
"So, what about quantum computing?\n", |
|
|
76 |
"\n", |
|
|
77 |
"Designs are actually quite prevalent in quantum computing. You\\'ve\n", |
|
|
78 |
"almost certainly come across one before, though you may not have\n", |
|
|
79 |
"realized it. At the end of the Haar measure demo, we asked a very\n", |
|
|
80 |
"important question: \\\"do we always *need* to sample from the full Haar\n", |
|
|
81 |
"measure?\\\". The answer to this is \\\"no\\\", and the reasoning lies in the\n", |
|
|
82 |
"study of *unitary designs*.\n", |
|
|
83 |
"\n", |
|
|
84 |
"In this demo, you\\'ll learn the definition of $t$-designs, what it means\n", |
|
|
85 |
"to generalize them to unitary $t$-designs, and you\\'ll see some\n", |
|
|
86 |
"canonical examples of designs in quantum computing. You\\'ll also learn\n", |
|
|
87 |
"about their connection with the Haar measure, what it means to *twirl* a\n", |
|
|
88 |
"quantum channel, and explore how to leverage 2-designs in PennyLane to\n", |
|
|
89 |
"compute the average fidelity of a noisy channel. You will experience\n", |
|
|
90 |
"directly a situation where we can use a $t$-design as a shortcut over\n", |
|
|
91 |
"the full Haar measure to greatly improve the efficiency of a task 🎉.\n", |
|
|
92 |
"\n", |
|
|
93 |
"From spheres to unitary $t$-designs\n", |
|
|
94 |
"-----------------------------------\n", |
|
|
95 |
"\n", |
|
|
96 |
"### Spherical designs\n", |
|
|
97 |
"\n", |
|
|
98 |
"Before diving into unitary designs, let\\'s look at the sphere for some\n", |
|
|
99 |
"intuition. Suppose we have a polynomial in $d$ variables, and we would\n", |
|
|
100 |
"like to compute its average over the surface of a real, $d$-dimensional\n", |
|
|
101 |
"unit sphere, $S(R^d)$. We can do so by integrating that function over\n", |
|
|
102 |
"the sphere (using the proper measure), but that would be a lot of\n", |
|
|
103 |
"parameters to keep track of.\n", |
|
|
104 |
"\n", |
|
|
105 |
"One could alternatively approximate the average by sampling thousands of\n", |
|
|
106 |
"points uniformly at random on the sphere, evaluating the function at\n", |
|
|
107 |
"those points, and computing their average value. That will always work,\n", |
|
|
108 |
"and it will get us close, but it will not be exact.\n", |
|
|
109 |
"\n", |
|
|
110 |
"In fact, both of those approaches may be overkill in some special\n", |
|
|
111 |
"cases---if the terms in the polynomial have the same degree of at most\n", |
|
|
112 |
"$t$, you can compute the average **exactly** over the sphere using only\n", |
|
|
113 |
"a small set of points rather than integrating over the entire sphere.\n", |
|
|
114 |
"That set of points is called a spherical $t$-design. More formally,:\n", |
|
|
115 |
"\n", |
|
|
116 |
"::: {.admonition .defn}\n", |
|
|
117 |
"Definition\n", |
|
|
118 |
"\n", |
|
|
119 |
"Let $p_t: \\mathcal{S}(R^d)\\rightarrow R$ be a polynomial in $d$\n", |
|
|
120 |
"variables, with all terms homogeneous in degree at most $t$. A set\n", |
|
|
121 |
"$X = \\{x: x \\in \\mathcal{S}(R^d)\\}$ is a spherical $t$-design if\n", |
|
|
122 |
"\n", |
|
|
123 |
"$$\\frac{1}{|X|} \\sum_{x \\in X} p_t(x) = \\int_{\\mathcal{S}(R^d)} p_t (u) d\\mu(u)$$\n", |
|
|
124 |
"\n", |
|
|
125 |
"holds for all possible $p_t$, where $d\\mu$ is the uniform, normalized\n", |
|
|
126 |
"spherical measure. A spherical $t$-design is also a $k$-design for all\n", |
|
|
127 |
"$k < t$.\n", |
|
|
128 |
":::\n", |
|
|
129 |
"\n", |
|
|
130 |
"Now this is a pretty abstract picture, so let\\'s consider the\n", |
|
|
131 |
"3-dimensional sphere. This definition tells us that if we want to take\n", |
|
|
132 |
"the average of a polynomial over a sphere where all terms have the same\n", |
|
|
133 |
"degree of at most 2, we can do so using a small, representative set of\n", |
|
|
134 |
"points called a 2-design, rather than the whole sphere. Similarly, if\n", |
|
|
135 |
"all terms of the polynomial have the same degree of at most 3, we could\n", |
|
|
136 |
"use a 3-design.\n", |
|
|
137 |
"\n", |
|
|
138 |
"But what are these representative sets of points? Since we are using\n", |
|
|
139 |
"these points as a stand-in for averaging over the whole sphere, we\\'d\n", |
|
|
140 |
"want the points in the set to be distributed in a way that provides\n", |
|
|
141 |
"sufficient \\\"coverage\\\". In the 3-dimensional case, the vertices of some\n", |
|
|
142 |
"familiar solids form $t$-designs ,:\n", |
|
|
143 |
"\n", |
|
|
144 |
"{.align-center\n", |
|
|
145 |
"width=\"80.0%\"}\n", |
|
|
146 |
"\n", |
|
|
147 |
"|\n", |
|
|
148 |
"\n", |
|
|
149 |
"We see from these illustrations that spherical designs are sets of\n", |
|
|
150 |
"*evenly-spaced points*. As $t$ increases, the configurations become\n", |
|
|
151 |
"increasingly sphere-like. Looking at this in a different way, the more\n", |
|
|
152 |
"complex a function becomes as its degree increases, the closer the\n", |
|
|
153 |
"$t$-design must be to a sphere; we need to evaluate the function at more\n", |
|
|
154 |
"points in order to gain sufficient information when a function is\n", |
|
|
155 |
"varying more quickly due to a higher degree. In 3 dimensions, we can\n", |
|
|
156 |
"compute the average of a polynomial with degree 2 by evaluating it only\n", |
|
|
157 |
"at the points of a tetrahedron, despite the fact that it doesn\\'t look\n", |
|
|
158 |
"spherical at all. More complex functions require more points and thus\n", |
|
|
159 |
"more intricate configurations for the design. Spherical designs exist\n", |
|
|
160 |
"for all $t$ and dimension $d$. They are not always unique, and may have\n", |
|
|
161 |
"varying numbers of points.\n", |
|
|
162 |
"\n", |
|
|
163 |
"To show that this really works, let\\'s look at an explicit example.\n", |
|
|
164 |
"Consider the following polynomial in 3 variables:\n", |
|
|
165 |
"\n", |
|
|
166 |
"$$f(x, y, z) = x^4 - 4 x^3 y + y^2 z^2$$\n", |
|
|
167 |
"\n", |
|
|
168 |
"We can compute the average value of $f$ by integrating over a unit\n", |
|
|
169 |
"sphere: the result is $4/15 \\approx 0.26667$. However, this integral is\n", |
|
|
170 |
"non-trivial to evaluate by hand; the most straightforward way is to\n", |
|
|
171 |
"convert to polar coordinates, and even then, it involves integrating\n", |
|
|
172 |
"functions with 4th and 5th powers of trigonometric functions.\n", |
|
|
173 |
"\n", |
|
|
174 |
"Instead, this is a case where we can leverage the fact that all terms in\n", |
|
|
175 |
"the polynomial have degree 4, and compute the average exactly using only\n", |
|
|
176 |
"a subset of points that form a 4-design. We choose a dodecahedron for\n", |
|
|
177 |
"convenience; while this is actually a 5 design, it also forms a\n", |
|
|
178 |
"4-design, and is a more familiar shape than the 4-design depicted above.\n", |
|
|
179 |
"\n", |
|
|
180 |
"First, we define the set of points that comprise a dodecahedron:\n" |
|
|
181 |
] |
|
|
182 |
}, |
|
|
183 |
{ |
|
|
184 |
"cell_type": "code", |
|
|
185 |
"execution_count": 3, |
|
|
186 |
"metadata": { |
|
|
187 |
"id": "g_cdAioPwQlu" |
|
|
188 |
}, |
|
|
189 |
"outputs": [], |
|
|
190 |
"source": [ |
|
|
191 |
"import numpy as np\n", |
|
|
192 |
"\n", |
|
|
193 |
"# The golden ratio\n", |
|
|
194 |
"g = (1 + np.sqrt(5)) / 2\n", |
|
|
195 |
"\n", |
|
|
196 |
"# A dodecahedron has 20 points\n", |
|
|
197 |
"dodecahedron = np.array([\n", |
|
|
198 |
" # 8 of them form a cube within the sphere\n", |
|
|
199 |
" [1, 1, 1], [1, 1, -1], [1, -1, 1], [1, -1, -1],\n", |
|
|
200 |
" [-1, 1, 1], [-1, 1, -1], [-1, -1, 1], [-1, -1, -1],\n", |
|
|
201 |
"\n", |
|
|
202 |
" # 4 of them form a rectangle within the y-z plane\n", |
|
|
203 |
" [0, g, 1/g], [0, g, -1/g], [0, -g, 1/g], [0, -g, -1/g],\n", |
|
|
204 |
"\n", |
|
|
205 |
" # 4 of them form a rectangle within the x-z plane\n", |
|
|
206 |
" [1/g, 0, g], [1/g, 0, -g], [-1/g, 0, g], [-1/g, 0, -g],\n", |
|
|
207 |
"\n", |
|
|
208 |
" # 4 of them form a rectangle within the x-y plane\n", |
|
|
209 |
" [g, 1/g, 0],[g, -1/g, 0], [-g, 1/g, 0], [-g, -1/g, 0],\n", |
|
|
210 |
"])\n", |
|
|
211 |
"\n", |
|
|
212 |
"# Normalize the points so they all fit in the unit sphere\n", |
|
|
213 |
"dodecahedron = np.array(\n", |
|
|
214 |
" [point / np.linalg.norm(point) for point in dodecahedron]\n", |
|
|
215 |
")" |
|
|
216 |
] |
|
|
217 |
}, |
|
|
218 |
{ |
|
|
219 |
"cell_type": "markdown", |
|
|
220 |
"metadata": { |
|
|
221 |
"id": "PBMbC8iewQlv" |
|
|
222 |
}, |
|
|
223 |
"source": [ |
|
|
224 |
"Now we define our function and compute the average over the\n", |
|
|
225 |
"dodecahedron:\n" |
|
|
226 |
] |
|
|
227 |
}, |
|
|
228 |
{ |
|
|
229 |
"cell_type": "code", |
|
|
230 |
"execution_count": 4, |
|
|
231 |
"metadata": { |
|
|
232 |
"colab": { |
|
|
233 |
"base_uri": "https://localhost:8080/", |
|
|
234 |
"height": 0 |
|
|
235 |
}, |
|
|
236 |
"id": "ErTDyta4wQlv", |
|
|
237 |
"outputId": "671a8656-0194-45a8-b499-5ab17c83a7c5" |
|
|
238 |
}, |
|
|
239 |
"outputs": [ |
|
|
240 |
{ |
|
|
241 |
"output_type": "stream", |
|
|
242 |
"name": "stdout", |
|
|
243 |
"text": [ |
|
|
244 |
"0.2666666666666668\n" |
|
|
245 |
] |
|
|
246 |
} |
|
|
247 |
], |
|
|
248 |
"source": [ |
|
|
249 |
"def f(x, y, z):\n", |
|
|
250 |
" return (x ** 4) - 4 * (x ** 3) * y + y ** 2 * z ** 2\n", |
|
|
251 |
"\n", |
|
|
252 |
"dodeca_average = np.mean([f(*point) for point in dodecahedron])\n", |
|
|
253 |
"print(dodeca_average)" |
|
|
254 |
] |
|
|
255 |
}, |
|
|
256 |
{ |
|
|
257 |
"cell_type": "markdown", |
|
|
258 |
"metadata": { |
|
|
259 |
"id": "czP6zKXlwQlw" |
|
|
260 |
}, |
|
|
261 |
"source": [ |
|
|
262 |
"This is exactly the value we expect. What happens if we try to do this\n", |
|
|
263 |
"using only a 3-design, the cube?\n" |
|
|
264 |
] |
|
|
265 |
}, |
|
|
266 |
{ |
|
|
267 |
"cell_type": "code", |
|
|
268 |
"execution_count": 5, |
|
|
269 |
"metadata": { |
|
|
270 |
"colab": { |
|
|
271 |
"base_uri": "https://localhost:8080/", |
|
|
272 |
"height": 0 |
|
|
273 |
}, |
|
|
274 |
"id": "vlX-usmgwQlw", |
|
|
275 |
"outputId": "d68333f6-c85a-49e0-eada-02d3311b142c" |
|
|
276 |
}, |
|
|
277 |
"outputs": [ |
|
|
278 |
{ |
|
|
279 |
"output_type": "stream", |
|
|
280 |
"name": "stdout", |
|
|
281 |
"text": [ |
|
|
282 |
"0.22222222222222235\n" |
|
|
283 |
] |
|
|
284 |
} |
|
|
285 |
], |
|
|
286 |
"source": [ |
|
|
287 |
"# The first 8 points of the dodecahedron are a cube\n", |
|
|
288 |
"cube = dodecahedron[:8]\n", |
|
|
289 |
"\n", |
|
|
290 |
"cube_average = np.mean([f(*point) for point in cube])\n", |
|
|
291 |
"print(cube_average)" |
|
|
292 |
] |
|
|
293 |
}, |
|
|
294 |
{ |
|
|
295 |
"cell_type": "markdown", |
|
|
296 |
"metadata": { |
|
|
297 |
"id": "lHNtu3-GwQlx" |
|
|
298 |
}, |
|
|
299 |
"source": [ |
|
|
300 |
"This clearly differs from the true value. We need a design with $t=4$ or\n", |
|
|
301 |
"better in order to compute this average, and when such a design is\n", |
|
|
302 |
"available, we may save significant computational time.\n", |
|
|
303 |
"\n", |
|
|
304 |
"Unitary designs\n", |
|
|
305 |
"===============\n", |
|
|
306 |
"\n", |
|
|
307 |
"We\\'ve learned now that spherical designs are sets of evenly-spaced\n", |
|
|
308 |
"points, and saw how they can be used as a shortcut to evaluate the\n", |
|
|
309 |
"average of a polynomial up to a given degree $t$. However, there was\n", |
|
|
310 |
"nothing quantum about this; there weren\\'t even any complex numbers\n", |
|
|
311 |
"involved. A *unitary design* extends this concept from\n", |
|
|
312 |
"evenly-distributed points to evenly-distributed unitaries. More\n", |
|
|
313 |
"formally, instead of averaging polynomials over spheres, we consider\n", |
|
|
314 |
"polynomials that are functions of the entries of unitary matrices,.\n", |
|
|
315 |
"\n", |
|
|
316 |
"::: {.admonition .defn}\n", |
|
|
317 |
"Definition\n", |
|
|
318 |
"\n", |
|
|
319 |
"Let $P_{t,t}(U)$ be a polynomial with homogeneous degree at most $t$ in\n", |
|
|
320 |
"$d$ variables in the entries of a unitary matrix $U$, and degree $t$ in\n", |
|
|
321 |
"the complex conjugates of those entries. A unitary $t$-design is a set\n", |
|
|
322 |
"of $K$ unitaries $\\{U_k\\}$ such that\n", |
|
|
323 |
"\n", |
|
|
324 |
"$$\\frac{1}{K} \\sum_{k=1}^{K} P_{t,t}(U_k) = \\int_{\\mathcal{U}(d)}\n", |
|
|
325 |
"P_{t,t} (U) d\\mu(U)$$\n", |
|
|
326 |
"\n", |
|
|
327 |
"holds for all possible $P_{t,t}$, and where $d\\mu$ is the uniform *Haar\n", |
|
|
328 |
"measure*.\n", |
|
|
329 |
":::\n", |
|
|
330 |
"\n", |
|
|
331 |
"We stress again that this expression is **exact**. The unitaries in a\n", |
|
|
332 |
"unitary design are a representative set of points that are \\\"evenly\n", |
|
|
333 |
"spaced\\\" across the unitary group. With just a subset of the full group,\n", |
|
|
334 |
"we can evaluate complex expressions that would be otherwise intractable.\n", |
|
|
335 |
"\n", |
|
|
336 |
"A surprising result about unitary designs is that they exist for all\n", |
|
|
337 |
"possible combinations of $t$ and $d$. There are some known lower bounds\n", |
|
|
338 |
"for the number of unitaries required; for example, a 2-design in\n", |
|
|
339 |
"dimension $d$ has at least $d^4 - 2d^2 + 2$ elements, . However,\n", |
|
|
340 |
"actually finding the sets (and in particular, finding ones with minimal\n", |
|
|
341 |
"size), is a challenging problem, though very recently some constructions\n", |
|
|
342 |
"have been put forward.\n", |
|
|
343 |
"\n", |
|
|
344 |
"::: {.admonition}\n", |
|
|
345 |
"Fun fact\n", |
|
|
346 |
"\n", |
|
|
347 |
"Applying the elements of a unitary design to a fixed pure state produces\n", |
|
|
348 |
"a set of vectors that form a *complex projective design*. These are much\n", |
|
|
349 |
"like spherical designs, but they live in a complex vector space. If\n", |
|
|
350 |
"you\\'ve ever studied the characterization of quantum systems, you may\n", |
|
|
351 |
"have come across some special sets of measurements called mutually\n", |
|
|
352 |
"unbiased bases (MUBs), or symmetric, informationally complete positive\n", |
|
|
353 |
"operator valued measurements (SIC-POVMs). Both of these sets of vectors\n", |
|
|
354 |
"are complex projective 2-designs.\n", |
|
|
355 |
"\n", |
|
|
356 |
"{.align-center\n", |
|
|
359 |
"width=\"80.0%\"}\n", |
|
|
360 |
":::\n", |
|
|
361 |
"\n", |
|
|
362 |
"Unitary $t$-designs in action\n", |
|
|
363 |
"-----------------------------\n", |
|
|
364 |
"\n", |
|
|
365 |
"Unitary designs come into play in applications that require\n", |
|
|
366 |
"randomization, or sampling of random unitaries---essentially, they can\n", |
|
|
367 |
"be used as a stand-in for the Haar measure. The way in which the\n", |
|
|
368 |
"unitaries are used in the application may place restrictions on the\n", |
|
|
369 |
"value of $t$ that is required; arguably the most common is the unitary\n", |
|
|
370 |
"2-design.\n", |
|
|
371 |
"\n", |
|
|
372 |
"While in general unitary designs are hard to construct, there are well\n", |
|
|
373 |
"known results for unitary 1-, 2-, and 3-designs based on familiar\n", |
|
|
374 |
"objects in quantum computing. Before we see what those are, let\\'s\n", |
|
|
375 |
"explore an important use case.\n", |
|
|
376 |
"\n", |
|
|
377 |
"Average fidelity\n", |
|
|
378 |
"================\n", |
|
|
379 |
"\n", |
|
|
380 |
"A key application of unitary 2-designs is benchmarking quantum\n", |
|
|
381 |
"operations. Suppose we have a noisy quantum channel $\\Lambda$ that\n", |
|
|
382 |
"should perform something close to the unitary operation $V$. What can we\n", |
|
|
383 |
"say about the performance of this channel?\n", |
|
|
384 |
"\n", |
|
|
385 |
"One metric of interest is the *fidelity*. Consider the state\n", |
|
|
386 |
"$|0\\rangle$. In an ideal case, we apply $V$ and obtain $V|0\\rangle$. But\n", |
|
|
387 |
"applying the channel $\\Lambda$ gives us something a little different.\n", |
|
|
388 |
"Since it\\'s noisy, we must consider the state as a density matrix. The\n", |
|
|
389 |
"action of $\\Lambda$ on our starting state is\n", |
|
|
390 |
"$\\Lambda(|0\\rangle \\langle 0|)$. If $\\Lambda$ was perfect, then\n", |
|
|
391 |
"$\\Lambda(|0\\rangle \\langle 0|) = V|0\\rangle \\langle\n", |
|
|
392 |
"0|V^\\dagger$, and the fidelity is\n", |
|
|
393 |
"\n", |
|
|
394 |
"$$F(\\Lambda, V) = \\langle 0 | V^\\dagger \\cdot \\Lambda(|0\\rangle \\langle 0|) \\cdot V|0\\rangle = 1.$$\n", |
|
|
395 |
"\n", |
|
|
396 |
"In reality, $\\Lambda$ is not going to implement $V$ perfectly, and\n", |
|
|
397 |
"$F < 1$. More importantly though, all we\\'ve computed so far is the\n", |
|
|
398 |
"fidelity when the initial state is $|0\\rangle$. What if the initial\n", |
|
|
399 |
"state is something different? What is the fidelity *on average*?\n", |
|
|
400 |
"\n", |
|
|
401 |
"To compute an average fidelity, we must do so with respect to the full\n", |
|
|
402 |
"set of Haar-random states. We usually generate random states by applying\n", |
|
|
403 |
"a Haar-random unitary $U$ to $|0\\rangle$. Thus to compute the average\n", |
|
|
404 |
"over all such $U$ we must evaluate\n", |
|
|
405 |
"\n", |
|
|
406 |
"$$\\bar{F}(\\Lambda, V) = \\int_{\\mathcal{U}} d\\mu(U) \\langle 0 | U^\\dagger V^\\dagger \\Lambda(U |0\\rangle \\langle 0| U^\\dagger) V U |0\\rangle.$$\n", |
|
|
407 |
"\n", |
|
|
408 |
"This is known as *twirling* the channel $\\Lambda$. Computing the average\n", |
|
|
409 |
"fidelity in this way would be a nightmare---we\\'d have to compute the\n", |
|
|
410 |
"fidelity with respect to an infinite number of states!\n", |
|
|
411 |
"\n", |
|
|
412 |
"However, consider the expression in the integral above. We have an inner\n", |
|
|
413 |
"product involving two instances of $U$, and two instances of\n", |
|
|
414 |
"$U^\\dagger$. This means that the expression is a polynomial of degree 2\n", |
|
|
415 |
"in both the elements of $U$ and its complex conjugates---this matches\n", |
|
|
416 |
"exactly the definition of a unitary 2-design. This means that if we can\n", |
|
|
417 |
"find a set of $K$ unitaries that form a 2-design, we can compute the\n", |
|
|
418 |
"average fidelity using only a finite set of initial states:\n", |
|
|
419 |
"\n", |
|
|
420 |
"$$\\frac{1}{K} \\sum_{j=1}^K \\langle 0 | U_j^\\dagger V^\\dagger \\Lambda(U_j |0\\rangle \\langle 0|\n", |
|
|
421 |
"U_j^\\dagger) V^\\dagger U_j |0\\rangle = \\int_{\\mathcal{U}} d\\mu(U) \\langle 0\n", |
|
|
422 |
"| U^\\dagger V^\\dagger \\Lambda(U |0\\rangle \\langle 0| U^\\dagger) V U |0\\rangle$$\n", |
|
|
423 |
"\n", |
|
|
424 |
"This is great, but a question remains: what is the representative set of\n", |
|
|
425 |
"unitaries?\n", |
|
|
426 |
"\n", |
|
|
427 |
"The Clifford group\n", |
|
|
428 |
"==================\n", |
|
|
429 |
"\n", |
|
|
430 |
"A beautiful result in quantum computing is that some special groups you\n", |
|
|
431 |
"may already be familiar with are unitary designs:\n", |
|
|
432 |
"\n", |
|
|
433 |
"- the Pauli group forms a unitary 1-design, and\n", |
|
|
434 |
"- the Clifford group forms a unitary 3-design.\n", |
|
|
435 |
"\n", |
|
|
436 |
"By the definition of designs, this means the Clifford group is also a\n", |
|
|
437 |
"1-and 2-design.\n", |
|
|
438 |
"\n", |
|
|
439 |
"The $n$-qubit Pauli group, $\\mathcal{P}(n)$, is the set of all tensor\n", |
|
|
440 |
"products of Pauli operations $X$, $Y$, $Z$, and $I$. The $n$-qubit\n", |
|
|
441 |
"Clifford group, $\\mathcal{C}(n)$, is the *normalizer* of the Pauli\n", |
|
|
442 |
"group. In simpler terms, the Clifford group is the set of operations\n", |
|
|
443 |
"that send Paulis to Paulis (up to a phase) under conjugation i.e.,\n", |
|
|
444 |
"\n", |
|
|
445 |
"$$C P C^\\dagger = \\pm P^\\prime, \\quad \\forall P, P^\\prime \\in \\mathcal{P}(n), \\quad C \\in \\mathcal{C}(n).$$\n", |
|
|
446 |
"\n", |
|
|
447 |
"The Clifford group has some profoundly interesting properties and\n", |
|
|
448 |
"countless uses across quantum computing, from circuit compilation to\n", |
|
|
449 |
"error correcting codes. For a single qubit, the group is built from just\n", |
|
|
450 |
"two operations. One is the Hadamard:\n", |
|
|
451 |
"\n", |
|
|
452 |
"$$H X H^\\dagger = Z, \\quad H Y H^\\dagger = -Y, \\quad H Z H^\\dagger = X.$$\n", |
|
|
453 |
"\n", |
|
|
454 |
"This clearly maps Paulis to Paulis (up to a phase). The other is the\n", |
|
|
455 |
"phase gate $S$:\n", |
|
|
456 |
"\n", |
|
|
457 |
"$$S X S^\\dagger = Y, \\quad S Y S^\\dagger = -X, \\quad S Z S^\\dagger = Z.$$\n", |
|
|
458 |
"\n", |
|
|
459 |
"If both $H$ and $S$ map Paulis to Paulis, then products of them do as\n", |
|
|
460 |
"well. In group theory terms, the single-qubit Clifford group is\n", |
|
|
461 |
"generated by $H$ and $S$. For example, consider the action of $HS$:\n", |
|
|
462 |
"\n", |
|
|
463 |
"$$(HS) X (HS)^\\dagger = -Y, \\quad (HS) Y (HS)^\\dagger = -Z, \\quad (HS) Z (HS)^\\dagger = X.$$\n", |
|
|
464 |
"\n", |
|
|
465 |
"Since $Y = iXZ$, it is enough to specify Clifford operations by how they\n", |
|
|
466 |
"act on $X$ and $Z$. For a particular Clifford, there are 6 possible ways\n", |
|
|
467 |
"it can transform $X$, namely $\\pm X, \\pm Y$, or $\\pm Z$. Once that is\n", |
|
|
468 |
"determined, there are four remaining options for the transformation of\n", |
|
|
469 |
"$Z$, leading to 24 elements total.\n", |
|
|
470 |
"\n", |
|
|
471 |
"It takes some work, but you can take combinations of $H$ and $S$ and\n", |
|
|
472 |
"evaluate their action on $X$ and $Z$ (or look at their matrix\n", |
|
|
473 |
"representations) until you find all 24 unique elements. The results of\n", |
|
|
474 |
"this endeavour are expressed below as strings:\n" |
|
|
475 |
] |
|
|
476 |
}, |
|
|
477 |
{ |
|
|
478 |
"cell_type": "code", |
|
|
479 |
"execution_count": 6, |
|
|
480 |
"metadata": { |
|
|
481 |
"id": "htyWtrFVwQly" |
|
|
482 |
}, |
|
|
483 |
"outputs": [], |
|
|
484 |
"source": [ |
|
|
485 |
"single_qubit_cliffords = [\n", |
|
|
486 |
" '',\n", |
|
|
487 |
" 'H', 'S',\n", |
|
|
488 |
" 'HS', 'SH', 'SS',\n", |
|
|
489 |
" 'HSH', 'HSS', 'SHS', 'SSH', 'SSS',\n", |
|
|
490 |
" 'HSHS', 'HSSH', 'HSSS', 'SHSS', 'SSHS',\n", |
|
|
491 |
" 'HSHSS', 'HSSHS', 'SHSSH', 'SHSSS', 'SSHSS',\n", |
|
|
492 |
" 'HSHSSH', 'HSHSSS', 'HSSHSS'\n", |
|
|
493 |
"]" |
|
|
494 |
] |
|
|
495 |
}, |
|
|
496 |
{ |
|
|
497 |
"cell_type": "markdown", |
|
|
498 |
"metadata": { |
|
|
499 |
"id": "pGo_-fX8wQlz" |
|
|
500 |
}, |
|
|
501 |
"source": [ |
|
|
502 |
"To see for yourself how this set of unitaries is evenly distributed, try\n", |
|
|
503 |
"applying each of the Cliffords to the initial state $|0\\rangle$, and\n", |
|
|
504 |
"plot the resulting states on the Bloch sphere. You\\'ll find they are\n", |
|
|
505 |
"symmetric and evenly spaced; in fact, they are all eigenstates of $X$,\n", |
|
|
506 |
"$Y$, and $Z$. Furthermore, under the full group action, the result is\n", |
|
|
507 |
"balanced in the sense that each eigenstate is obtained the same number\n", |
|
|
508 |
"of times.\n", |
|
|
509 |
"\n", |
|
|
510 |
"The multi-qubit Clifford group can also be specified by only a small set\n", |
|
|
511 |
"of generators (in fact, only one more than is needed for the\n", |
|
|
512 |
"single-qubit case). Together, $H$, $S$, and CNOT (on every possible\n", |
|
|
513 |
"qubit or pair of qubits) generate the $n$-qubit group. Be careful\n", |
|
|
514 |
"though---the size of the group increases exponentially. The 2-qubit\n", |
|
|
515 |
"group alone has 11520 elements! The size can be worked out in a manner\n", |
|
|
516 |
"analogous to that we used above in the single qubit case: by looking at\n", |
|
|
517 |
"the combinatorics of the possible ways the gates can map Paulis with\n", |
|
|
518 |
"only $X$ and $Z$ to other Paulis.\n", |
|
|
519 |
"\n", |
|
|
520 |
"An experiment\n", |
|
|
521 |
"=============\n", |
|
|
522 |
"\n", |
|
|
523 |
"The whole idea of unitary designs may sound too good to be true. Can we\n", |
|
|
524 |
"*really* compute the exact average fidelity using just 24 operations? In\n", |
|
|
525 |
"this section, we put them to the test: we\\'ll compute the average\n", |
|
|
526 |
"fidelity of an operation first with experiments using a large but finite\n", |
|
|
527 |
"amount of Haar-random unitaries, and then again with only the Clifford\n", |
|
|
528 |
"group.\n" |
|
|
529 |
] |
|
|
530 |
}, |
|
|
531 |
{ |
|
|
532 |
"cell_type": "code", |
|
|
533 |
"execution_count": 7, |
|
|
534 |
"metadata": { |
|
|
535 |
"id": "0D3Bw8IXwQlz" |
|
|
536 |
}, |
|
|
537 |
"outputs": [], |
|
|
538 |
"source": [ |
|
|
539 |
"import pennylane as qml\n", |
|
|
540 |
"\n", |
|
|
541 |
"# Scipy allows us to sample Haar-random unitaries directly\n", |
|
|
542 |
"from scipy.stats import unitary_group\n", |
|
|
543 |
"\n", |
|
|
544 |
"# set the random seed\n", |
|
|
545 |
"np.random.seed(42)\n", |
|
|
546 |
"\n", |
|
|
547 |
"# Use the mixed state simulator\n", |
|
|
548 |
"dev = qml.device(\"default.mixed\", wires=1)" |
|
|
549 |
] |
|
|
550 |
}, |
|
|
551 |
{ |
|
|
552 |
"cell_type": "markdown", |
|
|
553 |
"metadata": { |
|
|
554 |
"id": "AooBqsfDwQl0" |
|
|
555 |
}, |
|
|
556 |
"source": [ |
|
|
557 |
"Let\\'s set up a noisy quantum channel. To keep things simple, assume it\n", |
|
|
558 |
"consists of applying `~.pennylane.SX`{.interpreted-text role=\"class\"},\n", |
|
|
559 |
"the square-root of $X$ gate, followed by a few different types of noise.\n", |
|
|
560 |
"First, write a quantum function for our ideal experiment:\n" |
|
|
561 |
] |
|
|
562 |
}, |
|
|
563 |
{ |
|
|
564 |
"cell_type": "code", |
|
|
565 |
"execution_count": 8, |
|
|
566 |
"metadata": { |
|
|
567 |
"id": "yZtqAXHkwQl0" |
|
|
568 |
}, |
|
|
569 |
"outputs": [], |
|
|
570 |
"source": [ |
|
|
571 |
"def ideal_experiment():\n", |
|
|
572 |
" qml.SX(wires=0)\n", |
|
|
573 |
" return qml.state()" |
|
|
574 |
] |
|
|
575 |
}, |
|
|
576 |
{ |
|
|
577 |
"cell_type": "markdown", |
|
|
578 |
"metadata": { |
|
|
579 |
"id": "XZX2g2SswQl1" |
|
|
580 |
}, |
|
|
581 |
"source": [ |
|
|
582 |
"Next, we apply some noise. We do so by making use of a relatively new\n", |
|
|
583 |
"feature in PennyLane called [quantum function\n", |
|
|
584 |
"transforms](https://pennylane.readthedocs.io/en/latest/code/qml_transforms.html).\n", |
|
|
585 |
"Such transforms work by modifying the underlying, low-level quantum\n", |
|
|
586 |
"tapes which queue the quantum operations. Suppose the noisy channel is\n", |
|
|
587 |
"composed of the following:\n" |
|
|
588 |
] |
|
|
589 |
}, |
|
|
590 |
{ |
|
|
591 |
"cell_type": "code", |
|
|
592 |
"execution_count": 9, |
|
|
593 |
"metadata": { |
|
|
594 |
"id": "iWgu5nLXwQl1" |
|
|
595 |
}, |
|
|
596 |
"outputs": [], |
|
|
597 |
"source": [ |
|
|
598 |
"def noisy_operations(damp_factor, depo_factor, flip_prob):\n", |
|
|
599 |
" qml.AmplitudeDamping(damp_factor, wires=0)\n", |
|
|
600 |
" qml.DepolarizingChannel(depo_factor, wires=0)\n", |
|
|
601 |
" qml.BitFlip(flip_prob, wires=0)" |
|
|
602 |
] |
|
|
603 |
}, |
|
|
604 |
{ |
|
|
605 |
"cell_type": "markdown", |
|
|
606 |
"metadata": { |
|
|
607 |
"id": "hXMC2ARewQl1" |
|
|
608 |
}, |
|
|
609 |
"source": [ |
|
|
610 |
"Let\\'s create a transform that applies this noise to any quantum\n", |
|
|
611 |
"function *after* the original operations, but before the measurements.\n", |
|
|
612 |
"We use the convenient\n", |
|
|
613 |
"`~.pennylane.transforms.qfunc_transform`{.interpreted-text role=\"func\"}\n", |
|
|
614 |
"decorator:\n" |
|
|
615 |
] |
|
|
616 |
}, |
|
|
617 |
{ |
|
|
618 |
"cell_type": "code", |
|
|
619 |
"execution_count": 10, |
|
|
620 |
"metadata": { |
|
|
621 |
"id": "lhN6Ge4VwQl1" |
|
|
622 |
}, |
|
|
623 |
"outputs": [], |
|
|
624 |
"source": [ |
|
|
625 |
"@qml.qfunc_transform\n", |
|
|
626 |
"def apply_noise(tape, damp_factor, depo_factor, flip_prob):\n", |
|
|
627 |
" # Apply the original operations\n", |
|
|
628 |
" for op in tape.operations:\n", |
|
|
629 |
" qml.apply(op)\n", |
|
|
630 |
"\n", |
|
|
631 |
" # Apply the noisy sequence\n", |
|
|
632 |
" noisy_operations(damp_factor, depo_factor, flip_prob)\n", |
|
|
633 |
"\n", |
|
|
634 |
" # Apply the original measurements\n", |
|
|
635 |
" for m in tape.measurements:\n", |
|
|
636 |
" qml.apply(m)" |
|
|
637 |
] |
|
|
638 |
}, |
|
|
639 |
{ |
|
|
640 |
"cell_type": "markdown", |
|
|
641 |
"metadata": { |
|
|
642 |
"id": "nV2Mpa88wQl2" |
|
|
643 |
}, |
|
|
644 |
"source": [ |
|
|
645 |
"We can now apply this transform to create a noisy version of our ideal\n", |
|
|
646 |
"quantum function:\n" |
|
|
647 |
] |
|
|
648 |
}, |
|
|
649 |
{ |
|
|
650 |
"cell_type": "code", |
|
|
651 |
"execution_count": 11, |
|
|
652 |
"metadata": { |
|
|
653 |
"id": "N1eG4TFWwQl2" |
|
|
654 |
}, |
|
|
655 |
"outputs": [], |
|
|
656 |
"source": [ |
|
|
657 |
"# The strengths of various types of noise\n", |
|
|
658 |
"damp_factor = 0.02\n", |
|
|
659 |
"depo_factor = 0.02\n", |
|
|
660 |
"flip_prob = 0.0001\n", |
|
|
661 |
"\n", |
|
|
662 |
"noisy_experiment = apply_noise(damp_factor, depo_factor, flip_prob)(ideal_experiment)" |
|
|
663 |
] |
|
|
664 |
}, |
|
|
665 |
{ |
|
|
666 |
"cell_type": "markdown", |
|
|
667 |
"metadata": { |
|
|
668 |
"id": "EomIg-qmwQl2" |
|
|
669 |
}, |
|
|
670 |
"source": [ |
|
|
671 |
"The last part of the experiment involves applying a random unitary\n", |
|
|
672 |
"matrix before all the operations, and its inverse right before the\n", |
|
|
673 |
"measurements. We can write another transform here to streamline this\n", |
|
|
674 |
"process:\n" |
|
|
675 |
] |
|
|
676 |
}, |
|
|
677 |
{ |
|
|
678 |
"cell_type": "code", |
|
|
679 |
"execution_count": 12, |
|
|
680 |
"metadata": { |
|
|
681 |
"id": "kNLUeoQAwQl2" |
|
|
682 |
}, |
|
|
683 |
"outputs": [], |
|
|
684 |
"source": [ |
|
|
685 |
"@qml.qfunc_transform\n", |
|
|
686 |
"def conjugate_with_unitary(tape, matrix):\n", |
|
|
687 |
" qml.QubitUnitary(matrix, wires=0)\n", |
|
|
688 |
"\n", |
|
|
689 |
" for op in tape.operations:\n", |
|
|
690 |
" qml.apply(op)\n", |
|
|
691 |
"\n", |
|
|
692 |
" qml.QubitUnitary(matrix.conj().T, wires=0)\n", |
|
|
693 |
"\n", |
|
|
694 |
" for m in tape.measurements:\n", |
|
|
695 |
" qml.apply(m)" |
|
|
696 |
] |
|
|
697 |
}, |
|
|
698 |
{ |
|
|
699 |
"cell_type": "markdown", |
|
|
700 |
"metadata": { |
|
|
701 |
"id": "BbICvvouwQl3" |
|
|
702 |
}, |
|
|
703 |
"source": [ |
|
|
704 |
"Finally, in order to perform a comparison, we need a function to compute\n", |
|
|
705 |
"the [fidelity](https://en.wikipedia.org/wiki/Fidelity_of_quantum_states)\n", |
|
|
706 |
"compared to the ideal operation.\n" |
|
|
707 |
] |
|
|
708 |
}, |
|
|
709 |
{ |
|
|
710 |
"cell_type": "code", |
|
|
711 |
"execution_count": 13, |
|
|
712 |
"metadata": { |
|
|
713 |
"id": "aDrUBq_awQl3" |
|
|
714 |
}, |
|
|
715 |
"outputs": [], |
|
|
716 |
"source": [ |
|
|
717 |
"from scipy.linalg import sqrtm\n", |
|
|
718 |
"\n", |
|
|
719 |
"def fidelity(rho, sigma):\n", |
|
|
720 |
" # Inputs rho and sigma are density matrices\n", |
|
|
721 |
" sqrt_sigma = sqrtm(sigma)\n", |
|
|
722 |
" fid = np.trace(sqrtm(sqrt_sigma @ rho @ sqrt_sigma))\n", |
|
|
723 |
" return fid.real" |
|
|
724 |
] |
|
|
725 |
}, |
|
|
726 |
{ |
|
|
727 |
"cell_type": "markdown", |
|
|
728 |
"metadata": { |
|
|
729 |
"id": "77i6U6C4wQl3" |
|
|
730 |
}, |
|
|
731 |
"source": [ |
|
|
732 |
"Let\\'s now compute the average fidelity, averaging over 50000\n", |
|
|
733 |
"Haar-random unitaries:\n" |
|
|
734 |
] |
|
|
735 |
}, |
|
|
736 |
{ |
|
|
737 |
"cell_type": "code", |
|
|
738 |
"execution_count": 14, |
|
|
739 |
"metadata": { |
|
|
740 |
"colab": { |
|
|
741 |
"base_uri": "https://localhost:8080/", |
|
|
742 |
"height": 0 |
|
|
743 |
}, |
|
|
744 |
"id": "-SWuQCvHwQl3", |
|
|
745 |
"outputId": "4b8b328b-8cb0-46e7-b34f-b4789fcebd01" |
|
|
746 |
}, |
|
|
747 |
"outputs": [ |
|
|
748 |
{ |
|
|
749 |
"output_type": "stream", |
|
|
750 |
"name": "stdout", |
|
|
751 |
"text": [ |
|
|
752 |
"Mean fidelity = 0.9900781215223946\n" |
|
|
753 |
] |
|
|
754 |
} |
|
|
755 |
], |
|
|
756 |
"source": [ |
|
|
757 |
"n_samples = 50000\n", |
|
|
758 |
"\n", |
|
|
759 |
"fidelities = []\n", |
|
|
760 |
"\n", |
|
|
761 |
"for _ in range(n_samples):\n", |
|
|
762 |
" # Select a Haar-random unitary\n", |
|
|
763 |
" U = unitary_group.rvs(2)\n", |
|
|
764 |
"\n", |
|
|
765 |
" # Apply transform to construct the ideal and noisy quantum functions\n", |
|
|
766 |
" conjugated_ideal_experiment = conjugate_with_unitary(U)(ideal_experiment)\n", |
|
|
767 |
" conjugated_noisy_experiment = conjugate_with_unitary(U)(noisy_experiment)\n", |
|
|
768 |
"\n", |
|
|
769 |
" # Use the functions to create QNodes\n", |
|
|
770 |
" ideal_qnode = qml.QNode(conjugated_ideal_experiment, dev)\n", |
|
|
771 |
" noisy_qnode = qml.QNode(conjugated_noisy_experiment, dev)\n", |
|
|
772 |
"\n", |
|
|
773 |
" # Execute the QNodes\n", |
|
|
774 |
" ideal_state = ideal_qnode()\n", |
|
|
775 |
" noisy_state = noisy_qnode()\n", |
|
|
776 |
"\n", |
|
|
777 |
" # Compute the fidelity\n", |
|
|
778 |
" fidelities.append(fidelity(ideal_state, noisy_state))\n", |
|
|
779 |
"\n", |
|
|
780 |
"fid_mean = np.mean(fidelities)\n", |
|
|
781 |
"print(f\"Mean fidelity = {fid_mean}\")" |
|
|
782 |
] |
|
|
783 |
}, |
|
|
784 |
{ |
|
|
785 |
"cell_type": "markdown", |
|
|
786 |
"metadata": { |
|
|
787 |
"id": "hneAjRLbwQl3" |
|
|
788 |
}, |
|
|
789 |
"source": [ |
|
|
790 |
"Now let\\'s repeat the procedure using only Clifford group elements.\n", |
|
|
791 |
"First, we write a quantum function that performs a Clifford operation\n", |
|
|
792 |
"(or its inverse) based on its string representation.\n" |
|
|
793 |
] |
|
|
794 |
}, |
|
|
795 |
{ |
|
|
796 |
"cell_type": "code", |
|
|
797 |
"execution_count": 15, |
|
|
798 |
"metadata": { |
|
|
799 |
"id": "YAaqy1W0wQl4" |
|
|
800 |
}, |
|
|
801 |
"outputs": [], |
|
|
802 |
"source": [ |
|
|
803 |
"def apply_single_clifford(clifford_string, inverse=False):\n", |
|
|
804 |
" for gate in clifford_string:\n", |
|
|
805 |
" if gate == 'H':\n", |
|
|
806 |
" qml.Hadamard(wires=0)\n", |
|
|
807 |
" else:\n", |
|
|
808 |
" sign = -1 if inverse else 1\n", |
|
|
809 |
" qml.PhaseShift(sign * np.pi/2, wires=0)" |
|
|
810 |
] |
|
|
811 |
}, |
|
|
812 |
{ |
|
|
813 |
"cell_type": "markdown", |
|
|
814 |
"metadata": { |
|
|
815 |
"id": "2adwduIowQl4" |
|
|
816 |
}, |
|
|
817 |
"source": [ |
|
|
818 |
"Next, we write a transform that applies a Clifford in the context of the\n", |
|
|
819 |
"full experiment, i.e., apply the Clifford, then the operations, followed\n", |
|
|
820 |
"by the inverse of the Clifford.\n" |
|
|
821 |
] |
|
|
822 |
}, |
|
|
823 |
{ |
|
|
824 |
"cell_type": "code", |
|
|
825 |
"execution_count": 16, |
|
|
826 |
"metadata": { |
|
|
827 |
"id": "pI-3y8HzwQl4" |
|
|
828 |
}, |
|
|
829 |
"outputs": [], |
|
|
830 |
"source": [ |
|
|
831 |
"@qml.qfunc_transform\n", |
|
|
832 |
"def conjugate_with_clifford(tape, clifford_string):\n", |
|
|
833 |
" apply_single_clifford(clifford_string, inverse=False)\n", |
|
|
834 |
"\n", |
|
|
835 |
" for op in tape.operations:\n", |
|
|
836 |
" qml.apply(op)\n", |
|
|
837 |
"\n", |
|
|
838 |
" apply_single_clifford(clifford_string, inverse=True)\n", |
|
|
839 |
"\n", |
|
|
840 |
" for m in tape.measurements:\n", |
|
|
841 |
" qml.apply(m)" |
|
|
842 |
] |
|
|
843 |
}, |
|
|
844 |
{ |
|
|
845 |
"cell_type": "markdown", |
|
|
846 |
"metadata": { |
|
|
847 |
"id": "0kaDBhE5wQl4" |
|
|
848 |
}, |
|
|
849 |
"source": [ |
|
|
850 |
"You may have noticed this transform has exactly the same form as\n", |
|
|
851 |
"`conjugate_with_unitary` from above. Only the input type has changed,\n", |
|
|
852 |
"since the application of Cliffords here is specified by their string\n", |
|
|
853 |
"representation.\n", |
|
|
854 |
"\n", |
|
|
855 |
"It\\'s now time to run the experiments:\n" |
|
|
856 |
] |
|
|
857 |
}, |
|
|
858 |
{ |
|
|
859 |
"cell_type": "code", |
|
|
860 |
"execution_count": 17, |
|
|
861 |
"metadata": { |
|
|
862 |
"id": "85LSAbLpwQl4" |
|
|
863 |
}, |
|
|
864 |
"outputs": [], |
|
|
865 |
"source": [ |
|
|
866 |
"fidelities = []\n", |
|
|
867 |
"\n", |
|
|
868 |
"for C in single_qubit_cliffords:\n", |
|
|
869 |
" conjugated_ideal_experiment = conjugate_with_clifford(C)(ideal_experiment)\n", |
|
|
870 |
" conjugated_noisy_experiment = conjugate_with_clifford(C)(noisy_experiment)\n", |
|
|
871 |
"\n", |
|
|
872 |
" ideal_qnode = qml.QNode(conjugated_ideal_experiment, dev)\n", |
|
|
873 |
" noisy_qnode = qml.QNode(conjugated_noisy_experiment, dev)\n", |
|
|
874 |
"\n", |
|
|
875 |
" ideal_state = ideal_qnode()\n", |
|
|
876 |
" noisy_state = noisy_qnode()\n", |
|
|
877 |
"\n", |
|
|
878 |
" fidelities.append(fidelity(ideal_state, noisy_state))" |
|
|
879 |
] |
|
|
880 |
}, |
|
|
881 |
{ |
|
|
882 |
"cell_type": "markdown", |
|
|
883 |
"metadata": { |
|
|
884 |
"id": "cx0-SuYBwQl4" |
|
|
885 |
}, |
|
|
886 |
"source": [ |
|
|
887 |
"Let\\'s see how our results compare to the earlier simulation:\n" |
|
|
888 |
] |
|
|
889 |
}, |
|
|
890 |
{ |
|
|
891 |
"cell_type": "code", |
|
|
892 |
"execution_count": 18, |
|
|
893 |
"metadata": { |
|
|
894 |
"colab": { |
|
|
895 |
"base_uri": "https://localhost:8080/", |
|
|
896 |
"height": 0 |
|
|
897 |
}, |
|
|
898 |
"id": "P846UtObwQl5", |
|
|
899 |
"outputId": "b4a95c23-1d32-4831-e3ca-3ed1f89924bf" |
|
|
900 |
}, |
|
|
901 |
"outputs": [ |
|
|
902 |
{ |
|
|
903 |
"output_type": "stream", |
|
|
904 |
"name": "stdout", |
|
|
905 |
"text": [ |
|
|
906 |
"Haar-random mean fidelity = 0.9900781215223946\n", |
|
|
907 |
"Clifford mean fidelity = 0.9900574834455249\n" |
|
|
908 |
] |
|
|
909 |
} |
|
|
910 |
], |
|
|
911 |
"source": [ |
|
|
912 |
"clifford_fid_mean = np.mean(fidelities)\n", |
|
|
913 |
"\n", |
|
|
914 |
"print(f\"Haar-random mean fidelity = {fid_mean}\")\n", |
|
|
915 |
"print(f\"Clifford mean fidelity = {clifford_fid_mean}\")" |
|
|
916 |
] |
|
|
917 |
}, |
|
|
918 |
{ |
|
|
919 |
"cell_type": "markdown", |
|
|
920 |
"metadata": { |
|
|
921 |
"id": "kGKdKRmnwQl5" |
|
|
922 |
}, |
|
|
923 |
"source": [ |
|
|
924 |
"Incredible 🤯 🤯 🤯 We were able to compute the average fidelity using only\n", |
|
|
925 |
"24 experiments. Furthermore, the mean fidelity obtained from the\n", |
|
|
926 |
"Clifford experiments is **exact**; even with 50000 Haar-random\n", |
|
|
927 |
"experiments, we see deviations starting a few decimal places in.\n", |
|
|
928 |
"Consider the resources that would be saved if you were actually\n", |
|
|
929 |
"implementing this in a lab! It\\'s not hard to see why the Clifford group\n", |
|
|
930 |
"plays such an important role in characterization procedures.\n", |
|
|
931 |
"\n", |
|
|
932 |
"Conclusion\n", |
|
|
933 |
"==========\n", |
|
|
934 |
"\n", |
|
|
935 |
"In this demo, we\\'ve barely scratched the surface of designs and their\n", |
|
|
936 |
"applications in quantum computing. While benchmarking is a key\n", |
|
|
937 |
"application area, there are many others. The Pauli group as a unitary\n", |
|
|
938 |
"1-design has applications in the construction of private quantum\n", |
|
|
939 |
"channels[^1]. *Approximate* unitary $t$-designs (where the equality in\n", |
|
|
940 |
"the definition is replaced by approximately equal up to some finite\n", |
|
|
941 |
"precision) are also of interest, as there ways to construct them that\n", |
|
|
942 |
"are more efficient than those of exact designs[^2]. In particular, it\n", |
|
|
943 |
"has been shown that approximate complex projective 4-designs have\n", |
|
|
944 |
"applications to the state discrimination problem[^3].\n", |
|
|
945 |
"\n", |
|
|
946 |
"Furthermore, unitary designs are not the only designs that you\\'ll\n", |
|
|
947 |
"encounter in quantum computing. The familiar Hadamard gate is just a\n", |
|
|
948 |
"2-dimensional example of a broader family of *Hadamard designs*, on\n", |
|
|
949 |
"which there has been extensive research[^4]. Some sets of [mutually\n", |
|
|
950 |
"orthogonal Latin\n", |
|
|
951 |
"squares](https://en.wikipedia.org/wiki/Mutually_orthogonal_Latin_squares)\n", |
|
|
952 |
"have a direct correspondence with mutually unbiased bases, which are\n", |
|
|
953 |
"optimal quantum measurements[^5], as well as complex projective designs;\n", |
|
|
954 |
"and Latin squares themselves have direct correspondence with affine and\n", |
|
|
955 |
"projective planes, bringing us full circle back to the Fano plane from\n", |
|
|
956 |
"which we began.\n", |
|
|
957 |
"\n", |
|
|
958 |
"{.align-center\n", |
|
|
961 |
"width=\"80.0%\"}\n", |
|
|
962 |
"\n", |
|
|
963 |
"References\n", |
|
|
964 |
"==========\n", |
|
|
965 |
"\n", |
|
|
966 |
"About the author\n", |
|
|
967 |
"================\n", |
|
|
968 |
"\n", |
|
|
969 |
"[^1]: A. Ambainis, M. Mosca, A. Tapp, and R. de Wolf (2000) *Private\n", |
|
|
970 |
" Quantum Channels*. Proc. 41st FOCS, 547-553.\n", |
|
|
971 |
" [(PDF)](https://homepages.cwi.nl/~rdewolf/publ/qc/AMTW00.pdf).\n", |
|
|
972 |
"\n", |
|
|
973 |
"[^2]: C. Dankert, R. Cleve, J. Emerson, and E. Levine (2009) *Exact and\n", |
|
|
974 |
" Approximate Unitary 2-Designs: Constructions and Applications.*\n", |
|
|
975 |
" Phys. Rev. A 80, 012304.\n", |
|
|
976 |
" [(arXiv)](https://arxiv.org/abs/quant-ph/0606161).\n", |
|
|
977 |
"\n", |
|
|
978 |
"[^3]: A. Ambainis and J. Emerson (2007) *Quantum t-designs: t-wise\n", |
|
|
979 |
" independence in the quantum world.* Twenty-Second Annual IEEE\n", |
|
|
980 |
" Conference on Computational Complexity 129-140.\n", |
|
|
981 |
" [(arXiv)](https://arxiv.org/abs/quant-ph/0701126).\n", |
|
|
982 |
"\n", |
|
|
983 |
"[^4]: J. Seberry and M. Yamada (1992) *Hadamard matrices, sequences, and\n", |
|
|
984 |
" block designs.* Contemporary Design Theory -- A Collection of\n", |
|
|
985 |
" Surveys (D. J. Stinson and J. Dinitz, Eds.), John Wiley and Sons,\n", |
|
|
986 |
" 431-560. [(PDF)](http://mathscinet.ru/files/YamadaSeberry1992.pdf).\n", |
|
|
987 |
"\n", |
|
|
988 |
"[^5]: M. Gaeta, O. Di Matteo, A. B. Klimov, and H. de Guise (2014)\n", |
|
|
989 |
" *Discrete phase-space approach to mutually orthogonal Latin\n", |
|
|
990 |
" squares*. J. Phys. A: Math. Theor. 47 (43) 435303.\n", |
|
|
991 |
" [(arXiv)](https://arxiv.org/abs/1408.6742).\n" |
|
|
992 |
] |
|
|
993 |
} |
|
|
994 |
], |
|
|
995 |
"metadata": { |
|
|
996 |
"kernelspec": { |
|
|
997 |
"display_name": "Python 3", |
|
|
998 |
"name": "python3" |
|
|
999 |
}, |
|
|
1000 |
"language_info": { |
|
|
1001 |
"codemirror_mode": { |
|
|
1002 |
"name": "ipython", |
|
|
1003 |
"version": 3 |
|
|
1004 |
}, |
|
|
1005 |
"file_extension": ".py", |
|
|
1006 |
"mimetype": "text/x-python", |
|
|
1007 |
"name": "python", |
|
|
1008 |
"nbconvert_exporter": "python", |
|
|
1009 |
"pygments_lexer": "ipython3", |
|
|
1010 |
"version": "3.9.17" |
|
|
1011 |
}, |
|
|
1012 |
"colab": { |
|
|
1013 |
"provenance": [] |
|
|
1014 |
} |
|
|
1015 |
}, |
|
|
1016 |
"nbformat": 4, |
|
|
1017 |
"nbformat_minor": 0 |
|
|
1018 |
} |