microsoft/qdk
Publicmirrored fromhttps://github.com/microsoft/qdkAvailable
samples/estimation/estimation-heisenberg-2D.ipynb
675lines · modecode
| 1 | { |
| 2 | "cells": [ |
| 3 | { |
| 4 | "cell_type": "markdown", |
| 5 | "metadata": { |
| 6 | "nteract": { |
| 7 | "transient": { |
| 8 | "deleting": false |
| 9 | } |
| 10 | } |
| 11 | }, |
| 12 | "source": [ |
| 13 | "# Resource Estimation for simulating a 2D Heisenberg Model Hamiltonian" |
| 14 | ] |
| 15 | }, |
| 16 | { |
| 17 | "cell_type": "markdown", |
| 18 | "metadata": { |
| 19 | "nteract": { |
| 20 | "transient": { |
| 21 | "deleting": false |
| 22 | } |
| 23 | } |
| 24 | }, |
| 25 | "source": [ |
| 26 | "In this Python + Q# notebook we demonstrate how to *efficienty* estimate the resources for simulating a Heisenberg model Hamiltonian on an $N \\times N$ 2D\n", |
| 27 | "lattice using a *fourth-order Trotter Suzuki product formula* assuming a 2D planar qubit architecture with nearest-neighbor connectivity.\n", |
| 28 | "\n", |
| 29 | "First, we load the necessary packages." |
| 30 | ] |
| 31 | }, |
| 32 | { |
| 33 | "cell_type": "code", |
| 34 | "execution_count": null, |
| 35 | "metadata": { |
| 36 | "jupyter": { |
| 37 | "outputs_hidden": false, |
| 38 | "source_hidden": false |
| 39 | }, |
| 40 | "nteract": { |
| 41 | "transient": { |
| 42 | "deleting": false |
| 43 | } |
| 44 | } |
| 45 | }, |
| 46 | "outputs": [], |
| 47 | "source": [ |
| 48 | "import qsharp\n", |
| 49 | "import pandas as pd" |
| 50 | ] |
| 51 | }, |
| 52 | { |
| 53 | "cell_type": "markdown", |
| 54 | "metadata": { |
| 55 | "nteract": { |
| 56 | "transient": { |
| 57 | "deleting": false |
| 58 | } |
| 59 | } |
| 60 | }, |
| 61 | "source": [ |
| 62 | "## Background: 2D Heisenberg Model" |
| 63 | ] |
| 64 | }, |
| 65 | { |
| 66 | "cell_type": "markdown", |
| 67 | "metadata": { |
| 68 | "nteract": { |
| 69 | "transient": { |
| 70 | "deleting": false |
| 71 | } |
| 72 | } |
| 73 | }, |
| 74 | "source": [ |
| 75 | "The quantum Heisenberg model is a statistical mechanical model used in the study of magnetic systems. The family of Heisenberg model Hamiltonians considered in this notebook consist of three types of interaction terms between adjacent lattice sites: $\\{X \\otimes X, Y \\otimes Y, Z \\otimes Z\\}$. For our purposes we consider that the interaction strength $J$ is the same for each term. Formally, the Heisenberg model Hamiltonian on an $N \\times N$ lattices divided into sets of commuting terms is formulated as:\n", |
| 76 | "$$ H = \\underbrace{J \\sum_{i, j} X_i \\otimes X_j}_{A} + \\underbrace{J \\sum_{i, j} Z_i \\otimes Z_j}_{B} + \\underbrace{J \\sum_{i, j} Y_i \\otimes Y_j}_{C}.$$\n", |
| 77 | "\n", |
| 78 | "TThe time evolution $e^{-iHt}$ for the Hamiltonian is simulated with the fourth-order Trotter-Suzuki product formula so that any errors in simulation are sufficiently small. Essentially, this is done by simulating the evolution for small slices of time $\\Delta$ and repeating this for `nSteps` $= \\lceil t/\\Delta \\rceil$ to obtain the full time evolution. The Trotter-Suzuki formula for higher orders can be recursively defined using a *fractal decomposition* as discussed in Section 3 of [Hatanao and Suziki's survey](https://link.springer.com/chapter/10.1007/11526216_2). Then the fourth order formula $U_4(\\Delta)$ can be constructed using the second-order one $U_2(\\Delta)$ as follows.\n", |
| 79 | "$$\n", |
| 80 | "\\begin{aligned}\n", |
| 81 | "U_2(\\Delta) & = e^{-iA\\Delta/2} e^{-iB\\Delta/2} e^{-iC\\Delta} e^{-iB\\Delta/2} e^{-iA\\Delta/2}; \\\\\n", |
| 82 | "U_4(\\Delta) & = U_2(p\\Delta)U_2(p\\Delta)U_2((1 - 4p)\\Delta)U_2(p\\Delta)U_2(p\\Delta); \\\\\n", |
| 83 | "p & = (4 - 4^{1/3})^{-1}.\n", |
| 84 | "\\end{aligned}\n", |
| 85 | "$$\n", |
| 86 | "\n", |
| 87 | "For the rest of the notebook, we will present the code that computes the time evolution in a step by step fashion." |
| 88 | ] |
| 89 | }, |
| 90 | { |
| 91 | "cell_type": "markdown", |
| 92 | "metadata": { |
| 93 | "nteract": { |
| 94 | "transient": { |
| 95 | "deleting": false |
| 96 | } |
| 97 | } |
| 98 | }, |
| 99 | "source": [ |
| 100 | "## Implementation\n", |
| 101 | "\n", |
| 102 | "### Helper Functions" |
| 103 | ] |
| 104 | }, |
| 105 | { |
| 106 | "cell_type": "markdown", |
| 107 | "metadata": { |
| 108 | "nteract": { |
| 109 | "transient": { |
| 110 | "deleting": false |
| 111 | } |
| 112 | } |
| 113 | }, |
| 114 | "source": [ |
| 115 | "Note that expanding $U_4(\\Delta)$ to express it in terms of $A, B, C$ gives:\n", |
| 116 | "$$\n", |
| 117 | "\\begin{aligned}\n", |
| 118 | "U_4(\\Delta) & = e^{-iAp\\Delta/2} \\ T_1 \\ T_2 \\ T_1 \\ e^{-iAp\\Delta/2}, \\\\\n", |
| 119 | "\\text{where } T_1 & = e^{-iBp\\Delta/2} e^{-iCp\\Delta} e^{-iBp\\Delta/2} e^{-iAp\\Delta} e^{-iBp\\Delta/2} e^{-iCp\\Delta} e^{-iBp\\Delta/2}, \\\\\n", |
| 120 | "\\text{and } T_2 & = e^{-iA(1 - 3p)\\Delta/2} e^{-iB(1-4p)\\Delta/2} e^{-iC(1-4p)\\Delta} e^{-iB(1-4p)\\Delta/2} e^{-iA(1 - 3p)\\Delta/2}.\n", |
| 121 | "\\end{aligned}\n", |
| 122 | "$$\n", |
| 123 | "\n", |
| 124 | "The above equation has $21$ exponential terms and works for one time step. For `nSteps` $> 1$ time steps, some adjacent terms can be merged to give $20\\lceil t/\\Delta \\rceil+1$ exponential terms for time evolution $e^{-iHt}$.\n", |
| 125 | "\n", |
| 126 | "The function below sets the rotation angles used to apply the exponentials involving $A, B$ and $C$ in the formula above." |
| 127 | ] |
| 128 | }, |
| 129 | { |
| 130 | "cell_type": "code", |
| 131 | "execution_count": null, |
| 132 | "metadata": { |
| 133 | "jupyter": { |
| 134 | "outputs_hidden": false, |
| 135 | "source_hidden": false |
| 136 | }, |
| 137 | "microsoft": { |
| 138 | "language": "qsharp" |
| 139 | }, |
| 140 | "nteract": { |
| 141 | "transient": { |
| 142 | "deleting": false |
| 143 | } |
| 144 | }, |
| 145 | "vscode": { |
| 146 | "languageId": "qsharp" |
| 147 | } |
| 148 | }, |
| 149 | "outputs": [], |
| 150 | "source": [ |
| 151 | "%%qsharp\n", |
| 152 | "function SetAngleSequence(p : Double, dt : Double, J : Double) : Double[] {\n", |
| 153 | "\n", |
| 154 | " let len1 = 8;\n", |
| 155 | " let len2 = 4;\n", |
| 156 | " let valLength = 2*len1 + len2;\n", |
| 157 | "\n", |
| 158 | " mutable values = [0.0, size=valLength];\n", |
| 159 | "\n", |
| 160 | " let val1 = -J*p*dt/2.0;\n", |
| 161 | " let val2 = -J*(1.0-3.0*p)*dt/2.0;\n", |
| 162 | " let val3 = -J*(1.0-4.0*p)*dt/2.0;\n", |
| 163 | "\n", |
| 164 | " // Angles bookending Term2\n", |
| 165 | " set values w/= len1 <- val2;\n", |
| 166 | " set values w/= len1+len2 <- val2;\n", |
| 167 | "\n", |
| 168 | " for i in 0..len1-1 {\n", |
| 169 | "\n", |
| 170 | " if (i % 2 == 0) {\n", |
| 171 | " set values w/= i <- val1*2.0;\n", |
| 172 | " }\n", |
| 173 | " else {\n", |
| 174 | " set values w/= i <- val1;\n", |
| 175 | " }\n", |
| 176 | " }\n", |
| 177 | "\n", |
| 178 | " for i in len1+1..len1+len2-1 {\n", |
| 179 | "\n", |
| 180 | " if (i % 2 == 0) {\n", |
| 181 | " set values w/= i <- val3*2.0;\n", |
| 182 | " }\n", |
| 183 | " else {\n", |
| 184 | " set values w/= i <- val3;\n", |
| 185 | " }\n", |
| 186 | " }\n", |
| 187 | "\n", |
| 188 | " for i in len1+len2+1..valLength-1 {\n", |
| 189 | "\n", |
| 190 | " if (i % 2 == 0) {\n", |
| 191 | " set values w/= i <- val1*2.0;\n", |
| 192 | " }\n", |
| 193 | " else {\n", |
| 194 | " set values w/= i <- val1;\n", |
| 195 | " }\n", |
| 196 | " }\n", |
| 197 | "\n", |
| 198 | " return values;\n", |
| 199 | "}" |
| 200 | ] |
| 201 | }, |
| 202 | { |
| 203 | "cell_type": "markdown", |
| 204 | "metadata": { |
| 205 | "nteract": { |
| 206 | "transient": { |
| 207 | "deleting": false |
| 208 | } |
| 209 | } |
| 210 | }, |
| 211 | "source": [ |
| 212 | "### Quantum operations" |
| 213 | ] |
| 214 | }, |
| 215 | { |
| 216 | "cell_type": "markdown", |
| 217 | "metadata": { |
| 218 | "nteract": { |
| 219 | "transient": { |
| 220 | "deleting": false |
| 221 | } |
| 222 | } |
| 223 | }, |
| 224 | "source": [ |
| 225 | "There are three kinds of operations applied to neighboring pairs of qubits on the lattice: (i) $e^{-i(X \\otimes X)\\theta}$; (ii) $e^{-i(Z \\otimes Z)\\theta}$; and (iii) $e^{-i(Y \\otimes Y)\\theta}$.\n", |
| 226 | "\n", |
| 227 | "The following operation applies $e^{i(P \\otimes P)\\theta}$ for Pauli $P \\in \\{X, Y, Z\\}$ on pairs of horizontally (resp. vertically) neighboring qubits in a single row of the lattice if `dir` is `True` (resp. `False`). Additionally, the exponential is applied only to pairs where the first qubit id is even (resp. odd) if `grp` is `True` (resp. `False`)." |
| 228 | ] |
| 229 | }, |
| 230 | { |
| 231 | "cell_type": "code", |
| 232 | "execution_count": null, |
| 233 | "metadata": { |
| 234 | "jupyter": { |
| 235 | "outputs_hidden": false, |
| 236 | "source_hidden": false |
| 237 | }, |
| 238 | "microsoft": { |
| 239 | "language": "qsharp" |
| 240 | }, |
| 241 | "nteract": { |
| 242 | "transient": { |
| 243 | "deleting": false |
| 244 | } |
| 245 | }, |
| 246 | "vscode": { |
| 247 | "languageId": "qsharp" |
| 248 | } |
| 249 | }, |
| 250 | "outputs": [], |
| 251 | "source": [ |
| 252 | "%%qsharp\n", |
| 253 | "operation ApplyPoPRot(n : Int, m : Int, qArr : Qubit[][], P : Pauli, theta : Double, dir : Bool, grp : Bool) : Unit {\n", |
| 254 | "\n", |
| 255 | " let start = (grp ? 0 | 1); // Choose either odd or even indices based on group number\n", |
| 256 | " let P_op = [P, P];\n", |
| 257 | " let jmp = 2;\n", |
| 258 | " let end = dir ? m-2 | m-1;\n", |
| 259 | " let v_end = dir? n-1 | n-2;\n", |
| 260 | "\n", |
| 261 | " for row in 0..v_end {\n", |
| 262 | " for col in start..jmp..end { // Either odd or even columns are picked based on group number\n", |
| 263 | "\n", |
| 264 | " let row2 = dir? row | row+1; // Choose the next row if for vertical direction\n", |
| 265 | " let col2 = dir? col+1 | col; // Choose the next column for horizontal direction\n", |
| 266 | "\n", |
| 267 | " Exp(P_op, theta, [qArr[row][col], qArr[row2][col2]]);\n", |
| 268 | " }\n", |
| 269 | " }\n", |
| 270 | "}" |
| 271 | ] |
| 272 | }, |
| 273 | { |
| 274 | "cell_type": "markdown", |
| 275 | "metadata": { |
| 276 | "nteract": { |
| 277 | "transient": { |
| 278 | "deleting": false |
| 279 | } |
| 280 | } |
| 281 | }, |
| 282 | "source": [ |
| 283 | "The next operation puts everything together and calls the operations needed to\n", |
| 284 | "simulate the Heisenberg model Hamiltonian using a fourth order product formula.\n", |
| 285 | "Observe that the `ApplyPoPRot` operation is called four times for each row for different\n", |
| 286 | "choices of direction and starting index to ensure all possible pairs of qubits\n", |
| 287 | "are appropriately considered.\n", |
| 288 | "\n", |
| 289 | "The various parameters taken in by the operation correspond to:\n", |
| 290 | "\n", |
| 291 | "- `J`: parameter by which the Hamiltonian terms are scaled.\n", |
| 292 | "- `N1`, `N2`: row and columns size of the lattice.\n", |
| 293 | "- `totTime`: the total time for the Trotter simulation.\n", |
| 294 | "- `dt` : the step size for the simulation, sometimes denoted as $\\Delta$." |
| 295 | ] |
| 296 | }, |
| 297 | { |
| 298 | "cell_type": "code", |
| 299 | "execution_count": null, |
| 300 | "metadata": { |
| 301 | "jupyter": { |
| 302 | "outputs_hidden": false, |
| 303 | "source_hidden": false |
| 304 | }, |
| 305 | "microsoft": { |
| 306 | "language": "qsharp" |
| 307 | }, |
| 308 | "nteract": { |
| 309 | "transient": { |
| 310 | "deleting": false |
| 311 | } |
| 312 | }, |
| 313 | "vscode": { |
| 314 | "languageId": "qsharp" |
| 315 | } |
| 316 | }, |
| 317 | "outputs": [], |
| 318 | "source": [ |
| 319 | "%%qsharp\n", |
| 320 | "import Std.Math.*;\n", |
| 321 | "import Std.Arrays.*;\n", |
| 322 | "\n", |
| 323 | "operation HeisModel2DSim(N1 : Int, N2 : Int, J : Double, totTime : Double, dt : Double) : Unit {\n", |
| 324 | "\n", |
| 325 | " use qs = Qubit[N1*N2];\n", |
| 326 | "\n", |
| 327 | " let qubitArray = Chunks(N2, qs); // Create a 2D array of qubits\n", |
| 328 | "\n", |
| 329 | " let len = Length(qs);\n", |
| 330 | "\n", |
| 331 | " let p = 1.0/(4.0 - 4.0^(1.0/3.0));\n", |
| 332 | "\n", |
| 333 | " let nsteps = Ceiling(totTime/dt);\n", |
| 334 | "\n", |
| 335 | " let seqLen = 20*nsteps+1;\n", |
| 336 | "\n", |
| 337 | " let angSeq = SetAngleSequence(p, dt, J);\n", |
| 338 | "\n", |
| 339 | " let paulis = [PauliX, PauliZ, PauliY];\n", |
| 340 | "\n", |
| 341 | " for i in 0..seqLen-1 {\n", |
| 342 | "\n", |
| 343 | " let j = (i%4==0) ? 0 | ( (i%2==1) ? 1 | 2); // Choose which pauli rotation will be applied\n", |
| 344 | " let theta = (i==0 or i==seqLen-1) ? -J*p*dt/2.0 | angSeq[i%20];\n", |
| 345 | "\n", |
| 346 | " for (dir, grp) in [(true, true), (true, false), (false, true), (false, false)] {\n", |
| 347 | " ApplyPoPRot(N1, N2, qubitArray, paulis[j], theta, dir, grp);\n", |
| 348 | " }\n", |
| 349 | " }\n", |
| 350 | "\n", |
| 351 | " //Resetting qubits before release;\n", |
| 352 | " ResetAll(qs);\n", |
| 353 | "}" |
| 354 | ] |
| 355 | }, |
| 356 | { |
| 357 | "cell_type": "markdown", |
| 358 | "metadata": {}, |
| 359 | "source": [ |
| 360 | "Note that for typical choices of `totTime` and `dt` used in real-world applications, the `seqLen` can range in the hundreds or thousands of terms each of whose resources will be individually estimated. This results in a lot of time consumed (> 15 min) to compute the resource estimates. However, from the expansion of $U_4(\\Delta)$, it is clear that there are a few unique terms that repeat `nsteps` number of times. Hence, to efficiently estimate resources, we compute the resources for running one step of $U_4(\\Delta)$ and multiply the cost by `nsteps` repetitions." |
| 361 | ] |
| 362 | }, |
| 363 | { |
| 364 | "cell_type": "code", |
| 365 | "execution_count": null, |
| 366 | "metadata": { |
| 367 | "vscode": { |
| 368 | "languageId": "qsharp" |
| 369 | } |
| 370 | }, |
| 371 | "outputs": [], |
| 372 | "source": [ |
| 373 | "%%qsharp\n", |
| 374 | "import Std.ResourceEstimation.*;\n", |
| 375 | "\n", |
| 376 | "operation EstimateHeisModel2DSim(N1 : Int, N2 : Int, J : Double, totTime : Double, dt : Double) : Unit {\n", |
| 377 | "\n", |
| 378 | " use qs = Qubit[N1*N2];\n", |
| 379 | "\n", |
| 380 | " let qubitArray = Chunks(N2, qs); // Create a 2D array of qubits\n", |
| 381 | "\n", |
| 382 | " let len = Length(qs);\n", |
| 383 | "\n", |
| 384 | " let p = 1.0/(4.0 - 4.0^(1.0/3.0));\n", |
| 385 | "\n", |
| 386 | " let t = Ceiling(totTime/dt);\n", |
| 387 | "\n", |
| 388 | " let angSeq = SetAngleSequence(p, dt, J);\n", |
| 389 | "\n", |
| 390 | " let paulis = [PauliX, PauliZ, PauliY];\n", |
| 391 | "\n", |
| 392 | " within {\n", |
| 393 | " RepeatEstimates(t);\n", |
| 394 | " }\n", |
| 395 | " apply {\n", |
| 396 | " for i in 0..19 {\n", |
| 397 | " let j = (i%4==0) ? 0 | ( (i%2==1) ? 1 | 2); // Choose which pauli rotation will be applied\n", |
| 398 | " let theta = angSeq[i%20];\n", |
| 399 | "\n", |
| 400 | " for (dir, grp) in [(true, true), (true, false), (false, true), (false, false)] {\n", |
| 401 | " ApplyPoPRot(N1, N2, qubitArray, paulis[j], theta, dir, grp);\n", |
| 402 | " }\n", |
| 403 | " }\n", |
| 404 | " }\n", |
| 405 | "\n", |
| 406 | " let angle = -J*p*dt/2.0;\n", |
| 407 | " for (dir, grp) in [(true, true), (true, false), (false, true), (false, false)] {\n", |
| 408 | " ApplyPoPRot(N1, N2, qubitArray, paulis[0], angle, dir, grp);\n", |
| 409 | " }\n", |
| 410 | "\n", |
| 411 | " //Resetting qubits before release;\n", |
| 412 | " ResetAll(qs);\n", |
| 413 | "}" |
| 414 | ] |
| 415 | }, |
| 416 | { |
| 417 | "cell_type": "markdown", |
| 418 | "metadata": { |
| 419 | "nteract": { |
| 420 | "transient": { |
| 421 | "deleting": false |
| 422 | } |
| 423 | } |
| 424 | }, |
| 425 | "source": [ |
| 426 | "## Getting logical resource counts\n", |
| 427 | "\n", |
| 428 | "For the purpose of generating the rQOPS for some target runtime, it suffices that we obtain the logical resource estimates to simulate the Heisenberg model Hamiltonian. We consider three problem instances with lattice sizes $\\{20 \\times 20, 30 \\times 30, 40 \\times 40\\}$ with $J = 1.0$. These instances are simulated for a total time of $1000$ s, with step size `dt`$ = 0.1$, and overall probability of failure $\\varepsilon = 0.01$. Any one of the six pre-defined qubit parameters will do to obtain the logical coounts and in this notebook we choose a Majorana based qubit with the `floquet code`." |
| 429 | ] |
| 430 | }, |
| 431 | { |
| 432 | "cell_type": "code", |
| 433 | "execution_count": null, |
| 434 | "metadata": {}, |
| 435 | "outputs": [], |
| 436 | "source": [ |
| 437 | "# Set up problem parameters\n", |
| 438 | "N1 = [20, 30, 40]\n", |
| 439 | "N2 = [20, 30, 40]\n", |
| 440 | "J = 1.0\n", |
| 441 | "totTime = 1000.0\n", |
| 442 | "dt = 0.1" |
| 443 | ] |
| 444 | }, |
| 445 | { |
| 446 | "cell_type": "markdown", |
| 447 | "metadata": { |
| 448 | "nteract": { |
| 449 | "transient": { |
| 450 | "deleting": false |
| 451 | } |
| 452 | } |
| 453 | }, |
| 454 | "source": [ |
| 455 | "We submit a resource estimation job with all the problem instances sequentially and collect the estimates in `results`." |
| 456 | ] |
| 457 | }, |
| 458 | { |
| 459 | "cell_type": "code", |
| 460 | "execution_count": null, |
| 461 | "metadata": {}, |
| 462 | "outputs": [], |
| 463 | "source": [ |
| 464 | "# Submit jobs\n", |
| 465 | "results = []\n", |
| 466 | "\n", |
| 467 | "for i in range(3):\n", |
| 468 | " qsharp_string = f\"EstimateHeisModel2DSim({N1[i]}, {N2[i]}, {J}, {totTime}, {dt})\"\n", |
| 469 | "\n", |
| 470 | " result = qsharp.estimate(qsharp_string, params={\"errorBudget\": 0.01, \"qubitParams\": {\"name\": \"qubit_maj_ns_e6\"}, \"qecScheme\": {\"name\": \"floquet_code\"}, \"constraints\": {\"logicalDepthFactor\": 4}})\n", |
| 471 | " results.append(result)" |
| 472 | ] |
| 473 | }, |
| 474 | { |
| 475 | "cell_type": "markdown", |
| 476 | "metadata": {}, |
| 477 | "source": [ |
| 478 | "To see the complete information provided when invoking the resource estimator, we output the result for the $20 \\times 20$ lattice by displaying `results[0]`" |
| 479 | ] |
| 480 | }, |
| 481 | { |
| 482 | "cell_type": "code", |
| 483 | "execution_count": null, |
| 484 | "metadata": {}, |
| 485 | "outputs": [], |
| 486 | "source": [ |
| 487 | "# Displaying estimates for 20x20 lattice size.\n", |
| 488 | "results[0]\n", |
| 489 | "# Change index to 1 (resp. 2) for 30x30 (resp. 40x40) lattice size." |
| 490 | ] |
| 491 | }, |
| 492 | { |
| 493 | "cell_type": "markdown", |
| 494 | "metadata": { |
| 495 | "nteract": { |
| 496 | "transient": { |
| 497 | "deleting": false |
| 498 | } |
| 499 | } |
| 500 | }, |
| 501 | "source": [ |
| 502 | "## Visualizing and understanding the results\n", |
| 503 | "\n", |
| 504 | "### Result summary table" |
| 505 | ] |
| 506 | }, |
| 507 | { |
| 508 | "cell_type": "code", |
| 509 | "execution_count": null, |
| 510 | "metadata": { |
| 511 | "jupyter": { |
| 512 | "outputs_hidden": false, |
| 513 | "source_hidden": false |
| 514 | }, |
| 515 | "nteract": { |
| 516 | "transient": { |
| 517 | "deleting": false |
| 518 | } |
| 519 | } |
| 520 | }, |
| 521 | "outputs": [], |
| 522 | "source": [ |
| 523 | "# Define function to display information in summary format\n", |
| 524 | "def get_summary_table(results, labels):\n", |
| 525 | " logical_qubits = []\n", |
| 526 | " logical_depth = []\n", |
| 527 | " t_states = []\n", |
| 528 | " code_distance = []\n", |
| 529 | " t_factories = []\n", |
| 530 | " t_factory_fraction = []\n", |
| 531 | " physical_qubits = []\n", |
| 532 | " rqops = []\n", |
| 533 | " runtime = []\n", |
| 534 | " logical_error = []\n", |
| 535 | "\n", |
| 536 | " for i in range(3):\n", |
| 537 | " logical_qubits.append(results[i]['physicalCounts']['breakdown']['algorithmicLogicalQubits'])\n", |
| 538 | " logical_depth.append(results[i]['physicalCountsFormatted']['logicalDepth'])\n", |
| 539 | " t_states.append(results[i]['physicalCountsFormatted']['numTstates'])\n", |
| 540 | " t_factories.append(results[i]['physicalCounts']['breakdown']['numTfactories'])\n", |
| 541 | " logical_error.append(results[i]['physicalCountsFormatted']['requiredLogicalQubitErrorRate'])\n", |
| 542 | " physical_qubits.append(results[i]['physicalCountsFormatted']['physicalQubits'])\n", |
| 543 | " rqops.append(results[i]['physicalCountsFormatted']['rqops'])\n", |
| 544 | " runtime.append(results[i]['physicalCountsFormatted']['runtime'])\n", |
| 545 | " code_distance.append(results[i]['logicalQubit']['codeDistance'])\n", |
| 546 | " t_factory_fraction.append(results[i]['physicalCountsFormatted']['physicalQubitsForTfactoriesPercentage'])\n", |
| 547 | "\n", |
| 548 | " data = pd.DataFrame()\n", |
| 549 | " pd.options.display.float_format = '{:.2E}'.format\n", |
| 550 | " data['Logical qubits'] = logical_qubits\n", |
| 551 | " data['Logical depth'] = logical_depth\n", |
| 552 | " data['Logical error'] = logical_error\n", |
| 553 | " data['T states'] = t_states\n", |
| 554 | " # data['T states'] = data['T states'].astype('float64')\n", |
| 555 | " data['Code Distance'] = code_distance\n", |
| 556 | " data['T factories'] = t_factories\n", |
| 557 | " data['T factory fraction'] = t_factory_fraction\n", |
| 558 | " data['Physical qubits'] = physical_qubits\n", |
| 559 | " data['rQOPS'] = rqops\n", |
| 560 | " data['Physical runtime'] = runtime\n", |
| 561 | " data.index = labels\n", |
| 562 | "\n", |
| 563 | " return data\n", |
| 564 | "\n", |
| 565 | "# Display summarized information for all problem instances\n", |
| 566 | "labels = [\"Hei20\", \"Hei30\", \"Hei40\"]\n", |
| 567 | "table = get_summary_table(results, labels)\n", |
| 568 | "table" |
| 569 | ] |
| 570 | }, |
| 571 | { |
| 572 | "cell_type": "markdown", |
| 573 | "metadata": {}, |
| 574 | "source": [ |
| 575 | "> Note that in general, there is a trade-off between the logical depth and number of T factories used. \n", |
| 576 | "\n", |
| 577 | "> To ensure that T factories do not dominate the resource requirements, we set the `logical_depth_factor`${}=4$ adding some number of `noops` to increase the logical depth." |
| 578 | ] |
| 579 | }, |
| 580 | { |
| 581 | "cell_type": "markdown", |
| 582 | "metadata": {}, |
| 583 | "source": [ |
| 584 | "### Getting the target rQOPS\n", |
| 585 | "\n", |
| 586 | "While the resource estimator generates a runtime for the given hardware profile, we want to set a target runtime of 1 week i.e., 604800 seconds to obtain a practical quantum advantage. We collect the previous results to compute the corresponding target rQOPS as \n", |
| 587 | "$$ \\text{Target rQOPS} = \\frac{\\text{Logical qubits}\\cdot\\text{Logical Depth}}{\\text{Target runtime}}$$" |
| 588 | ] |
| 589 | }, |
| 590 | { |
| 591 | "cell_type": "code", |
| 592 | "execution_count": null, |
| 593 | "metadata": {}, |
| 594 | "outputs": [], |
| 595 | "source": [ |
| 596 | "def get_target_rqops(results, labels):\n", |
| 597 | "\n", |
| 598 | " target_runtime = 604800\n", |
| 599 | " logical_qubits = []\n", |
| 600 | " logical_depth = []\n", |
| 601 | " target_rqops = []\n", |
| 602 | " logical_error = []\n", |
| 603 | "\n", |
| 604 | " for i in range(3):\n", |
| 605 | " logical_qubits.append(results[i]['physicalCounts']['breakdown']['algorithmicLogicalQubits'])\n", |
| 606 | " logical_depth.append(results[i]['physicalCountsFormatted']['logicalDepth'])\n", |
| 607 | " logical_error.append(results[i]['physicalCountsFormatted']['requiredLogicalQubitErrorRate'])\n", |
| 608 | " target_rqops.append(round(results[i]['physicalCounts']['breakdown']['algorithmicLogicalQubits'] * results[i]['physicalCounts']['breakdown']['logicalDepth'] / target_runtime))\n", |
| 609 | "\n", |
| 610 | " data = pd.DataFrame()\n", |
| 611 | " pd.options.display.float_format = '{:.2e}'.format\n", |
| 612 | " data['Logical qubits'] = logical_qubits\n", |
| 613 | " data['Logical depth'] = logical_depth\n", |
| 614 | " data['Logical error'] = logical_error\n", |
| 615 | " data['Target rQOPS'] = target_rqops\n", |
| 616 | " data['Target rQOPS'] = data['Target rQOPS'].astype('float64')\n", |
| 617 | " data.index = labels\n", |
| 618 | "\n", |
| 619 | " return data\n", |
| 620 | "\n", |
| 621 | "rQOPS_table = get_target_rqops(results, labels)\n", |
| 622 | "rQOPS_table" |
| 623 | ] |
| 624 | }, |
| 625 | { |
| 626 | "cell_type": "markdown", |
| 627 | "metadata": { |
| 628 | "nteract": { |
| 629 | "transient": { |
| 630 | "deleting": false |
| 631 | } |
| 632 | } |
| 633 | }, |
| 634 | "source": [ |
| 635 | "## Next steps\n", |
| 636 | "\n", |
| 637 | "Feel free to use this notebook as a starting point for your own experiments. For\n", |
| 638 | "example, you can\n", |
| 639 | "\n", |
| 640 | "* explore how the results change considering other problem instances of the Heisenberg model\n", |
| 641 | "* explore space- and time-trade-offs by changing the value for\n", |
| 642 | " `logical_depth_factor` or `max_t_factories`\n", |
| 643 | "* visualize these trade-offs with the space and time diagrams\n", |
| 644 | "* use other or customized qubit parameters" |
| 645 | ] |
| 646 | } |
| 647 | ], |
| 648 | "metadata": { |
| 649 | "kernel_info": { |
| 650 | "name": "python3" |
| 651 | }, |
| 652 | "kernelspec": { |
| 653 | "display_name": "Python 3 (ipykernel)", |
| 654 | "language": "python", |
| 655 | "name": "python3" |
| 656 | }, |
| 657 | "language_info": { |
| 658 | "codemirror_mode": { |
| 659 | "name": "ipython", |
| 660 | "version": 3 |
| 661 | }, |
| 662 | "file_extension": ".py", |
| 663 | "mimetype": "text/x-python", |
| 664 | "name": "python", |
| 665 | "nbconvert_exporter": "python", |
| 666 | "pygments_lexer": "ipython3", |
| 667 | "version": "3.11.7" |
| 668 | }, |
| 669 | "nteract": { |
| 670 | "version": "nteract-front-end@1.0.0" |
| 671 | } |
| 672 | }, |
| 673 | "nbformat": 4, |
| 674 | "nbformat_minor": 0 |
| 675 | } |
| 676 | |