{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# An example of how to run GST on a 2-qubit system\n", "This tutorial gives an overview of the typical steps used to perform an end-to-end (i.e. experimental-data-to-report) Gate Set Tomography analysis on a 2-qubit system. The steps are very similar to the single-qubit case; the main differences are:\n", "- the use of more general syntax when constructing 2-qubit gate sets\n", "- the increased number of fiducial and germ gate sequences\n", "- the increased run time required to compute GST estimates\n", "- a different report style " ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "from __future__ import print_function\n", "import matplotlib\n", "matplotlib.use('Agg')" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import pygsti" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Step 1: Construct the desired 2-qubit gateset\n", "There are several ways to do this, as outlined by the comments in the cell below." ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# via build_gateset:\n", "# [4] = a 4-dimensional Hilbert (state) space\n", "# [('Q0','Q1')] = interpret this 4-d space as that of two qubits 'Q0', and 'Q1' (note these labels *must* begin with 'Q'!)\n", "# \"Gix\" = gate label; can be anything that begins with 'G' and is followed by lowercase letters\n", "# \"X(pi/2,Q1)\" = pi/2 single-qubit x-rotation gate on the qubit labeled Q1\n", "# \"CX(pi,Q0,Q1)\" = controlled pi x-rotation using qubits Q0 (control) and Q1 (target) \n", "# \"rho0\" = prep label; can be anything that begins with \"rho\"\n", "# \"E1\" = effect label; can be anything that begins with \"E\"\n", "# \"2\" = a prep or effect expression indicating a projection/preparation of the 3rd (b/c 0-based) computational basis element\n", "# 'dnup': ('rho0','E2') = designate the SPAM label \"dnup\" to mean preparation using \"rho0\" (a prep label) and measuring the outcome \"E2\" (an effect label)\n", "# \"pp\" = create all of these gate & SPAM operators in the Pauli-product basis.\n", "gs_target = pygsti.construction.build_gateset( \n", " [4], [('Q0','Q1')],['Gix','Giy','Gxi','Gyi','Gcnot'], \n", " [ \"X(pi/2,Q1)\", \"Y(pi/2,Q1)\", \"X(pi/2,Q0)\", \"Y(pi/2,Q0)\", \"CX(pi,Q0,Q1)\" ],\n", " prepLabels=['rho0'], prepExpressions=[\"0\"],\n", " effectLabels=['E0','E1','E2'], effectExpressions=[\"0\",\"1\",\"2\"], \n", " spamdefs={'upup': ('rho0','E0'), 'updn': ('rho0','E1'),\n", " 'dnup': ('rho0','E2'), 'dndn': ('rho0','remainder') }, basis=\"pp\")\n", "\n", "# Note that you can also explicity add identity operations, e.g. \"I(Q0)\" to get the same gate set,\n", "# and that this same syntax could be used for non-entangling 2-qubit gates, e.g. \"X(pi/2,Q0):X(pi/2,Q1)\".\n", "gs_targetB = pygsti.construction.build_gateset( \n", " [4], [('Q0','Q1')],['Gix','Giy','Gxi','Gyi','Gcnot'], \n", " [ \"I(Q0):X(pi/2,Q1)\", \"I(Q0):Y(pi/2,Q1)\", \"X(pi/2,Q0):I(Q1)\", \"Y(pi/2,Q0):I(Q1)\", \"CX(pi,Q0,Q1)\" ],\n", " prepLabels=['rho0'], prepExpressions=[\"0\"], \n", " effectLabels=['E0','E1','E2'], effectExpressions=[\"0\",\"1\",\"2\"], \n", " spamdefs={'upup': ('rho0','E0'), 'updn': ('rho0','E1'),\n", " 'dnup': ('rho0','E2'), 'dndn': ('rho0','remainder') }, basis=\"pp\")\n", "\n", "# If you're lucky and your gateset is one of pyGSTi's \"standard\" gate sets, you can just import it.\n", "from pygsti.construction import std2Q_XYCNOT\n", "gs_targetC = std2Q_XYCNOT.gs_target\n", "\n", "#check that these are all the same\n", "assert(abs(gs_target.frobeniusdist(gs_targetB)) < 1e-6)\n", "assert(abs(gs_target.frobeniusdist(gs_targetC)) < 1e-6)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Step 2: Obtain lists of fiducial and germ gate sequences\n", "These are the building blocks of the gate sequences performed in the experiment. Typically, these lists are either given to you by the folks at Sandia National Labs (email pygsti@sandia.gov), provided by pyGSTi because you're using a \"standard\" gate set, or computed using \"fiducial selection\" and \"germ selection\" algorithms (which are a part of pyGSTi, but not covered in this tutorial)." ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [], "source": [ "#If you know the fiducial strings you can create a list manually. Note\n", "# that in general there can be different \"preparation\" and \"measurement\"\n", "# (or \"effect\") fiducials.\n", "prep_fiducials = pygsti.construction.gatestring_list( \\\n", "[ (), ('Gix',), ('Giy',), ('Gix','Gix'), \n", "('Gxi',), ('Gxi','Gix'), ('Gxi','Giy'), ('Gxi','Gix','Gix'), \n", "('Gyi',), ('Gyi','Gix'), ('Gyi','Giy'), ('Gyi','Gix','Gix'), \n", "('Gxi','Gxi'), ('Gxi','Gxi','Gix'), ('Gxi','Gxi','Giy'), ('Gxi','Gxi','Gix','Gix') ] )\n", "\n", "effect_fiducials = pygsti.construction.gatestring_list( \\\n", "[(), ('Gix',), ('Giy',), \n", " ('Gix','Gix'), ('Gxi',),\n", " ('Gyi',), ('Gxi','Gxi'),\n", " ('Gxi','Gix'), ('Gxi','Giy'),\n", " ('Gyi','Gix'), ('Gyi','Giy')] )\n", "\n", "#Or, if you're lucky, you can just import them\n", "prep_fiducialsB = std2Q_XYCNOT.prepStrs\n", "effect_fiducialsB = std2Q_XYCNOT.effectStrs\n", "\n", "#check that these are the same\n", "assert(prep_fiducials == prep_fiducialsB)\n", "assert(effect_fiducials == effect_fiducialsB)\n", "\n", "#Use fiducial sequences to create a \"spam specifiers\" object, telling\n", "# GST which preparation and measurement fiducials to follow and precede which\n", "# state preparation and effect operators, respectively.\n", "specs = pygsti.construction.build_spam_specs(\n", " prepStrs=prep_fiducials,\n", " effectStrs=effect_fiducials,\n", " prep_labels=gs_target.get_prep_labels(),\n", " effect_labels=gs_target.get_effect_labels() )\n", "\n", "#Alternatively, if you're lucky, you can grab the specs directly:\n", "specsB = std2Q_XYCNOT.specs\n", "assert(specs[0] == specsB[0])" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": true }, "outputs": [], "source": [ "#germ lists can be specified in the same way. In this case, there are\n", "# 71 germs required to do honest GST. Since this would crowd this tutorial\n", "# notebook, we create some smaller lists of germs manually and import the\n", "# full 71-germ list from std2Q_XYCNOT\n", "germs4 = pygsti.construction.gatestring_list(\n", " [ ('Gix',), ('Giy',), ('Gxi',), ('Gyi',) ] )\n", "\n", "germs11 = pygsti.construction.gatestring_list(\n", " [ ('Gix',), ('Giy',), ('Gxi',), ('Gyi',), ('Gcnot',), ('Gxi','Gyi'), ('Gix','Giy'),\n", " ('Gix','Gcnot'), ('Gxi','Gcnot'), ('Giy','Gcnot'), ('Gyi','Gcnot') ] )\n", "\n", "germs71 = std2Q_XYCNOT.germs" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Step 3: Data generation\n", "Now that fiducial and germ strings have been found, we can generate the list of experiments needed to run GST, just like in the 1-qubit case. As an additional input we'll need a list of lengths indicating the maximum length strings to use on each successive GST iteration." ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [], "source": [ "#A list of maximum lengths for each GST iteration\n", "maxLengths = [1,2,4]\n", "\n", "#Create a list of GST experiments for this gateset, with\n", "#the specified fiducials, germs, and maximum lengths. We use\n", "#\"germs4\" here so that the tutorial runs quickly; really, you'd\n", "#want to use germs71!\n", "listOfExperiments = pygsti.construction.make_lsgst_experiment_list(gs_target.gates.keys(), prep_fiducials,\n", " effect_fiducials, germs4, maxLengths)\n", "\n", "#Create an empty dataset file, which stores the list of experiments\n", "# and zerod-out columns where data should be inserted. Note the use of the SPAM\n", "# labels in the \"Columns\" header line.\n", "pygsti.io.write_empty_dataset(\"tutorial_files/My2QDataTemplate.txt\", listOfExperiments,\n", " \"## Columns = upup count, updn count, dnup count, dndn count\")" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": true }, "outputs": [], "source": [ "#Generate some \"fake\" (simulated) data based on a depolarized version of the target gateset\n", "gs_datagen = gs_target.depolarize(gate_noise=0.1, spam_noise=0.001)\n", "ds = pygsti.construction.generate_fake_data(gs_datagen, listOfExperiments, nSamples=1000,\n", " sampleError=\"multinomial\", seed=2016)\n", "\n", "#if you have a dataset file with real data in it, load it using something like:\n", "#ds = pygsti.io.load_dataset(\"mydir/My2QDataset.txt\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Step 4: Run GST using `do_long_sequence_gst`\n", "Just like for 1-qubit GST, we call the driver routine `do_long_sequence_gst` to compute the GST estimates. Usually for two qubits this could take a long time (hours) based on the number of gate sequences used. However, since we chose an incomplete set of only 4 germs and set our maximum max-length to 4, this will run fairly quickly (~20min).\n", "\n", "Some notes about the options/arguments to `do_long_sequence_gst` that are particularly relevant to 2-qubit GST:\n", "- `mxBasis` indicates which basis the target gateset matrices are in -- this should be the same as that used to create the gateset. Here `'pp'` denotes the Pauli-product basis.\n", "- `advancedOptions` expects a dictionary of with option names as the keys. Relevant options are:\n", " - `memoryLimitInBytes` gives an estimate of how much memory is available to use on your system (in bytes). This is currently *not* a hard limit, and pyGSTi may require 50-100% more memory than this \"limit\". So you'll need to be conservative in the value you place here: if your machine has 10GB of RAM, set this to 3 or 5 GB initially and increase it as you see how much memory is actually used using a separate OS performance monitor tool.\n", " - `depolarizeLGST` gives an amount (in [0,1]) to depolarize the initial LGST estimate that is used as the initial guess for long-sequence GST. In practice, we find that in the larger 2-qubit Hilbert space, the LGST estimate may be so poor as to adversely affect the subsequent long-sequence GST (e.g. very slow convergence). Depolarizing the LGST estimate remedies this. If you're unsure what to put here, either don't specify `depolarizeLGST` at all (the same as using 0.0), or just use 0.1.\n", " - `verbosity` tells the routine how much detail to print to stdout. If you don't mind waiting a while without getting any output, you can leave this at its default value (2). If you can't standing wondering whether GST is still running or has locked up, set this to 3." ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false, "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "--- LGST ---\n", " Singular values of I_tilde (truncating to first 16 of 16) = \n", " 6.74761341289\n", " 2.34801058571\n", " 2.30618437979\n", " 1.24095704293\n", " 1.21875500467\n", " 1.19236743148\n", " 0.885151794781\n", " 0.820186469499\n", " 0.531857424077\n", " 0.513447431382\n", " 0.38887030472\n", " 0.372790668863\n", " 0.313243294171\n", " 0.237656955269\n", " 0.225848759754\n", " 0.170428615627\n", " \n", " Singular values of target I_tilde (truncating to first 16 of 16) = \n", " 6.86802764151\n", " 3.20253744687\n", " 3.20253744687\n", " 1.76923693223\n", " 1.76923693223\n", " 1.73205080757\n", " 1.23400485863\n", " 1.22474487139\n", " 0.707106781187\n", " 0.707106781187\n", " 0.5\n", " 0.493714392513\n", " 0.493714392513\n", " 0.346122344917\n", " 0.346122344917\n", " 0.239642075572\n", " \n", " Resulting gate set:\n", " \n", " rho0 = 0.5000 0 0 0.5000 0 0 0 0 0 0 0 0 0.5000 0 0 0.5000\n", " \n", " \n", " E0 = 0.5905 -0.0295 0.0465 0.4625 -0.0445 -0.0525 -0.0065 -0.0445 0.0255 0.0375 -0.0585 0.0395 0.4535 -0.0305 0.0495 0.4895\n", " \n", " E1 = 0.4945 0.0475 -0.0555 -0.4415 -0.0285 0.0305 -0.0245 0.0195 0.0245 0.0775 -0.0275 -0.0115 0.3525 0.0275 -0.0475 -0.4055\n", " \n", " E2 = 0.5015 -0.0435 0.0745 0.3435 0.0485 -0.0065 -0.0065 0.0565 -0.0245 -0.0375 0.0705 -0.0525 -0.4375 0.0175 -0.0545 -0.4055\n", " \n", " \n", " Gix = \n", " 0.9998 0 -0.0002 0.0002 0.0003 -0.0003 0.0003 -0.0003 0 0 0 0 0 -0.0001 0 0\n", " 0.0338 0.8427 0.0338 -0.0338 -0.0048 0.0214 -0.0048 0.0048 0.0081 -0.0125 0.0081 -0.0081 -0.0247 0.0104 -0.0247 0.0247\n", " -0.0780 0.0682 -0.0780 -0.9220 -0.0563 0.0865 -0.0563 0.0563 0.0331 -0.0429 0.0331 -0.0331 -0.0061 -0.0226 -0.0061 0.0061\n", " -0.0872 0.0506 0.9128 0.0872 -0.0350 0.0637 -0.0350 0.0350 -0.0074 -0.0427 -0.0074 0.0074 0.0266 -0.0310 0.0266 -0.0266\n", " 0.0159 -0.0322 0.0159 -0.0159 0.9020 -0.0334 -0.0980 0.0980 0.0179 -0.0392 0.0179 -0.0179 -0.0031 0.0339 -0.0031 0.0031\n", " 0.0164 -0.0582 0.0164 -0.0164 -0.0222 0.8757 -0.0222 0.0222 0.0648 -0.0887 0.0648 -0.0648 0.0106 0.0160 0.0106 -0.0106\n", " -0.0224 0.0222 -0.0224 0.0224 -0.0873 0.0338 -0.0873 -0.9127 0.0118 -0.0320 0.0118 -0.0118 -0.0005 -0.0116 -0.0005 0.0005\n", " 0.0039 -0.0506 0.0039 -0.0039 -0.1036 0.0987 0.8964 0.1036 0.0007 -0.1495 0.0007 -0.0007 0.0104 -0.0428 0.0104 -0.0104\n", " 0.0045 -0.0105 0.0045 -0.0045 0.0101 -0.0205 0.0101 -0.0101 0.9269 -0.0464 -0.0731 0.0731 0.0277 -0.0374 0.0277 -0.0277\n", " -0.0104 0.0177 -0.0104 0.0104 0.0219 -0.0527 0.0219 -0.0219 0.0540 0.7558 0.0540 -0.0540 0.0453 -0.0460 0.0453 -0.0453\n", " -0.0344 0.0488 -0.0344 0.0344 0.0912 -0.1458 0.0912 -0.0912 -0.1625 0.1341 -0.1625 -0.8375 0.0111 0.0705 0.0111 -0.0111\n", " 0.0078 -0.0357 0.0078 -0.0078 -0.0474 -0.0302 -0.0474 0.0474 -0.1102 0.0575 0.8898 0.1102 0.0445 -0.0574 0.0445 -0.0445\n", " -0.0186 0.0026 -0.0186 0.0186 0.0135 0.0012 0.0135 -0.0135 -0.0295 -0.0076 -0.0295 0.0295 0.9136 -0.0199 -0.0864 0.0864\n", " -0.0232 0.0068 -0.0232 0.0232 0.0207 0.0054 0.0207 -0.0207 -0.0514 -0.0661 -0.0514 0.0514 -0.0031 0.8811 -0.0031 0.0031\n", " -0.0473 0.1032 -0.0473 0.0473 0.0419 -0.0607 0.0419 -0.0419 -0.0994 0.1200 -0.0994 0.0994 -0.0967 0.0269 -0.0967 -0.9033\n", " 0.0172 -0.0304 0.0172 -0.0172 -0.0246 0.0880 -0.0246 0.0246 0.0382 -0.0134 0.0382 -0.0382 -0.0838 0.0402 0.9162 0.0838\n", " \n", " \n", " Giy = \n", " 0.9996 0.0002 -0.0005 0.0004 0.0005 0 0.0006 -0.0005 -0.0003 0.0002 -0.0003 0.0003 0 0.0001 0.0002 0\n", " 0.1359 -0.0765 0.1776 0.8641 -0.0332 0.0081 -0.0551 0.0332 0.0255 -0.0142 0.0619 -0.0255 -0.0267 -0.0376 -0.0303 0.0267\n", " 0.0087 -0.0196 0.9370 -0.0087 -0.0279 0.0411 -0.0583 0.0279 0.0197 0.0185 0.0712 -0.0197 -0.0124 -0.0075 -0.0007 0.0124\n", " -0.0924 -0.8894 -0.0734 0.0924 -0.0228 0.0018 -0.0426 0.0228 0 -0.0020 0.0067 0 -0.0189 0.0097 0.0105 0.0189\n", " 0.0197 -0.0517 -0.0054 -0.0197 0.8602 0.1212 -0.0114 0.1398 0.0128 -0.0144 -0.0374 -0.0128 0.0093 0.0383 0.0164 -0.0093\n", " 0.0067 -0.0609 0.0504 -0.0067 0.1326 -0.0479 0.1422 0.8674 -0.0021 -0.1106 0.1850 0.0021 -0.0095 -0.0554 0.0270 0.0095\n", " -0.0081 -0.0114 0.0526 0.0081 -0.0062 -0.0080 0.7457 0.0062 0.0373 0.0443 0.1540 -0.0373 -0.0039 0.0064 0.0017 0.0039\n", " -0.0005 -0.0242 0.0385 0.0005 -0.0480 -0.8089 -0.1164 0.0480 0.0114 -0.1649 0.0999 -0.0114 -0.0404 -0.0401 -0.0276 0.0404\n", " 0.0244 0.0420 0.0519 -0.0244 -0.0323 -0.0107 -0.0810 0.0323 0.9344 0.0954 0.0964 0.0656 0.0062 0.0126 0.0494 -0.0062\n", " -0.0027 0.0007 -0.0494 0.0027 0.0420 0.0469 0.0721 -0.0420 0.1639 -0.1615 0.1370 0.8361 0.0445 -0.0360 0.0338 -0.0445\n", " -0.0128 0.0148 0.0250 0.0128 0.0613 0.0930 0.0162 -0.0613 -0.0338 0.0316 0.8384 0.0338 0.0236 -0.0212 0.0210 -0.0236\n", " -0.0313 -0.0579 -0.0055 0.0313 0.0343 0.0400 -0.0127 -0.0343 -0.0900 -0.9696 -0.0570 0.0900 0.0153 -0.0360 0.0771 -0.0153\n", " -0.0125 0.0013 -0.0086 0.0125 0.0206 -0.0298 0.0539 -0.0206 0.0096 0.0606 -0.0240 -0.0096 0.9153 0.1099 0.0061 0.0847\n", " -0.0148 -0.0826 0.0167 0.0148 -0.0369 0.1061 0.0188 0.0369 -0.0262 -0.1056 0.0675 0.0262 0.1224 -0.0974 0.1939 0.8776\n", " -0.0521 0.1111 -0.1107 0.0521 0.0949 -0.2175 0.0250 -0.0949 -0.0295 -0.0016 -0.0705 0.0295 -0.0240 -0.0130 0.8990 0.0240\n", " -0.0152 0.0031 -0.0021 0.0152 -0.0182 0.0744 -0.0063 0.0182 -0.0429 -0.0660 0.0269 0.0429 -0.0679 -0.9327 -0.1044 0.0679\n", " \n", " \n", " Gxi = \n", " 0.9997 0.0003 -0.0005 0.0001 0.0004 -0.0006 0.0006 -0.0002 0 0 -0.0002 -0.0002 0.0002 -0.0003 -0.0003 0\n", " 0.0216 0.8796 0.0299 -0.0084 -0.0263 0.0350 -0.0103 -0.0061 0.0088 -0.1089 0.0289 0.0043 0.0059 0.1026 -0.0008 -0.0191\n", " -0.0061 -0.0066 0.9336 0.0153 -0.0008 -0.0048 -0.0253 -0.0208 0.0004 -0.0331 -0.0708 0.0087 -0.0184 0.0423 0.0595 0.0092\n", " -0.0048 -0.0030 -0.0144 0.9138 -0.0144 0.0154 0.0167 -0.0255 -0.0166 0.0516 -0.0471 -0.0744 -0.0014 0.0156 -0.0276 0.0925\n", " 0.0021 -0.0224 0.0058 0.0345 0.8540 0.0731 -0.0427 -0.0595 0.0027 0.0118 -0.0260 0.0339 0.0021 -0.0086 0.0081 -0.0387\n", " -0.0095 0.0373 -0.0030 0.0352 0.0310 0.7594 0.0349 -0.0106 0.0023 0.0152 0.0055 0.0235 0.0241 -0.0352 -0.0079 -0.0498\n", " 0.0212 0.0045 0.0176 0.0058 -0.0369 -0.0253 0.7738 0.0003 0.0593 -0.1162 0.1717 -0.0323 -0.0384 -0.0018 -0.0636 0.0114\n", " 0.0133 -0.0709 -0.0328 -0.0280 -0.0043 -0.0305 0.0137 0.8919 0.0366 0.0137 0.0508 -0.0513 0.0286 0.0411 0.0119 -0.0140\n", " -0.0570 -0.0469 0.0060 -0.0211 0.0520 0.0259 -0.0143 0.0142 -0.0832 -0.0467 0.0189 0.0051 -0.9196 -0.0080 0.0156 -0.0023\n", " 0.0466 -0.1352 0.0057 0.0381 -0.0921 0.2145 -0.1808 -0.0575 0.0499 -0.1763 0.0102 0.0348 -0.0586 -0.7886 -0.0635 -0.0261\n", " 0.0106 -0.0056 -0.0507 0.0045 0.0193 -0.0720 0.1464 0.0076 0.0131 0.1024 -0.0387 0.0020 0.0337 -0.0101 -0.7903 -0.0488\n", " -0.0170 0.0500 -0.0200 -0.0884 -0.0656 0.0240 -0.0765 0.1034 -0.0137 -0.0597 0.0479 -0.0918 0.0290 -0.0223 0.0152 -0.9235\n", " -0.1233 0.0191 -0.0028 0.0153 0.1246 -0.0429 0.0122 -0.0146 0.8815 0.0358 -0.0087 0.0104 0.0867 0.0403 -0.0338 0.0214\n", " -0.0346 -0.0633 -0.0197 -0.0134 -0.0268 0.1296 0.0449 0.0187 -0.0106 0.9295 -0.0335 -0.0374 0.0492 0.1055 0.0389 -0.0012\n", " 0.0126 0.0449 -0.1439 -0.0278 -0.0819 0.0242 -0.0612 0.0629 0.0084 -0.0378 0.9179 -0.0236 0.0110 -0.0486 0.0868 0.0042\n", " 0.0138 -0.0276 -0.0178 -0.0892 -0.0116 0.0566 0.0298 0.0806 0.0461 -0.0686 0.0068 0.8784 0.0349 -0.0019 -0.0221 0.0405\n", " \n", " \n", " Gyi = \n", " 0.9997 0.0004 -0.0003 0 0 0.0004 0 0.0002 -0.0004 0.0006 -0.0003 0 0.0005 -0.0003 0.0006 -0.0001\n", " 0.0238 0.8771 0.0143 0.0137 0.0126 0.0826 0.0224 -0.0423 0.0002 -0.0170 -0.0662 -0.0044 -0.0238 0.1211 -0.0271 -0.0137\n", " 0.0202 -0.0332 0.9192 0.0362 0.0108 0.0166 0.1554 -0.0167 0.0082 0.0122 -0.0071 0.0149 -0.0415 0.0744 0.0369 -0.0149\n", " -0.0069 -0.0085 0 0.8934 0.0285 -0.0191 0.0466 0.1013 0.0019 -0.0192 -0.0208 -0.0137 0.0048 -0.0043 0.0010 0.1086\n", " 0.1132 -0.0309 0.0024 0.0110 -0.1285 0.0088 -0.0183 0.0095 0.1039 -0.0615 0.0217 0.0513 0.8902 0.0434 0.0254 -0.0144\n", " 0.0024 0.0882 0.0501 0.0379 -0.0388 -0.1382 -0.0098 -0.0256 -0.0181 0.1843 -0.0014 -0.0018 0.0283 0.8787 -0.0121 -0.0686\n", " -0.0296 0.0479 0.1228 0.0132 0.0079 0.0700 -0.1671 -0.0337 0.0122 0.0078 0.1470 -0.0186 0.0104 0.0126 0.8215 0.0060\n", " 0.0138 -0.0725 0.0110 0.1069 0.0328 -0.0175 -0.0167 -0.0913 -0.0054 -0.0319 0.0261 0.0695 0.0313 -0.0445 -0.0002 0.8481\n", " 0.0274 -0.0237 0.0394 0.0023 0.0003 0.0230 -0.0469 -0.0302 0.9053 0.0084 0.0400 0.0465 -0.0411 0.0115 0.0172 0.0113\n", " 0.0039 0.0137 -0.0978 0.0283 -0.0119 0.0072 0.0163 0.0171 0.0700 0.7489 -0.0082 0.0039 0.0127 -0.0518 -0.0241 -0.0449\n", " 0.0075 -0.0606 -0.0247 -0.0146 -0.0264 0.1137 0.0600 -0.0017 -0.0656 0.1038 0.7263 0.0426 0.0895 -0.0532 0.0867 -0.0824\n", " -0.0406 0.0475 -0.0355 0.0047 0.0309 -0.0134 -0.0688 0.0443 0.0048 0.0012 -0.0129 0.9116 0.0675 -0.0984 0.0809 -0.0316\n", " -0.0862 -0.0322 -0.0029 -0.0072 -0.9270 0.0510 0.0009 0.0011 -0.0562 -0.0924 0.0006 -0.0177 0.1015 -0.0512 0.0042 -0.0081\n", " -0.0366 -0.0917 -0.0126 0.0561 -0.0413 -0.8153 -0.0262 -0.0602 -0.0885 -0.0505 -0.0443 0.0699 -0.0167 0.0934 0.0794 -0.0028\n", " -0.0421 0.0789 -0.1315 -0.0008 0.0182 -0.0203 -0.9726 -0.0790 0.0280 -0.0527 0.0035 -0.0179 0.0288 -0.1490 0.1132 0.0141\n", " -0.0129 0.0056 -0.0237 -0.0305 -0.0163 0.0129 -0.0038 -0.9416 -0.0486 0.0542 -0.0017 0.0240 -0.0278 0.0800 -0.0298 0.0712\n", " \n", " \n", " Gcnot = \n", " 0.9997 0.0002 0.0001 -0.0003 -0.0002 0.0002 0 -0.0003 -0.0003 0.0002 0.0001 -0.0002 0 -0.0002 -0.0001 0\n", " 0.0333 0.8508 0.0031 0.0096 -0.0220 0.0244 -0.0636 0.0398 0.0477 -0.0561 0.0697 -0.0106 0.0002 -0.0163 0.0586 -0.0006\n", " -0.0150 -0.0232 -0.0228 0.0023 0.0446 -0.0219 -0.0204 0.0396 -0.0073 0.0053 0.0905 -0.0071 0.0106 0.0032 0.9347 0.0290\n", " -0.1044 0.0643 0.0337 0.0056 -0.0048 0.0089 -0.0058 -0.1010 0.0494 -0.0573 0.0633 0.0867 0.0968 -0.0709 0.0114 0.9078\n", " 0.0035 -0.0343 -0.0237 -0.0208 -0.0280 0.0461 -0.1241 0.0002 -0.0051 0.8874 -0.0502 0.0164 0.0106 -0.0052 -0.0277 0.0166\n", " 0.0525 -0.1321 0.0649 0.0307 -0.1134 0.1125 0.0023 -0.1081 0.9547 -0.0763 0.0615 0.0801 0.0366 -0.0906 0.0017 0.0786\n", " -0.0200 -0.0170 0.0317 -0.0093 -0.0468 0.0929 -0.0978 -0.7667 -0.0490 -0.0425 -0.0034 -0.0812 0.0091 -0.0556 0.0130 -0.0015\n", " 0.0058 -0.0126 0.0340 0.0092 0.1195 -0.0307 0.9206 0.1247 0.0856 -0.0503 0.0692 -0.0449 -0.0257 0.0915 0.0381 0.0206\n", " 0.0541 -0.0499 0.0969 0.0177 0.0121 -0.9367 0.0335 0.0146 0.0223 -0.0398 -0.0315 0.0203 0.0036 0.0101 0.0112 0.0043\n", " -0.0150 0.0245 0.0800 -0.0286 -0.7647 -0.1021 -0.0606 -0.0715 -0.0824 0.0636 0.0453 -0.0900 0.0364 -0.0960 0.0156 0.0176\n", " -0.0379 -0.0327 -0.0286 0.0543 -0.0367 0.1006 -0.0617 -0.1445 -0.2509 0.1968 -0.0696 -0.7658 0.0525 -0.0658 -0.0114 0.0260\n", " -0.0439 0.0715 0.0662 -0.0258 -0.1056 0.0349 -0.0036 -0.0138 -0.0698 -0.0654 0.9349 0.0811 -0.0122 -0.0379 -0.0089 -0.0092\n", " -0.0371 0.0036 -0.0379 -0.0862 -0.0276 0.0709 0.0380 0.0145 0.0460 0.0815 -0.0489 0.0139 0.9290 -0.0193 0.0161 0.0882\n", " -0.0187 0.0536 0.0015 0.0054 -0.0021 -0.0080 0.0373 -0.0380 0.1421 0.0805 0.0358 0.1456 0.0675 0.7863 -0.0286 0.0244\n", " 0.0099 0.0744 0.9298 0.0103 -0.0418 -0.0459 0.0073 -0.0456 -0.1020 0.0255 -0.0163 0.0039 -0.0238 0.0166 -0.0291 -0.0153\n", " 0.0969 -0.0956 0.0229 0.9026 -0.0354 0.0737 0.0627 0.0332 0.0538 -0.0123 -0.0077 0.0013 -0.0798 0.0327 0.0320 -0.0083\n", " \n", " \n", " \n", "--- Iterative MLGST: Iter 1 of 3 731 gate strings ---: \n", " --- Minimum Chi^2 GST ---\n", " Memory limit = 3.00GB\n", " Cur, Persist, Gather = 0.08, 0.03, 0.30 GB\n", " Evaltree generation (deriv) w/mem limit = 2.59GB\n", " bulk_evaltree: created initial tree (731 strs) in 0s\n", " bulk_evaltree: split tree (1 subtrees) in 0s\n", " mem(1 subtrees, 1,1 param-grps, 1 proc-grps) in 0s = 1.88GB (2.44GB fc)\n", " Created evaluation tree with 1 subtrees. Will divide 1 procs into 1 (subtree-processing)\n", " groups of ~1 procs each, to distribute over 1344 params (taken as 1 param groups of ~1344 params).\n", " Memory estimate = 1.88GB (cache=731, wrtLen1=1344, wrtLen2=1344, subsPerProc=1).\n", "--- Outer Iter 0: norm_f = 32916.8, mu=0\n", "--- Outer Iter 1: norm_f = 29180.6, mu=2.83248e+06\n", "--- Outer Iter 2: norm_f = 24098.5, mu=944158\n", "--- Outer Iter 3: norm_f = 15729.7, mu=314719\n", "--- Outer Iter 4: norm_f = 8154.44, mu=104906\n", "--- Outer Iter 5: norm_f = 4442.94, mu=34968.8\n", "--- Outer Iter 6: norm_f = 2782.22, mu=11656.3\n", "--- Outer Iter 7: norm_f = 1933.34, mu=3885.43\n", "--- Outer Iter 8: norm_f = 1469.88, mu=1295.14\n", "--- Outer Iter 9: norm_f = 1244.05, mu=431.714\n", "--- Outer Iter 10: norm_f = 1152.3, mu=143.905\n", "--- Outer Iter 11: norm_f = 1118.86, mu=47.9682\n", "--- Outer Iter 12: norm_f = 1108.89, mu=15.9894\n", "--- Outer Iter 13: norm_f = 1107.1, mu=5.3298\n", "--- Outer Iter 14: norm_f = 1106.96, mu=1.7766\n", "--- Outer Iter 15: norm_f = 1106.95, mu=0.5922\n", " Least squares message = Both actual and predicted relative reductions in the sum of squares are at most 1e-06\n", " Sum of Chi^2 = 1106.95 (2193 data params - 1088 model params = expected mean of 1105; p-value = 0.477827)\n", " Completed in 561.9s\n", " 2*Delta(log(L)) = 1109.03\n", " Iteration 1 took 562.0s\n", " \n", "--- Iterative MLGST: Iter 2 of 3 1141 gate strings ---: \n", " --- Minimum Chi^2 GST ---\n", " Memory limit = 3.00GB\n", " Cur, Persist, Gather = 0.12, 0.05, 0.30 GB\n", " Evaltree generation (deriv) w/mem limit = 2.54GB\n", " bulk_evaltree: created initial tree (1141 strs) in 0s\n", " bulk_evaltree: split tree (1 subtrees) in 0s\n", " mem(1 subtrees, 1,1 param-grps, 1 proc-grps) in 0s = 2.93GB (3.81GB fc)\n", " Created evaluation tree with 1 subtrees. Will divide 1 procs into 1 (subtree-processing)\n", " groups of ~1 procs each, to distribute over 1344 params (taken as 2 param groups of ~672 params).\n", " Memory estimate = 1.47GB (cache=1141, wrtLen1=672, wrtLen2=1344, subsPerProc=1).\n", "--- Outer Iter 0: norm_f = 3828.54, mu=0\n", "--- Outer Iter 1: norm_f = 2883.48, mu=3129.75\n", "--- Outer Iter 2: norm_f = 2567.76, mu=1043.25\n", "--- Outer Iter 3: norm_f = 2431.23, mu=347.75\n", "--- Outer Iter 4: norm_f = 2386.94, mu=115.917\n", "--- Outer Iter 5: norm_f = 2379.08, mu=38.6389\n", "--- Outer Iter 6: norm_f = 2378.44, mu=12.8796\n", "--- Outer Iter 7: norm_f = 2378.41, mu=4.29321\n", " Least squares message = Both actual and predicted relative reductions in the sum of squares are at most 1e-06\n", " Sum of Chi^2 = 2378.41 (3423 data params - 1088 model params = expected mean of 2335; p-value = 0.26072)\n", " Completed in 225.4s\n", " 2*Delta(log(L)) = 2384.85\n", " Iteration 2 took 225.4s\n", " \n", "--- Iterative MLGST: Iter 3 of 3 1735 gate strings ---: \n", " --- Minimum Chi^2 GST ---\n", " Memory limit = 3.00GB\n", " Cur, Persist, Gather = 0.13, 0.07, 0.29 GB\n", " Evaltree generation (deriv) w/mem limit = 2.51GB\n", " bulk_evaltree: created initial tree (1735 strs) in 0s\n", " bulk_evaltree: split tree (1 subtrees) in 0s\n", " mem(1 subtrees, 1,1 param-grps, 1 proc-grps) in 0s = 4.45GB (5.79GB fc)\n", " Created evaluation tree with 1 subtrees. Will divide 1 procs into 1 (subtree-processing)\n", " groups of ~1 procs each, to distribute over 1344 params (taken as 2 param groups of ~672 params).\n", " Memory estimate = 2.23GB (cache=1735, wrtLen1=672, wrtLen2=1344, subsPerProc=1).\n", "--- Outer Iter 0: norm_f = 5002.2, mu=0\n", "--- Outer Iter 1: norm_f = 4393.33, mu=4065.3\n", "--- Outer Iter 2: norm_f = 4258.91, mu=1355.1\n", "--- Outer Iter 3: norm_f = 4206.65, mu=451.699\n", "--- Outer Iter 4: norm_f = 4192.11, mu=150.566\n", "--- Outer Iter 5: norm_f = 4189.62, mu=50.1888\n", "--- Outer Iter 6: norm_f = 4189.32, mu=16.7296\n", "--- Outer Iter 7: norm_f = 4189.3, mu=5.57654\n", " Least squares message = Both actual and predicted relative reductions in the sum of squares are at most 1e-06\n", " Sum of Chi^2 = 4189.3 (5205 data params - 1088 model params = expected mean of 4117; p-value = 0.212011)\n", " Completed in 330.3s\n", " 2*Delta(log(L)) = 4201.93\n", " Iteration 3 took 330.4s\n", " \n", " Switching to ML objective (last iteration)\n", " --- MLGST ---\n", " Memory: limit = 3.00GB(cur, persist, gthr = 0.17, 0.07, 0.29 GB)\n", " Evaltree generation (deriv) w/mem limit = 2.47GB\n", " bulk_evaltree: created initial tree (1735 strs) in 0s\n", " bulk_evaltree: split tree (1 subtrees) in 0s\n", " mem(1 subtrees, 1,1 param-grps, 1 proc-grps) in 0s = 4.45GB (5.79GB fc)\n", " Created evaluation tree with 1 subtrees. Will divide 1 procs into 1 (subtree-processing)\n", " groups of ~1 procs each, to distribute over 1344 params (taken as 2 param groups of ~672 params).\n", " Memory estimate = 2.23GB (cache=1735, wrtLen1=672, wrtLen2=1344, subsPerProc=1).\n", "--- Outer Iter 0: norm_f = 2100.96, mu=0\n", "--- Outer Iter 1: norm_f = 2098.59, mu=2036.38\n", "--- Outer Iter 2: norm_f = 2098.43, mu=1692.54\n", " Least squares message = Relative change in |x| is at most 1e-06\n", " Maximum log(L) = 2098.43 below upper bound of -3.93421e+06\n", " 2*Delta(log(L)) = 4196.86 (5205 data params - 1344 model params = expected mean of 3861; p-value = 9.8035e-05)\n", " Completed in 124.4s\n", " 2*Delta(log(L)) = 4196.86\n", " Final MLGST took 124.4s\n", " \n", "Iterative MLGST Total Time: 1242.2s\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "\n", "WARNING: Could not obtain number of *non-gauge* parameters - using total params instead\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Total time=0.359374 hours\n" ] } ], "source": [ "import time\n", "start = time.time()\n", "results = pygsti.do_long_sequence_gst(ds, gs_target, prep_fiducials, effect_fiducials, germs4,\n", " maxLengths, gaugeOptParams={'itemWeights': {'spam':0.1,'gates': 1.0}},\n", " advancedOptions={ 'depolarizeStart' : 0.1 }, memLimit=3*(1024)**3,\n", " verbosity=3 )\n", "end = time.time()\n", "print(\"Total time=%f hours\" % ((end - start) / 3600.0))\n", "\n", "#If you wanted to, you could pickle the results for later analysis:\n", "#pickle.dump(results, open(\"MySavedResults.pkl\", \"w\"))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Step 5: Create report(s) using the returned `Results` object\n", "The `Results` object returned from `do_long_sequence_gst` is able to generate several different types of reports. Most of these are designed to display single-qubit results (for historical reasons). The \"general\"-type report was designed with 2-qubit data presentation in mind, so creating reports with `create_general_report` will be the most useful." ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "pp\n", "[4]\n" ] } ], "source": [ "results.gatesets['final estimate'].set_basis(\"pp\", [4])\n", "print(results.gatesets['final estimate'].get_basis_name())\n", "print(results.gatesets['final estimate'].get_basis_dimension())" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "*** Generating tables *** (0.0s elapsed)\n", " Generating table: targetSpamBriefTable [0.0s]\n", " Generating table: bestGatesetSpamBriefTable [0.0s]\n", " Generating table: bestGatesetSpamParametersTable [0.0s]\n", " Generating table: bestGatesetVsTargetTable [6.4s]\n", " Generating table: bestGatesetSpamVsTargetTable [0.0s]\n", " Generating table: bestGatesetGaugeOptParamsTable [0.0s]\n", " Generating table: bestGatesetChoiEvalTable [5.1s]\n", " Generating table: datasetOverviewTable [0.1s]\n", " Generating table: bestGatesetEvalTable [1.4s]\n", " Generating table: bestGatesetRelEvalTable [1.1s]\n", " Generating table: targetGatesBoxTable [6.7s]\n", " Generating table: bestGatesetGatesBoxTable [13.3s]\n", " Generating table: bestGatesetErrGenBoxTable [11.3s]\n", " Generating table: metadataTable [0.0s]\n", " Generating table: softwareEnvTable [0.2s]\n", " Generating table: fiducialListTable [0.0s]\n", " Generating table: prepStrListTable [0.0s]\n", " Generating table: effectStrListTable [0.0s]\n", " Generating table: germList2ColTable [0.0s]\n", " Generating table: progressTable [13.2s]\n", "*** Generating plots *** (79.4s elapsed)\n", " -- LogL plots: Iter 1 of 3 : Generating figure: colorBoxPlotKeyPlot [2.0s]\n", " Iter 2 of 3 : Generating figure: bestEstimateSummedColorBoxPlot [0.6s]\n", " Iter 3 of 3 : Generating special: bestEstimateColorBoxPlotPages [10.2s]\n", "\n", "*** Merging into template file *** (97.4s elapsed)\n", "Latex file(s) successfully generated. Attempting to compile with pdflatex...\n", "Initial output PDF tutorial_files/easy_2q_general.pdf successfully generated.\n", "Final output PDF tutorial_files/easy_2q_general.pdf successfully generated. Cleaning up .aux and .log files.\n", "Report generation complete! [total time 99s]\n" ] } ], "source": [ "results.create_general_report_pdf(filename=\"tutorial_files/easy_2q_general.pdf\",verbosity=2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now open [tutorial_files/easy_2q_general.pdf](tutorial_files/easy_2q_general.pdf) to see the results. You've run 2-qubit GST!" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import pickle\n", "with open(\"tutorial_files/easy_2q_results.pkl\",\"wb\") as pklfile:\n", " pickle.dump(results, pklfile)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.5.2" } }, "nbformat": 4, "nbformat_minor": 0 }