microsoft/qdk
Publicmirrored fromhttps://github.com/microsoft/qdkAvailable
samples/estimation/estimation-hubbard-2D.ipynb
1038lines · 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 Hubbard model" |
| 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 *efficiently* estimate the resources required to simulate a Hubbard 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, 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 Hubbard Model" |
| 63 | ] |
| 64 | }, |
| 65 | { |
| 66 | "cell_type": "markdown", |
| 67 | "metadata": { |
| 68 | "nteract": { |
| 69 | "transient": { |
| 70 | "deleting": false |
| 71 | } |
| 72 | } |
| 73 | }, |
| 74 | "source": [ |
| 75 | "The Hubbard Model is a simple model of interacting particles in a lattice (in our case a 2D square lattice) with two kinds of terms in the Hamiltonian: (i) a hopping term between adjacent sites and (ii) a potential term for onsite interactions.\n", |
| 76 | "Formally, a Hubbard model Hamiltonian on an $N \\times N$ lattice where each site has two spins {up, dn} is given as:\n", |
| 77 | "\n", |
| 78 | "$$\n", |
| 79 | "H = \\underbrace{U \\sum_{i,j} c^{\\dagger}_{(i, j), \\text{up}} c_{(i, j), \\text{up}} c^{\\dagger}_{(i, j), \\text{dn}} c_{(i, j), \\text{dn}}}_{B} - \\underbrace{t \\sum_{\\sigma \\in \\{ \\text{up}, \\text{dn}\\} , i, j} ( c^\\dagger_{(i,j),\\sigma} c_{(i+1,j),\\sigma} + c^\\dagger_{(i+1,j),\\sigma} c_{(i,j),\\sigma})}_{A} - \\underbrace{t \\sum_{\\sigma \\in \\{ \\text{up}, \\text{dn}\\} , i, j} ( c^\\dagger_{(i,j),\\sigma} c_{(i,j+1),\\sigma} + c^\\dagger_{(i,j+1),\\sigma} c_{(i,j),\\sigma})}_{C}\n", |
| 80 | "$$\n", |
| 81 | "where $c$ is the annihilation operator, $c^\\dagger$ is the creation operator, the first set of terms are the on-site repulsion terms, the second set are the vertical row hops and last set is the horizontal column hops." |
| 82 | ] |
| 83 | }, |
| 84 | { |
| 85 | "cell_type": "markdown", |
| 86 | "metadata": { |
| 87 | "nteract": { |
| 88 | "transient": { |
| 89 | "deleting": false |
| 90 | } |
| 91 | } |
| 92 | }, |
| 93 | "source": [ |
| 94 | "### Converting to Pauli terms\n", |
| 95 | "\n", |
| 96 | "The first step needed to simulate $H$ is to map the fermionic terms into *local* Pauli operations involving only a few qubits. When the Hamiltoinan acts on a 1D lattice, using the Jordan-Wigner would suffice. However, for the 2D lattice, either row or column hops will end up being non-local terms involving $O(N)$ qubits.\n", |
| 97 | "To overcome this, we use the [Verstraete-Cirac](http://arxiv.org/abs/cond-mat/0508353v3) encoding to convert the repulsion and hopping terms into local Pauli operators involving at most 4 qubits at a time. This is done by adding one auxiliary qubit for each spin type in each lattice site such that the $N^2$ lattice sites are mapped to $4 N^2$ qubits. Specifically, each lattice site $m$ maps to the qubits $\\{u_m, d_m, \\tilde{u}_m \\tilde{d}_m\\}$ where the first two qubits correspond to the up and down spin types and the latter two to the corresponding auxiliary qubits.\n", |
| 98 | "\n", |
| 99 | "This converts the terms as follows:\n", |
| 100 | "$$\n", |
| 101 | "\\text{Repulsion Terms:} \\qquad c^{\\dagger}_{(i, j), \\text{up}} c_{(i, j), \\text{up}} c^{\\dagger}_{(i, j), \\text{dn}} c_{(i, j), \\text{dn}} \\mapsto \\frac{1}{4} \\left(\\mathbb{I} - Z_{(i,j), \\text{up}} - Z_{(i,j), \\text{dn}} + Z_{(i,j), \\text{up}} \\otimes Z_{(i,j), \\text{dn}}\\right)\n", |
| 102 | "$$\n", |
| 103 | "$$\n", |
| 104 | "\\text{Horizontal Hopping Terms:} \\qquad c^\\dagger_{(i,j),\\sigma} c_{(i,j+1),\\sigma} + c^\\dagger_{(i,j+1),\\sigma} c_{(i,j),\\sigma} \\mapsto \\frac{1}{2} \\left(X_{(i,j),\\sigma} X_{(i,j+1),\\sigma} + Y_{(i,j),\\sigma} Y_{(i,j+1),\\sigma} \\right) \\tilde{Z}_{(i,j),\\sigma}\n", |
| 105 | "$$\n", |
| 106 | "$$\n", |
| 107 | "\\text{Vertical Hopping Terms:} \\qquad c^\\dagger_{(i,j),\\sigma} c_{(i+1,j),\\sigma} + c^\\dagger_{(i+1,j),\\sigma} c_{(i,j),\\sigma} \\mapsto \\frac{(-1)^{i+1}}{2} \\begin{cases} \\left(X_{(i,j),\\sigma} Y_{(i+1,j), \\sigma} - Y_{(i,j),\\sigma} X_{(i+1,j),\\sigma} \\right) \\tilde{X}_{(i,j),\\sigma} \\tilde{Y}_{(i+1,j), \\sigma} & (j \\text{ is even}); \\\\\n", |
| 108 | "\\left(X_{(i,j),\\sigma} Y_{(i+1,j), \\sigma} - Y_{(i,j),\\sigma} X_{(i+1,j),\\sigma} \\right) \\tilde{Y}_{(i,j),\\sigma} \\tilde{X}_{(i+1,j), \\sigma} & (j \\text{ is odd}). \\end{cases}\n", |
| 109 | "$$\n", |
| 110 | "where the $\\tilde{(\\cdot)}$ terms are Paulis acting on the auxiliary system." |
| 111 | ] |
| 112 | }, |
| 113 | { |
| 114 | "cell_type": "markdown", |
| 115 | "metadata": { |
| 116 | "nteract": { |
| 117 | "transient": { |
| 118 | "deleting": false |
| 119 | } |
| 120 | } |
| 121 | }, |
| 122 | "source": [ |
| 123 | "### Simulation\n", |
| 124 | "\n", |
| 125 | "Now that the Hamiltonian has been converted into $H = \\sum_k h_k$ where each $h_k$ is a Local Hamiltonian term, we can consider how to implement $e^{-iHT}$ using the fourth order Trotter-Suzuki product formula. For this, we simulate 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", |
| 126 | "$$\n", |
| 127 | "\\begin{aligned}\n", |
| 128 | "U_2(\\Delta) & = e^{-iA\\Delta/2} e^{-iB\\Delta/2} e^{-iC\\Delta} e^{-iB\\Delta/2} e^{-iA\\Delta/2}; \\\\\n", |
| 129 | "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", |
| 130 | "p & = (4 - 4^{1/3})^{-1}.\n", |
| 131 | "\\end{aligned}\n", |
| 132 | "$$\n", |
| 133 | "\n", |
| 134 | "For the rest of the notebook, we will present the code that computes the time evolution in a step by step fashion." |
| 135 | ] |
| 136 | }, |
| 137 | { |
| 138 | "cell_type": "markdown", |
| 139 | "metadata": { |
| 140 | "nteract": { |
| 141 | "transient": { |
| 142 | "deleting": false |
| 143 | } |
| 144 | } |
| 145 | }, |
| 146 | "source": [ |
| 147 | "## Implementation\n", |
| 148 | "\n", |
| 149 | "### Helper functions" |
| 150 | ] |
| 151 | }, |
| 152 | { |
| 153 | "cell_type": "markdown", |
| 154 | "metadata": { |
| 155 | "nteract": { |
| 156 | "transient": { |
| 157 | "deleting": false |
| 158 | } |
| 159 | } |
| 160 | }, |
| 161 | "source": [ |
| 162 | "We will allocate all qubits in the 2D lattice in a one-dimensional array where every lattice point has 4 qubits ordered as $(u, u', d, d')$. Further we assume a snake-like order on the 2D lattice i.e., the ordering goes left-to-right on even rows and right-to-left on odd rows. The function `GetQubitIndex` converts a qubit identified by its 2D lattice point coordinates, `(row, col)`, its spin flag `f_spin` and auxiliary flag `f_aux` to an index in the qubit array. Note that `f_spin = True` for the down spin and `f_aux = True` for auxiliary qubits." |
| 163 | ] |
| 164 | }, |
| 165 | { |
| 166 | "cell_type": "code", |
| 167 | "execution_count": null, |
| 168 | "metadata": { |
| 169 | "jupyter": { |
| 170 | "outputs_hidden": false, |
| 171 | "source_hidden": false |
| 172 | }, |
| 173 | "microsoft": { |
| 174 | "language": "qsharp" |
| 175 | }, |
| 176 | "nteract": { |
| 177 | "transient": { |
| 178 | "deleting": false |
| 179 | } |
| 180 | }, |
| 181 | "vscode": { |
| 182 | "languageId": "qsharp" |
| 183 | } |
| 184 | }, |
| 185 | "outputs": [], |
| 186 | "source": [ |
| 187 | "%%qsharp\n", |
| 188 | "function GetQubitIndex(k : Int, l : Int, f_spin : Bool, f_aux : Bool, n : Int, m : Int) : Int {\n", |
| 189 | "\n", |
| 190 | " let sshift = f_spin ? 2 | 0;\n", |
| 191 | " let ashift = f_aux ? 1 | 0;\n", |
| 192 | "\n", |
| 193 | " return k % 2 == 0 //Check if row is even and return expression accordingly\n", |
| 194 | " ? 4*m*k + 4*l + ashift + sshift\n", |
| 195 | " | 4*m*k + 4*(m-l-1) + (ashift) + (sshift);\n", |
| 196 | "}" |
| 197 | ] |
| 198 | }, |
| 199 | { |
| 200 | "cell_type": "markdown", |
| 201 | "metadata": { |
| 202 | "nteract": { |
| 203 | "transient": { |
| 204 | "deleting": false |
| 205 | } |
| 206 | } |
| 207 | }, |
| 208 | "source": [ |
| 209 | "Expanding $U_4(\\Delta)$ to express it in terms of $A, B, C$ gives:\n", |
| 210 | "$$\n", |
| 211 | "\\begin{aligned}\n", |
| 212 | "U_4(\\Delta) & = e^{-iAp\\Delta/2} \\ T_1 \\ T_2 \\ T_1 \\ e^{-iAp\\Delta/2}, \\\\\n", |
| 213 | "\\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", |
| 214 | "\\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", |
| 215 | "\\end{aligned}\n", |
| 216 | "$$\n", |
| 217 | "\n", |
| 218 | "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", |
| 219 | "\n", |
| 220 | "The function below sets the rotation angles used to apply the exponentials involving $A, B$ and $C$ in the formula above." |
| 221 | ] |
| 222 | }, |
| 223 | { |
| 224 | "cell_type": "code", |
| 225 | "execution_count": null, |
| 226 | "metadata": { |
| 227 | "jupyter": { |
| 228 | "outputs_hidden": false, |
| 229 | "source_hidden": false |
| 230 | }, |
| 231 | "microsoft": { |
| 232 | "language": "qsharp" |
| 233 | }, |
| 234 | "nteract": { |
| 235 | "transient": { |
| 236 | "deleting": false |
| 237 | } |
| 238 | }, |
| 239 | "vscode": { |
| 240 | "languageId": "qsharp" |
| 241 | } |
| 242 | }, |
| 243 | "outputs": [], |
| 244 | "source": [ |
| 245 | "%%qsharp\n", |
| 246 | "function SetAngleSequence(p : Double, hop_angle : Double, rep_angle : Double, dt : Double) : Double[] {\n", |
| 247 | " let len1 = 8;\n", |
| 248 | " let len2 = 4;\n", |
| 249 | " let valLength = 2*len1 + len2;\n", |
| 250 | "\n", |
| 251 | " let val1 = -p*hop_angle*dt;\n", |
| 252 | " let val2 = -p*rep_angle*dt/2.0;\n", |
| 253 | "\n", |
| 254 | " let valB = -(1.0-4.0*p)*rep_angle*dt/2.0;\n", |
| 255 | " let valA = -(1.0-3.0*p)*hop_angle*dt/2.0;\n", |
| 256 | " let valC = -(1.0-4.0*p)*hop_angle*dt;\n", |
| 257 | "\n", |
| 258 | " mutable values = [0.0, size=valLength];\n", |
| 259 | "\n", |
| 260 | " // Angles bookending Term2\n", |
| 261 | " set values w/= len1 <- valA;\n", |
| 262 | " set values w/= len1+len2 <- valA;\n", |
| 263 | "\n", |
| 264 | " for i in 0..len1-1 {\n", |
| 265 | " if (i%2 == 0) {\n", |
| 266 | " set values w/= i <- val1;\n", |
| 267 | " }\n", |
| 268 | " else {\n", |
| 269 | " set values w/= i <- val2;\n", |
| 270 | " }\n", |
| 271 | " }\n", |
| 272 | "\n", |
| 273 | " for i in len1+1..len1+len2-1 {\n", |
| 274 | " if (i%2 == 0) {\n", |
| 275 | " set values w/= i <- valC;\n", |
| 276 | " }\n", |
| 277 | " else {\n", |
| 278 | " set values w/= i <- valB;\n", |
| 279 | " }\n", |
| 280 | " }\n", |
| 281 | "\n", |
| 282 | " for i in len1+len2+1..valLength-1 {\n", |
| 283 | " if (i%2 == 0) {\n", |
| 284 | " set values w/= i <- val1;\n", |
| 285 | " }\n", |
| 286 | " else {\n", |
| 287 | " set values w/= i <- val2;\n", |
| 288 | " }\n", |
| 289 | " }\n", |
| 290 | "\n", |
| 291 | " return values;\n", |
| 292 | "\n", |
| 293 | "}" |
| 294 | ] |
| 295 | }, |
| 296 | { |
| 297 | "cell_type": "markdown", |
| 298 | "metadata": { |
| 299 | "nteract": { |
| 300 | "transient": { |
| 301 | "deleting": false |
| 302 | } |
| 303 | } |
| 304 | }, |
| 305 | "source": [ |
| 306 | "### Quantum operations\n", |
| 307 | "\n", |
| 308 | "The first term we want to apply are the horizontal hops. For a given set of qubits and angle $\\theta$, the following operation applies the horizontal hop's evolution operator $e^{i(XZX+YZY)\\theta}$." |
| 309 | ] |
| 310 | }, |
| 311 | { |
| 312 | "cell_type": "code", |
| 313 | "execution_count": null, |
| 314 | "metadata": { |
| 315 | "jupyter": { |
| 316 | "outputs_hidden": false, |
| 317 | "source_hidden": false |
| 318 | }, |
| 319 | "microsoft": { |
| 320 | "language": "qsharp" |
| 321 | }, |
| 322 | "nteract": { |
| 323 | "transient": { |
| 324 | "deleting": false |
| 325 | } |
| 326 | }, |
| 327 | "vscode": { |
| 328 | "languageId": "qsharp" |
| 329 | } |
| 330 | }, |
| 331 | "outputs": [], |
| 332 | "source": [ |
| 333 | "%%qsharp\n", |
| 334 | "operation ApplyHorizontalTerm (qslice : Qubit[], theta : Double) : Unit {\n", |
| 335 | "\n", |
| 336 | " let P_x = [PauliX, PauliZ, PauliX];\n", |
| 337 | " let P_y = [PauliY, PauliZ, PauliY];\n", |
| 338 | "\n", |
| 339 | " Exp(P_x, theta, qslice);\n", |
| 340 | " Exp(P_y, theta, qslice);\n", |
| 341 | "\n", |
| 342 | "}" |
| 343 | ] |
| 344 | }, |
| 345 | { |
| 346 | "cell_type": "markdown", |
| 347 | "metadata": { |
| 348 | "nteract": { |
| 349 | "transient": { |
| 350 | "deleting": false |
| 351 | } |
| 352 | } |
| 353 | }, |
| 354 | "source": [ |
| 355 | "Observe that it is not possible to simultaneously apply all the rotations in one go. For example, while applying the rotation on the up spin qubits at $(0, 0)$ and $(0, 1)$, it is not possible to also apply the rotation on the up spin qubits $(0, 1)$ and $(0, 2)$. Instead, we try to apply as many rotations as possible while also giving consideration to some uniformity with respect to the spins. The operation is broken up as follows:\n", |
| 356 | "- consider pairs where the first qubit is in an odd (resp. even) column as given by `grp`;\n", |
| 357 | "- choose the spin up (resp. down) qubits in the array as chosen by `f_spin`,\n", |
| 358 | "- apply the exponential to all such sets of qubits in the array." |
| 359 | ] |
| 360 | }, |
| 361 | { |
| 362 | "cell_type": "code", |
| 363 | "execution_count": null, |
| 364 | "metadata": { |
| 365 | "jupyter": { |
| 366 | "outputs_hidden": false, |
| 367 | "source_hidden": false |
| 368 | }, |
| 369 | "microsoft": { |
| 370 | "language": "qsharp" |
| 371 | }, |
| 372 | "nteract": { |
| 373 | "transient": { |
| 374 | "deleting": false |
| 375 | } |
| 376 | }, |
| 377 | "vscode": { |
| 378 | "languageId": "qsharp" |
| 379 | } |
| 380 | }, |
| 381 | "outputs": [], |
| 382 | "source": [ |
| 383 | "%%qsharp\n", |
| 384 | "operation ApplyHorizontalHops(n : Int, m : Int, g_num : Bool, f_spin : Bool, qs : Qubit[], theta : Double) : Unit {\n", |
| 385 | "\n", |
| 386 | " let start = g_num ? 1 | 0; //Gives the group number for horizontal hop terms\n", |
| 387 | "\n", |
| 388 | " for row in 0..n-1 { // for all rows\n", |
| 389 | " for col in start..2..m-2 { // for alternate columns\n", |
| 390 | " //Message($\"Creating Pauli expr for Hop terms ({row}, {col}) <--> ({row}, {col+1})\");\n", |
| 391 | "\n", |
| 392 | " let aux_col = (row%2 == 0)? col | col+1;\n", |
| 393 | " let i1 = GetQubitIndex(row, col, f_spin, false, n, m);\n", |
| 394 | " let aux = GetQubitIndex(row, aux_col, f_spin, true, n, m);\n", |
| 395 | " let i2 = GetQubitIndex(row, col+1, f_spin, false, n, m);\n", |
| 396 | "\n", |
| 397 | " ApplyHorizontalTerm([qs[i1], qs[aux], qs[i2]], theta);\n", |
| 398 | "\n", |
| 399 | " } //end for col\n", |
| 400 | " } //end for row\n", |
| 401 | "\n", |
| 402 | "}" |
| 403 | ] |
| 404 | }, |
| 405 | { |
| 406 | "cell_type": "markdown", |
| 407 | "metadata": { |
| 408 | "nteract": { |
| 409 | "transient": { |
| 410 | "deleting": false |
| 411 | } |
| 412 | } |
| 413 | }, |
| 414 | "source": [ |
| 415 | "Next, we consider the vertical hopping terms. For a given set of qubits and angle $\\theta$, the following operation applies $e^{i (XXYY - YXXY) \\theta}$ for even columns and $e^{i (XYYX - YYXX) \\theta}$ for odd columns." |
| 416 | ] |
| 417 | }, |
| 418 | { |
| 419 | "cell_type": "code", |
| 420 | "execution_count": null, |
| 421 | "metadata": { |
| 422 | "jupyter": { |
| 423 | "outputs_hidden": false, |
| 424 | "source_hidden": false |
| 425 | }, |
| 426 | "microsoft": { |
| 427 | "language": "qsharp" |
| 428 | }, |
| 429 | "nteract": { |
| 430 | "transient": { |
| 431 | "deleting": false |
| 432 | } |
| 433 | }, |
| 434 | "vscode": { |
| 435 | "languageId": "qsharp" |
| 436 | } |
| 437 | }, |
| 438 | "outputs": [], |
| 439 | "source": [ |
| 440 | "%%qsharp\n", |
| 441 | "operation ApplyVerticalTerm(qslice : Qubit[], col : Int, angle : Double) : Unit {\n", |
| 442 | "\n", |
| 443 | " let P_xxyy = [PauliX, PauliX, PauliY, PauliY];\n", |
| 444 | " let P_yxxy = [PauliY, PauliX, PauliX, PauliY];\n", |
| 445 | " let P_xyyx = [PauliX, PauliY, PauliY, PauliX];\n", |
| 446 | " let P_yyxx = [PauliY, PauliY, PauliX, PauliX];\n", |
| 447 | "\n", |
| 448 | " if col%2 == 0 {\n", |
| 449 | " Exp(P_xxyy, angle, qslice);\n", |
| 450 | " Exp(P_yxxy, -angle, qslice);\n", |
| 451 | " }\n", |
| 452 | " else {\n", |
| 453 | " Exp(P_xyyx, angle, qslice);\n", |
| 454 | " Exp(P_yyxx, -angle, qslice);\n", |
| 455 | " }\n", |
| 456 | "\n", |
| 457 | "}" |
| 458 | ] |
| 459 | }, |
| 460 | { |
| 461 | "cell_type": "markdown", |
| 462 | "metadata": { |
| 463 | "nteract": { |
| 464 | "transient": { |
| 465 | "deleting": false |
| 466 | } |
| 467 | } |
| 468 | }, |
| 469 | "source": [ |
| 470 | "Like with the horizontal hops, it is not possible to simultaneously apply all the rotations in one go. For example, while applying the rotation on the up spin qubits at $(0, 0)$ and $(1, 0)$, it is not possible to also apply the rotation on the up spin qubits $(1, 0)$ and $(2, 0)$. The operation is accordingly broken up as follows:\n", |
| 471 | "- consider pairs where the first qubit is in an odd (resp. even) *row* as given by `grp`;\n", |
| 472 | "- choose the spin up (resp. down) qubits in the array as chosen by `f_spin`,\n", |
| 473 | "- apply the exponential to all such sets of qubits in the array." |
| 474 | ] |
| 475 | }, |
| 476 | { |
| 477 | "cell_type": "code", |
| 478 | "execution_count": null, |
| 479 | "metadata": { |
| 480 | "jupyter": { |
| 481 | "outputs_hidden": false, |
| 482 | "source_hidden": false |
| 483 | }, |
| 484 | "microsoft": { |
| 485 | "language": "qsharp" |
| 486 | }, |
| 487 | "nteract": { |
| 488 | "transient": { |
| 489 | "deleting": false |
| 490 | } |
| 491 | }, |
| 492 | "vscode": { |
| 493 | "languageId": "qsharp" |
| 494 | } |
| 495 | }, |
| 496 | "outputs": [], |
| 497 | "source": [ |
| 498 | "%%qsharp\n", |
| 499 | "operation ApplyVerticalHops(row : Int, n : Int, m : Int, f_spin : Bool, qs : Qubit[], theta : Double, grp : Bool) : Unit { //\n", |
| 500 | "\n", |
| 501 | " let start = grp ? 1 | 0;\n", |
| 502 | " for i in start..2..m-1 { // for each column // 0..m-1 {\n", |
| 503 | " let angle = i%2 == 0 ? theta | -theta;\n", |
| 504 | "\n", |
| 505 | " let i1_u = GetQubitIndex(row, i, f_spin, false, n, m);\n", |
| 506 | " let i1_ua = GetQubitIndex(row, i, f_spin, true, n, m);\n", |
| 507 | " let i2_u = GetQubitIndex(row+1, i, f_spin, false, n, m);\n", |
| 508 | " let i2_ua = GetQubitIndex(row+1, i, f_spin, true, n, m);\n", |
| 509 | "\n", |
| 510 | " ApplyVerticalTerm([qs[i1_u], qs[i1_ua], qs[i2_u], qs[i2_ua]], i, angle);\n", |
| 511 | "\n", |
| 512 | " } // end for i loop\n", |
| 513 | "}" |
| 514 | ] |
| 515 | }, |
| 516 | { |
| 517 | "cell_type": "markdown", |
| 518 | "metadata": { |
| 519 | "nteract": { |
| 520 | "transient": { |
| 521 | "deleting": false |
| 522 | } |
| 523 | } |
| 524 | }, |
| 525 | "source": [ |
| 526 | "Finally, there are two kinds of Pauli exponentials needed for applying the repulsion term for an angle $\\theta$:\n", |
| 527 | "- an $e^{iZ\\theta}$ applied to each up and down spin qubit;\n", |
| 528 | "- $e^{-i (Z \\otimes Z)\\theta}$ applied to pairs of $(u, d)$ qubits for each point in the lattice.\n", |
| 529 | "\n", |
| 530 | "The operation below applies $e^{iZ\\theta}$ on the up and down spin qubits." |
| 531 | ] |
| 532 | }, |
| 533 | { |
| 534 | "cell_type": "code", |
| 535 | "execution_count": null, |
| 536 | "metadata": { |
| 537 | "jupyter": { |
| 538 | "outputs_hidden": false, |
| 539 | "source_hidden": false |
| 540 | }, |
| 541 | "microsoft": { |
| 542 | "language": "qsharp" |
| 543 | }, |
| 544 | "nteract": { |
| 545 | "transient": { |
| 546 | "deleting": false |
| 547 | } |
| 548 | }, |
| 549 | "vscode": { |
| 550 | "languageId": "qsharp" |
| 551 | } |
| 552 | }, |
| 553 | "outputs": [], |
| 554 | "source": [ |
| 555 | "%%qsharp\n", |
| 556 | "operation ApplyZRot(n : Int, m : Int, qs : Qubit[], angle : Double) : Unit {\n", |
| 557 | "\n", |
| 558 | " for row in 0..n-1 {\n", |
| 559 | " for col in 0..m-1 {\n", |
| 560 | " let up = GetQubitIndex(row, col, false, false, n, m);\n", |
| 561 | " let down = GetQubitIndex(row, col, true, false, n, m);\n", |
| 562 | "\n", |
| 563 | " // Rz(θ, q) applies e^{-iZθ/2} to qubit q\n", |
| 564 | " Rz(-2.0*angle, qs[up]);\n", |
| 565 | " Rz(-2.0*angle, qs[down]);\n", |
| 566 | " }\n", |
| 567 | " }\n", |
| 568 | "}" |
| 569 | ] |
| 570 | }, |
| 571 | { |
| 572 | "cell_type": "markdown", |
| 573 | "metadata": { |
| 574 | "nteract": { |
| 575 | "transient": { |
| 576 | "deleting": false |
| 577 | } |
| 578 | } |
| 579 | }, |
| 580 | "source": [ |
| 581 | "The next operation applies $e^{-i(ZZ)\\theta}$ for every $(u, d)$ pair of qubits." |
| 582 | ] |
| 583 | }, |
| 584 | { |
| 585 | "cell_type": "code", |
| 586 | "execution_count": null, |
| 587 | "metadata": { |
| 588 | "jupyter": { |
| 589 | "outputs_hidden": false, |
| 590 | "source_hidden": false |
| 591 | }, |
| 592 | "microsoft": { |
| 593 | "language": "qsharp" |
| 594 | }, |
| 595 | "nteract": { |
| 596 | "transient": { |
| 597 | "deleting": false |
| 598 | } |
| 599 | }, |
| 600 | "vscode": { |
| 601 | "languageId": "qsharp" |
| 602 | } |
| 603 | }, |
| 604 | "outputs": [], |
| 605 | "source": [ |
| 606 | "%%qsharp\n", |
| 607 | "operation ApplyZoZRot(n : Int, m : Int, qs : Qubit[], angle : Double) : Unit {\n", |
| 608 | "\n", |
| 609 | " let P_op = [PauliZ, PauliZ];\n", |
| 610 | "\n", |
| 611 | " for row in 0..n-1 {\n", |
| 612 | " for col in 0..m-1 {\n", |
| 613 | " let up = GetQubitIndex(row, col, false, false, n, m);\n", |
| 614 | " let down = GetQubitIndex(row, col, true, false, n, m);\n", |
| 615 | "\n", |
| 616 | " Exp(P_op, angle, [qs[up], qs[down]]);\n", |
| 617 | "\n", |
| 618 | " }\n", |
| 619 | " }\n", |
| 620 | "}" |
| 621 | ] |
| 622 | }, |
| 623 | { |
| 624 | "cell_type": "markdown", |
| 625 | "metadata": { |
| 626 | "nteract": { |
| 627 | "transient": { |
| 628 | "deleting": false |
| 629 | } |
| 630 | } |
| 631 | }, |
| 632 | "source": [ |
| 633 | "The next operation puts everything together and calls the operations needed to\n", |
| 634 | "simulate the Hubbard model Hamiltonian using a fourth order product formula.\n", |
| 635 | "Observe that the operations `ApplyHorizontalHops` and `ApplyVerticalHops` are called four times for for different\n", |
| 636 | "choices of direction and starting index to ensure all possible pairs of qubits are appropriately considered.\n", |
| 637 | "\n", |
| 638 | "The various parameters taken in by the operation correspond to:\n", |
| 639 | "\n", |
| 640 | "- `N1`, `N2`: row and column size of the lattice.\n", |
| 641 | "- `t, u`: parameters by which the Hamiltonian terms are scaled.\n", |
| 642 | "- `totTime`: the total time for the Trotter simulation.\n", |
| 643 | "- `dt` : the step size for the simulation, sometimes denoted as $\\Delta$." |
| 644 | ] |
| 645 | }, |
| 646 | { |
| 647 | "cell_type": "code", |
| 648 | "execution_count": null, |
| 649 | "metadata": { |
| 650 | "jupyter": { |
| 651 | "outputs_hidden": false, |
| 652 | "source_hidden": false |
| 653 | }, |
| 654 | "microsoft": { |
| 655 | "language": "qsharp" |
| 656 | }, |
| 657 | "nteract": { |
| 658 | "transient": { |
| 659 | "deleting": false |
| 660 | } |
| 661 | }, |
| 662 | "vscode": { |
| 663 | "languageId": "qsharp" |
| 664 | } |
| 665 | }, |
| 666 | "outputs": [], |
| 667 | "source": [ |
| 668 | "%%qsharp\n", |
| 669 | "import Std.Math.*;\n", |
| 670 | "\n", |
| 671 | "operation HubModel2DSim(N1 : Int, N2 : Int, t: Double, u : Double, totTime : Double, dt : Double) : Unit {\n", |
| 672 | "\n", |
| 673 | " //Hubbard Hamiltonian: -t*Hopping terms + u*Repulsion Terms\n", |
| 674 | "\n", |
| 675 | " //Represent a 2D array of qubits with 4 qubits per lattice point laid out as a 4N1 x N2 array\n", |
| 676 | " use qs = Qubit[4*N1*N2];\n", |
| 677 | "\n", |
| 678 | " let p = 1.0/(4.0 - 4.0^(1.0/3.0));\n", |
| 679 | "\n", |
| 680 | " let nsteps = Ceiling(totTime/dt);\n", |
| 681 | "\n", |
| 682 | " let seqLen = 20*nsteps+1;\n", |
| 683 | "\n", |
| 684 | " // Calculate rotation angles\n", |
| 685 | " let hop_angle = -t/2.0;\n", |
| 686 | " let rep_angle = u/4.0;\n", |
| 687 | "\n", |
| 688 | " let angSeq = SetAngleSequence(p, hop_angle, rep_angle, dt);\n", |
| 689 | "\n", |
| 690 | " for i in 0..seqLen-1 {\n", |
| 691 | " let theta = (i==0 or i==seqLen-1) ? -p*hop_angle*dt/2.0 | angSeq[i%20];\n", |
| 692 | "\n", |
| 693 | " if (i%4 == 0) { // A = Vertical Hops\n", |
| 694 | " for row in 0..N1-2 {\n", |
| 695 | " for(f_spin, grp) in [(false, false), (false, true), (true, false), (true, true)] {\n", |
| 696 | " ApplyVerticalHops(row, N1, N2, f_spin, qs, theta, grp);\n", |
| 697 | " }\n", |
| 698 | " }\n", |
| 699 | " }\n", |
| 700 | " elif (i%2 == 1) { // B = Repulsion Term\n", |
| 701 | " ApplyZRot(N1, N2, qs, theta);\n", |
| 702 | " ApplyZoZRot(N1, N2, qs, theta);\n", |
| 703 | " }\n", |
| 704 | " else { // C = Horizontal Hops\n", |
| 705 | " for(f_spin, grp) in [(false, false), (false, true), (true, false), (true, true)] {\n", |
| 706 | " ApplyHorizontalHops(N1, N2, grp, f_spin, qs, theta);\n", |
| 707 | " }\n", |
| 708 | " }\n", |
| 709 | " }\n", |
| 710 | "\n", |
| 711 | " //Resetting qubits before release;\n", |
| 712 | " ResetAll(qs);\n", |
| 713 | "\n", |
| 714 | "}" |
| 715 | ] |
| 716 | }, |
| 717 | { |
| 718 | "cell_type": "markdown", |
| 719 | "metadata": {}, |
| 720 | "source": [ |
| 721 | "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." |
| 722 | ] |
| 723 | }, |
| 724 | { |
| 725 | "cell_type": "code", |
| 726 | "execution_count": null, |
| 727 | "metadata": { |
| 728 | "vscode": { |
| 729 | "languageId": "qsharp" |
| 730 | } |
| 731 | }, |
| 732 | "outputs": [], |
| 733 | "source": [ |
| 734 | "%%qsharp\n", |
| 735 | "import Std.ResourceEstimation.*;\n", |
| 736 | "\n", |
| 737 | "operation EstimateHubModel2DSim(N1 : Int, N2 : Int, t: Double, u : Double, totTime : Double, dt : Double) : Unit {\n", |
| 738 | "\n", |
| 739 | " //Represent a 2D array of qubits with 4 qubits per lattice point laid out as a 4N1 x N2 array\n", |
| 740 | " use qs = Qubit[4*N1*N2];\n", |
| 741 | "\n", |
| 742 | " let p = 1.0/(4.0 - 4.0^(1.0/3.0));\n", |
| 743 | "\n", |
| 744 | " let nsteps = Ceiling(totTime/dt);\n", |
| 745 | "\n", |
| 746 | " // Calculate rotation angles\n", |
| 747 | " let hop_angle = -t/2.0;\n", |
| 748 | " let rep_angle = u/4.0;\n", |
| 749 | "\n", |
| 750 | " let angSeq = SetAngleSequence(p, hop_angle, rep_angle, dt);\n", |
| 751 | "\n", |
| 752 | " within {\n", |
| 753 | " RepeatEstimates(nsteps);\n", |
| 754 | " }\n", |
| 755 | " apply {\n", |
| 756 | " for i in 0..19 {\n", |
| 757 | " let theta = angSeq[i%20];\n", |
| 758 | "\n", |
| 759 | " if (i%4 == 0) { // A = Vertical Hops\n", |
| 760 | " for row in 0..N1-2 {\n", |
| 761 | " for(f_spin, grp) in [(false, false), (false, true), (true, false), (true, true)] {\n", |
| 762 | " ApplyVerticalHops(row, N1, N2, f_spin, qs, theta, grp);\n", |
| 763 | " }\n", |
| 764 | " }\n", |
| 765 | " }\n", |
| 766 | " elif (i%2 == 1) { // B = Repulsion Term\n", |
| 767 | " ApplyZRot(N1, N2, qs, theta);\n", |
| 768 | " ApplyZoZRot(N1, N2, qs, theta);\n", |
| 769 | " }\n", |
| 770 | " else { // C = Horizontal Hops\n", |
| 771 | " for(f_spin, grp) in [(false, false), (false, true), (true, false), (true, true)] {\n", |
| 772 | " ApplyHorizontalHops(N1, N2, grp, f_spin, qs, theta);\n", |
| 773 | " }\n", |
| 774 | " }\n", |
| 775 | " }\n", |
| 776 | " }\n", |
| 777 | "\n", |
| 778 | " let angle = -p*hop_angle*dt/2.0;\n", |
| 779 | " for row in 0..N1-2 {\n", |
| 780 | " for(f_spin, grp) in [(false, false), (false, true), (true, false), (true, true)] {\n", |
| 781 | " ApplyVerticalHops(row, N1, N2, f_spin, qs, angle, grp);\n", |
| 782 | " }\n", |
| 783 | " }\n", |
| 784 | "\n", |
| 785 | " //Resetting qubits before release;\n", |
| 786 | " ResetAll(qs);\n", |
| 787 | "}" |
| 788 | ] |
| 789 | }, |
| 790 | { |
| 791 | "cell_type": "markdown", |
| 792 | "metadata": { |
| 793 | "nteract": { |
| 794 | "transient": { |
| 795 | "deleting": false |
| 796 | } |
| 797 | } |
| 798 | }, |
| 799 | "source": [ |
| 800 | "## Getting logical resource counts\n", |
| 801 | "\n", |
| 802 | "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 $t = u = 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`." |
| 803 | ] |
| 804 | }, |
| 805 | { |
| 806 | "cell_type": "code", |
| 807 | "execution_count": null, |
| 808 | "metadata": {}, |
| 809 | "outputs": [], |
| 810 | "source": [ |
| 811 | "# Set up problem parameters\n", |
| 812 | "N1 = [20, 30, 40]\n", |
| 813 | "N2 = [20, 30, 40]\n", |
| 814 | "t = 1.0\n", |
| 815 | "u = 1.0\n", |
| 816 | "totTime = 1000.0\n", |
| 817 | "dt = 0.1" |
| 818 | ] |
| 819 | }, |
| 820 | { |
| 821 | "cell_type": "markdown", |
| 822 | "metadata": {}, |
| 823 | "source": [ |
| 824 | "We submit a resource estimation job with all the problem instances sequentially and collect the estimates in `results`." |
| 825 | ] |
| 826 | }, |
| 827 | { |
| 828 | "cell_type": "code", |
| 829 | "execution_count": null, |
| 830 | "metadata": {}, |
| 831 | "outputs": [], |
| 832 | "source": [ |
| 833 | "# Submit jobs\n", |
| 834 | "results = []\n", |
| 835 | "\n", |
| 836 | "for i in range(3):\n", |
| 837 | " qsharp_string = f\"EstimateHubModel2DSim({N1[i]}, {N2[i]}, {t}, {u}, {totTime}, {dt})\"\n", |
| 838 | "\n", |
| 839 | " result = qsharp.estimate(qsharp_string, params={\"errorBudget\": 0.01, \"qubitParams\": {\"name\": \"qubit_maj_ns_e6\"}, \"qecScheme\": {\"name\": \"floquet_code\"}, \"constraints\": {\"logicalDepthFactor\": 4}})\n", |
| 840 | " results.append(result)" |
| 841 | ] |
| 842 | }, |
| 843 | { |
| 844 | "cell_type": "markdown", |
| 845 | "metadata": {}, |
| 846 | "source": [ |
| 847 | "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]`" |
| 848 | ] |
| 849 | }, |
| 850 | { |
| 851 | "cell_type": "code", |
| 852 | "execution_count": null, |
| 853 | "metadata": {}, |
| 854 | "outputs": [], |
| 855 | "source": [ |
| 856 | "# Displaying estimates for 20x20 lattice size.\n", |
| 857 | "results[0]\n", |
| 858 | "# Change index to 1 (resp. 2) for 30x30 (resp. 40x40) lattice size." |
| 859 | ] |
| 860 | }, |
| 861 | { |
| 862 | "cell_type": "markdown", |
| 863 | "metadata": { |
| 864 | "nteract": { |
| 865 | "transient": { |
| 866 | "deleting": false |
| 867 | } |
| 868 | } |
| 869 | }, |
| 870 | "source": [ |
| 871 | "## Visualizing and understanding the results\n", |
| 872 | "\n", |
| 873 | "### Result summary table" |
| 874 | ] |
| 875 | }, |
| 876 | { |
| 877 | "cell_type": "code", |
| 878 | "execution_count": null, |
| 879 | "metadata": { |
| 880 | "jupyter": { |
| 881 | "outputs_hidden": false, |
| 882 | "source_hidden": false |
| 883 | }, |
| 884 | "nteract": { |
| 885 | "transient": { |
| 886 | "deleting": false |
| 887 | } |
| 888 | } |
| 889 | }, |
| 890 | "outputs": [], |
| 891 | "source": [ |
| 892 | "# Define function to display information in summary format\n", |
| 893 | "def get_summary_table(results, labels):\n", |
| 894 | " logical_qubits = []\n", |
| 895 | " logical_depth = []\n", |
| 896 | " t_states = []\n", |
| 897 | " code_distance = []\n", |
| 898 | " t_factories = []\n", |
| 899 | " t_factory_fraction = []\n", |
| 900 | " physical_qubits = []\n", |
| 901 | " rqops = []\n", |
| 902 | " runtime = []\n", |
| 903 | " logical_error = []\n", |
| 904 | "\n", |
| 905 | " for i in range(3):\n", |
| 906 | " logical_qubits.append(results[i]['physicalCounts']['breakdown']['algorithmicLogicalQubits'])\n", |
| 907 | " logical_depth.append(results[i]['physicalCountsFormatted']['logicalDepth'])\n", |
| 908 | " t_states.append(results[i]['physicalCountsFormatted']['numTstates'])\n", |
| 909 | " t_factories.append(results[i]['physicalCounts']['breakdown']['numTfactories'])\n", |
| 910 | " logical_error.append(results[i]['physicalCountsFormatted']['requiredLogicalQubitErrorRate'])\n", |
| 911 | " physical_qubits.append(results[i]['physicalCountsFormatted']['physicalQubits'])\n", |
| 912 | " rqops.append(results[i]['physicalCountsFormatted']['rqops'])\n", |
| 913 | " runtime.append(results[i]['physicalCountsFormatted']['runtime'])\n", |
| 914 | " code_distance.append(results[i]['logicalQubit']['codeDistance'])\n", |
| 915 | " t_factory_fraction.append(results[i]['physicalCountsFormatted']['physicalQubitsForTfactoriesPercentage'])\n", |
| 916 | "\n", |
| 917 | " data = pd.DataFrame()\n", |
| 918 | " pd.options.display.float_format = '{:.2E}'.format\n", |
| 919 | " data['Logical qubits'] = logical_qubits\n", |
| 920 | " data['Logical depth'] = logical_depth\n", |
| 921 | " data['Logical error'] = logical_error\n", |
| 922 | " data['T states'] = t_states\n", |
| 923 | " # data['T states'] = data['T states'].astype('float64')\n", |
| 924 | " data['Code Distance'] = code_distance\n", |
| 925 | " data['T factories'] = t_factories\n", |
| 926 | " data['T factory fraction'] = t_factory_fraction\n", |
| 927 | " data['Physical qubits'] = physical_qubits\n", |
| 928 | " data['rQOPS'] = rqops\n", |
| 929 | " data['Physical runtime'] = runtime\n", |
| 930 | " data.index = labels\n", |
| 931 | "\n", |
| 932 | " return data\n", |
| 933 | "\n", |
| 934 | "# Display summarized information for all problem instances\n", |
| 935 | "labels = [\"Hub20\", \"Hub30\", \"Hub40\"]\n", |
| 936 | "table = get_summary_table(results, labels)\n", |
| 937 | "table" |
| 938 | ] |
| 939 | }, |
| 940 | { |
| 941 | "cell_type": "markdown", |
| 942 | "metadata": {}, |
| 943 | "source": [ |
| 944 | "> Note that in general, there is a trade-off between the logical depth and number of T factories used. \n", |
| 945 | "\n", |
| 946 | "> 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." |
| 947 | ] |
| 948 | }, |
| 949 | { |
| 950 | "cell_type": "markdown", |
| 951 | "metadata": {}, |
| 952 | "source": [ |
| 953 | "### Getting the target rQOPS\n", |
| 954 | "\n", |
| 955 | "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", |
| 956 | "$$ \\text{Target rQOPS} = \\frac{\\text{Logical qubits}\\cdot\\text{Logical Depth}}{\\text{Target runtime}}$$" |
| 957 | ] |
| 958 | }, |
| 959 | { |
| 960 | "cell_type": "code", |
| 961 | "execution_count": null, |
| 962 | "metadata": {}, |
| 963 | "outputs": [], |
| 964 | "source": [ |
| 965 | "def get_target_rqops(results, labels):\n", |
| 966 | "\n", |
| 967 | " target_runtime = 604800\n", |
| 968 | " logical_qubits = []\n", |
| 969 | " logical_depth = []\n", |
| 970 | " target_rqops = []\n", |
| 971 | " logical_error = []\n", |
| 972 | "\n", |
| 973 | " for i in range(3):\n", |
| 974 | " logical_qubits.append(results[i]['physicalCounts']['breakdown']['algorithmicLogicalQubits'])\n", |
| 975 | " logical_depth.append(results[i]['physicalCountsFormatted']['logicalDepth'])\n", |
| 976 | " logical_error.append(results[i]['physicalCountsFormatted']['requiredLogicalQubitErrorRate'])\n", |
| 977 | " target_rqops.append(round(results[i]['physicalCounts']['breakdown']['algorithmicLogicalQubits'] * results[i]['physicalCounts']['breakdown']['logicalDepth'] / target_runtime))\n", |
| 978 | "\n", |
| 979 | " data = pd.DataFrame()\n", |
| 980 | " pd.options.display.float_format = '{:.2e}'.format\n", |
| 981 | " data['Logical qubits'] = logical_qubits\n", |
| 982 | " data['Logical depth'] = logical_depth\n", |
| 983 | " data['Logical error'] = logical_error\n", |
| 984 | " data['Target rQOPS'] = target_rqops\n", |
| 985 | " data['Target rQOPS'] = data['Target rQOPS'].astype('float64')\n", |
| 986 | " data.index = labels\n", |
| 987 | "\n", |
| 988 | " return data\n", |
| 989 | "\n", |
| 990 | "rQOPS_table = get_target_rqops(results, labels)\n", |
| 991 | "rQOPS_table\n" |
| 992 | ] |
| 993 | }, |
| 994 | { |
| 995 | "cell_type": "markdown", |
| 996 | "metadata": {}, |
| 997 | "source": [ |
| 998 | "## Next steps\n", |
| 999 | "\n", |
| 1000 | "Feel free to use this notebook as a starting point for your own experiments. For\n", |
| 1001 | "example, you can\n", |
| 1002 | "\n", |
| 1003 | "* explore how the results change considering other problem instances of the Heisenberg model\n", |
| 1004 | "* explore space- and time-trade-offs by changing the value for\n", |
| 1005 | " `logical_depth_factor` or `max_t_factories`\n", |
| 1006 | "* visualize these trade-offs with the space and time diagrams\n", |
| 1007 | "* use other or customized qubit parameters" |
| 1008 | ] |
| 1009 | } |
| 1010 | ], |
| 1011 | "metadata": { |
| 1012 | "kernel_info": { |
| 1013 | "name": "python3" |
| 1014 | }, |
| 1015 | "kernelspec": { |
| 1016 | "display_name": "Python 3 (ipykernel)", |
| 1017 | "language": "python", |
| 1018 | "name": "python3" |
| 1019 | }, |
| 1020 | "language_info": { |
| 1021 | "codemirror_mode": { |
| 1022 | "name": "ipython", |
| 1023 | "version": 3 |
| 1024 | }, |
| 1025 | "file_extension": ".py", |
| 1026 | "mimetype": "text/x-python", |
| 1027 | "name": "python", |
| 1028 | "nbconvert_exporter": "python", |
| 1029 | "pygments_lexer": "ipython3", |
| 1030 | "version": "3.11.7" |
| 1031 | }, |
| 1032 | "nteract": { |
| 1033 | "version": "nteract-front-end@1.0.0" |
| 1034 | } |
| 1035 | }, |
| 1036 | "nbformat": 4, |
| 1037 | "nbformat_minor": 0 |
| 1038 | } |
| 1039 | |