microsoft/qdk

Public

mirrored fromhttps://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
alex/bounds

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

samples/notebooks/sample.ipynb

1473lines · modecode

1{
2 "cells": [
3 {
4 "cell_type": "markdown",
5 "id": "a2f48f2b",
6 "metadata": {},
7 "source": [
8 "Import the Q# module.\n",
9 "\n",
10 "This enables the `%%qsharp` magic and initializes a Q# interpreter singleton."
11 ]
12 },
13 {
14 "cell_type": "markdown",
15 "id": "ed1b75bf",
16 "metadata": {},
17 "source": []
18 },
19 {
20 "cell_type": "code",
21 "execution_count": 1,
22 "id": "1e8e4faa",
23 "metadata": {},
24 "outputs": [
25 {
26 "data": {
27 "application/javascript": "// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n// This file provides CodeMirror syntax highlighting for Q# magic cells\n// in classic Jupyter Notebooks. It does nothing in other (Jupyter Notebook 7,\n// VS Code, Azure Notebooks, etc.) environments.\n\n// Detect the prerequisites and do nothing if they don't exist.\nif (window.require && window.CodeMirror && window.Jupyter) {\n // The simple mode plugin for CodeMirror is not loaded by default, so require it.\n window.require([\"codemirror/addon/mode/simple\"], function defineMode() {\n let rules = [\n {\n token: \"comment\",\n regex: /(\\/\\/).*/,\n beginWord: false,\n },\n {\n token: \"string\",\n regex: String.raw`^\\\"(?:[^\\\"\\\\]|\\\\[\\s\\S])*(?:\\\"|$)`,\n beginWord: false,\n },\n {\n token: \"keyword\",\n regex: String.raw`(namespace|open|as|operation|function|body|adjoint|newtype|controlled|internal)\\b`,\n beginWord: true,\n },\n {\n token: \"keyword\",\n regex: String.raw`(if|elif|else|repeat|until|fixup|for|in|return|fail|within|apply)\\b`,\n beginWord: true,\n },\n {\n token: \"keyword\",\n regex: String.raw`(Adjoint|Controlled|Adj|Ctl|is|self|auto|distribute|invert|intrinsic)\\b`,\n beginWord: true,\n },\n {\n token: \"keyword\",\n regex: String.raw`(let|set|use|borrow|mutable)\\b`,\n beginWord: true,\n },\n {\n token: \"operatorKeyword\",\n regex: String.raw`(not|and|or)\\b|(w/)`,\n beginWord: true,\n },\n {\n token: \"operatorKeyword\",\n regex: String.raw`(=)|(!)|(<)|(>)|(\\+)|(-)|(\\*)|(/)|(\\^)|(%)|(\\|)|(&&&)|(~~~)|(\\.\\.\\.)|(\\.\\.)|(\\?)`,\n beginWord: false,\n },\n {\n token: \"meta\",\n regex: String.raw`(Int|BigInt|Double|Bool|Qubit|Pauli|Result|Range|String|Unit)\\b`,\n beginWord: true,\n },\n {\n token: \"atom\",\n regex: String.raw`(true|false|Pauli(I|X|Y|Z)|One|Zero)\\b`,\n beginWord: true,\n },\n ];\n let simpleRules = [];\n for (let rule of rules) {\n simpleRules.push({\n token: rule.token,\n regex: new RegExp(rule.regex, \"g\"),\n sol: rule.beginWord,\n });\n if (rule.beginWord) {\n // Need an additional rule due to the fact that CodeMirror simple mode doesn't work with ^ token\n simpleRules.push({\n token: rule.token,\n regex: new RegExp(String.raw`\\W` + rule.regex, \"g\"),\n sol: false,\n });\n }\n }\n\n // Register the mode defined above with CodeMirror\n window.CodeMirror.defineSimpleMode(\"qsharp\", { start: simpleRules });\n window.CodeMirror.defineMIME(\"text/x-qsharp\", \"qsharp\");\n\n // Tell Jupyter to associate %%qsharp magic cells with the qsharp mode\n window.Jupyter.CodeCell.options_default.highlight_modes[\"qsharp\"] = {\n reg: [/^%%qsharp/],\n };\n\n // Force re-highlighting of all cells the first time this code runs\n for (const cell of window.Jupyter.notebook.get_cells()) {\n cell.auto_highlight();\n }\n });\n}\n",
28 "text/plain": []
29 },
30 "metadata": {},
31 "output_type": "display_data"
32 }
33 ],
34 "source": [
35 "import qsharp\n"
36 ]
37 },
38 {
39 "cell_type": "markdown",
40 "id": "3a536d53",
41 "metadata": {},
42 "source": [
43 "Run Q# using the `%%qsharp` magic.\n",
44 "\n",
45 "`DumpMachine()` and `Message()` output get formatted as HTML. Return value is shown as cell output."
46 ]
47 },
48 {
49 "cell_type": "code",
50 "execution_count": 2,
51 "id": "9df62352",
52 "metadata": {
53 "vscode": {
54 "languageId": "qsharp"
55 }
56 },
57 "outputs": [
58 {
59 "data": {
60 "text/markdown": [
61 "<table class=\"qs-stateTable\">\n",
62 " <style>\n",
63 " .qs-stateTable thead tr {\n",
64 " background-color: var(\n",
65 " --vscode-list-hoverBackground,\n",
66 " var(--jp-layout-color1, inherit)\n",
67 " );\n",
68 " }\n",
69 " .qs-stateTable th {\n",
70 " text-align: left;\n",
71 " border: none;\n",
72 " }\n",
73 " .qs-stateTable tbody {\n",
74 " pointer-events: none;\n",
75 " }\n",
76 " .qs-stateTable tbody td {\n",
77 " text-align: left;\n",
78 " border: none;\n",
79 " }\n",
80 " .qs-stateTable tbody td span {\n",
81 " display: inline-block;\n",
82 " }\n",
83 " .qs-stateTable tbody tr:nth-child(even) {\n",
84 " background-color: var(\n",
85 " --vscode-list-hoverBackground,\n",
86 " var(--jp-layout-color1, inherit)\n",
87 " );\n",
88 " }\n",
89 " </style>\n",
90 " <thead>\n",
91 " <tr>\n",
92 " <th>Basis State<br />(|𝜓₁…𝜓ₙ⟩)</th>\n",
93 " <th>Amplitude</th>\n",
94 " <th>Measurement Probability</th>\n",
95 " <th colspan=\"2\">Phase</th>\n",
96 " </tr>\n",
97 " </thead>\n",
98 " <tbody>\n",
99 " <tr>\n",
100 " <td>\n",
101 " <span>|1⟩</span>\n",
102 " </td>\n",
103 " <td>\n",
104 " <span>1.0000+0.0000𝑖</span>\n",
105 " </td>\n",
106 " <td>\n",
107 " <progress max=\"100\" value=\"100\"></progress>\n",
108 " <span>100.0000%</span>\n",
109 " </td>\n",
110 " <td style=\"transform: rotate(0.0000rad)\">↑</td>\n",
111 " <td>\n",
112 " <span>0.0000</span>\n",
113 " </td>\n",
114 "</tr>\n",
115 "\n",
116 " </tbody>\n",
117 "</table>\n",
118 "\n",
119 "\n",
120 "$|\\psi\\rangle = |1\\rangle$"
121 ],
122 "text/plain": [
123 "STATE:\n",
124 "|1⟩: 1.0000+0.0000𝑖"
125 ]
126 },
127 "metadata": {},
128 "output_type": "display_data"
129 },
130 {
131 "data": {},
132 "metadata": {},
133 "output_type": "display_data"
134 },
135 {
136 "data": {
137 "text/plain": [
138 "The result of the measurement is One"
139 ]
140 },
141 "metadata": {},
142 "output_type": "display_data"
143 },
144 {
145 "data": {},
146 "metadata": {},
147 "output_type": "display_data"
148 },
149 {
150 "data": {
151 "text/plain": [
152 "One"
153 ]
154 },
155 "execution_count": 2,
156 "metadata": {},
157 "output_type": "execute_result"
158 }
159 ],
160 "source": [
161 "%%qsharp\n",
162 "\n",
163 "operation Main() : Result {\n",
164 " use q = Qubit();\n",
165 " X(q);\n",
166 " Microsoft.Quantum.Diagnostics.DumpMachine();\n",
167 " let r = M(q);\n",
168 " Message($\"The result of the measurement is {r}\");\n",
169 " Reset(q);\n",
170 " r\n",
171 "}\n",
172 "\n",
173 "Main()\n"
174 ]
175 },
176 {
177 "cell_type": "markdown",
178 "id": "4584c494",
179 "metadata": {},
180 "source": [
181 "`qsharp.eval()` does the same thing as the `%%qsharp` magic.\n",
182 "\n",
183 "`DumpMachine()` and `Message()` print to stdout and get displayed in the notebook as plain text"
184 ]
185 },
186 {
187 "cell_type": "code",
188 "execution_count": 3,
189 "id": "7d0995bf",
190 "metadata": {
191 "scrolled": true
192 },
193 "outputs": [
194 {
195 "data": {},
196 "metadata": {},
197 "output_type": "display_data"
198 },
199 {
200 "data": {
201 "text/markdown": [
202 "<table class=\"qs-stateTable\">\n",
203 " <style>\n",
204 " .qs-stateTable thead tr {\n",
205 " background-color: var(\n",
206 " --vscode-list-hoverBackground,\n",
207 " var(--jp-layout-color1, inherit)\n",
208 " );\n",
209 " }\n",
210 " .qs-stateTable th {\n",
211 " text-align: left;\n",
212 " border: none;\n",
213 " }\n",
214 " .qs-stateTable tbody {\n",
215 " pointer-events: none;\n",
216 " }\n",
217 " .qs-stateTable tbody td {\n",
218 " text-align: left;\n",
219 " border: none;\n",
220 " }\n",
221 " .qs-stateTable tbody td span {\n",
222 " display: inline-block;\n",
223 " }\n",
224 " .qs-stateTable tbody tr:nth-child(even) {\n",
225 " background-color: var(\n",
226 " --vscode-list-hoverBackground,\n",
227 " var(--jp-layout-color1, inherit)\n",
228 " );\n",
229 " }\n",
230 " </style>\n",
231 " <thead>\n",
232 " <tr>\n",
233 " <th>Basis State<br />(|𝜓₁…𝜓ₙ⟩)</th>\n",
234 " <th>Amplitude</th>\n",
235 " <th>Measurement Probability</th>\n",
236 " <th colspan=\"2\">Phase</th>\n",
237 " </tr>\n",
238 " </thead>\n",
239 " <tbody>\n",
240 " <tr>\n",
241 " <td>\n",
242 " <span>|1⟩</span>\n",
243 " </td>\n",
244 " <td>\n",
245 " <span>1.0000+0.0000𝑖</span>\n",
246 " </td>\n",
247 " <td>\n",
248 " <progress max=\"100\" value=\"100\"></progress>\n",
249 " <span>100.0000%</span>\n",
250 " </td>\n",
251 " <td style=\"transform: rotate(0.0000rad)\">↑</td>\n",
252 " <td>\n",
253 " <span>0.0000</span>\n",
254 " </td>\n",
255 "</tr>\n",
256 "\n",
257 " </tbody>\n",
258 "</table>\n",
259 "\n",
260 "\n",
261 "$|\\psi\\rangle = |1\\rangle$"
262 ],
263 "text/plain": [
264 "STATE:\n",
265 "|1⟩: 1.0000+0.0000𝑖"
266 ]
267 },
268 "metadata": {},
269 "output_type": "display_data"
270 },
271 {
272 "data": {
273 "text/plain": [
274 "The result of the measurement is One"
275 ]
276 },
277 "metadata": {},
278 "output_type": "display_data"
279 },
280 {
281 "data": {
282 "text/plain": [
283 "One"
284 ]
285 },
286 "execution_count": 3,
287 "metadata": {},
288 "output_type": "execute_result"
289 }
290 ],
291 "source": [
292 "qsharp.eval(\"Main()\")\n"
293 ]
294 },
295 {
296 "cell_type": "markdown",
297 "id": "a3bde193",
298 "metadata": {},
299 "source": [
300 "Assign a result to a Python variable."
301 ]
302 },
303 {
304 "cell_type": "code",
305 "execution_count": 4,
306 "id": "50383f8a",
307 "metadata": {},
308 "outputs": [
309 {
310 "data": {},
311 "metadata": {},
312 "output_type": "display_data"
313 },
314 {
315 "name": "stdout",
316 "output_type": "stream",
317 "text": [
318 "Result: 3 (type: int)\n"
319 ]
320 }
321 ],
322 "source": [
323 "result = qsharp.eval(\"1 + 2\")\n",
324 "\n",
325 "print(f\"Result: {result} (type: {type(result).__name__})\")\n"
326 ]
327 },
328 {
329 "cell_type": "markdown",
330 "id": "b06b7857",
331 "metadata": {},
332 "source": [
333 "Errors are exceptions. \n",
334 "\n",
335 "Catch and handle compilation errors."
336 ]
337 },
338 {
339 "cell_type": "code",
340 "execution_count": 5,
341 "id": "33fd3c4d",
342 "metadata": {},
343 "outputs": [
344 {
345 "data": {},
346 "metadata": {},
347 "output_type": "display_data"
348 },
349 {
350 "name": "stdout",
351 "output_type": "stream",
352 "text": [
353 "Qsc.Resolve.NotFound\n",
354 "\n",
355 " x name error\n",
356 " `-> `Bar` not found\n",
357 " ,-[line_3:3:5]\n",
358 " 2 | operation Foo() : Unit {\n",
359 " 3 | Bar();\n",
360 " : ^^^\n",
361 " 4 | Baz();\n",
362 " `----\n",
363 "Qsc.Resolve.NotFound\n",
364 "\n",
365 " x name error\n",
366 " `-> `Baz` not found\n",
367 " ,-[line_3:4:5]\n",
368 " 3 | Bar();\n",
369 " 4 | Baz();\n",
370 " : ^^^\n",
371 " 5 | }\n",
372 " `----\n",
373 "Qsc.TypeCk.AmbiguousTy\n",
374 "\n",
375 " x type error\n",
376 " `-> insufficient type information to infer type\n",
377 " ,-[line_3:3:5]\n",
378 " 2 | operation Foo() : Unit {\n",
379 " 3 | Bar();\n",
380 " : ^^^^^\n",
381 " 4 | Baz();\n",
382 " `----\n",
383 " help: provide a type annotation\n",
384 "Qsc.TypeCk.AmbiguousTy\n",
385 "\n",
386 " x type error\n",
387 " `-> insufficient type information to infer type\n",
388 " ,-[line_3:4:5]\n",
389 " 3 | Bar();\n",
390 " 4 | Baz();\n",
391 " : ^^^^^\n",
392 " 5 | }\n",
393 " `----\n",
394 " help: provide a type annotation\n",
395 "\n"
396 ]
397 }
398 ],
399 "source": [
400 "from qsharp import QSharpError\n",
401 "\n",
402 "try:\n",
403 " qsharp.eval(\n",
404 " \"\"\"\n",
405 "operation Foo() : Unit {\n",
406 " Bar();\n",
407 " Baz();\n",
408 "}\n",
409 "\"\"\"\n",
410 " )\n",
411 "except QSharpError as ex:\n",
412 " print(ex)\n"
413 ]
414 },
415 {
416 "cell_type": "markdown",
417 "id": "00f82a16",
418 "metadata": {},
419 "source": [
420 "Catch and handle runtime errors."
421 ]
422 },
423 {
424 "cell_type": "code",
425 "execution_count": 6,
426 "id": "e70a95d9",
427 "metadata": {},
428 "outputs": [
429 {
430 "data": {},
431 "metadata": {},
432 "output_type": "display_data"
433 },
434 {
435 "name": "stdout",
436 "output_type": "stream",
437 "text": [
438 "Error: Qubit0 released while not in |0⟩ state\n",
439 "Call stack:\n",
440 " at QIR.Runtime.__quantum__rt__qubit_release in qsharp-library-source:core/qir.qs\n",
441 " at Foo in line_4\n",
442 "Qsc.Eval.ReleasedQubitNotZero\n",
443 "\n",
444 " x runtime error\n",
445 " `-> Qubit0 released while not in |0⟩ state\n",
446 " ,-[line_4:1:26]\n",
447 " 1 | operation Foo() : Unit { use q = Qubit(); X(q) } Foo()\n",
448 " : ^^^^^^^^|^^^^^^^\n",
449 " : `-- Qubit0\n",
450 " `----\n",
451 " help: qubits should be returned to the |0⟩ state before being released to\n",
452 " satisfy the assumption that allocated qubits start in the |0⟩ state\n",
453 "\n"
454 ]
455 }
456 ],
457 "source": [
458 "try:\n",
459 " qsharp.eval(\"operation Foo() : Unit { use q = Qubit(); X(q) } Foo()\")\n",
460 "except QSharpError as ex:\n",
461 " print(ex)\n"
462 ]
463 },
464 {
465 "cell_type": "markdown",
466 "id": "3e294471",
467 "metadata": {},
468 "source": [
469 "A runtime error that's not caught gets reported as a Python exception."
470 ]
471 },
472 {
473 "cell_type": "code",
474 "execution_count": 7,
475 "id": "d40d86cb",
476 "metadata": {},
477 "outputs": [
478 {
479 "data": {},
480 "metadata": {},
481 "output_type": "display_data"
482 },
483 {
484 "ename": "QSharpError",
485 "evalue": "Error: Qubit0 released while not in |0⟩ state\nCall stack:\n at QIR.Runtime.__quantum__rt__qubit_release in qsharp-library-source:core/qir.qs\n at Foo in line_5\nQsc.Eval.ReleasedQubitNotZero\n\n x runtime error\n `-> Qubit0 released while not in |0⟩ state\n ,-[line_5:1:26]\n 1 | operation Foo() : Unit { use q = Qubit(); X(q) } Foo()\n : ^^^^^^^^|^^^^^^^\n : `-- Qubit0\n `----\n help: qubits should be returned to the |0⟩ state before being released to\n satisfy the assumption that allocated qubits start in the |0⟩ state\n",
486 "output_type": "error",
487 "traceback": [
488 "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
489 "\u001b[0;31mQSharpError\u001b[0m Traceback (most recent call last)",
490 "Cell \u001b[0;32mIn[7], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m qsharp\u001b[38;5;241m.\u001b[39meval(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124moperation Foo() : Unit \u001b[39m\u001b[38;5;124m{\u001b[39m\u001b[38;5;124m use q = Qubit(); X(q) } Foo()\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
491 "File \u001b[0;32m~/.local/lib/python3.12/site-packages/qsharp/_qsharp.py:241\u001b[0m, in \u001b[0;36meval\u001b[0;34m(source)\u001b[0m\n\u001b[1;32m 238\u001b[0m \u001b[38;5;28;01mpass\u001b[39;00m\n\u001b[1;32m 239\u001b[0m \u001b[38;5;28mprint\u001b[39m(output, flush\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)\n\u001b[0;32m--> 241\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m get_interpreter()\u001b[38;5;241m.\u001b[39minterpret(source, callback)\n",
492 "\u001b[0;31mQSharpError\u001b[0m: Error: Qubit0 released while not in |0⟩ state\nCall stack:\n at QIR.Runtime.__quantum__rt__qubit_release in qsharp-library-source:core/qir.qs\n at Foo in line_5\nQsc.Eval.ReleasedQubitNotZero\n\n x runtime error\n `-> Qubit0 released while not in |0⟩ state\n ,-[line_5:1:26]\n 1 | operation Foo() : Unit { use q = Qubit(); X(q) } Foo()\n : ^^^^^^^^|^^^^^^^\n : `-- Qubit0\n `----\n help: qubits should be returned to the |0⟩ state before being released to\n satisfy the assumption that allocated qubits start in the |0⟩ state\n"
493 ]
494 }
495 ],
496 "source": [
497 "qsharp.eval(\"operation Foo() : Unit { use q = Qubit(); X(q) } Foo()\")\n"
498 ]
499 },
500 {
501 "cell_type": "markdown",
502 "id": "ba2f98ad",
503 "metadata": {},
504 "source": [
505 "In `%%qsharp` cells, exceptions are handled and displayed as error text."
506 ]
507 },
508 {
509 "cell_type": "code",
510 "execution_count": 8,
511 "id": "1b55e53c",
512 "metadata": {
513 "scrolled": false,
514 "vscode": {
515 "languageId": "qsharp"
516 }
517 },
518 "outputs": [
519 {
520 "data": {
521 "text/markdown": [
522 "<table class=\"qs-stateTable\">\n",
523 " <style>\n",
524 " .qs-stateTable thead tr {\n",
525 " background-color: var(\n",
526 " --vscode-list-hoverBackground,\n",
527 " var(--jp-layout-color1, inherit)\n",
528 " );\n",
529 " }\n",
530 " .qs-stateTable th {\n",
531 " text-align: left;\n",
532 " border: none;\n",
533 " }\n",
534 " .qs-stateTable tbody {\n",
535 " pointer-events: none;\n",
536 " }\n",
537 " .qs-stateTable tbody td {\n",
538 " text-align: left;\n",
539 " border: none;\n",
540 " }\n",
541 " .qs-stateTable tbody td span {\n",
542 " display: inline-block;\n",
543 " }\n",
544 " .qs-stateTable tbody tr:nth-child(even) {\n",
545 " background-color: var(\n",
546 " --vscode-list-hoverBackground,\n",
547 " var(--jp-layout-color1, inherit)\n",
548 " );\n",
549 " }\n",
550 " </style>\n",
551 " <thead>\n",
552 " <tr>\n",
553 " <th>Basis State<br />(|𝜓₁…𝜓ₙ⟩)</th>\n",
554 " <th>Amplitude</th>\n",
555 " <th>Measurement Probability</th>\n",
556 " <th colspan=\"2\">Phase</th>\n",
557 " </tr>\n",
558 " </thead>\n",
559 " <tbody>\n",
560 " <tr>\n",
561 " <td>\n",
562 " <span>|0⟩</span>\n",
563 " </td>\n",
564 " <td>\n",
565 " <span>1.0000+0.0000𝑖</span>\n",
566 " </td>\n",
567 " <td>\n",
568 " <progress max=\"100\" value=\"100\"></progress>\n",
569 " <span>100.0000%</span>\n",
570 " </td>\n",
571 " <td style=\"transform: rotate(0.0000rad)\">↑</td>\n",
572 " <td>\n",
573 " <span>0.0000</span>\n",
574 " </td>\n",
575 "</tr>\n",
576 "\n",
577 " </tbody>\n",
578 "</table>\n",
579 "\n",
580 "\n",
581 "$|\\psi\\rangle = |0\\rangle$"
582 ],
583 "text/plain": [
584 "STATE:\n",
585 "|0⟩: 1.0000+0.0000𝑖"
586 ]
587 },
588 "metadata": {},
589 "output_type": "display_data"
590 },
591 {
592 "data": {},
593 "metadata": {},
594 "output_type": "display_data"
595 },
596 {
597 "ename": "QSharpCellError",
598 "evalue": "Error: Qubit0 released while not in |0⟩ state\nCall stack:\n at QIR.Runtime.__quantum__rt__qubit_release in qsharp-library-source:core/qir.qs\n at Bar in line_6\nQsc.Eval.ReleasedQubitNotZero\n\n x runtime error\n `-> Qubit0 released while not in |0⟩ state\n ,-[line_6:3:5]\n 2 | operation Bar() : Unit {\n 3 | use q = Qubit();\n : ^^^^^^^^|^^^^^^^\n : `-- Qubit0\n 4 | Microsoft.Quantum.Diagnostics.DumpMachine();\n `----\n help: qubits should be returned to the |0⟩ state before being released to\n satisfy the assumption that allocated qubits start in the |0⟩ state\n",
599 "output_type": "error",
600 "traceback": [
601 "Error: Qubit0 released while not in |0⟩ state",
602 "Call stack:",
603 " at QIR.Runtime.__quantum__rt__qubit_release in qsharp-library-source:core/qir.qs",
604 " at Bar in line_6",
605 "Qsc.Eval.ReleasedQubitNotZero",
606 "",
607 " x runtime error",
608 " `-> Qubit0 released while not in |0⟩ state",
609 " ,-[line_6:3:5]",
610 " 2 | operation Bar() : Unit {",
611 " 3 | use q = Qubit();",
612 " : ^^^^^^^^|^^^^^^^",
613 " : `-- Qubit0",
614 " 4 | Microsoft.Quantum.Diagnostics.DumpMachine();",
615 " `----",
616 " help: qubits should be returned to the |0⟩ state before being released to",
617 " satisfy the assumption that allocated qubits start in the |0⟩ state"
618 ]
619 }
620 ],
621 "source": [
622 "%%qsharp\n",
623 "\n",
624 "operation Bar() : Unit {\n",
625 " use q = Qubit();\n",
626 " Microsoft.Quantum.Diagnostics.DumpMachine();\n",
627 " X(q);\n",
628 "}\n",
629 "\n",
630 "Bar()\n"
631 ]
632 },
633 {
634 "cell_type": "markdown",
635 "id": "98247ac2",
636 "metadata": {},
637 "source": [
638 "Streaming output for long running operations."
639 ]
640 },
641 {
642 "cell_type": "code",
643 "execution_count": 9,
644 "id": "bd25ae87",
645 "metadata": {
646 "vscode": {
647 "languageId": "qsharp"
648 }
649 },
650 "outputs": [
651 {
652 "data": {
653 "text/plain": [
654 "Generating random bit... "
655 ]
656 },
657 "metadata": {},
658 "output_type": "display_data"
659 },
660 {
661 "data": {},
662 "metadata": {},
663 "output_type": "display_data"
664 },
665 {
666 "data": {
667 "text/markdown": [
668 "<table class=\"qs-stateTable\">\n",
669 " <style>\n",
670 " .qs-stateTable thead tr {\n",
671 " background-color: var(\n",
672 " --vscode-list-hoverBackground,\n",
673 " var(--jp-layout-color1, inherit)\n",
674 " );\n",
675 " }\n",
676 " .qs-stateTable th {\n",
677 " text-align: left;\n",
678 " border: none;\n",
679 " }\n",
680 " .qs-stateTable tbody {\n",
681 " pointer-events: none;\n",
682 " }\n",
683 " .qs-stateTable tbody td {\n",
684 " text-align: left;\n",
685 " border: none;\n",
686 " }\n",
687 " .qs-stateTable tbody td span {\n",
688 " display: inline-block;\n",
689 " }\n",
690 " .qs-stateTable tbody tr:nth-child(even) {\n",
691 " background-color: var(\n",
692 " --vscode-list-hoverBackground,\n",
693 " var(--jp-layout-color1, inherit)\n",
694 " );\n",
695 " }\n",
696 " </style>\n",
697 " <thead>\n",
698 " <tr>\n",
699 " <th>Basis State<br />(|𝜓₁…𝜓ₙ⟩)</th>\n",
700 " <th>Amplitude</th>\n",
701 " <th>Measurement Probability</th>\n",
702 " <th colspan=\"2\">Phase</th>\n",
703 " </tr>\n",
704 " </thead>\n",
705 " <tbody>\n",
706 " <tr>\n",
707 " <td>\n",
708 " <span>|1⟩</span>\n",
709 " </td>\n",
710 " <td>\n",
711 " <span>1.0000+0.0000𝑖</span>\n",
712 " </td>\n",
713 " <td>\n",
714 " <progress max=\"100\" value=\"100\"></progress>\n",
715 " <span>100.0000%</span>\n",
716 " </td>\n",
717 " <td style=\"transform: rotate(0.0000rad)\">↑</td>\n",
718 " <td>\n",
719 " <span>0.0000</span>\n",
720 " </td>\n",
721 "</tr>\n",
722 "\n",
723 " </tbody>\n",
724 "</table>\n",
725 "\n",
726 "\n",
727 "$|\\psi\\rangle = |1\\rangle$"
728 ],
729 "text/plain": [
730 "STATE:\n",
731 "|1⟩: 1.0000+0.0000𝑖"
732 ]
733 },
734 "metadata": {},
735 "output_type": "display_data"
736 },
737 {
738 "data": {},
739 "metadata": {},
740 "output_type": "display_data"
741 },
742 {
743 "data": {
744 "text/plain": [
745 "Result: One"
746 ]
747 },
748 "metadata": {},
749 "output_type": "display_data"
750 },
751 {
752 "data": {},
753 "metadata": {},
754 "output_type": "display_data"
755 },
756 {
757 "data": {
758 "text/markdown": [
759 "<table class=\"qs-stateTable\">\n",
760 " <style>\n",
761 " .qs-stateTable thead tr {\n",
762 " background-color: var(\n",
763 " --vscode-list-hoverBackground,\n",
764 " var(--jp-layout-color1, inherit)\n",
765 " );\n",
766 " }\n",
767 " .qs-stateTable th {\n",
768 " text-align: left;\n",
769 " border: none;\n",
770 " }\n",
771 " .qs-stateTable tbody {\n",
772 " pointer-events: none;\n",
773 " }\n",
774 " .qs-stateTable tbody td {\n",
775 " text-align: left;\n",
776 " border: none;\n",
777 " }\n",
778 " .qs-stateTable tbody td span {\n",
779 " display: inline-block;\n",
780 " }\n",
781 " .qs-stateTable tbody tr:nth-child(even) {\n",
782 " background-color: var(\n",
783 " --vscode-list-hoverBackground,\n",
784 " var(--jp-layout-color1, inherit)\n",
785 " );\n",
786 " }\n",
787 " </style>\n",
788 " <thead>\n",
789 " <tr>\n",
790 " <th>Basis State<br />(|𝜓₁…𝜓ₙ⟩)</th>\n",
791 " <th>Amplitude</th>\n",
792 " <th>Measurement Probability</th>\n",
793 " <th colspan=\"2\">Phase</th>\n",
794 " </tr>\n",
795 " </thead>\n",
796 " <tbody>\n",
797 " <tr>\n",
798 " <td>\n",
799 " <span>|0⟩</span>\n",
800 " </td>\n",
801 " <td>\n",
802 " <span>1.0000+0.0000𝑖</span>\n",
803 " </td>\n",
804 " <td>\n",
805 " <progress max=\"100\" value=\"100\"></progress>\n",
806 " <span>100.0000%</span>\n",
807 " </td>\n",
808 " <td style=\"transform: rotate(0.0000rad)\">↑</td>\n",
809 " <td>\n",
810 " <span>0.0000</span>\n",
811 " </td>\n",
812 "</tr>\n",
813 "\n",
814 " </tbody>\n",
815 "</table>\n",
816 "\n",
817 "\n",
818 "$|\\psi\\rangle = |0\\rangle$"
819 ],
820 "text/plain": [
821 "STATE:\n",
822 "|0⟩: 1.0000+0.0000𝑖"
823 ]
824 },
825 "metadata": {},
826 "output_type": "display_data"
827 },
828 {
829 "data": {},
830 "metadata": {},
831 "output_type": "display_data"
832 },
833 {
834 "data": {
835 "text/plain": [
836 "Result: Zero"
837 ]
838 },
839 "metadata": {},
840 "output_type": "display_data"
841 },
842 {
843 "data": {},
844 "metadata": {},
845 "output_type": "display_data"
846 },
847 {
848 "data": {
849 "text/markdown": [
850 "<table class=\"qs-stateTable\">\n",
851 " <style>\n",
852 " .qs-stateTable thead tr {\n",
853 " background-color: var(\n",
854 " --vscode-list-hoverBackground,\n",
855 " var(--jp-layout-color1, inherit)\n",
856 " );\n",
857 " }\n",
858 " .qs-stateTable th {\n",
859 " text-align: left;\n",
860 " border: none;\n",
861 " }\n",
862 " .qs-stateTable tbody {\n",
863 " pointer-events: none;\n",
864 " }\n",
865 " .qs-stateTable tbody td {\n",
866 " text-align: left;\n",
867 " border: none;\n",
868 " }\n",
869 " .qs-stateTable tbody td span {\n",
870 " display: inline-block;\n",
871 " }\n",
872 " .qs-stateTable tbody tr:nth-child(even) {\n",
873 " background-color: var(\n",
874 " --vscode-list-hoverBackground,\n",
875 " var(--jp-layout-color1, inherit)\n",
876 " );\n",
877 " }\n",
878 " </style>\n",
879 " <thead>\n",
880 " <tr>\n",
881 " <th>Basis State<br />(|𝜓₁…𝜓ₙ⟩)</th>\n",
882 " <th>Amplitude</th>\n",
883 " <th>Measurement Probability</th>\n",
884 " <th colspan=\"2\">Phase</th>\n",
885 " </tr>\n",
886 " </thead>\n",
887 " <tbody>\n",
888 " <tr>\n",
889 " <td>\n",
890 " <span>|0⟩</span>\n",
891 " </td>\n",
892 " <td>\n",
893 " <span>1.0000+0.0000𝑖</span>\n",
894 " </td>\n",
895 " <td>\n",
896 " <progress max=\"100\" value=\"100\"></progress>\n",
897 " <span>100.0000%</span>\n",
898 " </td>\n",
899 " <td style=\"transform: rotate(0.0000rad)\">↑</td>\n",
900 " <td>\n",
901 " <span>0.0000</span>\n",
902 " </td>\n",
903 "</tr>\n",
904 "\n",
905 " </tbody>\n",
906 "</table>\n",
907 "\n",
908 "\n",
909 "$|\\psi\\rangle = |0\\rangle$"
910 ],
911 "text/plain": [
912 "STATE:\n",
913 "|0⟩: 1.0000+0.0000𝑖"
914 ]
915 },
916 "metadata": {},
917 "output_type": "display_data"
918 },
919 {
920 "data": {},
921 "metadata": {},
922 "output_type": "display_data"
923 },
924 {
925 "data": {
926 "text/plain": [
927 "Result: Zero"
928 ]
929 },
930 "metadata": {},
931 "output_type": "display_data"
932 },
933 {
934 "data": {},
935 "metadata": {},
936 "output_type": "display_data"
937 },
938 {
939 "data": {
940 "text/markdown": [
941 "<table class=\"qs-stateTable\">\n",
942 " <style>\n",
943 " .qs-stateTable thead tr {\n",
944 " background-color: var(\n",
945 " --vscode-list-hoverBackground,\n",
946 " var(--jp-layout-color1, inherit)\n",
947 " );\n",
948 " }\n",
949 " .qs-stateTable th {\n",
950 " text-align: left;\n",
951 " border: none;\n",
952 " }\n",
953 " .qs-stateTable tbody {\n",
954 " pointer-events: none;\n",
955 " }\n",
956 " .qs-stateTable tbody td {\n",
957 " text-align: left;\n",
958 " border: none;\n",
959 " }\n",
960 " .qs-stateTable tbody td span {\n",
961 " display: inline-block;\n",
962 " }\n",
963 " .qs-stateTable tbody tr:nth-child(even) {\n",
964 " background-color: var(\n",
965 " --vscode-list-hoverBackground,\n",
966 " var(--jp-layout-color1, inherit)\n",
967 " );\n",
968 " }\n",
969 " </style>\n",
970 " <thead>\n",
971 " <tr>\n",
972 " <th>Basis State<br />(|𝜓₁…𝜓ₙ⟩)</th>\n",
973 " <th>Amplitude</th>\n",
974 " <th>Measurement Probability</th>\n",
975 " <th colspan=\"2\">Phase</th>\n",
976 " </tr>\n",
977 " </thead>\n",
978 " <tbody>\n",
979 " <tr>\n",
980 " <td>\n",
981 " <span>|0⟩</span>\n",
982 " </td>\n",
983 " <td>\n",
984 " <span>1.0000+0.0000𝑖</span>\n",
985 " </td>\n",
986 " <td>\n",
987 " <progress max=\"100\" value=\"100\"></progress>\n",
988 " <span>100.0000%</span>\n",
989 " </td>\n",
990 " <td style=\"transform: rotate(0.0000rad)\">↑</td>\n",
991 " <td>\n",
992 " <span>0.0000</span>\n",
993 " </td>\n",
994 "</tr>\n",
995 "\n",
996 " </tbody>\n",
997 "</table>\n",
998 "\n",
999 "\n",
1000 "$|\\psi\\rangle = |0\\rangle$"
1001 ],
1002 "text/plain": [
1003 "STATE:\n",
1004 "|0⟩: 1.0000+0.0000𝑖"
1005 ]
1006 },
1007 "metadata": {},
1008 "output_type": "display_data"
1009 },
1010 {
1011 "data": {},
1012 "metadata": {},
1013 "output_type": "display_data"
1014 },
1015 {
1016 "data": {
1017 "text/plain": [
1018 "Result: Zero"
1019 ]
1020 },
1021 "metadata": {},
1022 "output_type": "display_data"
1023 },
1024 {
1025 "data": {},
1026 "metadata": {},
1027 "output_type": "display_data"
1028 },
1029 {
1030 "data": {
1031 "text/markdown": [
1032 "<table class=\"qs-stateTable\">\n",
1033 " <style>\n",
1034 " .qs-stateTable thead tr {\n",
1035 " background-color: var(\n",
1036 " --vscode-list-hoverBackground,\n",
1037 " var(--jp-layout-color1, inherit)\n",
1038 " );\n",
1039 " }\n",
1040 " .qs-stateTable th {\n",
1041 " text-align: left;\n",
1042 " border: none;\n",
1043 " }\n",
1044 " .qs-stateTable tbody {\n",
1045 " pointer-events: none;\n",
1046 " }\n",
1047 " .qs-stateTable tbody td {\n",
1048 " text-align: left;\n",
1049 " border: none;\n",
1050 " }\n",
1051 " .qs-stateTable tbody td span {\n",
1052 " display: inline-block;\n",
1053 " }\n",
1054 " .qs-stateTable tbody tr:nth-child(even) {\n",
1055 " background-color: var(\n",
1056 " --vscode-list-hoverBackground,\n",
1057 " var(--jp-layout-color1, inherit)\n",
1058 " );\n",
1059 " }\n",
1060 " </style>\n",
1061 " <thead>\n",
1062 " <tr>\n",
1063 " <th>Basis State<br />(|𝜓₁…𝜓ₙ⟩)</th>\n",
1064 " <th>Amplitude</th>\n",
1065 " <th>Measurement Probability</th>\n",
1066 " <th colspan=\"2\">Phase</th>\n",
1067 " </tr>\n",
1068 " </thead>\n",
1069 " <tbody>\n",
1070 " <tr>\n",
1071 " <td>\n",
1072 " <span>|0⟩</span>\n",
1073 " </td>\n",
1074 " <td>\n",
1075 " <span>1.0000+0.0000𝑖</span>\n",
1076 " </td>\n",
1077 " <td>\n",
1078 " <progress max=\"100\" value=\"100\"></progress>\n",
1079 " <span>100.0000%</span>\n",
1080 " </td>\n",
1081 " <td style=\"transform: rotate(0.0000rad)\">↑</td>\n",
1082 " <td>\n",
1083 " <span>0.0000</span>\n",
1084 " </td>\n",
1085 "</tr>\n",
1086 "\n",
1087 " </tbody>\n",
1088 "</table>\n",
1089 "\n",
1090 "\n",
1091 "$|\\psi\\rangle = |0\\rangle$"
1092 ],
1093 "text/plain": [
1094 "STATE:\n",
1095 "|0⟩: 1.0000+0.0000𝑖"
1096 ]
1097 },
1098 "metadata": {},
1099 "output_type": "display_data"
1100 },
1101 {
1102 "data": {},
1103 "metadata": {},
1104 "output_type": "display_data"
1105 },
1106 {
1107 "data": {
1108 "text/plain": [
1109 "Result: Zero"
1110 ]
1111 },
1112 "metadata": {},
1113 "output_type": "display_data"
1114 },
1115 {
1116 "data": {},
1117 "metadata": {},
1118 "output_type": "display_data"
1119 }
1120 ],
1121 "source": [
1122 "%%qsharp\n",
1123 "\n",
1124 "open Microsoft.Quantum.Diagnostics;\n",
1125 "\n",
1126 "operation Main() : Unit {\n",
1127 " Message(\"Generating random bit... \");\n",
1128 " for i in 0..400000 {\n",
1129 " use q = Qubit();\n",
1130 " H(q);\n",
1131 " let r = M(q);\n",
1132 " if (i % 100000) == 0 {\n",
1133 " DumpMachine();\n",
1134 " Message($\"Result: {r}\");\n",
1135 " }\n",
1136 " Reset(q);\n",
1137 " }\n",
1138 "}\n",
1139 "\n",
1140 "Main()\n"
1141 ]
1142 },
1143 {
1144 "cell_type": "markdown",
1145 "id": "2a2d9e7d",
1146 "metadata": {},
1147 "source": [
1148 "Running multiple shots for an expression. Each shot uses an independent instance of the simulator. A list of results (or runtime errors) is returned."
1149 ]
1150 },
1151 {
1152 "cell_type": "code",
1153 "execution_count": 10,
1154 "id": "eb3cd29f",
1155 "metadata": {
1156 "vscode": {
1157 "languageId": "qsharp"
1158 }
1159 },
1160 "outputs": [],
1161 "source": [
1162 "%%qsharp\n",
1163 "\n",
1164 "operation RandomBit() : Result {\n",
1165 " use q = Qubit();\n",
1166 " H(q);\n",
1167 " let res = M(q);\n",
1168 " Reset(q);\n",
1169 " return res;\n",
1170 "}\n"
1171 ]
1172 },
1173 {
1174 "cell_type": "code",
1175 "execution_count": 11,
1176 "id": "9a9f5335",
1177 "metadata": {},
1178 "outputs": [
1179 {
1180 "data": {},
1181 "metadata": {},
1182 "output_type": "display_data"
1183 },
1184 {
1185 "data": {
1186 "text/plain": [
1187 "[One, Zero, One, Zero, One, Zero, One, One, Zero, One]"
1188 ]
1189 },
1190 "execution_count": 11,
1191 "metadata": {},
1192 "output_type": "execute_result"
1193 }
1194 ],
1195 "source": [
1196 "results = qsharp.run(\"RandomBit()\", 10)\n",
1197 "\n",
1198 "results\n"
1199 ]
1200 },
1201 {
1202 "cell_type": "markdown",
1203 "id": "6a476e6d",
1204 "metadata": {},
1205 "source": [
1206 "The results can then be processed, e.g. plotted in a histogram using popular Python libraries."
1207 ]
1208 },
1209 {
1210 "cell_type": "code",
1211 "execution_count": 12,
1212 "id": "7bd77379",
1213 "metadata": {},
1214 "outputs": [
1215 {
1216 "name": "stdout",
1217 "output_type": "stream",
1218 "text": [
1219 "Defaulting to user installation because normal site-packages is not writeable\n",
1220 "Requirement already satisfied: matplotlib in /home/vscode/.local/lib/python3.12/site-packages (3.8.2)\n",
1221 "Requirement already satisfied: contourpy>=1.0.1 in /home/vscode/.local/lib/python3.12/site-packages (from matplotlib) (1.2.0)\n",
1222 "Requirement already satisfied: cycler>=0.10 in /home/vscode/.local/lib/python3.12/site-packages (from matplotlib) (0.12.1)\n",
1223 "Requirement already satisfied: fonttools>=4.22.0 in /home/vscode/.local/lib/python3.12/site-packages (from matplotlib) (4.47.2)\n",
1224 "Requirement already satisfied: kiwisolver>=1.3.1 in /home/vscode/.local/lib/python3.12/site-packages (from matplotlib) (1.4.5)\n",
1225 "Requirement already satisfied: numpy<2,>=1.21 in /home/vscode/.local/lib/python3.12/site-packages (from matplotlib) (1.26.3)\n",
1226 "Requirement already satisfied: packaging>=20.0 in /home/vscode/.local/lib/python3.12/site-packages (from matplotlib) (23.2)\n",
1227 "Requirement already satisfied: pillow>=8 in /home/vscode/.local/lib/python3.12/site-packages (from matplotlib) (10.2.0)\n",
1228 "Requirement already satisfied: pyparsing>=2.3.1 in /home/vscode/.local/lib/python3.12/site-packages (from matplotlib) (3.1.1)\n",
1229 "Requirement already satisfied: python-dateutil>=2.7 in /home/vscode/.local/lib/python3.12/site-packages (from matplotlib) (2.8.2)\n",
1230 "Requirement already satisfied: six>=1.5 in /home/vscode/.local/lib/python3.12/site-packages (from python-dateutil>=2.7->matplotlib) (1.16.0)\n",
1231 "\n",
1232 "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.2.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.3.1\u001b[0m\n",
1233 "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n",
1234 "Note: you may need to restart the kernel to use updated packages.\n"
1235 ]
1236 }
1237 ],
1238 "source": [
1239 "%pip install matplotlib\n"
1240 ]
1241 },
1242 {
1243 "cell_type": "code",
1244 "execution_count": 13,
1245 "id": "83cee4e8",
1246 "metadata": {},
1247 "outputs": [
1248 {
1249 "data": {
1250 "image/png": "iVBORw0KGgoAAAANSUhEUgAAAhYAAAGdCAYAAABO2DpVAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8g+/7EAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAWKElEQVR4nO3de4xUhdn48Wd1uyPK7iIIArKA1htesApoKG0Fq1KqBm2ijcFKkLRR1gsSkwptao3VxaSvsU3teomtTaNCGkNtqkLVFDAIFbAabZUKal0vgIruAm8cLTu/P5ru790iyMAzwODnk5yEOXPOnGcSZvebM2dnakqlUikAABLst6cHAAD2HcICAEgjLACANMICAEgjLACANMICAEgjLACANMICAEhTu7sP2NnZGW+//XbU19dHTU3N7j48ALATSqVSbNy4MQYOHBj77bft8xK7PSzefvvtaGpq2t2HBQAStLW1xaBBg7Z5/24Pi/r6+oj492ANDQ27+/AAwE7o6OiIpqamrt/j27Lbw+I/b380NDQICwCoMp91GYOLNwGANMICAEgjLACANMICAEgjLACANMICAEgjLACANMICAEgjLACANMICAEhTdli89dZbcckll0SfPn2iR48eceKJJ8aKFSsqMRsAUGXK+q6QDz74IMaMGRPjxo2Lxx57LPr27RuvvPJKHHzwwZWaDwCoImWFxa233hpNTU3x61//umvd4Ycfnj4UAFCdynor5A9/+EOMHDkyLrzwwujXr1+cfPLJcc8992x3n2KxGB0dHd0WAGDfVNYZi1dffTVaW1tjxowZMWvWrFi+fHlcffXVUVdXF5MnT/7UfVpaWuLGG29MGRYgImLo9Y/s6RFgr/X67HP26PFrSqVSaUc3rquri5EjR8bTTz/dte7qq6+O5cuXx9KlSz91n2KxGMViset2R0dHNDU1RXt7ezQ0NOzC6MDnlbCAbatUWHR0dERjY+Nn/v4u662QAQMGxHHHHddt3bBhw+KNN97Y5j6FQiEaGhq6LQDAvqmssBgzZkysWrWq27p//OMfMWTIkNShAIDqVFZYXHvttbFs2bK45ZZbYvXq1fHAAw/E3XffHc3NzZWaDwCoImWFxahRo2LevHnx4IMPxgknnBA33XRT3H777TFp0qRKzQcAVJGy/iokIuLcc8+Nc889txKzAABVzneFAABphAUAkEZYAABphAUAkEZYAABphAUAkEZYAABphAUAkEZYAABphAUAkEZYAABphAUAkEZYAABphAUAkEZYAABphAUAkEZYAABphAUAkEZYAABphAUAkEZYAABphAUAkEZYAABphAUAkEZYAABphAUAkEZYAABphAUAkEZYAABphAUAkEZYAABphAUAkEZYAABphAUAkEZYAABphAUAkEZYAABphAUAkEZYAABphAUAkEZYAABphAUAkEZYAABphAUAkEZYAABphAUAkEZYAABphAUAkKassPjxj38cNTU13ZZjjz22UrMBAFWmttwdjj/++HjiiSf+/wPUlv0QAMA+quwqqK2tjf79+1diFgCgypV9jcUrr7wSAwcOjCOOOCImTZoUb7zxxna3LxaL0dHR0W0BAPZNZYXFaaedFvfdd1/Mnz8/Wltb47XXXouvfvWrsXHjxm3u09LSEo2NjV1LU1PTLg8NAOydakqlUmlnd/7www9jyJAhcdttt8XUqVM/dZtisRjFYrHrdkdHRzQ1NUV7e3s0NDTs7KGBz7Gh1z+yp0eAvdbrs8+pyON2dHREY2PjZ/7+3qUrL3v16hVHH310rF69epvbFAqFKBQKu3IYAKBK7NLnWGzatCnWrFkTAwYMyJoHAKhiZYXFddddF4sWLYrXX389nn766bjgggti//33j4svvrhS8wEAVaSst0LefPPNuPjii+P999+Pvn37xle+8pVYtmxZ9O3bt1LzAQBVpKywmDNnTqXmAAD2Ab4rBABIIywAgDTCAgBIIywAgDTCAgBIIywAgDTCAgBIIywAgDTCAgBIIywAgDTCAgBIIywAgDTCAgBIIywAgDTCAgBIIywAgDTCAgBIIywAgDTCAgBIIywAgDTCAgBIIywAgDTCAgBIIywAgDTCAgBIIywAgDTCAgBIIywAgDTCAgBIIywAgDTCAgBIIywAgDTCAgBIIywAgDTCAgBIIywAgDTCAgBIIywAgDTCAgBIIywAgDTCAgBIIywAgDTCAgBIIywAgDTCAgBIIywAgDTCAgBIs0thMXv27KipqYnp06cnjQMAVLOdDovly5fHXXfdFcOHD8+cBwCoYjsVFps2bYpJkybFPffcEwcffHD2TABAldqpsGhubo5zzjknzjzzzOx5AIAqVlvuDnPmzIlnn302li9fvkPbF4vFKBaLXbc7OjrKPSQAUCXKCou2tra45ppr4vHHH48DDjhgh/ZpaWmJG2+8caeGK9fQ6x/ZLceBavX67HP29AjAPq6st0JWrlwZ69evj1NOOSVqa2ujtrY2Fi1aFD//+c+jtrY2tmzZstU+M2fOjPb29q6lra0tbXgAYO9S1hmLr3/96/HCCy90WzdlypQ49thj4/vf/37sv//+W+1TKBSiUCjs2pQAQFUoKyzq6+vjhBNO6LbuoIMOij59+my1HgD4/PHJmwBAmrL/KuS/LVy4MGEMAGBf4IwFAJBGWAAAaYQFAJBGWAAAaYQFAJBGWAAAaYQFAJBGWAAAaYQFAJBGWAAAaYQFAJBGWAAAaYQFAJBGWAAAaYQFAJBGWAAAaYQFAJBGWAAAaYQFAJBGWAAAaYQFAJBGWAAAaYQFAJBGWAAAaYQFAJBGWAAAaYQFAJBGWAAAaYQFAJBGWAAAaYQFAJBGWAAAaYQFAJBGWAAAaYQFAJBGWAAAaYQFAJBGWAAAaYQFAJBGWAAAaYQFAJBGWAAAaYQFAJBGWAAAaYQFAJBGWAAAaYQFAJBGWAAAacoKi9bW1hg+fHg0NDREQ0NDjB49Oh577LFKzQYAVJmywmLQoEExe/bsWLlyZaxYsSLOOOOMmDhxYvztb3+r1HwAQBWpLWfj8847r9vtm2++OVpbW2PZsmVx/PHHpw4GAFSfssLi/9qyZUv87ne/i82bN8fo0aO3uV2xWIxisdh1u6OjY2cPCQDs5cq+ePOFF16Inj17RqFQiMsvvzzmzZsXxx133Da3b2lpicbGxq6lqalplwYGAPZeZYfFMcccE88991z85S9/iSuuuCImT54cf//737e5/cyZM6O9vb1raWtr26WBAYC9V9lvhdTV1cWRRx4ZEREjRoyI5cuXx89+9rO46667PnX7QqEQhUJh16YEAKrCLn+ORWdnZ7drKACAz6+yzljMnDkzJkyYEIMHD46NGzfGAw88EAsXLowFCxZUaj4AoIqUFRbr16+PSy+9NN55551obGyM4cOHx4IFC+Kss86q1HwAQBUpKyzuvffeSs0BAOwDfFcIAJBGWAAAaYQFAJBGWAAAaYQFAJBGWAAAaYQFAJBGWAAAaYQFAJBGWAAAaYQFAJBGWAAAaYQFAJBGWAAAaYQFAJBGWAAAaYQFAJBGWAAAaYQFAJBGWAAAaYQFAJBGWAAAaYQFAJBGWAAAaYQFAJBGWAAAaYQFAJBGWAAAaYQFAJBGWAAAaYQFAJBGWAAAaYQFAJBGWAAAaYQFAJBGWAAAaYQFAJBGWAAAaYQFAJBGWAAAaYQFAJBGWAAAaYQFAJBGWAAAaYQFAJBGWAAAaYQFAJBGWAAAacoKi5aWlhg1alTU19dHv3794vzzz49Vq1ZVajYAoMqUFRaLFi2K5ubmWLZsWTz++OPxySefxNlnnx2bN2+u1HwAQBWpLWfj+fPnd7t93333Rb9+/WLlypXxta99LXUwAKD6lBUW/629vT0iInr37r3NbYrFYhSLxa7bHR0du3JIAGAvttMXb3Z2dsb06dNjzJgxccIJJ2xzu5aWlmhsbOxampqadvaQAMBebqfDorm5OV588cWYM2fOdrebOXNmtLe3dy1tbW07e0gAYC+3U2+FXHnllfHHP/4xFi9eHIMGDdrutoVCIQqFwk4NBwBUl7LColQqxVVXXRXz5s2LhQsXxuGHH16puQCAKlRWWDQ3N8cDDzwQDz/8cNTX18fatWsjIqKxsTF69OhRkQEBgOpR1jUWra2t0d7eHmPHjo0BAwZ0LXPnzq3UfABAFSn7rRAAgG3xXSEAQBphAQCkERYAQBphAQCkERYAQBphAQCkERYAQBphAQCkERYAQBphAQCkERYAQBphAQCkERYAQBphAQCkERYAQBphAQCkERYAQBphAQCkERYAQBphAQCkERYAQBphAQCkERYAQBphAQCkERYAQBphAQCkERYAQBphAQCkERYAQBphAQCkERYAQBphAQCkERYAQBphAQCkERYAQBphAQCkERYAQBphAQCkERYAQBphAQCkERYAQBphAQCkERYAQBphAQCkERYAQBphAQCkERYAQJqyw2Lx4sVx3nnnxcCBA6OmpiZ+//vfV2AsAKAalR0WmzdvjpNOOinuuOOOSswDAFSx2nJ3mDBhQkyYMKESswAAVc41FgBAmrLPWJSrWCxGsVjsut3R0VHpQwIAe0jFz1i0tLREY2Nj19LU1FTpQwIAe0jFw2LmzJnR3t7etbS1tVX6kADAHlLxt0IKhUIUCoVKHwYA2AuUHRabNm2K1atXd91+7bXX4rnnnovevXvH4MGDU4cDAKpL2WGxYsWKGDduXNftGTNmRETE5MmT47777ksbDACoPmWHxdixY6NUKlViFgCgyvkcCwAgjbAAANIICwAgjbAAANIICwAgjbAAANIICwAgjbAAANIICwAgjbAAANIICwAgjbAAANIICwAgjbAAANIICwAgjbAAANIICwAgjbAAANIICwAgjbAAANIICwAgjbAAANIICwAgjbAAANIICwAgjbAAANIICwAgjbAAANIICwAgjbAAANIICwAgjbAAANIICwAgjbAAANIICwAgjbAAANIICwAgjbAAANIICwAgjbAAANIICwAgjbAAANIICwAgjbAAANIICwAgjbAAANIICwAgjbAAANLsVFjccccdMXTo0DjggAPitNNOi2eeeSZ7LgCgCpUdFnPnzo0ZM2bEDTfcEM8++2ycdNJJMX78+Fi/fn0l5gMAqkjZYXHbbbfFd7/73ZgyZUocd9xxceedd8aBBx4Yv/rVryoxHwBQRWrL2fjjjz+OlStXxsyZM7vW7bfffnHmmWfG0qVLP3WfYrEYxWKx63Z7e3tERHR0dOzMvNvVWfzf9MeEfUklXnd7gtc6bFulXuf/edxSqbTd7coKi/feey+2bNkShx56aLf1hx56aLz88sufuk9LS0vceOONW61vamoq59BAgsbb9/QEQKVV+nW+cePGaGxs3Ob9ZYXFzpg5c2bMmDGj63ZnZ2ds2LAh+vTpEzU1NZU+PHtIR0dHNDU1RVtbWzQ0NOzpcYAK8Vr//CiVSrFx48YYOHDgdrcrKywOOeSQ2H///WPdunXd1q9bty769+//qfsUCoUoFArd1vXq1aucw1LFGhoa/LCBzwGv9c+H7Z2p+I+yLt6sq6uLESNGxJNPPtm1rrOzM5588skYPXp0+RMCAPuUst8KmTFjRkyePDlGjhwZp556atx+++2xefPmmDJlSiXmAwCqSNlh8e1vfzvefffd+NGPfhRr166NL33pSzF//vytLujk861QKMQNN9yw1dtgwL7Fa53/VlP6rL8bAQDYQb4rBABIIywAgDTCAgBIIywAgDTCgu1auHBh1NTUbHMZN27cnh4RqIC2tra47LLLYuDAgVFXVxdDhgyJa665Jt5///09PRp7OWHBdn35y1+Od955Z6vlrrvuipqampg2bdpOPe7HH3+cPCmQ5dVXX42RI0fGK6+8Eg8++GCsXr067rzzzq4PQ9ywYcOeHpG9mLBgu+rq6qJ///7dlg8++CCuu+66mDVrVlx44YUREfHiiy/GhAkTomfPnnHooYfGd77znXjvvfe6Hmfs2LFx5ZVXxvTp0+OQQw6J8ePHR0TEokWL4tRTT41CoRADBgyI66+/Pv71r3/tkecK/Ftzc3PU1dXFn/70pzj99NNj8ODBMWHChHjiiSfirbfeih/84AcRETF06NC45ZZb4rLLLov6+voYPHhw3H333d0eq62tLS666KLo1atX9O7dOyZOnBivv/76HnhW7C7CgrJ8+OGHMXHixBg7dmzcdNNNXevOOOOMOPnkk2PFihUxf/78WLduXVx00UXd9v3Nb34TdXV1sWTJkrjzzjvjrbfeim9+85sxatSoeP7556O1tTXuvffe+MlPfrInnhoQERs2bIgFCxbEtGnTokePHt3u69+/f0yaNCnmzp3b9dXZ//M//xMjR46Mv/71rzFt2rS44oorYtWqVRER8cknn8T48eOjvr4+nnrqqViyZEn07NkzvvGNbzhruS8rwQ7asmVLacKECaVhw4aVOjo6utbfdNNNpbPPPrvbtm1tbaWIKK1atapUKpVKp59+eunkk0/uts2sWbNKxxxzTKmzs7Nr3R133FHq2bNnacuWLRV8JsC2LFu2rBQRpXnz5n3q/bfddlspIkrr1q0rDRkypHTJJZd03dfZ2Vnq169fqbW1tVQqlUq//e1vt3qNF4vFUo8ePUoLFiyo6PNgz6n416az75g1a1YsXbo0nnnmmaivr+9a//zzz8ef//zn6Nmz51b7rFmzJo4++uiIiBgxYkS3+1566aUYPXp01NTUdK0bM2ZMbNq0Kd58880YPHhwhZ4J8FlKO/ihzMOHD+/6d01NTfTv3z/Wr18fEf/+2bB69epuPy8iIj766KNYs2ZN3rDsVYQFO2TOnDnx05/+NB555JE46qijut23adOmOO+88+LWW2/dar8BAwZ0/fuggw6q+JzArjnyyCOjpqYmXnrppbjgggu2uv+ll16Kgw8+OPr27RsREV/4whe63V9TUxOdnZ0R8e+fDSNGjIj7779/q8f5z/7se4QFn+m5556LqVOnxuzZs7suuvy/TjnllHjooYdi6NChUVu74/+lhg0bFg899FCUSqWusxZLliyJ+vr6GDRoUNr8wI7r06dPnHXWWfHLX/4yrr322m7XWaxduzbuv//+uPTSS7udadyWU045JebOnRv9+vWLhoaGSo7NXsTFm2zXe++9F+eff36MHTs2Lrnkkli7dm235d13343m5ubYsGFDXHzxxbF8+fJYs2ZNLFiwIKZMmRJbtmzZ5mNPmzYt2tra4qqrroqXX345Hn744bjhhhtixowZsd9+/mvCnvKLX/wiisVijB8/PhYvXhxtbW0xf/78OOuss+Kwww6Lm2++eYceZ9KkSXHIIYfExIkT46mnnorXXnstFi5cGFdffXW8+eabFX4W7Cl+erNdjzzySPzzn/+MRx99NAYMGLDVMmrUqBg4cGAsWbIktmzZEmeffXaceOKJMX369OjVq9d2A+Gwww6LRx99NJ555pk46aST4vLLL4+pU6fGD3/4w934DIH/dtRRR8WKFSviiCOOiIsuuii++MUvxve+970YN25cLF26NHr37r1Dj3PggQfG4sWLY/DgwfGtb30rhg0bFlOnTo2PPvrIGYx9mK9NBwDSOGMBAKQRFgBAGmEBAKQRFgBAGmEBAKQRFgBAGmEBAKQRFgBAGmEBAKQRFgBAGmEBAKQRFgBAmv8HvX2m8Y1VbDQAAAAASUVORK5CYII=",
1251 "text/plain": [
1252 "<Figure size 640x480 with 1 Axes>"
1253 ]
1254 },
1255 "metadata": {},
1256 "output_type": "display_data"
1257 }
1258 ],
1259 "source": [
1260 "import matplotlib.pyplot as plt\n",
1261 "import numpy as np\n",
1262 "from collections import Counter\n",
1263 "\n",
1264 "# Sort the results so that the histogram labels appear in the correct order\n",
1265 "results.sort()\n",
1266 "# Count the number of times each result appears\n",
1267 "counts = Counter(results)\n",
1268 "\n",
1269 "(values, counts) = counts.keys(), counts.values()\n",
1270 "xlabels = np.arange(len(counts))\n",
1271 "plt.bar(xlabels, counts)\n",
1272 "plt.xticks(xlabels, values)\n",
1273 "plt.show()\n"
1274 ]
1275 },
1276 {
1277 "cell_type": "code",
1278 "execution_count": 14,
1279 "id": "eaf766f4",
1280 "metadata": {},
1281 "outputs": [
1282 {
1283 "name": "stdout",
1284 "output_type": "stream",
1285 "text": [
1286 "Defaulting to user installation because normal site-packages is not writeable\n",
1287 "Requirement already satisfied: pandas in /home/vscode/.local/lib/python3.12/site-packages (2.2.0)\n",
1288 "Requirement already satisfied: numpy<2,>=1.26.0 in /home/vscode/.local/lib/python3.12/site-packages (from pandas) (1.26.3)\n",
1289 "Requirement already satisfied: python-dateutil>=2.8.2 in /home/vscode/.local/lib/python3.12/site-packages (from pandas) (2.8.2)\n",
1290 "Requirement already satisfied: pytz>=2020.1 in /home/vscode/.local/lib/python3.12/site-packages (from pandas) (2023.3.post1)\n",
1291 "Requirement already satisfied: tzdata>=2022.7 in /home/vscode/.local/lib/python3.12/site-packages (from pandas) (2023.4)\n",
1292 "Requirement already satisfied: six>=1.5 in /home/vscode/.local/lib/python3.12/site-packages (from python-dateutil>=2.8.2->pandas) (1.16.0)\n",
1293 "\n",
1294 "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.2.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.3.1\u001b[0m\n",
1295 "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n",
1296 "Note: you may need to restart the kernel to use updated packages.\n"
1297 ]
1298 }
1299 ],
1300 "source": [
1301 "%pip install pandas\n"
1302 ]
1303 },
1304 {
1305 "cell_type": "code",
1306 "execution_count": 15,
1307 "id": "8095640a",
1308 "metadata": {},
1309 "outputs": [
1310 {
1311 "name": "stderr",
1312 "output_type": "stream",
1313 "text": [
1314 "/tmp/ipykernel_15611/2211578213.py:1: DeprecationWarning: \n",
1315 "Pyarrow will become a required dependency of pandas in the next major release of pandas (pandas 3.0),\n",
1316 "(to allow more performant data types, such as the Arrow string type, and better interoperability with other libraries)\n",
1317 "but was not found to be installed on your system.\n",
1318 "If this would cause problems for you,\n",
1319 "please provide us feedback at https://github.com/pandas-dev/pandas/issues/54466\n",
1320 " \n",
1321 " import pandas\n"
1322 ]
1323 },
1324 {
1325 "data": {
1326 "text/plain": [
1327 "<Axes: >"
1328 ]
1329 },
1330 "execution_count": 15,
1331 "metadata": {},
1332 "output_type": "execute_result"
1333 },
1334 {
1335 "data": {
1336 "image/png": "iVBORw0KGgoAAAANSUhEUgAAAhYAAAGvCAYAAAAHapzzAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8g+/7EAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAXaklEQVR4nO3da4wVhfn48ecgckS7uyIIQlhRihVRwQpqCNWoqHi3NqmX0JRYa6KsV2JiqVG0xi6+qKUNFqmxJU1jMW1ibWrFCyLGAhYw3qsFBV2kiIruAo1HZff3onH//y1ge5Zn9+yBzyeZFzNnxnlMXPebmTk7hba2trYAAEjQq9IDAAC7D2EBAKQRFgBAGmEBAKQRFgBAGmEBAKQRFgBAGmEBAKTp3d0nbG1tjfXr10dNTU0UCoXuPj0A0AltbW2xefPmGDJkSPTqtfPrEt0eFuvXr4/6+vruPi0AkKCpqSmGDh2608+7PSxqamoi4t+D1dbWdvfpAYBOaGlpifr6+vbf4zvT7WHxxe2P2tpaYQEAVea/Pcbg4U0AII2wAADSCAsAII2wAADSCAsAII2wAADSCAsAII2wAADSCAsAII2wAADSlB0W7777bnznO9+J/v37R9++fePoo4+OFStWdMVsAECVKetdIR999FFMmDAhTjnllHj00UfjwAMPjFWrVkW/fv26aj4AoIqUFRZ33XVX1NfXx69//ev2bYceemj6UABAdSrrVsif/vSnGDduXHz729+OgQMHxte//vW47777vvSYUqkULS0tHRYAYPdU1hWLt956K+bMmRPTpk2LH/7wh7F8+fK49tpro0+fPjFlypQdHtPY2Bi33357yrAAPdUhP3ik0iPQjdbOPKfSI/RYhba2trb/dec+ffrEuHHjYsmSJe3brr322li+fHksXbp0h8eUSqUolUrt6y0tLVFfXx/Nzc1RW1u7C6MD9BzCYs+yJ4ZFS0tL1NXV/dff32XdChk8eHCMGjWqw7Yjjjgi3nnnnZ0eUywWo7a2tsMCAOyeygqLCRMmxBtvvNFh2z/+8Y8YNmxY6lAAQHUqKyxuuOGGWLZsWfz4xz+O1atXxwMPPBC//OUvo6GhoavmAwCqSFlhcdxxx8VDDz0Uv/vd7+Koo46KO+64I2bNmhWTJ0/uqvkAgCpS1rdCIiLOPffcOPfcc7tiFgCgynlXCACQRlgAAGmEBQCQRlgAAGmEBQCQRlgAAGmEBQCQRlgAAGmEBQCQRlgAAGmEBQCQRlgAAGmEBQCQRlgAAGmEBQCQRlgAAGmEBQCQRlgAAGmEBQCQRlgAAGmEBQCQRlgAAGmEBQCQRlgAAGmEBQCQRlgAAGmEBQCQRlgAAGmEBQCQRlgAAGmEBQCQRlgAAGmEBQCQRlgAAGmEBQCQRlgAAGmEBQCQRlgAAGmEBQCQRlgAAGmEBQCQRlgAAGmEBQCQRlgAAGmEBQCQRlgAAGmEBQCQRlgAAGnKCovbbrstCoVCh2XkyJFdNRsAUGV6l3vAkUceGU8++eT/+wf0LvsfAQDspsqugt69e8dBBx3UFbMAAFWu7GcsVq1aFUOGDInhw4fH5MmT45133vnS/UulUrS0tHRYAIDdU1lhccIJJ8S8efNiwYIFMWfOnFizZk2ceOKJsXnz5p0e09jYGHV1de1LfX39Lg8NAPRMhba2trbOHvzxxx/HsGHD4u67747LL798h/uUSqUolUrt6y0tLVFfXx/Nzc1RW1vb2VMD9CiH/OCRSo9AN1o785xKj9DtWlpaoq6u7r/+/t6lJy/333//+NrXvharV6/e6T7FYjGKxeKunAYAqBK79HcstmzZEm+++WYMHjw4ax4AoIqVFRY33nhjLF68ONauXRtLliyJCy+8MPbaa6+49NJLu2o+AKCKlHUrZN26dXHppZfGhx9+GAceeGB84xvfiGXLlsWBBx7YVfMBAFWkrLCYP39+V80BAOwGvCsEAEgjLACANMICAEgjLACANMICAEgjLACANMICAEgjLACANMICAEgjLACANMICAEgjLACANMICAEgjLACANMICAEgjLACANMICAEgjLACANMICAEgjLACANMICAEgjLACANMICAEgjLACANMICAEgjLACANMICAEgjLACANMICAEgjLACANMICAEgjLACANMICAEgjLACANMICAEgjLACANMICAEgjLACANMICAEgjLACANMICAEgjLACANMICAEgjLACANMICAEgjLACANMICAEizS2Exc+bMKBQKcf311yeNAwBUs06HxfLly2Pu3LkxevTozHkAgCrWqbDYsmVLTJ48Oe67777o169f9kwAQJXqVFg0NDTEOeecE6eddlr2PABAFetd7gHz58+P559/PpYvX/4/7V8qlaJUKrWv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0dbW1hWzAABVzt+xAADSCAsAII2wAADSCAsAII2wAADSCAsAII2wAADSCAsAII2wAADSCAsAII2wAADSCAsAII2wAADSCAsAII2wAADSCAsAII2wAADSCAsAII2wAADSCAsAII2wAADSCAsAII2wAADSCAsAII2wAADSCAsAII2wAADSCAsAII2wAADSCAsAII2wAADSCAsAII2wAADSCAsAII2wAADSCAsAII2wAADSCAsAII2wAADSCAsAII2wAADSCAsAII2wAADSCAsAII2wAADSCAsAII2wAADSCAsAIE2nwuKee+6JQw45JPbZZ5844YQT4m9/+1v2XABAFSo7LB588MGYNm1azJgxI55//vkYM2ZMTJo0KTZu3NgV8wEAVaTssLj77rvjiiuuiMsuuyxGjRoV9957b+y7777xq1/9qivmAwCqSO9ydv70009j5cqVMX369PZtvXr1itNOOy2WLl26w2NKpVKUSqX29ebm5oiIaGlp6cy8Va219K9Kj0A32hP/G9+T+fnes+yJP99f/Du3tbV96X5lhcUHH3wQ27Zti0GDBnXYPmjQoHj99dd3eExjY2Pcfvvt222vr68v59RQdepmVXoCoKvsyT/fmzdvjrq6up1+XlZYdMb06dNj2rRp7eutra2xadOm6N+/fxQKha4+PRXW0tIS9fX10dTUFLW1tZUeB0jk53vP0tbWFps3b44hQ4Z86X5lhcWAAQNir732ivfee6/D9vfeey8OOuigHR5TLBajWCx22Lb//vuXc1p2A7W1tf7HA7spP997ji+7UvGFsh7e7NOnT4wdOzYWLlzYvq21tTUWLlwY48ePL39CAGC3UvatkGnTpsWUKVNi3Lhxcfzxx8esWbNi69atcdlll3XFfABAFSk7LC6++OJ4//3349Zbb40NGzbEMcccEwsWLNjugU6I+PetsBkzZmx3Owyofn6+2ZFC23/73ggAwP/Iu0IAgDTCAgBIIywAgDTCAgBIIywAgDTCgi6zbt26WLduXaXHABJ9/vnn8eSTT8bcuXNj8+bNERGxfv362LJlS4Uno6cQFqRqbW2NH/3oR1FXVxfDhg2LYcOGxf777x933HFHtLa2Vno8YBe8/fbbcfTRR8cFF1wQDQ0N8f7770dExF133RU33nhjhaejp+jyl5CxZ7n55pvj/vvvj5kzZ8aECRMiIuLZZ5+N2267LT755JO48847Kzwh0FnXXXddjBs3Ll588cXo379/+/YLL7wwrrjiigpORk/iD2SRasiQIXHvvffG+eef32H7ww8/HFOnTo133323QpMBu6p///6xZMmSOPzww6OmpiZefPHFGD58eKxduzZGjRoV//rXvyo9Ij2AWyGk2rRpU4wcOXK77SNHjoxNmzZVYCIgS2tra2zbtm277evWrYuampoKTERPJCxINWbMmJg9e/Z222fPnh1jxoypwERAljPOOCNmzZrVvl4oFGLLli0xY8aMOPvssys3GD2KWyGkWrx4cZxzzjlx8MEHx/jx4yMiYunSpdHU1BR/+ctf4sQTT6zwhEBnrVu3LiZNmhRtbW2xatWqGDduXKxatSoGDBgQzzzzTAwcOLDSI9IDCAvSrV+/Pu655554/fXXIyLiiCOOiKlTp8aQIUMqPBmwqz7//POYP39+vPTSS7Fly5Y49thjY/LkydG3b99Kj0YPISxI89lnn8WZZ54Z9957bxx22GGVHgeACvB1U9Lsvffe8dJLL1V6DKALrVq1KhYtWhQbN27c7m/T3HrrrRWaip7EFQtS3XDDDVEsFmPmzJmVHgVIdt9998VVV10VAwYMiIMOOigKhUL7Z4VCIZ5//vkKTkdPISxIdc0118RvfvObOOyww2Ls2LGx3377dfj87rvvrtBkwK4aNmxYTJ06NW666aZKj0IPJixIdcopp+z0s0KhEE899VQ3TgNkqq2tjRdeeCGGDx9e6VHowYQFAP+Tyy+/PI477ri48sorKz0KPZiHN+kSq1evjjfffDNOOumk6Nu3b7S1tXW4HwtUnxEjRsQtt9wSS5cujdGjR8fee+/d4fNrr722QpPRk7hiQaoPP/wwLrrooli0aFEUCoVYtWpVDB8+PL73ve9Fv3794ic/+UmlRwQ66dBDD93pZ4VCId56661unIaeyhULUt1www2x9957xzvvvBNHHHFE+/aLL744pk2bJiygiq1ZsyYiIj744IOIiBgwYEAlx6GH8q4QUj3++ONx1113xdChQztsP+yww+Ltt9+u0FTArvr444+joaEhBgwYEIMGDYpBgwbFgAED4uqrr47m5uZKj0cP4ooFqbZu3Rr77rvvdts3bdoUxWKxAhMBu2rTpk0xfvz4ePfdd2Py5MntVyNfe+21mDdvXixcuDCWLFkS/fr1q/Ck9ASesSDV2WefHWPHjo077rgjampq4qWXXophw4bFJZdcEq2trfGHP/yh0iMCZbr++utj4cKF8eSTT8agQYM6fLZhw4Y444wzYuLEifHTn/60QhPSkwgLUr3yyisxceLEOPbYY+Opp56K888/P1599dXYtGlT/PWvf42vfvWrlR4RKNMhhxwSc+fOjUmTJu3w8wULFsSVV14Za9eu7d7B6JGEBemam5tj9uzZ8eKLL7a//bChoSEGDx5c6dGATigWi/Hmm29u9+zUF9atWxcjRoyITz75pJsnoyfyjAUpJk6cGA0NDfGtb30r6urq4uabb+7w+QcffBDDhw/3dTSoQgMGDIi1a9fuNCzWrFkTBxxwQDdPRU/lWyGkWLRoUVx00UUxY8aMHX6+bds23wqBKjVp0qS4+eab49NPP93us1KpFLfcckuceeaZFZiMnsitEFL06tUr5s6dGzfeeGOceuqp8dvf/rbDC8jee++9GDJkSGzbtq2CUwKdsW7duhg3blwUi8VoaGiIkSNHRltbW/z973+PX/ziF1EqlWLFihVRX19f6VHpAYQFKXr16hUbNmyIDz/8MC644IIoFovx8MMPt7+sSFhAdVuzZk1MnTo1Hn/88fji10ahUIjTTz89Zs+eHSNGjKjwhPQUwoIUX4TFwIEDo7m5OS699NJ47rnn4sEHH4zTTjtNWMBu4qOPPopVq1ZFxL/fHeLZCv6TZyxIV1dXF4888khcccUVcfbZZ/tuO+xG+vXrF8cff3wcf/zxooId8q0QUvznm0sLhULMnDkzjjnmmPj+978fTz31VIUmA6A7uWJBip3dUbvkkkvi2WefjZdffrmbJwKgElyxIMWiRYt2eln0mGOOiZUrV8YjjzzSzVMB0N08vAkApHErBABIIywAgDTCAgBIIywAgDTCAgBIIywAgDTCAgBIIywAgDT/BzRqNf3Uih03AAAAAElFTkSuQmCC",
1337 "text/plain": [
1338 "<Figure size 640x480 with 1 Axes>"
1339 ]
1340 },
1341 "metadata": {},
1342 "output_type": "display_data"
1343 }
1344 ],
1345 "source": [
1346 "import pandas\n",
1347 "from collections import Counter\n",
1348 "\n",
1349 "# Sort the results so that the histogram labels appear in the correct order\n",
1350 "results.sort()\n",
1351 "pandas.Series(results).value_counts(sort=False).plot(kind='bar')\n"
1352 ]
1353 },
1354 {
1355 "cell_type": "markdown",
1356 "id": "990642e4",
1357 "metadata": {},
1358 "source": [
1359 "A compiler error in the entry expression:"
1360 ]
1361 },
1362 {
1363 "cell_type": "code",
1364 "execution_count": 16,
1365 "id": "f045ad9c",
1366 "metadata": {},
1367 "outputs": [
1368 {
1369 "data": {},
1370 "metadata": {},
1371 "output_type": "display_data"
1372 },
1373 {
1374 "ename": "QSharpError",
1375 "evalue": "Qsc.TypeCk.TyMismatch\n\n x type error\n `-> expected Unit, found String\n ,-[<entry>:1:1]\n 1 | RandomBit(\"a\")\n : ^^^^^^^^^^^^^^\n `----\n",
1376 "output_type": "error",
1377 "traceback": [
1378 "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
1379 "\u001b[0;31mQSharpError\u001b[0m Traceback (most recent call last)",
1380 "Cell \u001b[0;32mIn[16], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m qsharp\u001b[38;5;241m.\u001b[39mrun(\u001b[38;5;124m\"\"\"\u001b[39m\u001b[38;5;124mRandomBit(\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124ma\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m)\u001b[39m\u001b[38;5;124m\"\"\"\u001b[39m, \u001b[38;5;241m10\u001b[39m)\n",
1381 "File \u001b[0;32m~/.local/lib/python3.12/site-packages/qsharp/_qsharp.py:307\u001b[0m, in \u001b[0;36mrun\u001b[0;34m(entry_expr, shots, on_result, save_events, noise)\u001b[0m\n\u001b[1;32m 305\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m shot \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mrange\u001b[39m(shots):\n\u001b[1;32m 306\u001b[0m results\u001b[38;5;241m.\u001b[39mappend({\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mresult\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;28;01mNone\u001b[39;00m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mevents\u001b[39m\u001b[38;5;124m\"\u001b[39m: []})\n\u001b[0;32m--> 307\u001b[0m run_results \u001b[38;5;241m=\u001b[39m get_interpreter()\u001b[38;5;241m.\u001b[39mrun(\n\u001b[1;32m 308\u001b[0m entry_expr,\n\u001b[1;32m 309\u001b[0m on_save_events \u001b[38;5;28;01mif\u001b[39;00m save_events \u001b[38;5;28;01melse\u001b[39;00m print_output,\n\u001b[1;32m 310\u001b[0m noise,\n\u001b[1;32m 311\u001b[0m )\n\u001b[1;32m 312\u001b[0m results[\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m1\u001b[39m][\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mresult\u001b[39m\u001b[38;5;124m\"\u001b[39m] \u001b[38;5;241m=\u001b[39m run_results\n\u001b[1;32m 313\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m on_result:\n",
1382 "\u001b[0;31mQSharpError\u001b[0m: Qsc.TypeCk.TyMismatch\n\n x type error\n `-> expected Unit, found String\n ,-[<entry>:1:1]\n 1 | RandomBit(\"a\")\n : ^^^^^^^^^^^^^^\n `----\n"
1383 ]
1384 }
1385 ],
1386 "source": [
1387 "qsharp.run(\"\"\"RandomBit(\"a\")\"\"\", 10)\n"
1388 ]
1389 },
1390 {
1391 "cell_type": "markdown",
1392 "id": "0ba56462",
1393 "metadata": {},
1394 "source": [
1395 "Some shots throw runtime errors:"
1396 ]
1397 },
1398 {
1399 "cell_type": "code",
1400 "execution_count": 17,
1401 "id": "9b85eb2d",
1402 "metadata": {
1403 "vscode": {
1404 "languageId": "qsharp"
1405 }
1406 },
1407 "outputs": [],
1408 "source": [
1409 "%%qsharp\n",
1410 "\n",
1411 "operation Bad() : Unit {\n",
1412 " use q = Qubit();\n",
1413 " H(q);\n",
1414 " let res = M(q);\n",
1415 " if (res == One) {\n",
1416 " // Do something bad, sometimes\n",
1417 " use q2 = Qubit();\n",
1418 " X(q2);\n",
1419 " }\n",
1420 "}\n"
1421 ]
1422 },
1423 {
1424 "cell_type": "code",
1425 "execution_count": 18,
1426 "id": "2445df05",
1427 "metadata": {},
1428 "outputs": [
1429 {
1430 "data": {},
1431 "metadata": {},
1432 "output_type": "display_data"
1433 },
1434 {
1435 "ename": "QSharpError",
1436 "evalue": "Error: Qubit1 released while not in |0⟩ state\nCall stack:\n at QIR.Runtime.__quantum__rt__qubit_release in qsharp-library-source:core/qir.qs\n at Bad in line_9\nQsc.Eval.ReleasedQubitNotZero\n\n x runtime error\n `-> Qubit1 released while not in |0⟩ state\n ,-[line_9:8:9]\n 7 | // Do something bad, sometimes\n 8 | use q2 = Qubit();\n : ^^^^^^^^|^^^^^^^^\n : `-- Qubit1\n 9 | X(q2);\n `----\n help: qubits should be returned to the |0⟩ state before being released to\n satisfy the assumption that allocated qubits start in the |0⟩ state\n",
1437 "output_type": "error",
1438 "traceback": [
1439 "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
1440 "\u001b[0;31mQSharpError\u001b[0m Traceback (most recent call last)",
1441 "Cell \u001b[0;32mIn[18], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m qsharp\u001b[38;5;241m.\u001b[39mrun(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mBad()\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;241m10\u001b[39m)\n",
1442 "File \u001b[0;32m~/.local/lib/python3.12/site-packages/qsharp/_qsharp.py:307\u001b[0m, in \u001b[0;36mrun\u001b[0;34m(entry_expr, shots, on_result, save_events, noise)\u001b[0m\n\u001b[1;32m 305\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m shot \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mrange\u001b[39m(shots):\n\u001b[1;32m 306\u001b[0m results\u001b[38;5;241m.\u001b[39mappend({\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mresult\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;28;01mNone\u001b[39;00m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mevents\u001b[39m\u001b[38;5;124m\"\u001b[39m: []})\n\u001b[0;32m--> 307\u001b[0m run_results \u001b[38;5;241m=\u001b[39m get_interpreter()\u001b[38;5;241m.\u001b[39mrun(\n\u001b[1;32m 308\u001b[0m entry_expr,\n\u001b[1;32m 309\u001b[0m on_save_events \u001b[38;5;28;01mif\u001b[39;00m save_events \u001b[38;5;28;01melse\u001b[39;00m print_output,\n\u001b[1;32m 310\u001b[0m noise,\n\u001b[1;32m 311\u001b[0m )\n\u001b[1;32m 312\u001b[0m results[\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m1\u001b[39m][\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mresult\u001b[39m\u001b[38;5;124m\"\u001b[39m] \u001b[38;5;241m=\u001b[39m run_results\n\u001b[1;32m 313\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m on_result:\n",
1443 "\u001b[0;31mQSharpError\u001b[0m: Error: Qubit1 released while not in |0⟩ state\nCall stack:\n at QIR.Runtime.__quantum__rt__qubit_release in qsharp-library-source:core/qir.qs\n at Bad in line_9\nQsc.Eval.ReleasedQubitNotZero\n\n x runtime error\n `-> Qubit1 released while not in |0⟩ state\n ,-[line_9:8:9]\n 7 | // Do something bad, sometimes\n 8 | use q2 = Qubit();\n : ^^^^^^^^|^^^^^^^^\n : `-- Qubit1\n 9 | X(q2);\n `----\n help: qubits should be returned to the |0⟩ state before being released to\n satisfy the assumption that allocated qubits start in the |0⟩ state\n"
1444 ]
1445 }
1446 ],
1447 "source": [
1448 "qsharp.run(\"Bad()\", 10)\n"
1449 ]
1450 }
1451 ],
1452 "metadata": {
1453 "kernelspec": {
1454 "display_name": "Python 3",
1455 "language": "python",
1456 "name": "python3"
1457 },
1458 "language_info": {
1459 "codemirror_mode": {
1460 "name": "ipython",
1461 "version": 3
1462 },
1463 "file_extension": ".py",
1464 "mimetype": "text/x-python",
1465 "name": "python",
1466 "nbconvert_exporter": "python",
1467 "pygments_lexer": "ipython3",
1468 "version": "3.12.1"
1469 }
1470 },
1471 "nbformat": 4,
1472 "nbformat_minor": 5
1473}
1474