microsoft/qdk

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
iadavis/pipeline-issue-debugging

Branches

Tags

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

Clone

HTTPS

Download ZIP

samples/estimation/estimation-openqasm.ipynb

605lines · modecode

1{
2 "cells": [
3 {
4 "cell_type": "markdown",
5 "metadata": {},
6 "source": [
7 "# Getting Started with QDK Resource Estimation using OpenQASM\n",
8 "\n",
9 "👋 Welcome to the QDK Resource Estimator using OpenQASM. In this notebook we will\n",
10 "guide you how to estimate and analyze the physical resource estimates of a\n",
11 "quantum program targeted for execution based on the architecture design of a\n",
12 "fault-tolerant quantum computer. As a running example we are using a multiplier."
13 ]
14 },
15 {
16 "cell_type": "markdown",
17 "metadata": {},
18 "source": [
19 "## Implementing the algorithm"
20 ]
21 },
22 {
23 "cell_type": "markdown",
24 "metadata": {},
25 "source": [
26 "As a first step, we will create a sample application which will be used throughout this Resource Estimation notebook. To start, we'll import some utilities from the `qiskit` Python package eventually generating the OpenQASM program."
27 ]
28 },
29 {
30 "cell_type": "code",
31 "execution_count": null,
32 "metadata": {},
33 "outputs": [],
34 "source": [
35 "from qiskit.circuit.library import RGQFTMultiplier"
36 ]
37 },
38 {
39 "cell_type": "markdown",
40 "metadata": {},
41 "source": [
42 "We are creating a quantum circuit for a multiplier based on the construction presented in [arXiv:1411.5949](https://arxiv.org/abs/1411.5949) which uses the Quantum Fourier Transform to implement arithmetic. You can adjust the size of the multiplier by changing the `bitwidth` variable. The circuit generation is wrapped in a function that can be called with the bitwidth of the multiplier. The circuit will have two input registers with that bitwidth, and one output register with the size of twice the bitwidth."
43 ]
44 },
45 {
46 "cell_type": "code",
47 "execution_count": null,
48 "metadata": {},
49 "outputs": [],
50 "source": [
51 "def create_algorithm(bitwidth):\n",
52 " print(f\"[INFO] Create a QFT-based multiplier with bitwidth {bitwidth}\")\n",
53 "\n",
54 " circ = RGQFTMultiplier(num_state_qubits=bitwidth)\n",
55 "\n",
56 " return circ"
57 ]
58 },
59 {
60 "cell_type": "markdown",
61 "metadata": {},
62 "source": [
63 "## Estimating the algorithm\n",
64 "Next we will create an instance of our algorithm using the `create_algorithm` function. You can adjust the size of the multiplier by changing the `bitwidth` variable."
65 ]
66 },
67 {
68 "cell_type": "code",
69 "execution_count": null,
70 "metadata": {},
71 "outputs": [],
72 "source": [
73 "from qiskit.qasm3.exporter import Exporter\n",
74 "\n",
75 "bitwidth = 4\n",
76 "circ = create_algorithm(bitwidth)\n",
77 "\n",
78 "# Export the circuit to QASM vis Qiskit's OpenQASM 3 exporter\n",
79 "program = Exporter().dumps(circ)\n",
80 "\n",
81 "print(program)"
82 ]
83 },
84 {
85 "cell_type": "markdown",
86 "metadata": {},
87 "source": [
88 "Let's now estimate the physical resources for this program using the default assumptions. We've used `qiskit` package to create our OpenQASM program here demonstrating how OpenQASM programs, or any tool that generates OpenQASM, can be used with the QDK's resource estimation capabilities.\n",
89 "\n",
90 "The `estimate` call accepts and OpenQASM program as a string, so we can simply call it."
91 ]
92 },
93 {
94 "cell_type": "code",
95 "execution_count": null,
96 "metadata": {},
97 "outputs": [],
98 "source": [
99 "from qsharp.estimator import EstimatorParams\n",
100 "from qsharp.openqasm import estimate\n",
101 "\n",
102 "params = EstimatorParams()\n",
103 "result = estimate(program, params)"
104 ]
105 },
106 {
107 "cell_type": "markdown",
108 "metadata": {},
109 "source": [
110 "The simplest way to inspect the results of the job is to output them to the notebook. This will output a table with the overall physical resource counts. You can further inspect more details about the resource estimates by collapsing various groups which have more information. For example, if you collapse the *Logical qubit parameters* group, you can see that the quantum error correction (QEC) code distance is 15. In the last group you can see the physical qubit properties that were assumed for this estimation. For example, we see that the time to perform a single-qubit measurement and a single-qubit gate are assumed to be 100 ns and 50 ns, respectively."
111 ]
112 },
113 {
114 "cell_type": "code",
115 "execution_count": null,
116 "metadata": {},
117 "outputs": [],
118 "source": [
119 "from qsharp_widgets import EstimateDetails\n",
120 "\n",
121 "EstimateDetails(result)"
122 ]
123 },
124 {
125 "cell_type": "markdown",
126 "metadata": {},
127 "source": [
128 "The distribution of physical qubits used for the execution of the algorithm instructions and the supporting T factories can provide us valuable information to guide us in applying space and time optimizations. We can visualize this distribution to better understand the estimated space requirements for our algorithm."
129 ]
130 },
131 {
132 "cell_type": "code",
133 "execution_count": null,
134 "metadata": {},
135 "outputs": [],
136 "source": [
137 "from qsharp_widgets import SpaceChart\n",
138 "\n",
139 "SpaceChart(result)"
140 ]
141 },
142 {
143 "cell_type": "markdown",
144 "metadata": {},
145 "source": [
146 "We can also programmatically access all the values that can be passed to the job execution and see which default values were assumed:"
147 ]
148 },
149 {
150 "cell_type": "code",
151 "execution_count": null,
152 "metadata": {},
153 "outputs": [],
154 "source": [
155 "result.data()[\"jobParams\"]"
156 ]
157 },
158 {
159 "cell_type": "markdown",
160 "metadata": {},
161 "source": [
162 "We see that there are three input parameters that can be customized: `qubitParams`, `qecScheme`, and `errorBudget`.\n",
163 "\n",
164 "### Qubit parameters\n",
165 "\n",
166 "The first parameter `qubitParams` is used to specify qubit parameters. When\n",
167 "modeling the physical qubit abstractions, we distinguish between two different\n",
168 "physical instruction sets that are used to operate the qubits. The physical\n",
169 "instruction set can be either *gate-based* or *Majorana*. A gate-based\n",
170 "instruction set provides single-qubit measurement, single-qubit gates (incl. T\n",
171 " gates), and two-qubit gates. A Majorana instruction set provides a physical T\n",
172 " gate, single-qubit measurement and two-qubit joint measurement operations.\n",
173 "\n",
174 "Qubit parameters can be completely customized. Before we show this, we show hot\n",
175 "to choose from six pre-defined qubit parameters, four of which have gate-based\n",
176 "instruction sets and two with a Majorana instruction set. An overview of all\n",
177 "pre-defined qubit parameters is provided by the following table:\n",
178 "\n",
179 "| Pre-defined qubit parameters | Instruction set | References |\n",
180 "|------------------------------|-----------------|------------------------------------------------------------------------------------------------------------|\n",
181 "| `\"qubit_gate_ns_e3\"` | gate-based | [arXiv:2003.00024](https://arxiv.org/abs/2003.00024), [arXiv:2111.11937](https://arxiv.org/abs/2111.11937) |\n",
182 "| `\"qubit_gate_ns_e4\"` | gate-based | [arXiv:2003.00024](https://arxiv.org/abs/2003.00024), [arXiv:2111.11937](https://arxiv.org/abs/2111.11937) |\n",
183 "| `\"qubit_gate_us_e3\"` | gate-based | [arXiv:1701.04195](https://arxiv.org/abs/1701.04195) |\n",
184 "| `\"qubit_gate_us_e4\"` | gate-based | [arXiv:1701.04195](https://arxiv.org/abs/1701.04195) |\n",
185 "| `\"qubit_maj_ns_e4\"` | Majorana | [arXiv:1610.05289](https://arxiv.org/abs/1610.05289) |\n",
186 "| `\"qubit_maj_ns_e6\"` | Majorana | [arXiv:1610.05289](https://arxiv.org/abs/1610.05289) |\n",
187 "\n",
188 "Pre-defined qubit parameters can be selected by specifying the `name` field in\n",
189 "the `qubitParams`. If no value is provided, `\"qubit_gate_ns_e3\"` is chosen as\n",
190 "the default qubit parameters.\n",
191 "\n",
192 "Let's re-run resource estimation for our running example on the Majorana-based\n",
193 "qubit parameters `\"qubit_maj_ns_e6\"`."
194 ]
195 },
196 {
197 "cell_type": "code",
198 "execution_count": null,
199 "metadata": {},
200 "outputs": [],
201 "source": [
202 "qubitParams = {\n",
203 " \"name\": \"qubit_maj_ns_e6\"\n",
204 "}\n",
205 "\n",
206 "result = estimate(program, qubitParams)"
207 ]
208 },
209 {
210 "cell_type": "markdown",
211 "metadata": {},
212 "source": [
213 "Let's inspect the physical counts programmatically. For example, we can show all physical resource estimates and their breakdown using the `physicalCounts` field in the result data. This will show the logical qubit error and logical T-state error rates required to match the error budget. By default runtimes are shown in nanoseconds."
214 ]
215 },
216 {
217 "cell_type": "code",
218 "execution_count": null,
219 "metadata": {},
220 "outputs": [],
221 "source": [
222 "result.data()[\"physicalCounts\"]\n"
223 ]
224 },
225 {
226 "cell_type": "markdown",
227 "metadata": {},
228 "source": [
229 "We can also explore details about the T factory that was created to execute this algorithm."
230 ]
231 },
232 {
233 "cell_type": "code",
234 "execution_count": null,
235 "metadata": {},
236 "outputs": [],
237 "source": [
238 "result.data()[\"tfactory\"]\n"
239 ]
240 },
241 {
242 "cell_type": "markdown",
243 "metadata": {},
244 "source": [
245 "Next, we are using this data to produce some explanations of how the T factories produce the required T states."
246 ]
247 },
248 {
249 "cell_type": "code",
250 "execution_count": null,
251 "metadata": {},
252 "outputs": [],
253 "source": [
254 "data = result.data()\n",
255 "tfactory = data[\"tfactory\"]\n",
256 "breakdown = data[\"physicalCounts\"][\"breakdown\"]\n",
257 "producedTstates = breakdown[\"numTfactories\"] * breakdown[\"numTfactoryRuns\"] * tfactory[\"numTstates\"]\n",
258 "\n",
259 "print(f\"\"\"A single T factory produces {tfactory[\"logicalErrorRate\"]:.2e} T states with an error rate of (required T state error rate is {breakdown[\"requiredLogicalTstateErrorRate\"]:.2e}).\"\"\")\n",
260 "print(f\"\"\"{breakdown[\"numTfactories\"]} copie(s) of a T factory are executed {breakdown[\"numTfactoryRuns\"]} time(s) to produce {producedTstates} T states ({breakdown[\"numTstates\"]} are required by the algorithm).\"\"\")\n",
261 "print(f\"\"\"A single T factory is composed of {tfactory[\"numRounds\"]} rounds of distillation:\"\"\")\n",
262 "for round in range(tfactory[\"numRounds\"]):\n",
263 " print(f\"\"\"- {tfactory[\"numUnitsPerRound\"][round]} {tfactory[\"unitNamePerRound\"][round]} unit(s)\"\"\")\n"
264 ]
265 },
266 {
267 "cell_type": "markdown",
268 "metadata": {},
269 "source": [
270 "Custom qubit parameters must completely specify all required parameters. These are the values that are\n",
271 "considered when the `instructionSet` is `\"GateBased\"`.\n",
272 "\n",
273 "| Field (*required) | Description |\n",
274 "|---------------------------------|----------------------------------------------------------------------|\n",
275 "| `name` | Some descriptive name for the parameters |\n",
276 "| `oneQubitMeasurementTime`* | Operation time for single-qubit measurement ($t_{\\rm meas}$) in ns |\n",
277 "| `oneQubitGateTime`* | Operation time for single-qubit Clifford gate ($t_{\\rm gate}$) in ns |\n",
278 "| `twoQubitGateTime` | Operation time for two-qubit Clifford gate in ns |\n",
279 "| `tGateTime` | Operation time for single-qubit non-Clifford gate in ns |\n",
280 "| `oneQubitMeasurementErrorRate`* | Error rate for single-qubit measurement |\n",
281 "| `oneQubitGateErrorRate`* | Error rate for single-qubit Clifford gate ($p$) |\n",
282 "| `twoQubitGateErrorRate` | Error rate for two-qubit Clifford gate |\n",
283 "| `tGateErrorRate` | Error rate to prepare single-qubit non-Clifford state ($p_T$) |\n",
284 "\n",
285 "The values for `twoQubitGateTime` and `tGateTime` default to `oneQubitGateTime`\n",
286 "when not specified; the values for `twoQubitGateErrorRate` and `tGateErrorRate`\n",
287 "default to `oneQubitGateErrorRate` when not specified.\n",
288 "\n",
289 "A minimum template for qubit parameters based on a gate-based instruction set\n",
290 "with all required values is:\n",
291 "\n",
292 "```json\n",
293 "{\n",
294 " \"qubitParams\": {\n",
295 " \"instructionSet\": \"GateBased\",\n",
296 " \"oneQubitMeasurementTime\": <time string>,\n",
297 " \"oneQubitGateTime\": <time string>,\n",
298 " \"oneQubitMeasurementErrorRate\": <double>,\n",
299 " \"oneQubitGateErrorRate\": <double>\n",
300 " }\n",
301 "}\n",
302 "```\n",
303 "\n",
304 "For time units, you need to specify time strings which are double-precision\n",
305 "floating point numbers followed by a space and a unit prefix which is `ns`, `µs`\n",
306 "(alternatively `us`), `ms`, or `s`.\n",
307 "\n",
308 "These are the values that are considered when the `instructionSet` is\n",
309 "`\"Majorana\"`.\n",
310 "\n",
311 "| Field (*required) | Description |\n",
312 "|-------------------------------------|---------------------------------------------------------------------|\n",
313 "| `name` | Some descriptive name for the parameters |\n",
314 "| `oneQubitMeasurementTime`* | Operation time for single-qubit measurement ($t_{\\rm meas}$) in ns |\n",
315 "| `twoQubitJointMeasurementTime` | Operation time for two-qubit joint measurement in ns |\n",
316 "| `tGateTime` | Operation time for single-qubit non-Clifford gate in ns |\n",
317 "| `oneQubitMeasurementErrorRate`* | Error rate for single-qubit measurement |\n",
318 "| `twoQubitJointMeasurementErrorRate` | Error rate for two-qubit joint measurement |\n",
319 "| `tGateErrorRate`* | Error rate to prepare single-qubit non-Clifford state ($p_T$) |\n",
320 "\n",
321 "The values for `twoQubitJointMeasurementTime` and `tGateTime` default to\n",
322 "`oneQubitGateTime` when not specified; the value for\n",
323 "`twoQubitJointMeasurementErrorRate` defaults to `oneQubitMeasurementErrorRate`\n",
324 "when not specified.\n",
325 "\n",
326 "A minimum template for qubit parameters based on a Majorana instruction set with\n",
327 "all required values is:\n",
328 "\n",
329 "```json\n",
330 "{\n",
331 " \"qubitParams\": {\n",
332 " \"instructionSet\": \"Majorana\",\n",
333 " \"oneQubitMeasurementTime\": <time string>,\n",
334 " \"oneQubitMeasurementErrorRate\": <double>,\n",
335 " \"tGateErrorRate\": <double>\n",
336 " }\n",
337 "}\n",
338 "```"
339 ]
340 },
341 {
342 "cell_type": "markdown",
343 "metadata": {},
344 "source": [
345 "### QEC schemes"
346 ]
347 },
348 {
349 "cell_type": "markdown",
350 "metadata": {},
351 "source": [
352 "To execute practical-scale quantum applications, we require operations with very\n",
353 "low error rates. These error rate targets are typically beyond the capabilities\n",
354 "of raw physical qubits. To overcome this limitation, quantum error correction\n",
355 "(QEC) and fault-tolerant computation are two crucial techniques that form the\n",
356 "building blocks of large-scale quantum computers. First, QEC allows us to\n",
357 "compose multiple error-prone physical qubits and build a more reliable logical\n",
358 "qubit that preserves quantum information better than the underlying physical\n",
359 "qubits. Several QEC schemes have been developed since the last three decades,\n",
360 "including popular schemes such as the Shor-code, surface code, color codes and\n",
361 "others, and recently the [Hastings-Haah code](https://arxiv.org/abs/2107.02194).\n",
362 "These schemes vary based on the number of physical qubits they require, the\n",
363 "connectivity among qubits and other factors. By using QEC techniques, we can\n",
364 "achieve a fault-tolerant quantum computation, enabling reliable storing and\n",
365 "processing of quantum information in the presence of noise. To store information\n",
366 "reliably, we require that the QEC scheme is able to suppress errors when the\n",
367 "physical qubits meet a certain threshold error rate. To process information, we\n",
368 "require fault-tolerant operations that allow applications to perform general\n",
369 "purpose quantum computations efficiently and limit the spread of errors that\n",
370 "occur while computing with logical qubits. Schemes for fault-tolerant operations\n",
371 "include techniques such as lattice surgery and transversal operations. Together,\n",
372 "QEC and fault-tolerance techniques bridges the accuracy gap between quantum\n",
373 "hardware and algorithms.\n",
374 "\n",
375 "The error correction code distance (or just code distance in short) is a\n",
376 "parameter that controls the number of errors that can be corrected, and thus the\n",
377 "error rate of the logical qubits and the number of physical qubits required to\n",
378 "encode them. The higher the code distance, the better the accuracy, but also\n",
379 "the higher the amount of physical qubits. The goal is to find the minimum code\n",
380 "distance that can achieve the required error rate set for a particular\n",
381 "application. We will explain later in this notebook how a global error budget\n",
382 "is provided as input and how it is distributed throughout the estimation,\n",
383 "including the logical error rate of logical qubits.\n",
384 "\n",
385 "We follow the standard way of modeling logical error rates using an exponential\n",
386 "model parameterized by the code distance $d$, physical error rate $p$, QEC\n",
387 "threshold $p^*$. The physical error rate $p$ is extracted from the qubit\n",
388 "parameters above as the worst-case error rate any physical Clifford operation in\n",
389 "the device. In particular, we set $p = {}$ `max(oneQubitMeasurementErrorRate,\n",
390 "oneQubitGateErrorRate, twoQubitGateErrorRate)` for qubit parameters with a\n",
391 "gate-based instruction set, and $p = {}$ `max(oneQubitMeasurementErrorRate,\n",
392 "twoQubitJointMeasurementErrorRate)` for qubit parameters with a Majorana\n",
393 "instruction set. QEC schemes typically have a error rate threshold $p^*$ below\n",
394 "which error correction suppresses errors.\n",
395 "\n",
396 "Our current implementation uses the formula\n",
397 "\n",
398 "$$\n",
399 "P = a\\left(\\frac{p}{p^*}\\right)^{\\frac{d+1}{2}}\n",
400 "$$\n",
401 "\n",
402 "as the generic model. The exact parameters for each pre-defined QEC scheme\n",
403 "(including a crossing pre-factor $a$ which can be extracted numerically for\n",
404 "simulations) are listed below.\n",
405 "\n",
406 "In Microsoft Quantum Resource Estimation we can abstract the quantum error\n",
407 "correction scheme based on the above formula by providing values for the\n",
408 "crossing pre-factor $a$ and the error correction threshold $p^*$. Further, one\n",
409 "needs to specify the logical cycle time, i.e., the time to execute a single\n",
410 "logical operation, which depends on the code distance and the physical\n",
411 "operation time assumptions of the underlying physical qubits. Finally, a second\n",
412 "formula computes the number of physical qubits required to encode one logical\n",
413 "qubit based on the code distance.\n",
414 "\n",
415 "As with the physical qubit parameters, one can choose from several pre-defined\n",
416 "QEC schemes, can extend pre-defined ones, and can provide custom schemes by\n",
417 "providing all parameters. Note that QEC schemes are tightly connected to the\n",
418 "physical instruction set of the physical qubit parameters, and therefore are\n",
419 "defined specifically for one of the two instruction sets.\n",
420 "\n",
421 "We provide three pre-defined QEC schemes, two `\"surface_code\"` protocols for\n",
422 "gate-based and Majorana physical instruction sets, and the `\"floquet_code\"`\n",
423 "protocol that is so far only implemented for a Majorana physical instruction set\n",
424 "in the resource estimator.\n",
425 "\n",
426 "| QEC scheme | Instruction set | References |\n",
427 "|----------------|-----------------|------------------------------------------------------------------------------------------------------------|\n",
428 "| `surface_code` | gate-based | [arXiv:1208.0928](https://arxiv.org/abs/1208.0928), [arXiv:1009.3686](https://arxiv.org/abs/1009.3686) |\n",
429 "| `surface_code` | Majorana | [arXiv:1909.03002](https://arxiv.org/abs/1909.03002), [arXiv:2007.00307](https://arxiv.org/abs/2007.00307) |\n",
430 "| `floquet_code` | Majorana | [arXiv:2202.11829](https://arxiv.org/abs/2202.11829) |\n",
431 "\n",
432 "In case of `\"surface_code\"` the corresponding scheme is selected based on the\n",
433 "qubit type of the physical qubit parameters. The gate-based surface code is\n",
434 "based on [[arXiv:1208.0928](https://arxiv.org/abs/1208.0928)] and\n",
435 "[[arXiv:1009.3686](https://arxiv.org/abs/1009.3686)]. The surface code for\n",
436 "Majorana qubits is based on\n",
437 "[[arXiv:1909.03002](https://arxiv.org/abs/1909.03002)] and\n",
438 "[[arXiv:2007.00307](https://arxiv.org/abs/2007.00307)] (replacing 8 steps to\n",
439 "measure a single stabilizer in the former reference by 20 steps to measure all\n",
440 "stabilizers). The floquet code, which can only be selected for Majorana qubits,\n",
441 "is based on [[arXiv:2202.11829](https://arxiv.org/abs/2202.11829)].\n",
442 "\n",
443 "Pre-defined qubit parameters can be selected by specifying the `name` field in\n",
444 "the `qecScheme` parameter. If no value is provided, `\"surface_code\"` is used as\n",
445 "default value.\n",
446 "\n",
447 "Let's re-run resource estimation for our running example on the Majorana-based\n",
448 "qubit parameters with a Floquet code."
449 ]
450 },
451 {
452 "cell_type": "code",
453 "execution_count": null,
454 "metadata": {},
455 "outputs": [],
456 "source": [
457 "params = {\n",
458 " \"qubitParams\": {\"name\": \"qubit_maj_ns_e6\"},\n",
459 " \"qecScheme\": {\"name\": \"floquet_code\"}\n",
460 "}\n",
461 "\n",
462 "result_maj_floquet = estimate(program, params)\n",
463 "EstimateDetails(result_maj_floquet)"
464 ]
465 },
466 {
467 "cell_type": "markdown",
468 "metadata": {},
469 "source": [
470 "To specify a QEC scheme the user has to specify 2 values, the\n",
471 "`errorCorrectionThreshold` and the `crossingPrefactor`, as well as 2 formulas\n",
472 "for the `logicalCycleTime`, and the `physicalQubitsPerLogicalQubit`. A template\n",
473 "for QEC schemes is as follows:\n",
474 "\n",
475 "```json\n",
476 "{\n",
477 " \"qecScheme\": {\n",
478 " \"crossingPrefactor\": <double>,\n",
479 " \"errorCorrectionThreshold\": <double>,\n",
480 " \"logicalCycleTime\": <formula string>,\n",
481 " \"physicalQubitsPerLogicalQubit\": <formula string>\n",
482 " }\n",
483 "}\n",
484 "```\n",
485 "\n",
486 "Inside the formulas, the user can make use of the following variables\n",
487 "\n",
488 "* `oneQubitGateTime`\n",
489 "* `twoQubitGateTime`\n",
490 "* `oneQubitMeasurementTime`\n",
491 "* `twoQubitJointMeasurementTime`\n",
492 "\n",
493 "whose value is taken from the corresponding field from the physical qubit\n",
494 "parameters (note that some variables are not available based on the qubit\n",
495 "parameters' instruction set), as well as the variable\n",
496 "\n",
497 "* `codeDistance`\n",
498 "\n",
499 "for the code distance computed for the logical qubit, based on the physical\n",
500 "qubit properties, the error correction threshold, and the crossing prefactor.\n",
501 "The time variables and `codeDistance` can be used to describe the\n",
502 "`logicalCycleTime` formula. For the formula `physicalQubitsPerLogicalQubit`\n",
503 "only the `codeDistance` can be used."
504 ]
505 },
506 {
507 "cell_type": "markdown",
508 "metadata": {},
509 "source": [
510 "### Error budget\n",
511 "\n",
512 "The third parameter `errorBudget` models the total error budget $\\epsilon$. It\n",
513 "sets the overall allowed error for the algorithm, i.e., the number of times it\n",
514 "is allowed to fail. Its value must be between 0 and 1 and the default value is\n",
515 "0.001, which corresponds to 0.1%, and means that the algorithm is allowed to\n",
516 "fail once in 1000 executions. This parameter is highly application specific.\n",
517 "For example, if one is running Shor's algorithm for factoring integers, a large\n",
518 "value for the error budget may be tolerated as one can check that the output are\n",
519 "indeed the prime factors of the input. On the other hand, a much smaller error\n",
520 "budget may be needed for an algorithm solving a problem with a solution which\n",
521 "cannot be efficiently verified. This budget\n",
522 "\n",
523 "$$\n",
524 " \\epsilon = \\epsilon_{\\log} + \\epsilon_{\\rm dis} + \\epsilon_{\\rm syn}\n",
525 "$$\n",
526 "\n",
527 "is uniformly distributed and applies to errors $\\epsilon_{\\log}$ to implement\n",
528 "logical qubits, an error budget $\\epsilon_{\\rm dis}$ to produce T states through\n",
529 "distillation, and an error budget $\\epsilon_{\\rm syn}$ to synthesize rotation\n",
530 "gates with arbitrary angles. Note that for distillation and rotation synthesis,\n",
531 "the respective error budgets $\\epsilon_{\\rm dis}$ and $\\epsilon_{\\rm syn}$ are\n",
532 "uniformly distributed among all required T states and all required rotation\n",
533 "gates, respectively. If there are no rotation gates in the input algorithm, the\n",
534 "error budget is uniformly distributed to logical errors and T state errors.\n",
535 "\n",
536 "Next, we re-run the last experiment with a an error budget of 10%."
537 ]
538 },
539 {
540 "cell_type": "code",
541 "execution_count": null,
542 "metadata": {},
543 "outputs": [],
544 "source": [
545 "params = {\n",
546 " \"errorBudget\": 0.01,\n",
547 " \"qubitParams\": {\"name\": \"qubit_maj_ns_e6\"},\n",
548 " \"qecScheme\": {\"name\": \"floquet_code\"},\n",
549 "}\n",
550 "result_maj_floquet_e1 = estimate(program, params)\n",
551 "EstimateDetails(result_maj_floquet_e1)"
552 ]
553 },
554 {
555 "cell_type": "markdown",
556 "metadata": {},
557 "source": [
558 "## Next steps\n",
559 "\n",
560 "We hope you enjoyed this notebook and found it helpful in exploring the physical resource estimates for quantum programs. Here are some suggested next steps:\n",
561 "\n",
562 "* Try estimating the resources for a different OpenQASM programs.\n",
563 "* Explore how qubit parameters and QEC schemes affect the error correction code distance of the logical qubit.\n",
564 "* Visualize your and compare your results from different parameter sets with the space and time diagrams.\n",
565 "* Use the output data to derive logical qubit properties.\n",
566 "* Learn how to setup complex resource estimation experiments in the _Advanced analysis of estimates_ notebook."
567 ]
568 }
569 ],
570 "metadata": {
571 "kernel_info": {
572 "name": "python3"
573 },
574 "kernelspec": {
575 "display_name": ".venv",
576 "language": "python",
577 "name": "python3"
578 },
579 "language_info": {
580 "codemirror_mode": {
581 "name": "ipython",
582 "version": 3
583 },
584 "file_extension": ".py",
585 "mimetype": "text/x-python",
586 "name": "python",
587 "nbconvert_exporter": "python",
588 "pygments_lexer": "ipython3",
589 "version": "3.13.3"
590 },
591 "microsoft": {
592 "host": {
593 "AzureQuantum": {
594 "sourceLink": "https://raw.githubusercontent.com/microsoft/azure-quantum-python/41b21e8fdb4da00608d7473efa1c74e9aa7082b3/samples/resource-estimator/estimation-qiskit.ipynb",
595 "sourceType": "SampleGallery"
596 }
597 }
598 },
599 "nteract": {
600 "version": "nteract-front-end@1.0.0"
601 }
602 },
603 "nbformat": 4,
604 "nbformat_minor": 1
605}
606