{ "cells": [ { "cell_type": "markdown", "metadata": { "collapsed": false, "deletable": true, "editable": true }, "source": [ "## Tutorial showing use of a `Workspace` object\n", "### Part 2: Switchboards\n", "\n", "\"This tutorial introduces the `Switchboard` workspace object and demonstrates its use. You may have gotten the sense from the last tutorial that screen real estate can quickly be taken up by plots and tables. Wouldn't it me nice if we could interactively switch between plots or figures using buttons or sliders instead of having to scroll through endless pages of plots? `Switchboard` to the rescue!\n", "\n", "First though, let's run GST on the standard 1Q gate set to get some results (the same ones as the first tutorial)." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/Users/enielse/research/pyGSTi/packages/pygsti/tools/matrixtools.py:23: UserWarning: Could not import Cython extension - falling back to slower pure-python routines\n", " _warnings.warn(\"Could not import Cython extension - falling back to slower pure-python routines\")\n" ] } ], "source": [ "import numpy as np\n", "import pygsti\n", "from pygsti.construction import std1Q_XYI\n", "\n", "#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,4,8]\n", "listOfExperiments = pygsti.construction.make_lsgst_experiment_list(\n", " gs_target.gates.keys(), fiducials, fiducials, germs, maxLengths)\n", "\n", "#Create some datasets for analysis\n", "gs_datagen1 = gs_target.depolarize(gate_noise=0.1, spam_noise=0.001)\n", "gs_datagen2 = gs_target.depolarize(gate_noise=0.05, spam_noise=0.01).rotate(rotate=(0.01,0,0))\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()\n", "\n", "#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": [ "Next we create the workspace, as before. This time, we'll leave `autodisplay=False` (the default), to demonstrate how this gives us more control over when workspace items are displayed. In particular, we'll build up a several workspace objects and display them all at once. **NOTE that setting `connected=True` means you need to have an internet connection!**" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "
Loading...
\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "w = pygsti.report.Workspace() #create a new workspace\n", "w.init_notebook_mode(connected=False) # and initialize it so it works within a notebook" ] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "Note that if we create a table it doesn't get displayed automatically." ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [], "source": [ "tbl1 = w.GatesVsTargetTable(gs1, tgt)" ] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "To see it, we need to call `display()`:" ] }, { "cell_type": "code", "execution_count": 4, "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.072510.048340.0725540.0725660.0724910.048328
Gx0.0753940.0502630.07540.0754040.0753860.050257
Gy0.0749810.0499870.0750290.0750320.0749640.049976
\n", "
\n", "\n", "
\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "tbl1.display()" ] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "### Switchboards\n", "A `Switchboard` is essentially a collection of one or more switches along with a dictionary of \"values\" which depend on some or all of the switch positions. Each value looks like a NumPy `ndarray` whose axes correspond to the switches that value depends upon. The array can hold whatever you want: `GateSet`s, `DataSet`s, `float`s, etc., and from the perspective of the plot and table workspace objects the value looks like the thing contained in its array (e.g. a *single* `GateSet`, `DataSet`, or `float`, etc.). \n", "\n", "Let's start off simple and create a switchboard with a single switch named \"My Switch\" that has two positions \"On\" and \"Off\":" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": true, "deletable": true, "editable": true }, "outputs": [], "source": [ "switchbd = w.Switchboard([\"My Switch\"],[[\"On\",\"Off\"]],[\"buttons\"])" ] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "Next, add a \"value\" to the switchboard called \"gs\" (for \"gate set\"), with is dependent on the 0-th (and only) switch of the switchboard:" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": true, "deletable": true, "editable": true }, "outputs": [], "source": [ "switchbd.add(\"gs\", [0])" ] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "Now `switchbd` has a member, `gs`, which looks like a 1-dimensional Numpy array (since `gs` only depends on a single switch) of length 2 (because that single switch has 2 positions). " ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "data": { "text/plain": [ "(2,)" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "switchbd.gs.shape" ] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "We'll use `switchbd.gs` to switch between the gate sets `gs1` and `gs2`. We associate the \"On\" position with `gs1` and the \"Off\" position with `gs2` by simply assigning them to the corresponding locations of the array. Note that we can use NumPy's fancy indexing to make this a breeze." ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": true, "deletable": true, "editable": true }, "outputs": [], "source": [ "switchbd.gs[:] = [gs1,gs2]" ] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "Ok, now here's the magical part: even though `switchbd.gs` is really an array holding `GateSet` objects, when you provide it as an input to create a workspace item such as a plot or a table, it *behaves* like a single `GateSet` and can thus be used for any `GateSet`-type argument. We'll use it as the first argument to `GatesVsTargetTable`. " ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": true, "deletable": true, "editable": true }, "outputs": [], "source": [ "tbl2 = w.GatesVsTargetTable(switchbd.gs, tgt)" ] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "Note the the second argument (`tgt`, the target gate set) in the above call is just a plain old `GateSet`, just like it's always been up to this point. The above line creates a table, `tbl2`, that is *connected* to the switchboard `switchbd`. Let's display both the switchboard and the table together." ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "data": { "text/html": [ "
\n", "
\n", "My Switch: \n", "\n", "\n", "\n", "\n", "
\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "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.072510.048340.0725540.0725660.0724910.048328
Gx0.0753940.0502630.07540.0754040.0753860.050257
Gy0.0749810.0499870.0750290.0750320.0749640.049976
\n", "
\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
Gi0.0372750.024850.0379270.0379440.0372380.024825
Gx0.0386010.0257340.0388730.0388780.0385850.025724
Gy0.0373770.0249180.0374170.0374180.0373740.024916
\n", "
\n", "\n", "
\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "switchbd.display()\n", "tbl2.display()" ] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "My pressing the \"On\" or \"Off\" button the table changes between displaying metrics for `gs1` vs. `tgt` and `gs2` vs. `tgt`, as expected. In this simple example there was one switch controlling on table. It is possible to have any number of switches controlling any number of tables and/or plots, and also to have multiple switchboards controlling a single plot or table. In the following cells, more sophisticated uses of switchboards are demonstrated." ] }, { "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", "\n", "\n", "
\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\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", "\n", "
\n", "
\n", "
\n", "\n", "
\n", "
\n", "
\n", "\n", "
\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# Create a switchboard with straighforward dataset and gateset dropdown switches\n", "switchbd2 = w.Switchboard([\"dataset\",\"gateset\"], [[\"DS1\",\"DS2\",\"DS3\"],[\"GS1\",\"GS2\",\"GS3\"]], [\"dropdown\",\"dropdown\"])\n", "switchbd2.add(\"ds\",(0,))\n", "switchbd2.add(\"gs\",(1,))\n", "switchbd2.ds[:] = [ds1, ds2, ds3]\n", "switchbd2.gs[:] = [gs1, gs2, gs3]\n", "\n", "#Then create a chi2 plot that can show the goodness-of-fit between any gateset-dataset pair\n", "gss2 = gss.copy(); gss2.germs = gss.germs[0:5] #truncate gss to only a subset of the germs\n", "chi2plot = w.ColorBoxPlot((\"chi2\",), gss2, switchbd2.ds, switchbd2.gs, scale=0.75)\n", "\n", "switchbd2.display()\n", "chi2plot.display()" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "collapsed": true, "deletable": true, "editable": true }, "outputs": [], "source": [ "#Perform gauge optimizations of gs1 using different spam weights\n", "spamWts = np.linspace(0.0,1.0,20)\n", "gs_gaugeopts = [ pygsti.gaugeopt_to_target(gs1, tgt,{'gates': 1, 'spam': x}) for x in spamWts]" ] }, { "cell_type": "code", "execution_count": 13, "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/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.072510.048340.072550.0725510.0724910.048328
Gx0.0753940.0502630.0753990.0753990.0753860.050257
Gy0.0749810.0499870.0750280.0750280.0749640.049976
\n", "
\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
Gi0.072510.048340.0725540.0725660.0724910.048328
Gx0.0753940.0502630.07540.0754040.0753860.050257
Gy0.0749810.0499870.0750290.0750320.0749640.049976
\n", "
\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
Gi0.072510.048340.0725540.0725660.0724910.048328
Gx0.0753940.0502630.07540.0754040.0753860.050257
Gy0.0749810.0499870.0750290.0750320.0749640.049976
\n", "
\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
Gi0.072510.048340.0725540.0725660.0724910.048328
Gx0.0753940.0502630.07540.0754040.0753860.050257
Gy0.0749810.0499870.0750290.0750320.0749640.049976
\n", "
\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
Gi0.072510.048340.0725540.0725660.0724910.048328
Gx0.0753940.0502620.07540.0754040.0753860.050257
Gy0.0749810.0499870.0750290.0750330.0749640.049976
\n", "
\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
Gi0.072510.048340.0725540.0725660.0724910.048328
Gx0.0753940.0502620.07540.0754040.0753860.050257
Gy0.0749810.0499870.075030.0750330.0749640.049976
\n", "
\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
Gi0.072510.048340.0725540.0725660.0724910.048328
Gx0.0753940.0502620.07540.0754040.0753860.050257
Gy0.0749810.0499870.075030.0750330.0749640.049976
\n", "
\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
Gi0.072510.048340.0725540.0725660.0724910.048328
Gx0.0753940.0502620.0754010.0754040.0753860.050257
Gy0.0749810.0499870.075030.0750340.0749640.049976
\n", "
\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
Gi0.072510.048340.0725540.0725660.0724910.048328
Gx0.0753940.0502620.0754010.0754050.0753860.050257
Gy0.0749810.0499870.0750310.0750350.0749640.049976
\n", "
\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
Gi0.072510.048340.0725540.0725660.0724910.048328
Gx0.0753940.0502620.0754010.0754050.0753860.050257
Gy0.0749810.0499870.0750310.0750360.0749640.049976
\n", "
\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
Gi0.072510.048340.0725540.0725660.0724910.048328
Gx0.0753940.0502620.0754010.0754050.0753860.050257
Gy0.0749810.0499870.0750320.0750370.0749640.049976
\n", "
\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
Gi0.072510.048340.0725540.0725660.0724910.048328
Gx0.0753940.0502620.0754010.0754060.0753850.050257
Gy0.0749810.0499870.0750320.0750380.0749640.049976
\n", "
\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
Gi0.072510.048340.0725540.0725660.0724910.048328
Gx0.0753940.0502620.0754020.0754060.0753850.050257
Gy0.0749810.0499870.0750330.075040.0749640.049976
\n", "
\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
Gi0.072510.048340.0725540.0725660.0724910.048328
Gx0.0753940.0502620.0754020.0754070.0753850.050257
Gy0.0749810.0499870.0750330.0750420.0749640.049976
\n", "
\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
Gi0.072510.048340.0725540.0725650.0724910.048328
Gx0.0753940.0502620.0754020.0754070.0753850.050257
Gy0.0749810.0499870.0750340.0750430.0749640.049976
\n", "
\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
Gi0.072510.048340.0725540.0725650.0724910.048328
Gx0.0753940.0502620.0754030.0754080.0753850.050257
Gy0.0749810.0499870.0750350.0750450.0749640.049976
\n", "
\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
Gi0.072510.048340.0725540.0725650.0724910.048328
Gx0.0753940.0502620.0754030.0754080.0753850.050257
Gy0.0749810.0499880.0750360.0750470.0749640.049976
\n", "
\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
Gi0.072510.048340.0725540.0725650.0724910.048328
Gx0.0753940.0502620.0754030.0754090.0753850.050257
Gy0.0749810.0499880.0750370.075050.0749640.049976
\n", "
\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
Gi0.072510.048340.0725540.0725650.0724910.048328
Gx0.0753940.0502620.0754040.0754090.0753850.050257
Gy0.0749810.0499880.0750380.0750520.0749640.049976
\n", "
\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
Gi0.072510.048340.0725540.0725650.0724910.048328
Gx0.0753940.0502620.0754040.075410.0753850.050257
Gy0.0749810.0499880.0750390.0750540.0749640.049976
\n", "
\n", "\n", "
\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", "
\n", "
Prep/POVM Infidelity 1/2 Trace Distance 1/2 Diamond-Dist
ρ00.4354970.435498--
Mdefault-3.3780313.3780653.378344
\n", "
\n", "\n", "
\n", "
Prep/POVM Infidelity 1/2 Trace Distance 1/2 Diamond-Dist
ρ0-0.0001420.005372--
Mdefault-0.0001440.0019590.002236
\n", "
\n", "\n", "
\n", "
Prep/POVM Infidelity 1/2 Trace Distance 1/2 Diamond-Dist
ρ0-0.0001550.005316--
Mdefault-0.0001280.0019380.002212
\n", "
\n", "\n", "
\n", "
Prep/POVM Infidelity 1/2 Trace Distance 1/2 Diamond-Dist
ρ0-0.0001350.005243--
Mdefault-0.0001470.0019140.002187
\n", "
\n", "\n", "
\n", "
Prep/POVM Infidelity 1/2 Trace Distance 1/2 Diamond-Dist
ρ0-0.0001380.00516--
Mdefault-0.0001410.0018860.002154
\n", "
\n", "\n", "
\n", "
Prep/POVM Infidelity 1/2 Trace Distance 1/2 Diamond-Dist
ρ0-0.0001480.00507--
Mdefault-0.0001280.0018530.002119
\n", "
\n", "\n", "
\n", "
Prep/POVM Infidelity 1/2 Trace Distance 1/2 Diamond-Dist
ρ0-0.0001590.004974--
Mdefault-0.0001130.0018190.002081
\n", "
\n", "\n", "
\n", "
Prep/POVM Infidelity 1/2 Trace Distance 1/2 Diamond-Dist
ρ0-0.0001390.004872--
Mdefault-0.000130.0017860.002044
\n", "
\n", "\n", "
\n", "
Prep/POVM Infidelity 1/2 Trace Distance 1/2 Diamond-Dist
ρ0-0.0001370.004769--
Mdefault-0.0001270.001750.002004
\n", "
\n", "\n", "
\n", "
Prep/POVM Infidelity 1/2 Trace Distance 1/2 Diamond-Dist
ρ0-0.0001620.004664--
Mdefault-0.0000980.0017130.001961
\n", "
\n", "\n", "
\n", "
Prep/POVM Infidelity 1/2 Trace Distance 1/2 Diamond-Dist
ρ0-0.0001430.004557--
Mdefault-0.0001130.0016770.001922
\n", "
\n", "\n", "
\n", "
Prep/POVM Infidelity 1/2 Trace Distance 1/2 Diamond-Dist
ρ0-0.0001580.004452--
Mdefault-0.0000940.001640.001879
\n", "
\n", "\n", "
\n", "
Prep/POVM Infidelity 1/2 Trace Distance 1/2 Diamond-Dist
ρ0-0.0001510.004346--
Mdefault-0.0000970.0016040.001839
\n", "
\n", "\n", "
\n", "
Prep/POVM Infidelity 1/2 Trace Distance 1/2 Diamond-Dist
ρ0-0.0001720.004241--
Mdefault-0.0000710.0015660.001796
\n", "
\n", "\n", "
\n", "
Prep/POVM Infidelity 1/2 Trace Distance 1/2 Diamond-Dist
ρ0-0.0001570.004137--
Mdefault-0.0000820.0015310.001757
\n", "
\n", "\n", "
\n", "
Prep/POVM Infidelity 1/2 Trace Distance 1/2 Diamond-Dist
ρ0-0.0001470.004035--
Mdefault-0.0000870.0014970.001718
\n", "
\n", "\n", "
\n", "
Prep/POVM Infidelity 1/2 Trace Distance 1/2 Diamond-Dist
ρ0-0.0001420.003934--
Mdefault-0.0000890.0014630.00168
\n", "
\n", "\n", "
\n", "
Prep/POVM Infidelity 1/2 Trace Distance 1/2 Diamond-Dist
ρ0-0.0001380.003836--
Mdefault-0.0000880.001430.001642
\n", "
\n", "\n", "
\n", "
Prep/POVM Infidelity 1/2 Trace Distance 1/2 Diamond-Dist
ρ0-0.0001350.003741--
Mdefault-0.0000860.0013970.001605
\n", "
\n", "\n", "
\n", "
Prep/POVM Infidelity 1/2 Trace Distance 1/2 Diamond-Dist
ρ0-0.0001330.003652--
Mdefault-0.0000850.001370.001573
\n", "
\n", "\n", "
\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# Create a switchboard with a slider that controls the spam-weight used in gauge optimization\n", "switchbd3 = w.Switchboard([\"spam-weight\"], [[\"%.2f\" % x for x in spamWts]], [\"slider\"])\n", "switchbd3.add(\"gsGO\",(0,))\n", "switchbd3.gsGO[:] = gs_gaugeopts\n", "\n", "#Then create a comparison vs. target tables\n", "tbl3 = w.GatesVsTargetTable(switchbd3.gsGO, tgt)\n", "tbl4 = w.SpamVsTargetTable(switchbd3.gsGO, tgt)\n", "\n", "switchbd3.display()\n", "tbl3.display()\n", "tbl4.display()" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "collapsed": false, "deletable": true, "editable": true, "scrolled": false }, "outputs": [ { "data": { "text/html": [ "
\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/html": [ "
\n", "
\n", "\n", "
\n", "
\n", "
\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# Create a slider showing the color box plot at different GST iterations\n", "switchbd4 = w.Switchboard([\"max(L)\"], [list(map(str,gss.Ls))], [\"slider\"])\n", "switchbd4.add(\"gs\",(0,))\n", "switchbd4.add(\"gss\",(0,))\n", "switchbd4.gs[:] = results1.estimates['default'].gatesets['iteration estimates']\n", "switchbd4.gss[:] = results1.gatestring_structs['iteration']\n", " \n", "#Then create a logl plot that can show the goodness-of-fit at different iterations\n", "logLProgress = w.ColorBoxPlot((\"logl\",), switchbd4.gss, ds1, switchbd4.gs, scale=0.75)\n", "\n", "logLProgress.display()\n", "switchbd4.display()" ] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "### Switchboard Views\n", "If you want to duplicate a switch board in order to have the same switches accessible at different (multiple) location in a page, you need to create switchboard *views*. These are somewhat like NumPy array views in that they are windows into some base data - in this case the original `Switchboard` object. Let's create a view of the `Switchboard` above." ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "data": { "text/html": [ "
\n", "
\n", "\n", "
\n", "
\n", "
\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "sbv = switchbd4.view()\n", "sbv.display()" ] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "Note that when you move one slider, the other moves with it. This is because there's really only *one* switch.\n", "\n", "Views don't need to contain *all* of the switches of the base `Switchboard` either. Here's an example where each view only shows only a subset of the switches. We also demonstrate here how the *initial positions* of each switch can be set via the `initial_pos` argument." ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "data": { "text/html": [ "
\n", "
\n", "My Buttons: \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" } ], "source": [ "parent = w.Switchboard([\"My Buttons\",\"My Dropdown\", \"My Slider\"],\n", " [[\"On\",\"Off\"],[\"A\",\"B\",\"C\"],[\"0\",\"0.5\",\"0.8\",\"1.0\"]],\n", " [\"buttons\",\"dropdown\",\"slider\"], initial_pos=[0,1,2])\n", "parent.display()" ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "data": { "text/html": [ "
\n", "
\n", "My Buttons: \n", "\n", "\n", "\n", "\n", "
\n", "\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "buttonsView = parent.view([\"My Buttons\"])\n", "buttonsView.display()" ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "\n", "\n", "
\n", "\n", "
\n", "
\n", "\n", "
\n", "
\n", "
\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "otherView = parent.view([\"My Dropdown\",\"My Slider\"])\n", "otherView.display()" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true, "deletable": true, "editable": true }, "source": [ "### Exporting to HTML\n", "Again, 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 *and switch* interactivity, and in this case doesn't need the `offline` folder (because we set `connected=True` in `init_notebook_mode` above) but does need an internet connection." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true, "deletable": true, "editable": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.10" } }, "nbformat": 4, "nbformat_minor": 2 }