{ "cells": [ { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "# Tutorial showing use of a `Workspace` object\n", "\n", "## Part 1: making tables and plots\n", "PyGSTi's `Workspace` object is first a foremost a container and factory for plots and tables. At the most basic level, it can be used to generate nice output based on quantities (e.g. GateSets, DataSets, etc.) that you've computed or loaded within a notebook. For this, it's useful to call `init_notebook_mode` with `autodisplay=True` (see below) so that you don't have to `.display()` everything - `display()` gets called automatically when a plot or table is created.\n", "\n", "First, let's run GST on the standard 1Q gate set to get some results to play with." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [], "source": [ "import numpy as np\n", "import pygsti\n", "from pygsti.construction import std1Q_XYI" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [], "source": [ "#The usual GST setup: we're going to run GST on the standard XYI 1-qubit gateset\n", "gs_target = std1Q_XYI.gs_target\n", "fiducials = std1Q_XYI.fiducials\n", "germs = std1Q_XYI.germs\n", "maxLengths = [1,2]\n", "listOfExperiments = pygsti.construction.make_lsgst_experiment_list(\n", " gs_target.gates.keys(), fiducials, fiducials, germs, maxLengths)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [], "source": [ "#Create some datasets for analysis\n", "gs_datagen1 = gs_target.depolarize(gate_noise=0.1, spam_noise=0.02)\n", "gs_datagen2 = gs_target.depolarize(gate_noise=0.05, spam_noise=0.01).rotate(rotate=(0.01,0.01,0.01))\n", "\n", "ds1 = pygsti.construction.generate_fake_data(gs_datagen1, listOfExperiments, nSamples=1000,\n", " sampleError=\"binomial\", seed=1234)\n", "ds2 = pygsti.construction.generate_fake_data(gs_datagen2, listOfExperiments, nSamples=1000,\n", " sampleError=\"binomial\", seed=1234)\n", "ds3 = ds1.copy_nonstatic(); ds3.add_counts_from_dataset(ds2); ds3.done_adding_data()" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [], "source": [ "#Run GST on all three datasets\n", "gs_target.set_all_parameterizations(\"TP\")\n", "results1 = pygsti.do_long_sequence_gst(ds1, gs_target, fiducials, fiducials, germs, maxLengths, verbosity=0)\n", "results2 = pygsti.do_long_sequence_gst(ds2, gs_target, fiducials, fiducials, germs, maxLengths, verbosity=0)\n", "results3 = pygsti.do_long_sequence_gst(ds3, gs_target, fiducials, fiducials, germs, maxLengths, verbosity=0)\n", "\n", "#make some shorthand variable names for later\n", "tgt = results1.estimates['default'].gatesets['target']\n", "\n", "ds1 = results1.dataset\n", "ds2 = results2.dataset\n", "ds3 = results3.dataset\n", "\n", "gs1 = results1.estimates['default'].gatesets['go0']\n", "gs2 = results2.estimates['default'].gatesets['go0']\n", "gs3 = results3.estimates['default'].gatesets['go0']\n", "\n", "gss = results1.gatestring_structs['final']" ] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "#### Now that we have some results, let's create a `Workspace` and make some plots and tables.\n", "\n", "To get tables and plots to display properly, one must run `init_notebook_mode`. The `connected` argument indicates whether you want to rely on an active internet connection. If `True`, then resources will be loaded from the web (e.g. a CDN), and if you save a notebook as HTML the file size may be smaller. If `False`, then all the needed resources (except MathJax) are provided by pyGSTi, and an `offline` directory is automatically created in the same directory as your notebook. This directory contains all the necessary resources, and must \"tag along\" with the notebook and any saved-as-HTML versions of it in order for everything to work. The second argument, `autodisplay`, determines whether tables and plots are automatically displayed when they are created. If `autodisplay=False`, one must call the `display()` member function of a table or plot to display it. " ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false, "deletable": true, "editable": true, "scrolled": true }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "
Gate | \">Entanglement Infidelity | Avg. Gate Infidelity | 1/2 Trace Distance | 1/2 Diamond-Dist | Non-unitary Ent. Infidelity | Non-unitary Avg. Gate Infidelity |
---|---|---|---|---|---|---|
Gi | 0.074748 | 0.049832 | 0.076617 | 0.07684 | 0.074477 | 0.049652 |
Gx | 0.077108 | 0.051405 | 0.077591 | 0.077595 | 0.077018 | 0.051345 |
Gy | 0.075148 | 0.050098 | 0.075248 | 0.075267 | 0.07511 | 0.050073 |
Prep/POVM | Infidelity | 1/2 Trace Distance | 1/2 Diamond-Dist |
---|---|---|---|
ρ0 | 0.042312 | 0.043714 | -- |
Mdefault | -0.04156 | 0.042419 | 0.043467 |
L | 2Δ(log L) | k | 2Δ(log L)-k | √2k | Nsigma | Ns | Np | Rating |
---|---|---|---|---|---|---|---|---|
1 | 80.98834 | 61 | 19.98834 | 11.04536 | 1.81 | 92 | 31 | |
2 | 166.8526 | 137 | 29.85256 | 16.55295 | 1.8 | 168 | 31 |
GateSet | 2Δ(log L) | k | 2Δ(log L)-k | √2k | Nsigma | Ns | Np | Rating |
---|---|---|---|---|---|---|---|---|
GS1 | 166.8526 | 137 | 29.85256 | 16.55295 | 1.8 | 168 | 31 | |
GS2 | 4088.064 | 137 | 3951.064 | 16.55295 | 2×102 | 168 | 31 | |
GS3 | 1006.891 | 137 | 869.8905 | 16.55295 | 52.6 | 168 | 31 |
Gate | Choi matrix (Pauli-Product basis) | Eigenvalue Magnitudes |
---|---|---|
Gi | $ \\begin{pmatrix}\n", "0.944851 & 0.010383e^{i0.450\\pi} & 0.007336e^{i0.464\\pi} & 0.001242e^{i0.710\\pi} \\\\ \n", "0.010383e^{-i0.450\\pi} & 0.015242 & 0.003872e^{i0.063\\pi} & 0.001952e^{i0.138\\pi} \\\\ \n", "0.007336e^{-i0.464\\pi} & 0.003872e^{-i0.063\\pi} & 0.020849 & 0.001798e^{-i0.639\\pi} \\\\ \n", "0.001242e^{-i0.710\\pi} & 0.001952e^{-i0.138\\pi} & 0.001798e^{i0.639\\pi} & 0.019058\n", " \\end{pmatrix} $\n", " | \n",
" \n",
"\n",
" \n",
"\n",
"\n",
" |
Gx | $ \\begin{pmatrix}\n", "0.482477 & 0.462924e^{i0.501\\pi} & 0.00285e^{i0.508\\pi} & 0.000055e^{i0.786\\pi} \\\\ \n", "0.462924e^{-i0.501\\pi} & 0.480083 & 0.002985e^{i0.005\\pi} & 0.000079e^{-i0.643\\pi} \\\\ \n", "0.00285e^{-i0.508\\pi} & 0.002985e^{-i0.005\\pi} & 0.019276 & 0.001123e^{i0.486\\pi} \\\\ \n", "0.000055e^{-i0.786\\pi} & 0.000079e^{i0.643\\pi} & 0.001123e^{-i0.486\\pi} & 0.018164\n", " \\end{pmatrix} $\n", " | \n",
" \n",
"\n",
" \n",
"\n",
"\n",
" |
Gy | $ \\begin{pmatrix}\n", "0.480739 & 0.002381e^{i0.514\\pi} & 0.463008e^{i0.500\\pi} & 0.00008e^{-i0.107\\pi} \\\\ \n", "0.002381e^{-i0.514\\pi} & 0.017701 & 0.003456e^{-i0.007\\pi} & 0.000538e^{-i0.531\\pi} \\\\ \n", "0.463008e^{-i0.500\\pi} & 0.003456e^{i0.007\\pi} & 0.484353 & 0.000107e^{i0.420\\pi} \\\\ \n", "0.00008e^{i0.107\\pi} & 0.000538e^{i0.531\\pi} & 0.000107e^{-i0.420\\pi} & 0.017208\n", " \\end{pmatrix} $\n", " | \n",
" \n",
"\n",
" \n",
"\n",
"\n",
" |
Gate | Error Generator | Pauli Hamiltonian Projections | Pauli Stochastic Projections | Pauli Affine Projections |
---|---|---|---|---|
Gi | \n",
" \n",
"\n",
" \n",
"\n",
"\n",
" | \n",
" \n",
"\n",
" \n",
"\n",
"\n",
" | \n",
" \n",
"\n",
" \n",
"\n",
"\n",
" | \n",
" \n",
"\n",
" \n",
"\n",
"\n",
" |
Gx | \n",
" \n",
"\n",
" \n",
"\n",
"\n",
" | \n",
" \n",
"\n",
" \n",
"\n",
"\n",
" | \n",
" \n",
"\n",
" \n",
"\n",
"\n",
" | \n",
" \n",
"\n",
" \n",
"\n",
"\n",
" |
Gy | \n",
" \n",
"\n",
" \n",
"\n",
"\n",
" | \n",
" \n",
"\n",
" \n",
"\n",
"\n",
" | \n",
" \n",
"\n",
" \n",
"\n",
"\n",
" | \n",
" \n",
"\n",
" \n",
"\n",
"\n",
" |
Gate | Eigenvalues ($E$) | Eigenvalues |
---|---|---|
Gi | $ \\begin{pmatrix}\n", "1 \\\\ \n", "0.955547 \\\\ \n", "0.94681e^{i0.008\\pi} \\\\ \n", "0.94681e^{-i0.008\\pi}\n", " \\end{pmatrix} $\n", " | \n",
" \n",
"\n",
" \n",
"\n",
"\n",
" |
Gx | $ \\begin{pmatrix}\n", "1 \\\\ \n", "0.95118 \\\\ \n", "0.949197e^{i0.502\\pi} \\\\ \n", "0.949197e^{-i0.502\\pi}\n", " \\end{pmatrix} $\n", " | \n",
" \n",
"\n",
" \n",
"\n",
"\n",
" |
Gy | $ \\begin{pmatrix}\n", "1 \\\\ \n", "0.957594 \\\\ \n", "0.948507e^{i0.502\\pi} \\\\ \n", "0.948507e^{-i0.502\\pi}\n", " \\end{pmatrix} $\n", " | \n",
" \n",
"\n",
" \n",
"\n",
"\n",
" |
Gate | Ham. Evals. | Rotn. angle | Rotn. axis | Log Error | Axis angle w/Gi | Axis angle w/Gx | Axis angle w/Gy |
---|---|---|---|---|---|---|---|
Gi | $ \\begin{pmatrix}\n", "-0.004833 \\\\ \n", "0.004833\n", " \\end{pmatrix} $\n", "π | 0.009667π | \n",
" \n",
"\n",
" \n",
"\n",
"\n",
" | 0 | 0.285541π | 0.222932π | |
Gx | $ \\begin{pmatrix}\n", "-0.24771 \\\\ \n", "0.24771\n", " \\end{pmatrix} $\n", "π | 0.495421π | \n",
" \n",
"\n",
" \n",
"\n",
"\n",
" | 0 | 0.285541π | 0.496963π | |
Gy | $ \\begin{pmatrix}\n", "-0.25023 \\\\ \n", "0.25023\n", " \\end{pmatrix} $\n", "π | 0.500461π | \n",
" \n",
"\n",
" \n",
"\n",
"\n",
" | 0 | 0.222932π | 0.496963π |
Gate | Ham. Evals. | Rotn. angle | Rotn. axis | Log Error | Axis angle w/Gii | Axis angle w/Gix | Axis angle w/Giy | Axis angle w/Gxi | Axis angle w/Gyi | Axis angle w/Gxx | Axis angle w/Gyy | Axis angle w/Gxy | Axis angle w/Gyx |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Gii | $ \\begin{pmatrix}\n", "0 \\\\ \n", "0 \\\\ \n", "0 \\\\ \n", "0\n", " \\end{pmatrix} $\n", "π | 0π | \n",
" \n",
"\n",
" \n",
"\n",
"\n",
" | 0 | -- | -- | -- | -- | -- | -- | -- | -- | |
Gix | $ \\begin{pmatrix}\n", "0.25 \\\\ \n", "-0.25 \\\\ \n", "0.25 \\\\ \n", "-0.25\n", " \\end{pmatrix} $\n", "π | 0.5π | \n",
" \n",
"\n",
" \n",
"\n",
"\n",
" | 0 | -- | 0.5π | 0.5π | 0.5π | 0.25π | 0.499996π | 0.499993π | 0.25π | |
Giy | $ \\begin{pmatrix}\n", "-0.25 \\\\ \n", "0.25 \\\\ \n", "-0.25 \\\\ \n", "0.25\n", " \\end{pmatrix} $\n", "π | 0.5π | \n",
" \n",
"\n",
" \n",
"\n",
"\n",
" | 0 | -- | 0.5π | 0.5π | 0.5π | 0.5π | 0.25π | 0.25π | 0.500006π | |
Gxi | $ \\begin{pmatrix}\n", "-0.25 \\\\ \n", "0.25 \\\\ \n", "-0.25 \\\\ \n", "0.25\n", " \\end{pmatrix} $\n", "π | 0.5π | \n",
" \n",
"\n",
" \n",
"\n",
"\n",
" | 0 | -- | 0.5π | 0.5π | 0.5π | 0.25π | 0.499996π | 0.25π | 0.499993π | |
Gyi | $ \\begin{pmatrix}\n", "0.25 \\\\ \n", "-0.25 \\\\ \n", "0.25 \\\\ \n", "-0.25\n", " \\end{pmatrix} $\n", "π | 0.5π | \n",
" \n",
"\n",
" \n",
"\n",
"\n",
" | 0 | -- | 0.5π | 0.5π | 0.5π | 0.5π | 0.25π | 0.499996π | 0.25π | |
Gxx | $ \\begin{pmatrix}\n", "-0.500016 \\\\ \n", "0.500017 \\\\ \n", "-0.000001 \\\\ \n", "0\n", " \\end{pmatrix} $\n", "π | 0.707131π | \n",
" \n",
"\n",
" \n",
"\n",
"\n",
" | 0.002766 | -- | 0.25π | 0.5π | 0.25π | 0.5π | 0.499995π | 0.333328π | 0.333328π | |
Gyy | $ \\begin{pmatrix}\n", "-0.499994 \\\\ \n", "0.499997 \\\\ \n", "-0.000002 \\\\ \n", "0\n", " \\end{pmatrix} $\n", "π | 0.7071π | \n",
" \n",
"\n",
" \n",
"\n",
"\n",
" | 0.007928 | -- | 0.499996π | 0.25π | 0.499996π | 0.25π | 0.499995π | 0.333327π | 0.333335π | |
Gxy | $ \\begin{pmatrix}\n", "0.499982 \\\\ \n", "-0.499982 \\\\ \n", "0 \\\\ \n", "3\\times 10^{-7}\n", " \\end{pmatrix} $\n", "π | 0.707082π | \n",
" \n",
"\n",
" \n",
"\n",
"\n",
" | 0.002956 | -- | 0.499993π | 0.25π | 0.25π | 0.499996π | 0.333328π | 0.333327π | 0.499991π | |
Gyx | $ \\begin{pmatrix}\n", "0.499976 \\\\ \n", "-0.499975 \\\\ \n", "-0.000001 \\\\ \n", "0\n", " \\end{pmatrix} $\n", "π | 0.707072π | \n",
" \n",
"\n",
" \n",
"\n",
"\n",
" | 0.003983 | -- | 0.25π | 0.500006π | 0.499993π | 0.25π | 0.333328π | 0.333335π | 0.499991π |
Gate | Ham. Evals. | Rotn. angle | Rotn. axis | Log Error | Axis angle w/Gix | Axis angle w/Giy | Axis angle w/Gxi | Axis angle w/Gyi | Axis angle w/Gcnot | Axis angle w/Gtest |
---|---|---|---|---|---|---|---|---|---|---|
Gix | $ \\begin{pmatrix}\n", "0.25 \\\\ \n", "-0.25 \\\\ \n", "0.25 \\\\ \n", "-0.25\n", " \\end{pmatrix} $\n", "π | 0.5π | \n",
" \n",
"\n",
" \n",
"\n",
"\n",
" | 0 | 0.5π | 0.5π | 0.5π | 0.304092π | 0.5π | |
Giy | $ \\begin{pmatrix}\n", "-0.25 \\\\ \n", "0.25 \\\\ \n", "-0.25 \\\\ \n", "0.25\n", " \\end{pmatrix} $\n", "π | 0.5π | \n",
" \n",
"\n",
" \n",
"\n",
"\n",
" | 0 | 0.5π | 0.5π | 0.5π | 0.499999π | 0.500001π | |
Gxi | $ \\begin{pmatrix}\n", "-0.25 \\\\ \n", "0.25 \\\\ \n", "-0.25 \\\\ \n", "0.25\n", " \\end{pmatrix} $\n", "π | 0.5π | \n",
" \n",
"\n",
" \n",
"\n",
"\n",
" | 0 | 0.5π | 0.5π | 0.5π | 0.500001π | 0.499999π | |
Gyi | $ \\begin{pmatrix}\n", "0.25 \\\\ \n", "-0.25 \\\\ \n", "0.25 \\\\ \n", "-0.25\n", " \\end{pmatrix} $\n", "π | 0.5π | \n",
" \n",
"\n",
" \n",
"\n",
"\n",
" | 0 | 0.5π | 0.5π | 0.5π | 0.500001π | 0.499999π | |
Gcnot | $ \\begin{pmatrix}\n", "-0.749999 \\\\ \n", "0.249988 \\\\ \n", "0.250011 \\\\ \n", "0.25\n", " \\end{pmatrix} $\n", "π | 0.866024π | \n",
" \n",
"\n",
" \n",
"\n",
"\n",
" | 0.004202 | 0.304092π | 0.499999π | 0.500001π | 0.500001π | 0.5π | |
Gtest | $ \\begin{pmatrix}\n", "-0.499977 \\\\ \n", "-0.499972 \\\\ \n", "0.499979 \\\\ \n", "0.499971\n", " \\end{pmatrix} $\n", "π | 0.999949π | \n",
" \n",
"\n",
" \n",
"\n",
"\n",
" | 0.000936 | 0.5π | 0.500001π | 0.499999π | 0.499999π | 0.5π |
Gate | \">Entanglement Infidelity | Avg. Gate Infidelity | 1/2 Trace Distance | 1/2 Diamond-Dist | Non-unitary Ent. Infidelity | Non-unitary Avg. Gate Infidelity |
---|---|---|---|---|---|---|
Gi | 0.074748 | 0.049832 | 0.076617 | 0.07684 | 0.074477 | 0.049652 |
Gx | 0.077108 | 0.051405 | 0.077591 | 0.077595 | 0.077018 | 0.051345 |
Gy | 0.075148 | 0.050098 | 0.075248 | 0.075267 | 0.07511 | 0.050073 |