microsoft/qdk
Publicmirrored fromhttps://github.com/microsoft/qdkAvailable
samples/notebooks/circuits.ipynb
559lines · modecode
| 1 | { |
| 2 | "cells": [ |
| 3 | { |
| 4 | "cell_type": "markdown", |
| 5 | "metadata": {}, |
| 6 | "source": [ |
| 7 | "# Synthesizing circuit diagrams from Q# code" |
| 8 | ] |
| 9 | }, |
| 10 | { |
| 11 | "cell_type": "code", |
| 12 | "execution_count": 1, |
| 13 | "metadata": {}, |
| 14 | "outputs": [ |
| 15 | { |
| 16 | "data": { |
| 17 | "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", |
| 18 | "text/plain": [] |
| 19 | }, |
| 20 | "metadata": {}, |
| 21 | "output_type": "display_data" |
| 22 | } |
| 23 | ], |
| 24 | "source": [ |
| 25 | "import qsharp" |
| 26 | ] |
| 27 | }, |
| 28 | { |
| 29 | "cell_type": "markdown", |
| 30 | "metadata": {}, |
| 31 | "source": [ |
| 32 | "The `dump_circuit()` function displays a circuit that contains the gates that have been applied in the simulator up to this point." |
| 33 | ] |
| 34 | }, |
| 35 | { |
| 36 | "cell_type": "code", |
| 37 | "execution_count": 2, |
| 38 | "metadata": { |
| 39 | "vscode": { |
| 40 | "languageId": "qsharp" |
| 41 | } |
| 42 | }, |
| 43 | "outputs": [], |
| 44 | "source": [ |
| 45 | "%%qsharp\n", |
| 46 | "\n", |
| 47 | "// Prepare a Bell State.\n", |
| 48 | "use register = Qubit[2];\n", |
| 49 | "H(register[0]);\n", |
| 50 | "CNOT(register[0], register[1]);" |
| 51 | ] |
| 52 | }, |
| 53 | { |
| 54 | "cell_type": "code", |
| 55 | "execution_count": 3, |
| 56 | "metadata": {}, |
| 57 | "outputs": [ |
| 58 | { |
| 59 | "data": { |
| 60 | "text/plain": [ |
| 61 | "q_0 ── H ──── ● ──\n", |
| 62 | "q_1 ───────── X ──" |
| 63 | ] |
| 64 | }, |
| 65 | "execution_count": 3, |
| 66 | "metadata": {}, |
| 67 | "output_type": "execute_result" |
| 68 | } |
| 69 | ], |
| 70 | "source": [ |
| 71 | "qsharp.dump_circuit()" |
| 72 | ] |
| 73 | }, |
| 74 | { |
| 75 | "cell_type": "markdown", |
| 76 | "metadata": {}, |
| 77 | "source": [ |
| 78 | "If you have the Q# widgets installed, you can display the circuit as an SVG image.\n", |
| 79 | "\n", |
| 80 | "_Run `pip install qsharp-widgets` in the command line to install the Q# widgets._" |
| 81 | ] |
| 82 | }, |
| 83 | { |
| 84 | "cell_type": "code", |
| 85 | "execution_count": 4, |
| 86 | "metadata": {}, |
| 87 | "outputs": [ |
| 88 | { |
| 89 | "data": { |
| 90 | "application/vnd.jupyter.widget-view+json": { |
| 91 | "model_id": "4a760784b95c464cbeeb20e6cb39493f", |
| 92 | "version_major": 2, |
| 93 | "version_minor": 0 |
| 94 | }, |
| 95 | "text/plain": [ |
| 96 | "Circuit(circuit_json='{\"operations\":[{\"gate\":\"H\",\"targets\":[{\"qId\":0,\"type\":0}]},{\"gate\":\"X\",\"isControlled\":tr…" |
| 97 | ] |
| 98 | }, |
| 99 | "execution_count": 4, |
| 100 | "metadata": {}, |
| 101 | "output_type": "execute_result" |
| 102 | } |
| 103 | ], |
| 104 | "source": [ |
| 105 | "from qsharp_widgets import Circuit\n", |
| 106 | "\n", |
| 107 | "Circuit(qsharp.dump_circuit())" |
| 108 | ] |
| 109 | }, |
| 110 | { |
| 111 | "cell_type": "markdown", |
| 112 | "metadata": {}, |
| 113 | "source": [ |
| 114 | "You can synthesize a circuit diagram for any program by calling `qsharp.circuit()` with an entry expression." |
| 115 | ] |
| 116 | }, |
| 117 | { |
| 118 | "cell_type": "code", |
| 119 | "execution_count": 5, |
| 120 | "metadata": { |
| 121 | "vscode": { |
| 122 | "languageId": "qsharp" |
| 123 | } |
| 124 | }, |
| 125 | "outputs": [], |
| 126 | "source": [ |
| 127 | "%%qsharp\n", |
| 128 | "\n", |
| 129 | "open Microsoft.Quantum.Diagnostics;\n", |
| 130 | "open Microsoft.Quantum.Measurement;\n", |
| 131 | "\n", |
| 132 | "operation GHZSample(n: Int) : Result[] {\n", |
| 133 | " use qs = Qubit[n];\n", |
| 134 | "\n", |
| 135 | " H(qs[0]);\n", |
| 136 | " ApplyToEach(CNOT(qs[0], _), qs[1...]);\n", |
| 137 | "\n", |
| 138 | " let results = MeasureEachZ(qs);\n", |
| 139 | " ResetAll(qs);\n", |
| 140 | " return results;\n", |
| 141 | "}" |
| 142 | ] |
| 143 | }, |
| 144 | { |
| 145 | "cell_type": "code", |
| 146 | "execution_count": 6, |
| 147 | "metadata": {}, |
| 148 | "outputs": [ |
| 149 | { |
| 150 | "data": { |
| 151 | "application/vnd.jupyter.widget-view+json": { |
| 152 | "model_id": "739e08c87275454186529bcd76156a0d", |
| 153 | "version_major": 2, |
| 154 | "version_minor": 0 |
| 155 | }, |
| 156 | "text/plain": [ |
| 157 | "Circuit(circuit_json='{\"operations\":[{\"gate\":\"H\",\"targets\":[{\"qId\":0,\"type\":0}]},{\"gate\":\"X\",\"isControlled\":tr…" |
| 158 | ] |
| 159 | }, |
| 160 | "execution_count": 6, |
| 161 | "metadata": {}, |
| 162 | "output_type": "execute_result" |
| 163 | } |
| 164 | ], |
| 165 | "source": [ |
| 166 | "Circuit(qsharp.circuit(\"GHZSample(3)\"))" |
| 167 | ] |
| 168 | }, |
| 169 | { |
| 170 | "cell_type": "markdown", |
| 171 | "metadata": {}, |
| 172 | "source": [ |
| 173 | "Circuit diagrams can also be generated for any operation that takes qubits or arrays of qubits.\n", |
| 174 | "\n", |
| 175 | "The diagram will show as many wires as there are input qubit, plus any additional qubits that are allocated within the operation.\n", |
| 176 | "\n", |
| 177 | "When the operation takes an array of qubits (`Qubit[]`), the circuit will show the array as a register of 2 qubits." |
| 178 | ] |
| 179 | }, |
| 180 | { |
| 181 | "cell_type": "code", |
| 182 | "execution_count": 7, |
| 183 | "metadata": { |
| 184 | "vscode": { |
| 185 | "languageId": "qsharp" |
| 186 | } |
| 187 | }, |
| 188 | "outputs": [], |
| 189 | "source": [ |
| 190 | "%%qsharp\n", |
| 191 | "\n", |
| 192 | "operation PrepareCatState(register : Qubit[]) : Unit {\n", |
| 193 | " H(register[0]);\n", |
| 194 | " ApplyToEach(CNOT(register[0], _), register[1...]);\n", |
| 195 | "}" |
| 196 | ] |
| 197 | }, |
| 198 | { |
| 199 | "cell_type": "code", |
| 200 | "execution_count": 8, |
| 201 | "metadata": {}, |
| 202 | "outputs": [ |
| 203 | { |
| 204 | "data": { |
| 205 | "application/vnd.jupyter.widget-view+json": { |
| 206 | "model_id": "17f2fea978c24ccb8ae137888ac4aa05", |
| 207 | "version_major": 2, |
| 208 | "version_minor": 0 |
| 209 | }, |
| 210 | "text/plain": [ |
| 211 | "Circuit(circuit_json='{\"operations\":[{\"gate\":\"H\",\"targets\":[{\"qId\":0,\"type\":0}]},{\"gate\":\"X\",\"isControlled\":tr…" |
| 212 | ] |
| 213 | }, |
| 214 | "execution_count": 8, |
| 215 | "metadata": {}, |
| 216 | "output_type": "execute_result" |
| 217 | } |
| 218 | ], |
| 219 | "source": [ |
| 220 | "Circuit(qsharp.circuit(operation=\"PrepareCatState\"))" |
| 221 | ] |
| 222 | }, |
| 223 | { |
| 224 | "cell_type": "markdown", |
| 225 | "metadata": {}, |
| 226 | "source": [ |
| 227 | "Circuit synthesis takes into account the currently chosen target, and will perform the same gate decompositions and other transformations that compiling for that target would produce.\n", |
| 228 | "\n", |
| 229 | "Here, we show what the circuit looks like for a random bit generator when the Unrestricted target profile is chosen." |
| 230 | ] |
| 231 | }, |
| 232 | { |
| 233 | "cell_type": "code", |
| 234 | "execution_count": 9, |
| 235 | "metadata": { |
| 236 | "vscode": { |
| 237 | "languageId": "qsharp" |
| 238 | } |
| 239 | }, |
| 240 | "outputs": [], |
| 241 | "source": [ |
| 242 | "%%qsharp\n", |
| 243 | "\n", |
| 244 | "operation TwoRandomBits() : Result[] {\n", |
| 245 | " let r1 = RandomBit();\n", |
| 246 | " let r2 = RandomBit();\n", |
| 247 | " return [r1, r2];\n", |
| 248 | "}\n", |
| 249 | "\n", |
| 250 | "operation RandomBit() : Result {\n", |
| 251 | " use q = Qubit();\n", |
| 252 | " H(q);\n", |
| 253 | " MResetZ(q)\n", |
| 254 | "}" |
| 255 | ] |
| 256 | }, |
| 257 | { |
| 258 | "cell_type": "code", |
| 259 | "execution_count": 10, |
| 260 | "metadata": {}, |
| 261 | "outputs": [ |
| 262 | { |
| 263 | "data": { |
| 264 | "application/vnd.jupyter.widget-view+json": { |
| 265 | "model_id": "2dac021b8bf449b5a8df9fef0894f7b2", |
| 266 | "version_major": 2, |
| 267 | "version_minor": 0 |
| 268 | }, |
| 269 | "text/plain": [ |
| 270 | "Circuit(circuit_json='{\"operations\":[{\"gate\":\"H\",\"targets\":[{\"qId\":0,\"type\":0}]},{\"gate\":\"Measure\",\"isMeasurem…" |
| 271 | ] |
| 272 | }, |
| 273 | "execution_count": 10, |
| 274 | "metadata": {}, |
| 275 | "output_type": "execute_result" |
| 276 | } |
| 277 | ], |
| 278 | "source": [ |
| 279 | "Circuit(qsharp.circuit(\"TwoRandomBits()\"))" |
| 280 | ] |
| 281 | }, |
| 282 | { |
| 283 | "cell_type": "markdown", |
| 284 | "metadata": {}, |
| 285 | "source": [ |
| 286 | "If we generate a circuit for the same program, but targeting the Base profile, the resulting circuit avoids reset gates and uses two qubits instead." |
| 287 | ] |
| 288 | }, |
| 289 | { |
| 290 | "cell_type": "code", |
| 291 | "execution_count": 11, |
| 292 | "metadata": {}, |
| 293 | "outputs": [ |
| 294 | { |
| 295 | "data": { |
| 296 | "application/x.qsharp-config": "{\"targetProfile\":\"base\",\"languageFeatures\":[]}", |
| 297 | "text/plain": [ |
| 298 | "Q# initialized with configuration: {'targetProfile': 'base', 'languageFeatures': []}" |
| 299 | ] |
| 300 | }, |
| 301 | "execution_count": 11, |
| 302 | "metadata": {}, |
| 303 | "output_type": "execute_result" |
| 304 | } |
| 305 | ], |
| 306 | "source": [ |
| 307 | "qsharp.init(target_profile=qsharp.TargetProfile.Base)" |
| 308 | ] |
| 309 | }, |
| 310 | { |
| 311 | "cell_type": "code", |
| 312 | "execution_count": 12, |
| 313 | "metadata": { |
| 314 | "vscode": { |
| 315 | "languageId": "qsharp" |
| 316 | } |
| 317 | }, |
| 318 | "outputs": [], |
| 319 | "source": [ |
| 320 | "%%qsharp\n", |
| 321 | "\n", |
| 322 | "operation TwoRandomBits() : Result[] {\n", |
| 323 | " let r1 = RandomBit();\n", |
| 324 | " let r2 = RandomBit();\n", |
| 325 | " return [r1, r2];\n", |
| 326 | "}\n", |
| 327 | "\n", |
| 328 | "operation RandomBit() : Result {\n", |
| 329 | " use q = Qubit();\n", |
| 330 | " H(q);\n", |
| 331 | " MResetZ(q)\n", |
| 332 | "}" |
| 333 | ] |
| 334 | }, |
| 335 | { |
| 336 | "cell_type": "code", |
| 337 | "execution_count": 13, |
| 338 | "metadata": {}, |
| 339 | "outputs": [ |
| 340 | { |
| 341 | "data": { |
| 342 | "application/vnd.jupyter.widget-view+json": { |
| 343 | "model_id": "df689aa58fa842ccb668294f5ce1e56b", |
| 344 | "version_major": 2, |
| 345 | "version_minor": 0 |
| 346 | }, |
| 347 | "text/plain": [ |
| 348 | "Circuit(circuit_json='{\"operations\":[{\"gate\":\"H\",\"targets\":[{\"qId\":0,\"type\":0}]},{\"gate\":\"H\",\"targets\":[{\"qId\"…" |
| 349 | ] |
| 350 | }, |
| 351 | "execution_count": 13, |
| 352 | "metadata": {}, |
| 353 | "output_type": "execute_result" |
| 354 | } |
| 355 | ], |
| 356 | "source": [ |
| 357 | "Circuit(qsharp.circuit(\"TwoRandomBits()\"))" |
| 358 | ] |
| 359 | }, |
| 360 | { |
| 361 | "cell_type": "markdown", |
| 362 | "metadata": {}, |
| 363 | "source": [ |
| 364 | "Regardless of the target chosen, conditionals that compare `Result` values are not permitted during circuit synthesis. This is because they may introduce nondeterminism such that the circuit will look different depending on measurement outcome. Representing conditionals visually is not supported." |
| 365 | ] |
| 366 | }, |
| 367 | { |
| 368 | "cell_type": "code", |
| 369 | "execution_count": 14, |
| 370 | "metadata": {}, |
| 371 | "outputs": [ |
| 372 | { |
| 373 | "data": { |
| 374 | "application/x.qsharp-config": "{\"targetProfile\":\"unrestricted\",\"languageFeatures\":[]}", |
| 375 | "text/plain": [ |
| 376 | "Q# initialized with configuration: {'targetProfile': 'unrestricted', 'languageFeatures': []}" |
| 377 | ] |
| 378 | }, |
| 379 | "execution_count": 14, |
| 380 | "metadata": {}, |
| 381 | "output_type": "execute_result" |
| 382 | } |
| 383 | ], |
| 384 | "source": [ |
| 385 | "qsharp.init(target_profile=qsharp.TargetProfile.Unrestricted)" |
| 386 | ] |
| 387 | }, |
| 388 | { |
| 389 | "cell_type": "code", |
| 390 | "execution_count": 15, |
| 391 | "metadata": { |
| 392 | "vscode": { |
| 393 | "languageId": "qsharp" |
| 394 | } |
| 395 | }, |
| 396 | "outputs": [], |
| 397 | "source": [ |
| 398 | "%%qsharp\n", |
| 399 | "\n", |
| 400 | "operation ResetIfOne() : Result {\n", |
| 401 | " use q = Qubit();\n", |
| 402 | " H(q);\n", |
| 403 | " let r = M(q);\n", |
| 404 | " if (r == One) {\n", |
| 405 | " Message(\"result was One, applying X gate\");\n", |
| 406 | " X(q);\n", |
| 407 | " } else {\n", |
| 408 | " Message(\"result was Zero\");\n", |
| 409 | " }\n", |
| 410 | " Reset(q);\n", |
| 411 | " return r\n", |
| 412 | "}" |
| 413 | ] |
| 414 | }, |
| 415 | { |
| 416 | "cell_type": "code", |
| 417 | "execution_count": 16, |
| 418 | "metadata": {}, |
| 419 | "outputs": [ |
| 420 | { |
| 421 | "name": "stdout", |
| 422 | "output_type": "stream", |
| 423 | "text": [ |
| 424 | "Simulating program...\n", |
| 425 | "result was Zero\n", |
| 426 | "result was Zero\n", |
| 427 | "result was Zero\n", |
| 428 | "\n", |
| 429 | "Synthesizing circuit for program (should raise error)...\n", |
| 430 | "Error: cannot compare measurement results\n", |
| 431 | "Call stack:\n", |
| 432 | " at ResetIfOne in line_0\n", |
| 433 | "\u001b[31mQsc.Eval.ResultComparisonUnsupported\u001b[0m\n", |
| 434 | "\n", |
| 435 | " \u001b[31m×\u001b[0m runtime error\n", |
| 436 | "\u001b[31m ╰─▶ \u001b[0mcannot compare measurement results\n", |
| 437 | " ╭─[\u001b[36;1;4mline_0\u001b[0m:5:1]\n", |
| 438 | " \u001b[2m5\u001b[0m │ let r = M(q);\n", |
| 439 | " \u001b[2m6\u001b[0m │ if (r == One) {\n", |
| 440 | " · \u001b[35;1m ─┬─\u001b[0m\n", |
| 441 | " · \u001b[35;1m╰── \u001b[35;1mcannot compare to result\u001b[0m\u001b[0m\n", |
| 442 | " \u001b[2m7\u001b[0m │ Message(\"result was One, applying X gate\");\n", |
| 443 | " ╰────\n", |
| 444 | "\u001b[36m help: \u001b[0mcomparing measurement results is not supported when performing\n", |
| 445 | " circuit synthesis or base profile QIR generation\n", |
| 446 | "\n" |
| 447 | ] |
| 448 | } |
| 449 | ], |
| 450 | "source": [ |
| 451 | "# Program can be simulated. Differerent shots may produce different results.\n", |
| 452 | "print(\"Simulating program...\")\n", |
| 453 | "qsharp.run(\"ResetIfOne()\", 3)\n", |
| 454 | "\n", |
| 455 | "print()\n", |
| 456 | "\n", |
| 457 | "# The same program cannot be synthesized as a circuit because of the conditional X gate.\n", |
| 458 | "print(\"Synthesizing circuit for program (should raise error)...\")\n", |
| 459 | "try:\n", |
| 460 | " qsharp.circuit(\"ResetIfOne()\")\n", |
| 461 | "except qsharp.QSharpError as e:\n", |
| 462 | " print(e)" |
| 463 | ] |
| 464 | }, |
| 465 | { |
| 466 | "cell_type": "markdown", |
| 467 | "metadata": {}, |
| 468 | "source": [ |
| 469 | "Even though we can't synthesize the above program into a circuit, we still have the option of running it in the simulator, and displaying the resulting circuit.\n", |
| 470 | "\n", |
| 471 | "Note that the resulting circuit diagram shows only one of the two branches that could have been taken." |
| 472 | ] |
| 473 | }, |
| 474 | { |
| 475 | "cell_type": "code", |
| 476 | "execution_count": 17, |
| 477 | "metadata": { |
| 478 | "vscode": { |
| 479 | "languageId": "qsharp" |
| 480 | } |
| 481 | }, |
| 482 | "outputs": [ |
| 483 | { |
| 484 | "data": { |
| 485 | "text/html": [ |
| 486 | "<p>result was Zero</p>" |
| 487 | ], |
| 488 | "text/plain": [ |
| 489 | "result was Zero" |
| 490 | ] |
| 491 | }, |
| 492 | "metadata": {}, |
| 493 | "output_type": "display_data" |
| 494 | }, |
| 495 | { |
| 496 | "data": { |
| 497 | "text/plain": [ |
| 498 | "Zero" |
| 499 | ] |
| 500 | }, |
| 501 | "execution_count": 17, |
| 502 | "metadata": {}, |
| 503 | "output_type": "execute_result" |
| 504 | } |
| 505 | ], |
| 506 | "source": [ |
| 507 | "%%qsharp\n", |
| 508 | "\n", |
| 509 | "ResetIfOne()" |
| 510 | ] |
| 511 | }, |
| 512 | { |
| 513 | "cell_type": "code", |
| 514 | "execution_count": 18, |
| 515 | "metadata": {}, |
| 516 | "outputs": [ |
| 517 | { |
| 518 | "data": { |
| 519 | "application/vnd.jupyter.widget-view+json": { |
| 520 | "model_id": "c4ef7327e1194d37991f5b46b35f3a9d", |
| 521 | "version_major": 2, |
| 522 | "version_minor": 0 |
| 523 | }, |
| 524 | "text/plain": [ |
| 525 | "Circuit(circuit_json='{\"operations\":[{\"gate\":\"H\",\"targets\":[{\"qId\":0,\"type\":0}]},{\"gate\":\"Measure\",\"isMeasurem…" |
| 526 | ] |
| 527 | }, |
| 528 | "execution_count": 18, |
| 529 | "metadata": {}, |
| 530 | "output_type": "execute_result" |
| 531 | } |
| 532 | ], |
| 533 | "source": [ |
| 534 | "Circuit(qsharp.dump_circuit())" |
| 535 | ] |
| 536 | } |
| 537 | ], |
| 538 | "metadata": { |
| 539 | "kernelspec": { |
| 540 | "display_name": "Python 3", |
| 541 | "language": "python", |
| 542 | "name": "python3" |
| 543 | }, |
| 544 | "language_info": { |
| 545 | "codemirror_mode": { |
| 546 | "name": "ipython", |
| 547 | "version": 3 |
| 548 | }, |
| 549 | "file_extension": ".py", |
| 550 | "mimetype": "text/x-python", |
| 551 | "name": "python", |
| 552 | "nbconvert_exporter": "python", |
| 553 | "pygments_lexer": "ipython3", |
| 554 | "version": "3.11.9" |
| 555 | } |
| 556 | }, |
| 557 | "nbformat": 4, |
| 558 | "nbformat_minor": 2 |
| 559 | } |
| 560 | |