{ "cells": [ { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "# Getting started with pyGSTi and Gate Set Tomography" ] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "The `pygsti` package provides multiple levels of abstraction over the core Gate Set Tomography (GST) algorithms. This initial tutorial will show you how to run Gate Set Tomography on some simulated (generated) data, hopefully giving you an overall sense of what it takes (and how easy it is!) to run GST. Subsequent tutorials will delve into the details of `pygsti` objects and algorithms, and how to use them in detail.\n", "\n", "To run GST, we need three inputs:\n", "1. a \"**target gate set**\" which describes the desired, or ideal, operations we want our experimental hardware to perform. In the example below, we use one of pyGSTi's \"standard\" gate sets - the on acting on a single qubit with the following operations:\n", " - three gates: the identity, and $\\pi/2$ rotations around the $x$- and $y$-axes.\n", " - a single state preparation in the $|0\\rangle$ state.\n", " - a 2-outcome measurement with the label \"0\" associated with measuring $|0\\rangle$ and \"1\" with measuring $|1\\rangle$.\n", " \n", "2. a list of GST sequences corresponding to the target gate set; essentially a list of what experiments (= gate sequences) we need to run. Using a standard gate set makes things especially straightforward here, since the building blocks, called *germ* and *fiducial* sequences needed to make good GST sequences have already been computed.\n", "\n", "3. data, in the form of experimental outcome counts, for each of the required sequences. In this example we'll generate \"fake\" or \"simulated\" data from a depolarized version of our ideal gate set.\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [], "source": [ "#Make print statements compatible with Python 2 and 3\n", "from __future__ import print_function\n", "\n", "#Import the pygsti module (always do this) and the standard XYI gate set\n", "import pygsti\n", "from pygsti.construction import std1Q_XYI\n", "\n", "# 1) get the target GateSet\n", "gs_target = std1Q_XYI.gs_target\n", "\n", "# 2) get the building blocks needed to specify which gate sequences are needed\n", "prep_fiducials, meas_fiducials = std1Q_XYI.prepStrs, std1Q_XYI.effectStrs\n", "germs = std1Q_XYI.germs\n", "maxLengths = [1,2,4,8,16,32] # roughly gives the length of the sequences used by GST\n", "\n", "# 3) generate \"fake\" data from a depolarized version of gs_target\n", "gs_datagen = gs_target.depolarize(gate_noise=0.1, spam_noise=0.001)\n", "listOfExperiments = pygsti.construction.make_lsgst_experiment_list(\n", " gs_target, prep_fiducials, meas_fiducials, germs, maxLengths)\n", "ds = pygsti.construction.generate_fake_data(gs_datagen, listOfExperiments, nSamples=1000,\n", " sampleError=\"binomial\", seed=1234)\n", "\n", "#Note: from listOfExperiments we can also create an empty dataset file\n", "# which has columns of zeros where actual data should go. \n", "pygsti.io.write_empty_dataset(\"tutorial_files/GettingStartedDataTemplate.txt\", listOfExperiments,\n", " \"## Columns = 1 count, count total\")\n", "# After replacing the zeros with actual data, the data set can be \n", "# loaded back into pyGSTi using the line below and used in the rest\n", "# of this tutorial. \n", "#ds = pygsti.io.load_dataset(\"tutorial_files/GettingStartedDataTemplate.txt\")\n" ] }, { "cell_type": "markdown", "metadata": { "collapsed": false, "deletable": true, "editable": true }, "source": [ "Now that we have all of the inputs, we can run GST in a standard way using the `do_stdpractice_gst` high-level driver function. This returns a `pygsti.report.Results` object, from which we can generate a report giving us a summary of the analysis. " ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "-- Std Practice: Iter 1 of 3 (TP) --: \n", " --- Gate Sequence Creation ---\n", " --- LGST ---\n", " --- Iterative MLGST: [##################################################] 100.0% 1702 gate strings ---\n", " Iterative MLGST Total Time: 5.6s\n", " --- Re-optimizing logl after robust data scaling ---\n", " -- Performing 'single' gauge optimization on TP estimate --\n", " -- Performing 'single' gauge optimization on TP.Robust+ estimate --\n", "-- Std Practice: Iter 2 of 3 (CPTP) --: \n", " --- Gate Sequence Creation ---\n", " --- Iterative MLGST: [##################################################] 100.0% 1702 gate strings ---\n", " Iterative MLGST Total Time: 7.3s\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "\n", "WARNING: MLGST failed to improve logl: retaining chi2-objective estimate\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ " --- Re-optimizing logl after robust data scaling ---\n", " -- Performing 'single' gauge optimization on CPTP estimate --\n", " -- Performing 'single' gauge optimization on CPTP.Robust+ estimate --\n", "-- Std Practice: Iter 3 of 3 (Target) --: \n", " --- Gate Sequence Creation ---\n", " -- Performing 'single' gauge optimization on Target estimate --\n", "*** Creating workspace ***\n", "*** Generating switchboard ***\n", "Found standard clifford compilation from std1Q_XYI\n", "Found standard clifford compilation from std1Q_XYI\n", "Found standard clifford compilation from std1Q_XYI\n", "*** Generating tables ***\n", " targetSpamBriefTable took 0.024079 seconds\n", " targetGatesBoxTable took 0.049723 seconds\n", " datasetOverviewTable took 0.039473 seconds\n", " bestGatesetSpamParametersTable took 0.001409 seconds\n", " bestGatesetSpamBriefTable took 0.055416 seconds\n", " bestGatesetSpamVsTargetTable took 0.128986 seconds\n", " bestGatesetGaugeOptParamsTable took 0.000854 seconds\n", " bestGatesetGatesBoxTable took 0.060875 seconds\n", " bestGatesetChoiEvalTable took 0.093545 seconds\n", " bestGatesetDecompTable took 0.10065 seconds\n", " bestGatesetEvalTable took 0.006569 seconds\n", " bestGermsEvalTable took 0.034415 seconds\n", " bestGatesetVsTargetTable took 0.684849 seconds\n", " bestGatesVsTargetTable_gv took 0.250023 seconds\n", " bestGatesVsTargetTable_gvgerms took 0.12361 seconds\n", " bestGatesVsTargetTable_gi took 0.024128 seconds\n", " bestGatesVsTargetTable_gigerms took 0.041821 seconds\n", " bestGatesVsTargetTable_sum took 0.258897 seconds\n", " bestGatesetErrGenBoxTable took 0.287524 seconds\n", " metadataTable took 0.058242 seconds\n", " stdoutBlock took 0.000254 seconds\n", " profilerTable took 0.051182 seconds\n", " softwareEnvTable took 0.040222 seconds\n", " exampleTable took 0.008485 seconds\n", " singleMetricTable_gv took 0.262942 seconds\n", " singleMetricTable_gi took 0.027719 seconds\n", " fiducialListTable took 0.000513 seconds\n", " prepStrListTable took 0.000213 seconds\n", " effectStrListTable took 0.000173 seconds\n", " colorBoxPlotKeyPlot took 0.008731 seconds\n", " germList2ColTable took 0.000237 seconds\n", " progressTable took 5.194163 seconds\n", "*** Generating plots ***\n", " gramBarPlot took 0.07588 seconds\n", " progressBarPlot took 0.494943 seconds\n", " progressBarPlot_sum took 0.000721 seconds\n", " finalFitComparePlot took 0.124227 seconds\n", " bestEstimateColorBoxPlot took 53.459833 seconds\n", " bestEstimateTVDColorBoxPlot took 75.98059 seconds\n", " bestEstimateColorScatterPlot took 67.750746 seconds\n", " bestEstimateColorHistogram took 44.380899 seconds\n", " progressTable_scl took 7.325267 seconds\n", " progressBarPlot_scl took 0.456446 seconds\n", " bestEstimateColorBoxPlot_scl took 26.304752 seconds\n", " bestEstimateColorScatterPlot_scl took 29.553466 seconds\n", " bestEstimateColorHistogram_scl took 24.489201 seconds\n", " dataScalingColorBoxPlot took 0.20727 seconds\n", "*** Merging into template file ***\n", " Rendering dataScalingColorBoxPlot took 0.031526 seconds\n", " Rendering targetGatesBoxTable took 0.04459 seconds\n", " Rendering bestEstimateColorScatterPlot_scl took 0.077408 seconds\n", " Rendering bestGatesetGaugeOptParamsTable took 0.002586 seconds\n", " Rendering progressBarPlot_sum took 0.00886 seconds\n", " Rendering exampleTable took 0.00435 seconds\n", " Rendering metricSwitchboard_gi took 5.9e-05 seconds\n", " Rendering bestGatesVsTargetTable_gvgerms took 0.01121 seconds\n", " Rendering progressTable_scl took 0.009098 seconds\n", " Rendering bestGatesetEvalTable took 0.047385 seconds\n", " Rendering progressBarPlot_scl took 0.004798 seconds\n", " Rendering topSwitchboard took 0.000179 seconds\n", " Rendering fiducialListTable took 0.003567 seconds\n", " Rendering finalFitComparePlot took 0.003468 seconds\n", " Rendering singleMetricTable_gv took 0.010852 seconds\n", " Rendering bestGatesetVsTargetTable took 0.002282 seconds\n", " Rendering progressTable took 0.013737 seconds\n", " Rendering bestEstimateColorHistogram_scl took 0.061162 seconds\n", " Rendering progressBarPlot took 0.009722 seconds\n", " Rendering targetSpamBriefTable took 0.046351 seconds\n", " Rendering bestEstimateTVDColorBoxPlot took 0.169958 seconds\n", " Rendering bestEstimateColorBoxPlot took 0.149958 seconds\n", " Rendering singleMetricTable_gi took 0.008114 seconds\n", " Rendering prepStrListTable took 0.002203 seconds\n", " Rendering datasetOverviewTable took 0.000727 seconds\n", " Rendering gramBarPlot took 0.009352 seconds\n", " Rendering bestEstimateColorHistogram took 0.097909 seconds\n", " Rendering bestGatesetErrGenBoxTable took 0.165587 seconds\n", " Rendering bestGatesVsTargetTable_gv took 0.007542 seconds\n", " Rendering metadataTable took 0.00877 seconds\n", " Rendering bestGatesetSpamVsTargetTable took 0.005208 seconds\n", " Rendering bestGatesVsTargetTable_gigerms took 0.013734 seconds\n", " Rendering bestGermsEvalTable took 0.17799 seconds\n", " Rendering profilerTable took 0.003852 seconds\n", " Rendering colorBoxPlotKeyPlot took 0.008674 seconds\n", " Rendering bestGatesetSpamParametersTable took 0.004761 seconds\n", " Rendering softwareEnvTable took 0.003435 seconds\n", " Rendering metricSwitchboard_gv took 6.6e-05 seconds\n", " Rendering bestGatesetChoiEvalTable took 0.054143 seconds\n", " Rendering bestGatesetSpamBriefTable took 0.087761 seconds\n", " Rendering bestEstimateColorScatterPlot took 0.125594 seconds\n", " Rendering bestGatesVsTargetTable_gi took 0.012523 seconds\n", " Rendering bestEstimateColorBoxPlot_scl took 0.120259 seconds\n", " Rendering bestGatesetDecompTable took 0.069713 seconds\n", " Rendering bestGatesetGatesBoxTable took 0.104572 seconds\n", " Rendering effectStrListTable took 0.002777 seconds\n", " Rendering maxLSwitchboard1 took 0.000195 seconds\n", " Rendering bestGatesVsTargetTable_sum took 0.011025 seconds\n", " Rendering stdoutBlock took 0.0017 seconds\n", " Rendering germList2ColTable took 0.003185 seconds\n", "Output written to tutorial_files/gettingStartedReport directory\n", "*** Report Generation Complete! Total time 340.85s ***\n" ] }, { "data": { "text/plain": [ "" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#Run GST and create a report\n", "results = pygsti.do_stdpractice_gst(ds, gs_target, prep_fiducials, meas_fiducials, germs, maxLengths)\n", "pygsti.report.create_standard_report(results, filename=\"tutorial_files/gettingStartedReport\",\n", " title=\"Tutorial0 Example Report\", verbosity=2)" ] }, { "cell_type": "markdown", "metadata": { "collapsed": false, "deletable": true, "editable": true }, "source": [ "You can now open the file [tutorial_files/gettingStartedReport/main.html](tutorial_files/gettingStartedReport/main.html) in your browser to view the report. **That's it! You've just run GST!**\n", "\n", "The other tutorials in this directory will explain how to use the various objects and algorithms that comprise pyGSTi. These **tutorial notebooks are meant to be fairly pedagogical** and include details about the inner workings of and design choices within pyGSTi. In contrast, the **\"FAQ\" directory contains notebooks with attempt to address specific questions as quickly and directly as possible, with little or no explanation of related topics or broader context**. " ] }, { "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": 0 }