{ "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", "
Loading...
\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from pygsti.report import workspace\n", "w = workspace.Workspace()\n", "w.init_notebook_mode(connected=False, autodisplay=True) " ] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "Plots and tables are created via member functions of a `Workspace` (`w` in our case). Note that you can start typing \"`w.`\" and TAB-complete to see the different things a `Workspace` can make for you. Furthermore, pressing SHIFT-TAB after the opening parenthesis of a function, e.g. after typing \"`w.GatesVsTargetTable(`\", will bring up Jupyter's help window showing you the function signature (the arguments you need to give the function).\n", "\n", "#### The remainder of this tutorial demonstrates some of the tables and plots you can create. \n", "Note that displayed objects have a resize handle in their lower right corner." ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "data": { "text/html": [ "
\n", "
\n", "
\n", "
\n", "\n", "
\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", "
\n", "
\n", "
\n", "\n", "
\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", "
\n", "
\n", "
\n", "\n", "
\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "w.ColorBoxPlot((\"logl\",), gss, ds1, gs1, typ='scatter')\n", "w.ColorBoxPlot((\"logl\",), gss, ds1, gs1, typ='boxes')\n", "w.ColorBoxPlot((\"logl\",), gss, ds1, gs1, typ='histogram')" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "data": { "text/html": [ "
\n", "
\n", "
\n", "
\n", "\n", "
\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "w.FitComparisonBarPlot(gss.Ls, results1.gatestring_structs['iteration'],\n", " results1.estimates['default'].gatesets['iteration estimates'], ds1)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "data": { "text/html": [ "
\n", "
\n", "
\n", "
\n", "\n", "
\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "w.GramMatrixBarPlot(ds1,tgt)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "data": { "text/html": [ "
\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
Gi0.0736770.0491180.0763470.0765440.0733440.048896
Gx0.0771530.0514350.0773370.0773620.0771190.051413
Gy0.0745620.0497080.0746870.074710.074540.049693
\n", "
\n", "\n", "
\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "w.GatesVsTargetTable(gs1, tgt)" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false, "deletable": true, "editable": true, "scrolled": true }, "outputs": [ { "data": { "text/html": [ "
\n", "
\n", "
Prep/POVM Infidelity 1/2 Trace Distance 1/2 Diamond-Dist
ρ00.0423120.043714--
Mdefault-0.041560.0424190.043467
\n", "
\n", "\n", "
\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "w.SpamVsTargetTable(gs2, tgt)" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": false, "deletable": true, "editable": true, "scrolled": false }, "outputs": [ { "data": { "text/html": [ "
\n", "
\n", "
\n", "
\n", "\n", "
\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "w.ColorBoxPlot((\"chi2\",\"logl\"), gss, ds1, gs1, boxLabels=True)\n", " #Notice how long it takes to switch between \"chi2\" and \"logl\". This \n", " # is due to drawing all of the box labels (boxLabels=True)." ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "data": { "text/html": [ "
\n", "
\n", "
L 2Δ(log L) k 2Δ(log L)-k 2k Nsigma Ns Np Rating
185.324016124.3240111.045362.29231\">★★★★
2174.854413737.854416.552952.2916831\">★★★★
\n", "
\n", "\n", "
\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#This one requires knowng that each Results object holds a list of gatesets\n", "# from each GST intation along with the corresponding gate strings that were used.\n", "w.FitComparisonTable(gss.Ls, results1.gatestring_structs['iteration'],\n", " results1.estimates['default'].gatesets['iteration estimates'], ds1)" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "data": { "text/html": [ "
\n", "
\n", "
GateSet 2Δ(log L) k 2Δ(log L)-k 2k Nsigma Ns Np Rating
GS1174.854413737.854416.552952.2916831\">★★★★
GS24080.2391373943.23916.552952×10216831\">★★
GS31011.162137874.161916.5529552.816831\">★★★
\n", "
\n", "\n", "
\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# We can reuse 'gss' for all three since the gate sequences are the same.\n", "w.FitComparisonTable([\"GS1\",\"GS2\",\"GS3\"], [gss, gss, gss], [gs1,gs2,gs3], ds1, Xlabel=\"GateSet\")" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "collapsed": false, "deletable": true, "editable": true, "scrolled": false }, "outputs": [ { "data": { "text/html": [ "
\n", "
\n", "
Gate Choi matrix (Pauli-Product basis) Eigenvalue Magnitudes
Gi$ \\begin{pmatrix}\n", "0.945288 & 0.010275e^{i0.457\\pi} & 0.008389e^{i0.461\\pi} & 0.003784e^{i0.585\\pi} \\\\ \n", "0.010275e^{-i0.457\\pi} & 0.015084 & 0.00101e^{i0.446\\pi} & 0.00151e^{i0.239\\pi} \\\\ \n", "0.008389e^{-i0.461\\pi} & 0.00101e^{-i0.446\\pi} & 0.020759 & 0.001615e^{-i0.671\\pi} \\\\ \n", "0.003784e^{-i0.585\\pi} & 0.00151e^{-i0.239\\pi} & 0.001615e^{i0.671\\pi} & 0.018868\n", " \\end{pmatrix} $\n", "
\n", "
\n", "
\n", "
\n", "\n", "
\n", "
Gx$ \\begin{pmatrix}\n", "0.481096 & 0.462824e^{i0.501\\pi} & 0.000737e^{i0.583\\pi} & 0.000757e^{i0.540\\pi} \\\\ \n", "0.462824e^{-i0.501\\pi} & 0.481492 & 0.001962e^{i0.015\\pi} & 0.000775e^{-i0.922\\pi} \\\\ \n", "0.000737e^{-i0.583\\pi} & 0.001962e^{-i0.015\\pi} & 0.017386 & 0.00086e^{i0.479\\pi} \\\\ \n", "0.000757e^{-i0.540\\pi} & 0.000775e^{i0.922\\pi} & 0.00086e^{-i0.479\\pi} & 0.020027\n", " \\end{pmatrix} $\n", "
\n", "
\n", "
\n", "
\n", "\n", "
\n", "
Gy$ \\begin{pmatrix}\n", "0.480139 & 0.002583e^{i0.523\\pi} & 0.463077e^{i0.500\\pi} & 0.000684e^{i0.419\\pi} \\\\ \n", "0.002583e^{-i0.523\\pi} & 0.017842 & 0.000197e^{-i0.340\\pi} & 0.000052e^{i0.742\\pi} \\\\ \n", "0.463077e^{-i0.500\\pi} & 0.000197e^{i0.340\\pi} & 0.485588 & 0.000687e^{i0.914\\pi} \\\\ \n", "0.000684e^{-i0.419\\pi} & 0.000052e^{-i0.742\\pi} & 0.000687e^{-i0.914\\pi} & 0.016431\n", " \\end{pmatrix} $\n", "
\n", "
\n", "
\n", "
\n", "\n", "
\n", "
\n", "
\n", "\n", "
\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "w.ChoiTable(gs3, display=('matrix','barplot'))" ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "collapsed": false, "deletable": true, "editable": true, "scrolled": true }, "outputs": [ { "data": { "text/html": [ "
\n", "
\n", "
\n", "
\n", "\n", "
\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", "
\n", "
\n", "
\n", "\n", "
\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "w.GateMatrixPlot(gs1['Gx'],scale=1.0, boxLabels=True,ylabel=\"hello\")\n", "w.GateMatrixPlot(pygsti.tools.error_generator(gs1['Gx'], tgt['Gx'], 'pp'), scale=1.5)" ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "data": { "text/html": [ "
\n", "
\n", "
\n", "
\n", "\n", "
\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from pygsti.construction import std2Q_XYCNOT\n", "w.GateMatrixPlot(std2Q_XYCNOT.gs_target['Gxi'],scale=1.0, boxLabels=False,ylabel=\"hello\",mxBasis=\"pp\")" ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "data": { "text/html": [ "
\n", "
\n", "
\n", "
\n", "\n", "
\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mx = np.array( \n", "[[ 7.3380823, 8.28446943, 7.4593754, 3.91256384, 0.68631199],\n", " [ 3.36139818, 7.42955114, 6.78516082, 0.35863173, 5.57713093],\n", " [ 2.61489939, 3.40182958, 6.77389064, 9.29736475, 0.33824271],\n", " [ 9.64258149, 9.45928809, 6.91516602, 5.61423854, 0.56480777],\n", " [ 2.15195669, 9.37588783, 5.1781991, 7.20087591, 1.46096288]], 'd')\n", "cMap = pygsti.report.colormaps.LinlogColormap(vmin=0, vmax=10, n_boxes=25, pcntle=0.55, dof_per_box=1, color='blue')\n", "w.MatrixPlot(mx, colormap=cMap, colorbar=False)" ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "data": { "text/html": [ "
\n", "
\n", "
\n", "
\n", "\n", "
\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mx = np.identity(3,'d')\n", "mx[0,1] = 2.1\n", "mx[2,2] = 4.0\n", "mx[2,0] = 3.0\n", "mx[0,2] = 7.0\n", "mx[2,1] = 10.0\n", "mx[0,0] = np.nan\n", "cMap = pygsti.report.colormaps.PiecewiseLinearColormap(\n", " [[0,(0,0.5,0)],[1,(0,1.0,0)],[2,(1.0,1.0,0)],\n", " [4,(1.0,0.5,0)],[10,(1.0,0,0)]])\n", "#print(cMap.get_colorscale())\n", "w.MatrixPlot(mx, colormap=cMap, colorbar=False, grid=\"white:1\", boxLabels=True, prec=2,\n", " xlabels=('TP',\"CPTP\",\"full\"),ylabels=(\"DS0\",\"DS1\",\"DS2\"))" ] }, { "cell_type": "code", "execution_count": 19, "metadata": { "collapsed": false, "deletable": true, "editable": true, "scrolled": false }, "outputs": [ { "data": { "text/html": [ "
\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", "
\n", "
\n", "\n", "
\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "w.ErrgenTable(gs3,tgt)" ] }, { "cell_type": "code", "execution_count": 20, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "data": { "text/html": [ "
\n", "
\n", "
\n", "
\n", "\n", "
\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "w.PolarEigenvaluePlot([np.linalg.eigvals(gs2['Gx'])],[\"purple\"],scale=1.5)" ] }, { "cell_type": "code", "execution_count": 21, "metadata": { "collapsed": false, "deletable": true, "editable": true, "scrolled": false }, "outputs": [ { "data": { "text/html": [ "
\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", "
\n", "
\n", "\n", "
\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "w.GateEigenvalueTable(gs2, display=('evals','polar'))" ] }, { "cell_type": "code", "execution_count": 22, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "data": { "text/html": [ "
\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.005597 \\\\ \n", "-0.005597\n", " \\end{pmatrix} $\n", "π0.011194π
\n", "
\n", "
\n", "
\n", "\n", "
\n", "
00.323973π0.193153π
Gx$ \\begin{pmatrix}\n", "0.248752 \\\\ \n", "-0.248752\n", " \\end{pmatrix} $\n", "π0.497505π
\n", "
\n", "
\n", "
\n", "\n", "
\n", "
00.323973π0.502221π
Gy$ \\begin{pmatrix}\n", "-0.250936 \\\\ \n", "0.250936\n", " \\end{pmatrix} $\n", "π0.501872π
\n", "
\n", "
\n", "
\n", "\n", "
\n", "
00.193153π0.502221π
\n", "
\n", "\n", "
\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "w.GateDecompTable(gs1,gs_target)\n", "#w.old_GateDecompTable(gs1) #historical; 1Q only" ] }, { "cell_type": "code", "execution_count": 23, "metadata": { "collapsed": false, "deletable": true, "editable": true, "scrolled": false }, "outputs": [ { "data": { "text/html": [ "
\n", "
\n", "
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", "π
\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π
\n", "
\n", "\n", "
\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", "
\n", "
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", "
00.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", "
00.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", "
00.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", "
00.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.0042020.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.0009360.5π0.500001π0.499999π0.499999π0.5π
\n", "
\n", "\n", "
\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#Note 2Q angle decompositions\n", "from pygsti.construction import std2Q_XXYYII\n", "from pygsti.construction import std2Q_XYCNOT\n", "\n", "w.GateDecompTable(std2Q_XXYYII.gs_target, std2Q_XXYYII.gs_target)\n", "\n", "import scipy\n", "I = np.array([[1,0],[0,1]],'complex')\n", "X = np.array([[0,1],[1,0]],'complex')\n", "Y = np.array([[0,1j],[-1j,0]],'complex')\n", "XX = np.kron(X,X)\n", "YY = np.kron(Y,Y)\n", "IX = np.kron(I,X)\n", "XI = np.kron(X,I)\n", "testU = scipy.linalg.expm(-1j*np.pi/2*XX)\n", "testS = pygsti.unitary_to_process_mx(testU)\n", "testS = pygsti.change_basis(testS,\"std\",\"pp\")\n", "\n", "std2Q_XYCNOT.gs_target.gates['Gtest'] = testS\n", "w.GateDecompTable(std2Q_XYCNOT.gs_target, std2Q_XYCNOT.gs_target)" ] }, { "cell_type": "code", "execution_count": 24, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "data": { "text/html": [ "
\n", "
\n", "
\n", "
\n", "\n", "
\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dsLabels = [\"A\",\"B\",\"C\"]\n", "datasets = [ds1, ds2, ds3]\n", "dscmps = {}\n", "for i,ds1 in enumerate(datasets):\n", " for j,ds2 in enumerate(datasets[i+1:],start=i+1):\n", " dscmps[(i,j)] = pygsti.objects.DataComparator([datasets[i],datasets[j]])\n", "\n", "w.DatasetComparisonSummaryPlot(dsLabels, dscmps)" ] }, { "cell_type": "code", "execution_count": 25, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "data": { "text/html": [ "
\n", "
\n", "
\n", "
\n", "\n", "
\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "w.DatasetComparisonHistogramPlot(dscmps[(1,2)])" ] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "### Saving figures to file\n", "You can also save plot and figures to separate files using their `saveas` method. The output format is determined by the file extension, and allowed extensions are:\n", "\n", "- 'pdf': Adobe portable document format\n", "- 'tex': LaTeX source (uncompiled, *tables only*)\n", "- 'pkl': Python pickle (of a pandas `DataFrame` for tables, a dict for plots)\n", "- 'html': A stand-alone HTML document" ] }, { "cell_type": "code", "execution_count": 26, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "data": { "text/html": [ "
\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
Gi0.0736770.0491180.0763470.0765440.0733440.048896
Gx0.0771530.0514350.0773370.0773620.0771190.051413
Gy0.0745620.0497080.0746870.074710.074540.049693
\n", "
\n", "\n", "
\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "obj = w.GatesVsTargetTable(gs1, tgt)\n", "#obj = w.ErrgenTable(gs3,tgt)\n", "#obj = w.ColorBoxPlot((\"logl\",), gss, ds1, gs1, typ='boxes')\n", "\n", "obj.saveas(\"tutorial_files/tempTest/testSave.pdf\")\n", "obj.saveas(\"tutorial_files/tempTest/testSave.tex\")\n", "obj.saveas(\"tutorial_files/tempTest/testSave.pkl\")\n", "obj.saveas(\"tutorial_files/tempTest/testSave.html\")" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true, "deletable": true, "editable": true }, "source": [ "## Exporting to HTML\n", "If you want, you can save this notebook as an HTML file by going to **File => Download As => HTML** in the Jupyter menu. The resulting file will retain all of the plot interactivity, so long as its in a directory with an `offline` folder (because we set `connected=False` above)." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true, "deletable": true, "editable": 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": 2 }