microsoft/qdk

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
billti/wgpu

Branches

Tags

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

Clone

HTTPS

Download ZIP

samples/notebooks/sample.ipynb

1073lines ยท 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/html": [
61 "<table>\n",
62 " <thead>\n",
63 " <tr>\n",
64 " <th style=\"text-align: left\">Basis State<br />(|๐œ“โ‚โ€ฆ๐œ“โ‚™โŸฉ)</th>\n",
65 " <th style=\"text-align: left\">Amplitude</th>\n",
66 " <th style=\"text-align: left\">Measurement Probability</th>\n",
67 " <th style=\"text-align: left\" colspan=\"2\">Phase</th>\n",
68 " </tr>\n",
69 " </thead>\n",
70 " <tbody>\n",
71 " <tr>\n",
72 " <td style=\"text-align: left\">\n",
73 " <span style=\"display: inline-block\">|1โŸฉ</span>\n",
74 " </td>\n",
75 " <td style=\"text-align: left\">\n",
76 " <span style=\"display: inline-block\">1.0000+0.0000๐‘–</span>\n",
77 " </td>\n",
78 " <td style=\"text-align: left\">\n",
79 " <progress max=\"100\" value=\"100\"></progress>\n",
80 " <span style=\"display: inline-block\">100.0000%</span>\n",
81 " </td>\n",
82 " <td style=\"text-align: left; transform: rotate(0.0000rad)\">โ†‘</td>\n",
83 " <td style=\"text-align: left\">\n",
84 " <span style=\"display: inline-block\">0.0000</span>\n",
85 " </td>\n",
86 "</tr>\n",
87 "\n",
88 " </tbody>\n",
89 "</table>\n"
90 ],
91 "text/plain": [
92 "STATE:\n",
93 "|1โŸฉ: 1.0000+0.0000๐‘–"
94 ]
95 },
96 "metadata": {},
97 "output_type": "display_data"
98 },
99 {
100 "data": {
101 "text/html": [
102 "<p>The result of the measurement is One</p>"
103 ],
104 "text/plain": [
105 "The result of the measurement is One"
106 ]
107 },
108 "metadata": {},
109 "output_type": "display_data"
110 },
111 {
112 "data": {
113 "text/plain": [
114 "One"
115 ]
116 },
117 "execution_count": 2,
118 "metadata": {},
119 "output_type": "execute_result"
120 }
121 ],
122 "source": [
123 "%%qsharp\n",
124 "\n",
125 "operation Main() : Result {\n",
126 " use q = Qubit();\n",
127 " X(q);\n",
128 " Microsoft.Quantum.Diagnostics.DumpMachine();\n",
129 " let r = M(q);\n",
130 " Message($\"The result of the measurement is {r}\");\n",
131 " Reset(q);\n",
132 " r\n",
133 "}\n",
134 "\n",
135 "Main()\n"
136 ]
137 },
138 {
139 "cell_type": "markdown",
140 "id": "4584c494",
141 "metadata": {},
142 "source": [
143 "`qsharp.eval()` does the same thing as the `%%qsharp` magic.\n",
144 "\n",
145 "`DumpMachine()` and `Message()` print to stdout and get displayed in the notebook as plain text"
146 ]
147 },
148 {
149 "cell_type": "code",
150 "execution_count": 3,
151 "id": "7d0995bf",
152 "metadata": {
153 "scrolled": true
154 },
155 "outputs": [
156 {
157 "name": "stdout",
158 "output_type": "stream",
159 "text": [
160 "STATE:\n",
161 "|1โŸฉ: 1.0000+0.0000๐‘–\n",
162 "The result of the measurement is One\n"
163 ]
164 },
165 {
166 "data": {
167 "text/plain": [
168 "One"
169 ]
170 },
171 "execution_count": 3,
172 "metadata": {},
173 "output_type": "execute_result"
174 }
175 ],
176 "source": [
177 "qsharp.eval(\"Main()\")\n"
178 ]
179 },
180 {
181 "cell_type": "markdown",
182 "id": "a3bde193",
183 "metadata": {},
184 "source": [
185 "Assign a result to a Python variable."
186 ]
187 },
188 {
189 "cell_type": "code",
190 "execution_count": 4,
191 "id": "50383f8a",
192 "metadata": {},
193 "outputs": [
194 {
195 "name": "stdout",
196 "output_type": "stream",
197 "text": [
198 "Result: 3 (type: int)\n"
199 ]
200 }
201 ],
202 "source": [
203 "result = qsharp.eval(\"1 + 2\")\n",
204 "\n",
205 "print(f\"Result: {result} (type: {type(result).__name__})\")\n"
206 ]
207 },
208 {
209 "cell_type": "markdown",
210 "id": "b06b7857",
211 "metadata": {},
212 "source": [
213 "Errors are exceptions. \n",
214 "\n",
215 "Catch and handle compilation errors."
216 ]
217 },
218 {
219 "cell_type": "code",
220 "execution_count": 5,
221 "id": "33fd3c4d",
222 "metadata": {},
223 "outputs": [
224 {
225 "name": "stdout",
226 "output_type": "stream",
227 "text": [
228 "\u001b[31mQsc.Resolve.NotFound\u001b[0m\n",
229 "\n",
230 " \u001b[31mร—\u001b[0m name error\n",
231 "\u001b[31m โ•ฐโ”€โ–ถ \u001b[0m`Bar` not found\n",
232 " โ•ญโ”€[\u001b[36;1;4mline_3\u001b[0m:2:1]\n",
233 " \u001b[2m2\u001b[0m โ”‚ operation Foo() : Unit {\n",
234 " \u001b[2m3\u001b[0m โ”‚ Bar();\n",
235 " ยท \u001b[35;1m โ”€โ”€โ”€\u001b[0m\n",
236 " \u001b[2m4\u001b[0m โ”‚ Baz();\n",
237 " โ•ฐโ”€โ”€โ”€โ”€\n",
238 "\u001b[31mQsc.Resolve.NotFound\u001b[0m\n",
239 "\n",
240 " \u001b[31mร—\u001b[0m name error\n",
241 "\u001b[31m โ•ฐโ”€โ–ถ \u001b[0m`Baz` not found\n",
242 " โ•ญโ”€[\u001b[36;1;4mline_3\u001b[0m:3:1]\n",
243 " \u001b[2m3\u001b[0m โ”‚ Bar();\n",
244 " \u001b[2m4\u001b[0m โ”‚ Baz();\n",
245 " ยท \u001b[35;1m โ”€โ”€โ”€\u001b[0m\n",
246 " \u001b[2m5\u001b[0m โ”‚ }\n",
247 " โ•ฐโ”€โ”€โ”€โ”€\n",
248 "\u001b[31mQsc.TypeCk.AmbiguousTy\u001b[0m\n",
249 "\n",
250 " \u001b[31mร—\u001b[0m type error\n",
251 "\u001b[31m โ•ฐโ”€โ–ถ \u001b[0minsufficient type information to infer type\n",
252 " โ•ญโ”€[\u001b[36;1;4mline_3\u001b[0m:2:1]\n",
253 " \u001b[2m2\u001b[0m โ”‚ operation Foo() : Unit {\n",
254 " \u001b[2m3\u001b[0m โ”‚ Bar();\n",
255 " ยท \u001b[35;1m โ”€โ”€โ”€โ”€โ”€\u001b[0m\n",
256 " \u001b[2m4\u001b[0m โ”‚ Baz();\n",
257 " โ•ฐโ”€โ”€โ”€โ”€\n",
258 "\u001b[36m help: \u001b[0mprovide a type annotation\n",
259 "\u001b[31mQsc.TypeCk.AmbiguousTy\u001b[0m\n",
260 "\n",
261 " \u001b[31mร—\u001b[0m type error\n",
262 "\u001b[31m โ•ฐโ”€โ–ถ \u001b[0minsufficient type information to infer type\n",
263 " โ•ญโ”€[\u001b[36;1;4mline_3\u001b[0m:3:1]\n",
264 " \u001b[2m3\u001b[0m โ”‚ Bar();\n",
265 " \u001b[2m4\u001b[0m โ”‚ Baz();\n",
266 " ยท \u001b[35;1m โ”€โ”€โ”€โ”€โ”€\u001b[0m\n",
267 " \u001b[2m5\u001b[0m โ”‚ }\n",
268 " โ•ฐโ”€โ”€โ”€โ”€\n",
269 "\u001b[36m help: \u001b[0mprovide a type annotation\n",
270 "\n"
271 ]
272 }
273 ],
274 "source": [
275 "from qsharp import QSharpError\n",
276 "\n",
277 "try:\n",
278 " qsharp.eval(\n",
279 " \"\"\"\n",
280 "operation Foo() : Unit {\n",
281 " Bar();\n",
282 " Baz();\n",
283 "}\n",
284 "\"\"\"\n",
285 " )\n",
286 "except QSharpError as ex:\n",
287 " print(ex)\n"
288 ]
289 },
290 {
291 "cell_type": "markdown",
292 "id": "00f82a16",
293 "metadata": {},
294 "source": [
295 "Catch and handle runtime errors."
296 ]
297 },
298 {
299 "cell_type": "code",
300 "execution_count": 6,
301 "id": "e70a95d9",
302 "metadata": {},
303 "outputs": [
304 {
305 "name": "stdout",
306 "output_type": "stream",
307 "text": [
308 "Error: Qubit0 released while not in |0โŸฉ state\n",
309 "Call stack:\n",
310 " at QIR.Runtime.__quantum__rt__qubit_release in core/qir.qs\n",
311 " at Foo in line_4\n",
312 "\u001b[31mQsc.Eval.ReleasedQubitNotZero\u001b[0m\n",
313 "\n",
314 " \u001b[31mร—\u001b[0m runtime error\n",
315 "\u001b[31m โ•ฐโ”€โ–ถ \u001b[0mQubit0 released while not in |0โŸฉ state\n",
316 " โ•ญโ”€[\u001b[36;1;4mline_4\u001b[0m:1:1]\n",
317 " \u001b[2m1\u001b[0m โ”‚ operation Foo() : Unit { use q = Qubit(); X(q) } Foo()\n",
318 " ยท \u001b[35;1m โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€\u001b[0m\n",
319 " ยท \u001b[35;1mโ•ฐโ”€โ”€ \u001b[35;1mQubit0\u001b[0m\u001b[0m\n",
320 " โ•ฐโ”€โ”€โ”€โ”€\n",
321 "\u001b[36m help: \u001b[0mqubits should be returned to the |0โŸฉ state before being released to\n",
322 " satisfy the assumption that allocated qubits start in the |0โŸฉ state\n",
323 "\n"
324 ]
325 }
326 ],
327 "source": [
328 "try:\n",
329 " qsharp.eval(\"operation Foo() : Unit { use q = Qubit(); X(q) } Foo()\")\n",
330 "except QSharpError as ex:\n",
331 " print(ex)\n"
332 ]
333 },
334 {
335 "cell_type": "markdown",
336 "id": "3e294471",
337 "metadata": {},
338 "source": [
339 "A runtime error that's not caught gets reported as a Python exception."
340 ]
341 },
342 {
343 "cell_type": "code",
344 "execution_count": 7,
345 "id": "d40d86cb",
346 "metadata": {},
347 "outputs": [
348 {
349 "ename": "QSharpError",
350 "evalue": "Error: Qubit1 released while not in |0โŸฉ state\nCall stack:\n at QIR.Runtime.__quantum__rt__qubit_release in core/qir.qs\n at Foo in line_5\n\u001b[31mQsc.Eval.ReleasedQubitNotZero\u001b[0m\n\n \u001b[31mร—\u001b[0m runtime error\n\u001b[31m โ•ฐโ”€โ–ถ \u001b[0mQubit1 released while not in |0โŸฉ state\n โ•ญโ”€[\u001b[36;1;4mline_5\u001b[0m:1:1]\n \u001b[2m1\u001b[0m โ”‚ operation Foo() : Unit { use q = Qubit(); X(q) } Foo()\n ยท \u001b[35;1m โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€\u001b[0m\n ยท \u001b[35;1mโ•ฐโ”€โ”€ \u001b[35;1mQubit1\u001b[0m\u001b[0m\n โ•ฐโ”€โ”€โ”€โ”€\n\u001b[36m help: \u001b[0mqubits should be returned to the |0โŸฉ state before being released to\n satisfy the assumption that allocated qubits start in the |0โŸฉ state\n",
351 "output_type": "error",
352 "traceback": [
353 "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
354 "\u001b[0;31mQSharpError\u001b[0m Traceback (most recent call last)",
355 "Cell \u001b[0;32mIn[7], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mqsharp\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43meval\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43moperation Foo() : Unit \u001b[39;49m\u001b[38;5;124;43m{\u001b[39;49m\u001b[38;5;124;43m use q = Qubit(); X(q) } Foo()\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n",
356 "File \u001b[0;32m~/Programming/qsharp/pip/qsharp/_qsharp.py:120\u001b[0m, in \u001b[0;36meval\u001b[0;34m(source)\u001b[0m\n\u001b[1;32m 117\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mcallback\u001b[39m(output: Output) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 118\u001b[0m \u001b[38;5;28mprint\u001b[39m(output)\n\u001b[0;32m--> 120\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mget_interpreter\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43minterpret\u001b[49m\u001b[43m(\u001b[49m\u001b[43msource\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcallback\u001b[49m\u001b[43m)\u001b[49m\n",
357 "\u001b[0;31mQSharpError\u001b[0m: Error: Qubit1 released while not in |0โŸฉ state\nCall stack:\n at QIR.Runtime.__quantum__rt__qubit_release in core/qir.qs\n at Foo in line_5\n\u001b[31mQsc.Eval.ReleasedQubitNotZero\u001b[0m\n\n \u001b[31mร—\u001b[0m runtime error\n\u001b[31m โ•ฐโ”€โ–ถ \u001b[0mQubit1 released while not in |0โŸฉ state\n โ•ญโ”€[\u001b[36;1;4mline_5\u001b[0m:1:1]\n \u001b[2m1\u001b[0m โ”‚ operation Foo() : Unit { use q = Qubit(); X(q) } Foo()\n ยท \u001b[35;1m โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€\u001b[0m\n ยท \u001b[35;1mโ•ฐโ”€โ”€ \u001b[35;1mQubit1\u001b[0m\u001b[0m\n โ•ฐโ”€โ”€โ”€โ”€\n\u001b[36m help: \u001b[0mqubits should be returned to the |0โŸฉ state before being released to\n satisfy the assumption that allocated qubits start in the |0โŸฉ state\n"
358 ]
359 }
360 ],
361 "source": [
362 "qsharp.eval(\"operation Foo() : Unit { use q = Qubit(); X(q) } Foo()\")\n"
363 ]
364 },
365 {
366 "cell_type": "markdown",
367 "id": "ba2f98ad",
368 "metadata": {},
369 "source": [
370 "In `%%qsharp` cells, exceptions are handled and displayed as error text."
371 ]
372 },
373 {
374 "cell_type": "code",
375 "execution_count": 8,
376 "id": "1b55e53c",
377 "metadata": {
378 "scrolled": false,
379 "vscode": {
380 "languageId": "qsharp"
381 }
382 },
383 "outputs": [
384 {
385 "data": {
386 "text/html": [
387 "<table>\n",
388 " <thead>\n",
389 " <tr>\n",
390 " <th style=\"text-align: left\">Basis State<br />(|๐œ“โ‚โ€ฆ๐œ“โ‚™โŸฉ)</th>\n",
391 " <th style=\"text-align: left\">Amplitude</th>\n",
392 " <th style=\"text-align: left\">Measurement Probability</th>\n",
393 " <th style=\"text-align: left\" colspan=\"2\">Phase</th>\n",
394 " </tr>\n",
395 " </thead>\n",
396 " <tbody>\n",
397 " <tr>\n",
398 " <td style=\"text-align: left\">\n",
399 " <span style=\"display: inline-block\">|110โŸฉ</span>\n",
400 " </td>\n",
401 " <td style=\"text-align: left\">\n",
402 " <span style=\"display: inline-block\">1.0000+0.0000๐‘–</span>\n",
403 " </td>\n",
404 " <td style=\"text-align: left\">\n",
405 " <progress max=\"100\" value=\"100\"></progress>\n",
406 " <span style=\"display: inline-block\">100.0000%</span>\n",
407 " </td>\n",
408 " <td style=\"text-align: left; transform: rotate(0.0000rad)\">โ†‘</td>\n",
409 " <td style=\"text-align: left\">\n",
410 " <span style=\"display: inline-block\">0.0000</span>\n",
411 " </td>\n",
412 "</tr>\n",
413 "\n",
414 " </tbody>\n",
415 "</table>\n"
416 ],
417 "text/plain": [
418 "STATE:\n",
419 "|110โŸฉ: 1.0000+0.0000๐‘–"
420 ]
421 },
422 "metadata": {},
423 "output_type": "display_data"
424 },
425 {
426 "ename": "QSharpCellError",
427 "evalue": "Error: Qubit2 released while not in |0โŸฉ state\nCall stack:\n at QIR.Runtime.__quantum__rt__qubit_release in core/qir.qs\n at Bar in line_6\n\u001b[31mQsc.Eval.ReleasedQubitNotZero\u001b[0m\n\n \u001b[31mร—\u001b[0m runtime error\n\u001b[31m โ•ฐโ”€โ–ถ \u001b[0mQubit2 released while not in |0โŸฉ state\n โ•ญโ”€[\u001b[36;1;4mline_6\u001b[0m:2:1]\n \u001b[2m2\u001b[0m โ”‚ operation Bar() : Unit {\n \u001b[2m3\u001b[0m โ”‚ use q = Qubit();\n ยท \u001b[35;1m โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€\u001b[0m\n ยท \u001b[35;1mโ•ฐโ”€โ”€ \u001b[35;1mQubit2\u001b[0m\u001b[0m\n \u001b[2m4\u001b[0m โ”‚ Microsoft.Quantum.Diagnostics.DumpMachine();\n โ•ฐโ”€โ”€โ”€โ”€\n\u001b[36m help: \u001b[0mqubits should be returned to the |0โŸฉ state before being released to\n satisfy the assumption that allocated qubits start in the |0โŸฉ state\n",
428 "output_type": "error",
429 "traceback": [
430 "Error: Qubit2 released while not in |0โŸฉ state",
431 "Call stack:",
432 " at QIR.Runtime.__quantum__rt__qubit_release in core/qir.qs",
433 " at Bar in line_6",
434 "\u001b[31mQsc.Eval.ReleasedQubitNotZero\u001b[0m",
435 "",
436 " \u001b[31mร—\u001b[0m runtime error",
437 "\u001b[31m โ•ฐโ”€โ–ถ \u001b[0mQubit2 released while not in |0โŸฉ state",
438 " โ•ญโ”€[\u001b[36;1;4mline_6\u001b[0m:2:1]",
439 " \u001b[2m2\u001b[0m โ”‚ operation Bar() : Unit {",
440 " \u001b[2m3\u001b[0m โ”‚ use q = Qubit();",
441 " ยท \u001b[35;1m โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€\u001b[0m",
442 " ยท \u001b[35;1mโ•ฐโ”€โ”€ \u001b[35;1mQubit2\u001b[0m\u001b[0m",
443 " \u001b[2m4\u001b[0m โ”‚ Microsoft.Quantum.Diagnostics.DumpMachine();",
444 " โ•ฐโ”€โ”€โ”€โ”€",
445 "\u001b[36m help: \u001b[0mqubits should be returned to the |0โŸฉ state before being released to",
446 " satisfy the assumption that allocated qubits start in the |0โŸฉ state"
447 ]
448 }
449 ],
450 "source": [
451 "%%qsharp\n",
452 "\n",
453 "operation Bar() : Unit {\n",
454 " use q = Qubit();\n",
455 " Microsoft.Quantum.Diagnostics.DumpMachine();\n",
456 " X(q);\n",
457 "}\n",
458 "\n",
459 "Bar()\n"
460 ]
461 },
462 {
463 "cell_type": "markdown",
464 "id": "98247ac2",
465 "metadata": {},
466 "source": [
467 "Streaming output for long running operations."
468 ]
469 },
470 {
471 "cell_type": "code",
472 "execution_count": 9,
473 "id": "bd25ae87",
474 "metadata": {
475 "vscode": {
476 "languageId": "qsharp"
477 }
478 },
479 "outputs": [
480 {
481 "data": {
482 "text/html": [
483 "<p>Generating random bit... </p>"
484 ],
485 "text/plain": [
486 "Generating random bit... "
487 ]
488 },
489 "metadata": {},
490 "output_type": "display_data"
491 },
492 {
493 "data": {
494 "text/html": [
495 "<table>\n",
496 " <thead>\n",
497 " <tr>\n",
498 " <th style=\"text-align: left\">Basis State<br />(|๐œ“โ‚โ€ฆ๐œ“โ‚™โŸฉ)</th>\n",
499 " <th style=\"text-align: left\">Amplitude</th>\n",
500 " <th style=\"text-align: left\">Measurement Probability</th>\n",
501 " <th style=\"text-align: left\" colspan=\"2\">Phase</th>\n",
502 " </tr>\n",
503 " </thead>\n",
504 " <tbody>\n",
505 " <tr>\n",
506 " <td style=\"text-align: left\">\n",
507 " <span style=\"display: inline-block\">|1111โŸฉ</span>\n",
508 " </td>\n",
509 " <td style=\"text-align: left\">\n",
510 " <span style=\"display: inline-block\">1.0000+0.0000๐‘–</span>\n",
511 " </td>\n",
512 " <td style=\"text-align: left\">\n",
513 " <progress max=\"100\" value=\"100\"></progress>\n",
514 " <span style=\"display: inline-block\">100.0000%</span>\n",
515 " </td>\n",
516 " <td style=\"text-align: left; transform: rotate(0.0000rad)\">โ†‘</td>\n",
517 " <td style=\"text-align: left\">\n",
518 " <span style=\"display: inline-block\">0.0000</span>\n",
519 " </td>\n",
520 "</tr>\n",
521 "\n",
522 " </tbody>\n",
523 "</table>\n"
524 ],
525 "text/plain": [
526 "STATE:\n",
527 "|1111โŸฉ: 1.0000+0.0000๐‘–"
528 ]
529 },
530 "metadata": {},
531 "output_type": "display_data"
532 },
533 {
534 "data": {
535 "text/html": [
536 "<p>Result: One</p>"
537 ],
538 "text/plain": [
539 "Result: One"
540 ]
541 },
542 "metadata": {},
543 "output_type": "display_data"
544 },
545 {
546 "data": {
547 "text/html": [
548 "<table>\n",
549 " <thead>\n",
550 " <tr>\n",
551 " <th style=\"text-align: left\">Basis State<br />(|๐œ“โ‚โ€ฆ๐œ“โ‚™โŸฉ)</th>\n",
552 " <th style=\"text-align: left\">Amplitude</th>\n",
553 " <th style=\"text-align: left\">Measurement Probability</th>\n",
554 " <th style=\"text-align: left\" colspan=\"2\">Phase</th>\n",
555 " </tr>\n",
556 " </thead>\n",
557 " <tbody>\n",
558 " <tr>\n",
559 " <td style=\"text-align: left\">\n",
560 " <span style=\"display: inline-block\">|1111โŸฉ</span>\n",
561 " </td>\n",
562 " <td style=\"text-align: left\">\n",
563 " <span style=\"display: inline-block\">1.0000+0.0000๐‘–</span>\n",
564 " </td>\n",
565 " <td style=\"text-align: left\">\n",
566 " <progress max=\"100\" value=\"100\"></progress>\n",
567 " <span style=\"display: inline-block\">100.0000%</span>\n",
568 " </td>\n",
569 " <td style=\"text-align: left; transform: rotate(0.0000rad)\">โ†‘</td>\n",
570 " <td style=\"text-align: left\">\n",
571 " <span style=\"display: inline-block\">0.0000</span>\n",
572 " </td>\n",
573 "</tr>\n",
574 "\n",
575 " </tbody>\n",
576 "</table>\n"
577 ],
578 "text/plain": [
579 "STATE:\n",
580 "|1111โŸฉ: 1.0000+0.0000๐‘–"
581 ]
582 },
583 "metadata": {},
584 "output_type": "display_data"
585 },
586 {
587 "data": {
588 "text/html": [
589 "<p>Result: One</p>"
590 ],
591 "text/plain": [
592 "Result: One"
593 ]
594 },
595 "metadata": {},
596 "output_type": "display_data"
597 },
598 {
599 "data": {
600 "text/html": [
601 "<table>\n",
602 " <thead>\n",
603 " <tr>\n",
604 " <th style=\"text-align: left\">Basis State<br />(|๐œ“โ‚โ€ฆ๐œ“โ‚™โŸฉ)</th>\n",
605 " <th style=\"text-align: left\">Amplitude</th>\n",
606 " <th style=\"text-align: left\">Measurement Probability</th>\n",
607 " <th style=\"text-align: left\" colspan=\"2\">Phase</th>\n",
608 " </tr>\n",
609 " </thead>\n",
610 " <tbody>\n",
611 " <tr>\n",
612 " <td style=\"text-align: left\">\n",
613 " <span style=\"display: inline-block\">|1111โŸฉ</span>\n",
614 " </td>\n",
615 " <td style=\"text-align: left\">\n",
616 " <span style=\"display: inline-block\">1.0000+0.0000๐‘–</span>\n",
617 " </td>\n",
618 " <td style=\"text-align: left\">\n",
619 " <progress max=\"100\" value=\"100\"></progress>\n",
620 " <span style=\"display: inline-block\">100.0000%</span>\n",
621 " </td>\n",
622 " <td style=\"text-align: left; transform: rotate(0.0000rad)\">โ†‘</td>\n",
623 " <td style=\"text-align: left\">\n",
624 " <span style=\"display: inline-block\">0.0000</span>\n",
625 " </td>\n",
626 "</tr>\n",
627 "\n",
628 " </tbody>\n",
629 "</table>\n"
630 ],
631 "text/plain": [
632 "STATE:\n",
633 "|1111โŸฉ: 1.0000+0.0000๐‘–"
634 ]
635 },
636 "metadata": {},
637 "output_type": "display_data"
638 },
639 {
640 "data": {
641 "text/html": [
642 "<p>Result: One</p>"
643 ],
644 "text/plain": [
645 "Result: One"
646 ]
647 },
648 "metadata": {},
649 "output_type": "display_data"
650 },
651 {
652 "data": {
653 "text/html": [
654 "<table>\n",
655 " <thead>\n",
656 " <tr>\n",
657 " <th style=\"text-align: left\">Basis State<br />(|๐œ“โ‚โ€ฆ๐œ“โ‚™โŸฉ)</th>\n",
658 " <th style=\"text-align: left\">Amplitude</th>\n",
659 " <th style=\"text-align: left\">Measurement Probability</th>\n",
660 " <th style=\"text-align: left\" colspan=\"2\">Phase</th>\n",
661 " </tr>\n",
662 " </thead>\n",
663 " <tbody>\n",
664 " <tr>\n",
665 " <td style=\"text-align: left\">\n",
666 " <span style=\"display: inline-block\">|1111โŸฉ</span>\n",
667 " </td>\n",
668 " <td style=\"text-align: left\">\n",
669 " <span style=\"display: inline-block\">1.0000+0.0000๐‘–</span>\n",
670 " </td>\n",
671 " <td style=\"text-align: left\">\n",
672 " <progress max=\"100\" value=\"100\"></progress>\n",
673 " <span style=\"display: inline-block\">100.0000%</span>\n",
674 " </td>\n",
675 " <td style=\"text-align: left; transform: rotate(0.0000rad)\">โ†‘</td>\n",
676 " <td style=\"text-align: left\">\n",
677 " <span style=\"display: inline-block\">0.0000</span>\n",
678 " </td>\n",
679 "</tr>\n",
680 "\n",
681 " </tbody>\n",
682 "</table>\n"
683 ],
684 "text/plain": [
685 "STATE:\n",
686 "|1111โŸฉ: 1.0000+0.0000๐‘–"
687 ]
688 },
689 "metadata": {},
690 "output_type": "display_data"
691 },
692 {
693 "data": {
694 "text/html": [
695 "<p>Result: One</p>"
696 ],
697 "text/plain": [
698 "Result: One"
699 ]
700 },
701 "metadata": {},
702 "output_type": "display_data"
703 },
704 {
705 "data": {
706 "text/html": [
707 "<table>\n",
708 " <thead>\n",
709 " <tr>\n",
710 " <th style=\"text-align: left\">Basis State<br />(|๐œ“โ‚โ€ฆ๐œ“โ‚™โŸฉ)</th>\n",
711 " <th style=\"text-align: left\">Amplitude</th>\n",
712 " <th style=\"text-align: left\">Measurement Probability</th>\n",
713 " <th style=\"text-align: left\" colspan=\"2\">Phase</th>\n",
714 " </tr>\n",
715 " </thead>\n",
716 " <tbody>\n",
717 " <tr>\n",
718 " <td style=\"text-align: left\">\n",
719 " <span style=\"display: inline-block\">|1111โŸฉ</span>\n",
720 " </td>\n",
721 " <td style=\"text-align: left\">\n",
722 " <span style=\"display: inline-block\">1.0000+0.0000๐‘–</span>\n",
723 " </td>\n",
724 " <td style=\"text-align: left\">\n",
725 " <progress max=\"100\" value=\"100\"></progress>\n",
726 " <span style=\"display: inline-block\">100.0000%</span>\n",
727 " </td>\n",
728 " <td style=\"text-align: left; transform: rotate(0.0000rad)\">โ†‘</td>\n",
729 " <td style=\"text-align: left\">\n",
730 " <span style=\"display: inline-block\">0.0000</span>\n",
731 " </td>\n",
732 "</tr>\n",
733 "\n",
734 " </tbody>\n",
735 "</table>\n"
736 ],
737 "text/plain": [
738 "STATE:\n",
739 "|1111โŸฉ: 1.0000+0.0000๐‘–"
740 ]
741 },
742 "metadata": {},
743 "output_type": "display_data"
744 },
745 {
746 "data": {
747 "text/html": [
748 "<p>Result: One</p>"
749 ],
750 "text/plain": [
751 "Result: One"
752 ]
753 },
754 "metadata": {},
755 "output_type": "display_data"
756 }
757 ],
758 "source": [
759 "%%qsharp\n",
760 "\n",
761 "open Microsoft.Quantum.Diagnostics;\n",
762 "\n",
763 "operation Main() : Unit {\n",
764 " Message(\"Generating random bit... \");\n",
765 " for i in 0..400000 {\n",
766 " use q = Qubit();\n",
767 " H(q);\n",
768 " let r = M(q);\n",
769 " if (i % 100000) == 0 {\n",
770 " DumpMachine();\n",
771 " Message($\"Result: {r}\");\n",
772 " }\n",
773 " Reset(q);\n",
774 " }\n",
775 "}\n",
776 "\n",
777 "Main()\n"
778 ]
779 },
780 {
781 "cell_type": "markdown",
782 "id": "2a2d9e7d",
783 "metadata": {},
784 "source": [
785 "Running multiple shots for an expression. Each shot uses an independent instance of the simulator. A list of results (or runtime errors) is returned."
786 ]
787 },
788 {
789 "cell_type": "code",
790 "execution_count": 10,
791 "id": "eb3cd29f",
792 "metadata": {
793 "vscode": {
794 "languageId": "qsharp"
795 }
796 },
797 "outputs": [],
798 "source": [
799 "%%qsharp\n",
800 "\n",
801 "operation RandomBit() : Result {\n",
802 " use q = Qubit();\n",
803 " H(q);\n",
804 " let res = M(q);\n",
805 " Reset(q);\n",
806 " return res;\n",
807 "}\n"
808 ]
809 },
810 {
811 "cell_type": "code",
812 "execution_count": 11,
813 "id": "9a9f5335",
814 "metadata": {},
815 "outputs": [
816 {
817 "data": {
818 "text/plain": [
819 "[One, Zero, Zero, Zero, Zero, Zero, Zero, One, Zero, Zero]"
820 ]
821 },
822 "execution_count": 11,
823 "metadata": {},
824 "output_type": "execute_result"
825 }
826 ],
827 "source": [
828 "results = qsharp.run(\"RandomBit()\", 10)\n",
829 "\n",
830 "results\n"
831 ]
832 },
833 {
834 "cell_type": "markdown",
835 "id": "6a476e6d",
836 "metadata": {},
837 "source": [
838 "The results can then be processed, e.g. plotted in a histogram using popular Python libraries."
839 ]
840 },
841 {
842 "cell_type": "code",
843 "execution_count": null,
844 "id": "7bd77379",
845 "metadata": {},
846 "outputs": [
847 {
848 "name": "stdout",
849 "output_type": "stream",
850 "text": [
851 "Requirement already satisfied: matplotlib in /opt/homebrew/lib/python3.11/site-packages (3.8.2)\n",
852 "Requirement already satisfied: contourpy>=1.0.1 in /opt/homebrew/lib/python3.11/site-packages (from matplotlib) (1.2.0)\n",
853 "Requirement already satisfied: cycler>=0.10 in /opt/homebrew/lib/python3.11/site-packages (from matplotlib) (0.12.1)\n",
854 "Requirement already satisfied: fonttools>=4.22.0 in /opt/homebrew/lib/python3.11/site-packages (from matplotlib) (4.46.0)\n",
855 "Requirement already satisfied: kiwisolver>=1.3.1 in /opt/homebrew/lib/python3.11/site-packages (from matplotlib) (1.4.5)\n",
856 "Requirement already satisfied: numpy<2,>=1.21 in /opt/homebrew/lib/python3.11/site-packages (from matplotlib) (1.23.5)\n",
857 "Requirement already satisfied: packaging>=20.0 in /Users/swernli/Library/Python/3.11/lib/python/site-packages (from matplotlib) (23.2)\n",
858 "Requirement already satisfied: pillow>=8 in /opt/homebrew/lib/python3.11/site-packages (from matplotlib) (10.1.0)\n",
859 "Requirement already satisfied: pyparsing>=2.3.1 in /opt/homebrew/lib/python3.11/site-packages (from matplotlib) (3.1.1)\n",
860 "Requirement already satisfied: python-dateutil>=2.7 in /Users/swernli/Library/Python/3.11/lib/python/site-packages (from matplotlib) (2.8.2)\n",
861 "Requirement already satisfied: six>=1.5 in /opt/homebrew/lib/python3.11/site-packages (from python-dateutil>=2.7->matplotlib) (1.16.0)\n",
862 "Note: you may need to restart the kernel to use updated packages.\n"
863 ]
864 }
865 ],
866 "source": [
867 "%pip install matplotlib\n"
868 ]
869 },
870 {
871 "cell_type": "code",
872 "execution_count": 12,
873 "id": "83cee4e8",
874 "metadata": {},
875 "outputs": [
876 {
877 "data": {
878 "image/png": "iVBORw0KGgoAAAANSUhEUgAAAhYAAAGdCAYAAABO2DpVAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8g+/7EAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAYm0lEQVR4nO3de4xU9fn48WeFMqLsLoIgrCzgXUSxCmiQ9itY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AsAIBlhAQAkIywAgGSEBQCQjLAAAJIRFgBAMsICAEhGWAAAyQgLACAZYQEAJCMsAIBkhAUAkIywAACSERYAQDIFhUXv3r2jrKxsl2XSpEnFmg8AKCFtC9l57dq10djY2Lz+3HPPxbBhw+Liiy9OPhgAUHoKCosuXbq0WJ81a1Ycd9xxce655yYdCgAoTQWFxX/76KOP4je/+U1MnTo1ysrKdrtfLpeLXC7XvJ7NZlt7SgDgANfqmzcfeOCB+OCDD+Lb3/72Hverq6uLysrK5qW6urq1pwQADnCtDou77747ampqoqqqao/71dbWRkNDQ/NSX1/f2lMCAAe4Vn0U8tprr8WyZcvi97///afum8lkIpPJtOY0AECJadUVi3vuuSe6du0aI0eOTD0PAFDCCg6LpqamuOeee2Ls2LHRtm2r7/0EAA5CBYfFsmXL4vXXX4/x48cXYx4AoIQVfMlh+PDhkc/nizELAFDifFcIAJCMsAAAkhEWAEAywgIASEZYAADJCAsAIBlhAQAkIywAgGSEBQCQjLAAAJIRFgBAMsICAEhGWAAAyQgLACAZYQEAJCMsAIBkhAUAkIywAACSERYAQDLCAgBIRlgAAMkICwAgGWEBACQjLACAZIQFAJCMsAAAkhEWAEAywgIASEZYAADJCAsAIBlhAQAkIywAgGSEBQCQTMFh8eabb8Zll10WnTt3jvbt28dpp50W69atK8ZsAECJaVvIzu+//34MHjw4hg4dGo888kh06dIlXnrppTjiiCOKNR8AUEIKCoubb745qqur45577mnedswxxyQfCgAoTQV9FPKHP/whBgwYEBdffHF07do1zjjjjLjrrrv2eEwul4tsNttiAQAOTgWFxcsvvxxz586NE044IZYuXRpXXnllTJ48OebNm7fbY+rq6qKysrJ5qa6u3uehAYADU1k+n8/v7c7t2rWLAQMGxBNPPNG8bfLkybF27dpYtWrVJx6Ty+Uil8s1r2ez2aiuro6GhoaoqKjYh9F31XvaQ0mfDw42r84aub9HAEpUNpuNysrKT/33u6ArFt27d49TTjmlxbY+ffrE66+/vttjMplMVFRUtFgAgINTQWExePDg2LBhQ4ttL774YvTq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AAAJIRFgBAMsICAEhGWAAAyQgLACAZYQEAJCMsAIBkhAUAkIywAACSERYAQDLCAgBIRlgAAMkICwAgGWEBACQjLACAZIQFAJCMsAAAkhEWAEAywgIASEZYAADJCAsAIBlhAQAkIywAgGSEBQCQjLAAAJIRFgBAMq0Ki9tuuy169+4dhx56aJx99tmxZs2a1HMBACWo4LBYtGhRTJ06NW666aZ48skn4/TTT48RI0bE1q1bizEfAFBCCg6L2bNnx3e+850YN25cnHLKKXH77bfHYYcdFr/61a+KMR8AUELaFrLzRx99FOvXr4/a2trmbYccckicf/75sWrVqk88JpfLRS6Xa15vaGiIiIhsNtuaefeoKffP5M8JB5NivO/2B+912L1ivc//87z5fH6P+xUUFu+++240NjbGUUcd1WL7UUcdFS+88MInHlNXVxfTp0/fZXt1dXUhpwYSqJyzvycAiq3Y7/Pt27dHZWXlbh8vKCxao7a2NqZOndq83tTUFNu2bYvOnTtHWVlZsU/PfpLNZqO6ujrq6+ujoqJif48DFIn3+udHPp+P7du3R1VV1R73KygsjjzyyGjTpk1s2bKlxfYtW7ZEt27dPvGYTCYTmUymxbaOHTsWclpKWEVFhR828Dngvf75sKcrFf9R0M2b7dq1i/79+8ejjz7avK2pqSkeffTRGDRoUOETAgAHlYI/Cpk6dWqMHTs2BgwYEGeddVbMmTMndu7cGePGjSvGfABACSk4LL7xjW/EO++8EzfeeGNs3rw5vvjFL8aSJUt2uaGTz7dMJhM33XTTLh+DAQcX73X+V1n+0/7fCADAXvJdIQBAMsICAEhGWAAAyQgLACAZYcEeLV++PMrKyna7DB06dH+PCBRBfX19jB8/PqqqqqJdu3bRq1evuOaaa+K9997b36NxgBMW7NE555wTb7/99i7LHXfcEWVlZTFx4sRWPe9HH32UeFIglZdffjkGDBgQL730Utx3332xcePGuP3225t/GeK2bdv294gcwIQFe9SuXbvo1q1bi+X999+P6667Lq6//vq4+OKLIyLiueeei5qamujQoUMcddRR8a1vfSvefffd5ucZMmRIXHXVVTFlypQ48sgjY8SIERER8dhjj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o5tgcQNy8yR69++67ceGFF8aQIUPisssui82bN7dY3nnnnZg0aVJs27YtLr300li7dm1s2rQpli5dGuPGjYvGxsbdPvfEiROjvr4+rr766njhhRfiwQcfjJtuuimmTp0ahxzirybsL7feemvkcrkYMWJErFixIurr62PJkiUxbNiwOProo2PmzJl79TxjxoyJI488MkaPHh2PP/54vPLKK7F8+fKYPHlyvPHGG0V+FewvfnqzRw899FC89tpr8fDDD0f37t13WQYOHBhVVVWxcuXKaGxsjOHDh8dpp50WU6ZMiY4dO+4xEI4++uh4+OGHY82aNXH66afHFVdcERMmTIgf/ehHn+ErBP7XCSecEOvWrYtjjz02LrnkkjjuuOPiu9/9bgwdOjRWrVoVnTp12qvnOeyww2LFihXRs2fP+PrXvx59+vSJCRMmxIcffugKxkHM16YDAMm4YgEAJCMsAIBkhAUAkIywAACSERYAQDLCAgBIRlgAAMkICwAgGWEBACQjLACAZIQFAJCMsAAAkvl/ckGCHgMKFIgAAAAASUVORK5CYII=",
879 "text/plain": [
880 "<Figure size 640x480 with 1 Axes>"
881 ]
882 },
883 "metadata": {},
884 "output_type": "display_data"
885 }
886 ],
887 "source": [
888 "import matplotlib.pyplot as plt\n",
889 "import numpy as np\n",
890 "from collections import Counter\n",
891 "\n",
892 "# Sort the results so that the histogram labels appear in the correct order\n",
893 "results.sort()\n",
894 "# Count the number of times each result appears\n",
895 "counts = Counter(results)\n",
896 "\n",
897 "(values, counts) = counts.keys(), counts.values()\n",
898 "xlabels = np.arange(len(counts))\n",
899 "plt.bar(xlabels, counts)\n",
900 "plt.xticks(xlabels, values)\n",
901 "plt.show()\n"
902 ]
903 },
904 {
905 "cell_type": "code",
906 "execution_count": null,
907 "id": "eaf766f4",
908 "metadata": {},
909 "outputs": [
910 {
911 "name": "stdout",
912 "output_type": "stream",
913 "text": [
914 "Requirement already satisfied: pandas in /opt/homebrew/lib/python3.11/site-packages (2.1.3)\n",
915 "Requirement already satisfied: numpy<2,>=1.23.2 in /opt/homebrew/lib/python3.11/site-packages (from pandas) (1.23.5)\n",
916 "Requirement already satisfied: python-dateutil>=2.8.2 in /Users/swernli/Library/Python/3.11/lib/python/site-packages (from pandas) (2.8.2)\n",
917 "Requirement already satisfied: pytz>=2020.1 in /opt/homebrew/lib/python3.11/site-packages (from pandas) (2023.3.post1)\n",
918 "Requirement already satisfied: tzdata>=2022.1 in /opt/homebrew/lib/python3.11/site-packages (from pandas) (2023.3)\n",
919 "Requirement already satisfied: six>=1.5 in /opt/homebrew/lib/python3.11/site-packages (from python-dateutil>=2.8.2->pandas) (1.16.0)\n",
920 "Note: you may need to restart the kernel to use updated packages.\n"
921 ]
922 }
923 ],
924 "source": [
925 "%pip install pandas\n"
926 ]
927 },
928 {
929 "cell_type": "code",
930 "execution_count": 13,
931 "id": "8095640a",
932 "metadata": {},
933 "outputs": [
934 {
935 "data": {
936 "text/plain": [
937 "<Axes: >"
938 ]
939 },
940 "execution_count": 13,
941 "metadata": {},
942 "output_type": "execute_result"
943 },
944 {
945 "data": {
946 "image/png": "iVBORw0KGgoAAAANSUhEUgAAAhYAAAGvCAYAAAAHapzzAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8g+/7EAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAZ40lEQVR4nO3de4wV9fn48ecAekS7uyI32bDchIqoYAU1lGqrKIh4qU28haZUramyikpsdGMQqaGLSUtpikVqrNAoYttUbWq9FLwQCyhgxVtVVMBFiqjoLmA86u7+/mjc33eLaM/yOZw9+Hol88fMmXEeE9d9Z2bOTqa5ubk5AAAS6FDsAQCAvYewAACSERYAQDLCAgBIRlgAAMkICwAgGWEBACQjLACAZDrt6RM2NTXFpk2boqysLDKZzJ4+PQDQBs3NzbFt27aorKyMDh12fV1ij4fFpk2boqqqak+fFgBIoK6uLnr37r3Lz/d4WJSVlUXEfwYrLy/f06cHANqgoaEhqqqqWn6P78oeD4vPbn+Ul5cLCwA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etnji/2CO1Wm78VUl1dHS+88EIsWrToC/erqamJ+vr6lqWurq6tpwQA2rk2XbG4/PLL469//WssXbo0evfu/YX7ZrPZyGazbRoOACgteYVFc3NzXHHFFXHvvffG448/Hv379y/UXABACcorLKqrq2PhwoVx//33R1lZWWzevDkiIioqKqJz584FGRAAKB15PWMxd+7cqK+vj+985zvRq1evluWee+4p1HwAQAnJ+1YIAMCueFcIAJCMsAAAkhEWAEAywgIASEZYAADJCAsAIBlhAQAkIywAgGSEBQCQjLAAAJIRFgBAMsICAEhGWAAAyQgLACAZYQEAJCMsAIBkhAUAkIywAACSERYAQDLCAgBIRlgAAMkICwAgGWEBACQjLACAZIQFAJCMsAAAkhEWAEAywgIASEZYAADJCAsAIBlhAQAkIywAgGSEBQCQTN5hsXTp0jjjjDOisrIyMplM3HfffQUYCwAoRXmHxY4dO2LYsGFxyy23FGIeAKCEdcr3gHHjxsW4ceMKMQsAUOLyDot85XK5yOVyLesNDQ2FPiUAUCQFf3iztrY2KioqWpaqqqpCnxIAKJKCh0VNTU3U19e3LHV1dYU+JQBQJAW/FZLNZiObzRb6NABAO+DvWAAAyeR9xWL79u3x2muvtayvW7cunn322TjooIOiT58+SYcDAEpL3mGxatWqOPHEE1vWp0yZEhEREydOjPnz5ycbDAAoPXmHxXe+851obm4uxCwAQInzjAUAkIywAACSERYAQDLCAgBIRlgAAMkICwAgGWEBACQjLACAZIQFAJCMsAAAkhEWAEAywgIASEZYAADJCAsAIBlhAQAkIywAgGSEBQCQjLAAAJIRFgBAMsICAEhGWAAAyQgLACAZYQEAJCMsAIBkhAUAkIywAACSERYAQDLCAgBIRlgAAMkICwAgGWEBACQjLACAZIQFAJBMm8LilltuiX79+sV+++0Xxx13XDz99NOp5wIASlDeYXHPPffElClTYtq0afHMM8/EsGHDYuzYsbFly5ZCzAcAlJC8w2LWrFlxySWXxIUXXhhDhgyJW2+9Nfbff//43e9+V4j5AIAS0imfnT/++ONYvXp11NTUtGzr0KFDnHzyybF8+fLPPS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NHj47q6ur43ve+FxUVFXH99de3+vzdd9+NAQMG+DoalKBu3brF+vXrdxkW69ati4MOOmgPT0V75VshJPHYY4/FueeeG9OmTfvczxsbG30rBErU2LFj4/rrr4+PP/54p89yuVxMnTo1Tj311CJMRnvkVghJdOjQIebNmxfXXHNNnHTSSXHnnXe2egHZ22+/HZWVldHY2FjEKYG22LhxY4wYMSKy2WxUV1fH4MGDo7m5Of71r3/Fb37zm8jlcrFq1aqoqqoq9qi0A8KCJDp06BCbN2+O9957L84666zIZrNx//33t7ysSFhAaVu3bl1MmjQpHnnkkfjs10Ymk4lTTjkl5syZEwMHDizyhLQXwoIkPguLHj16RH19fVxwwQXx1FNPxT333BMnn3yysIC9xPvvvx9r166NiP+8O8SzFfw3z1iQXEVFRTzwwANxySWXxGmnnea77bAX6dKlSxx77LFx7LHHigo+l2+FkMR/v7k0k8nEzJkz46ijjoof/ehH8eijjxZpMgD2JFcsSGJXd9TOP//8ePLJJ+P555/fwxMBUAyuWJDEY489tsvLokcddVSsXr06HnjggT08FQB7moc3AYBk3AoBAJIRFgBAMsICAEhGWAAAyQgLACAZYQEAJCMsAIBkhAUAkMz/A0oPESovBdCBAAAAAElFTkSuQmCC",
947 "text/plain": [
948 "<Figure size 640x480 with 1 Axes>"
949 ]
950 },
951 "metadata": {},
952 "output_type": "display_data"
953 }
954 ],
955 "source": [
956 "import pandas\n",
957 "from collections import Counter\n",
958 "\n",
959 "# Sort the results so that the histogram labels appear in the correct order\n",
960 "results.sort()\n",
961 "pandas.Series(results).value_counts(sort=False).plot(kind='bar')\n"
962 ]
963 },
964 {
965 "cell_type": "markdown",
966 "id": "990642e4",
967 "metadata": {},
968 "source": [
969 "A compiler error in the entry expression:"
970 ]
971 },
972 {
973 "cell_type": "code",
974 "execution_count": 14,
975 "id": "f045ad9c",
976 "metadata": {},
977 "outputs": [
978 {
979 "ename": "QSharpError",
980 "evalue": "\u001b[31mQsc.TypeCk.TyMismatch\u001b[0m\n\n \u001b[31mร—\u001b[0m type error\n\u001b[31m โ•ฐโ”€โ–ถ \u001b[0mexpected Unit, found String\n โ•ญโ”€[\u001b[36;1;4m<entry>\u001b[0m:1:1]\n \u001b[2m1\u001b[0m โ”‚ RandomBit(\"a\")\n ยท \u001b[35;1mโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€\u001b[0m\n โ•ฐโ”€โ”€โ”€โ”€\n",
981 "output_type": "error",
982 "traceback": [
983 "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
984 "\u001b[0;31mQSharpError\u001b[0m Traceback (most recent call last)",
985 "Cell \u001b[0;32mIn[14], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mqsharp\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrun\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\"\"\u001b[39;49m\u001b[38;5;124;43mRandomBit(\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43ma\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m)\u001b[39;49m\u001b[38;5;124;43m\"\"\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m10\u001b[39;49m\u001b[43m)\u001b[49m\n",
986 "File \u001b[0;32m~/Programming/qsharp/pip/qsharp/_qsharp.py:165\u001b[0m, in \u001b[0;36mrun\u001b[0;34m(entry_expr, shots, on_result, save_events)\u001b[0m\n\u001b[1;32m 163\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m _ \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mrange\u001b[39m(shots):\n\u001b[1;32m 164\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--> 165\u001b[0m run_results \u001b[38;5;241m=\u001b[39m \u001b[43mget_interpreter\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrun\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 166\u001b[0m \u001b[43m \u001b[49m\u001b[43mentry_expr\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mon_save_events\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mif\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43msave_events\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01melse\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mprint_output\u001b[49m\n\u001b[1;32m 167\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 168\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 169\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m on_result:\n",
987 "\u001b[0;31mQSharpError\u001b[0m: \u001b[31mQsc.TypeCk.TyMismatch\u001b[0m\n\n \u001b[31mร—\u001b[0m type error\n\u001b[31m โ•ฐโ”€โ–ถ \u001b[0mexpected Unit, found String\n โ•ญโ”€[\u001b[36;1;4m<entry>\u001b[0m:1:1]\n \u001b[2m1\u001b[0m โ”‚ RandomBit(\"a\")\n ยท \u001b[35;1mโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€\u001b[0m\n โ•ฐโ”€โ”€โ”€โ”€\n"
988 ]
989 }
990 ],
991 "source": [
992 "qsharp.run(\"\"\"RandomBit(\"a\")\"\"\", 10)\n"
993 ]
994 },
995 {
996 "cell_type": "markdown",
997 "id": "0ba56462",
998 "metadata": {},
999 "source": [
1000 "Some shots throw runtime errors:"
1001 ]
1002 },
1003 {
1004 "cell_type": "code",
1005 "execution_count": 15,
1006 "id": "9b85eb2d",
1007 "metadata": {
1008 "vscode": {
1009 "languageId": "qsharp"
1010 }
1011 },
1012 "outputs": [],
1013 "source": [
1014 "%%qsharp\n",
1015 "\n",
1016 "operation Bad() : Unit {\n",
1017 " use q = Qubit();\n",
1018 " H(q);\n",
1019 " let res = M(q);\n",
1020 " if (res == One) {\n",
1021 " // Do something bad, sometimes\n",
1022 " use q2 = Qubit();\n",
1023 " X(q2);\n",
1024 " }\n",
1025 "}\n"
1026 ]
1027 },
1028 {
1029 "cell_type": "code",
1030 "execution_count": 16,
1031 "id": "2445df05",
1032 "metadata": {},
1033 "outputs": [
1034 {
1035 "ename": "QSharpError",
1036 "evalue": "Error: Qubit1 released while not in |0โŸฉ state\nCall stack:\n at QIR.Runtime.__quantum__rt__qubit_release in core/qir.qs\n at Bad in line_9\n\u001b[31mQsc.Eval.ReleasedQubitNotZero\u001b[0m\n\n \u001b[31mร—\u001b[0m runtime error\n\u001b[31m โ•ฐโ”€โ–ถ \u001b[0mQubit1 released while not in |0โŸฉ state\n โ•ญโ”€[\u001b[36;1;4mline_9\u001b[0m:7:1]\n \u001b[2m7\u001b[0m โ”‚ // Do something bad, sometimes\n \u001b[2m8\u001b[0m โ”‚ use q2 = Qubit();\n ยท \u001b[35;1m โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€\u001b[0m\n ยท \u001b[35;1mโ•ฐโ”€โ”€ \u001b[35;1mQubit1\u001b[0m\u001b[0m\n \u001b[2m9\u001b[0m โ”‚ X(q2);\n โ•ฐโ”€โ”€โ”€โ”€\n\u001b[36m help: \u001b[0mqubits should be returned to the |0โŸฉ state before being released to\n satisfy the assumption that allocated qubits start in the |0โŸฉ state\n",
1037 "output_type": "error",
1038 "traceback": [
1039 "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
1040 "\u001b[0;31mQSharpError\u001b[0m Traceback (most recent call last)",
1041 "Cell \u001b[0;32mIn[16], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mqsharp\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrun\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mBad()\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m10\u001b[39;49m\u001b[43m)\u001b[49m\n",
1042 "File \u001b[0;32m~/Programming/qsharp/pip/qsharp/_qsharp.py:165\u001b[0m, in \u001b[0;36mrun\u001b[0;34m(entry_expr, shots, on_result, save_events)\u001b[0m\n\u001b[1;32m 163\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m _ \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mrange\u001b[39m(shots):\n\u001b[1;32m 164\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--> 165\u001b[0m run_results \u001b[38;5;241m=\u001b[39m \u001b[43mget_interpreter\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrun\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 166\u001b[0m \u001b[43m \u001b[49m\u001b[43mentry_expr\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mon_save_events\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mif\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43msave_events\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01melse\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mprint_output\u001b[49m\n\u001b[1;32m 167\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 168\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 169\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m on_result:\n",
1043 "\u001b[0;31mQSharpError\u001b[0m: Error: Qubit1 released while not in |0โŸฉ state\nCall stack:\n at QIR.Runtime.__quantum__rt__qubit_release in core/qir.qs\n at Bad in line_9\n\u001b[31mQsc.Eval.ReleasedQubitNotZero\u001b[0m\n\n \u001b[31mร—\u001b[0m runtime error\n\u001b[31m โ•ฐโ”€โ–ถ \u001b[0mQubit1 released while not in |0โŸฉ state\n โ•ญโ”€[\u001b[36;1;4mline_9\u001b[0m:7:1]\n \u001b[2m7\u001b[0m โ”‚ // Do something bad, sometimes\n \u001b[2m8\u001b[0m โ”‚ use q2 = Qubit();\n ยท \u001b[35;1m โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€\u001b[0m\n ยท \u001b[35;1mโ•ฐโ”€โ”€ \u001b[35;1mQubit1\u001b[0m\u001b[0m\n \u001b[2m9\u001b[0m โ”‚ X(q2);\n โ•ฐโ”€โ”€โ”€โ”€\n\u001b[36m help: \u001b[0mqubits should be returned to the |0โŸฉ state before being released to\n satisfy the assumption that allocated qubits start in the |0โŸฉ state\n"
1044 ]
1045 }
1046 ],
1047 "source": [
1048 "qsharp.run(\"Bad()\", 10)\n"
1049 ]
1050 }
1051 ],
1052 "metadata": {
1053 "kernelspec": {
1054 "display_name": "Python 3 (ipykernel)",
1055 "language": "python",
1056 "name": "python3"
1057 },
1058 "language_info": {
1059 "codemirror_mode": {
1060 "name": "ipython",
1061 "version": 3
1062 },
1063 "file_extension": ".py",
1064 "mimetype": "text/x-python",
1065 "name": "python",
1066 "nbconvert_exporter": "python",
1067 "pygments_lexer": "ipython3",
1068 "version": "3.11.6"
1069 }
1070 },
1071 "nbformat": 4,
1072 "nbformat_minor": 5
1073}
1074