{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Getting started with pyGSTi and Gate Set Tomography" ] }, { "cell_type": "markdown", "metadata": {}, "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": {}, "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": {}, "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": {}, "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: 8.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: 9.9s\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.029784 seconds\n", " targetGatesBoxTable took 0.073533 seconds\n", " datasetOverviewTable took 0.067227 seconds\n", " bestGatesetSpamParametersTable took 0.001424 seconds\n", " bestGatesetSpamBriefTable took 0.078665 seconds\n", " bestGatesetSpamVsTargetTable took 0.600843 seconds\n", " bestGatesetGaugeOptParamsTable took 0.001099 seconds\n", " bestGatesetGatesBoxTable took 0.099083 seconds\n", " bestGatesetChoiEvalTable took 0.13824 seconds\n", " bestGatesetDecompTable took 0.126771 seconds\n", " bestGatesetEvalTable took 0.01089 seconds\n", " bestGermsEvalTable took 0.046017 seconds\n", " bestGatesetVsTargetTable took 1.00876 seconds\n", " bestGatesVsTargetTable_gv took 1.750243 seconds\n", " bestGatesVsTargetTable_gvgerms took 0.265853 seconds\n", " bestGatesVsTargetTable_gi took 0.040023 seconds\n", " bestGatesVsTargetTable_gigerms took 0.078355 seconds\n", " bestGatesVsTargetTable_sum took 1.75444 seconds\n", " bestGatesetErrGenBoxTable took 0.346165 seconds\n", " metadataTable took 0.076896 seconds\n", " stdoutBlock took 0.000291 seconds\n", " profilerTable took 0.001549 seconds\n", " softwareEnvTable took 0.014964 seconds\n", " exampleTable took 0.01149 seconds\n", " singleMetricTable_gv took 1.743935 seconds\n", " singleMetricTable_gi took 0.041049 seconds\n", " fiducialListTable took 0.000722 seconds\n", " prepStrListTable took 0.000168 seconds\n", " effectStrListTable took 0.000159 seconds\n", " colorBoxPlotKeyPlot took 0.010593 seconds\n", " germList2ColTable took 0.000259 seconds\n", " progressTable took 7.121575 seconds\n", "*** Generating plots ***\n", " gramBarPlot took 0.08473 seconds\n", " progressBarPlot took 0.792423 seconds\n", " progressBarPlot_sum took 0.001194 seconds\n", " finalFitComparePlot took 0.195339 seconds\n", " bestEstimateColorBoxPlot took 36.530809 seconds\n", " bestEstimateTVDColorBoxPlot took 36.321816 seconds\n", " bestEstimateColorScatterPlot took 42.492365 seconds\n", " bestEstimateColorHistogram took 35.946169 seconds\n", " progressTable_scl took 6.923695 seconds\n", " progressBarPlot_scl took 0.522607 seconds\n", " bestEstimateColorBoxPlot_scl took 24.227339 seconds\n", " bestEstimateColorScatterPlot_scl took 28.239644 seconds\n", " bestEstimateColorHistogram_scl took 24.613683 seconds\n", " dataScalingColorBoxPlot took 0.198145 seconds\n", "*** Merging into template file ***\n", " Rendering topSwitchboard took 0.000246 seconds\n", " Rendering maxLSwitchboard1 took 0.000136 seconds\n", " Rendering targetSpamBriefTable took 0.040771 seconds\n", " Rendering targetGatesBoxTable took 0.03743 seconds\n", " Rendering datasetOverviewTable took 0.000966 seconds\n", " Rendering bestGatesetSpamParametersTable took 0.003958 seconds\n", " Rendering bestGatesetSpamBriefTable took 0.073358 seconds\n", " Rendering bestGatesetSpamVsTargetTable took 0.00688 seconds\n", " Rendering bestGatesetGaugeOptParamsTable took 0.002755 seconds\n", " Rendering bestGatesetGatesBoxTable took 0.072141 seconds\n", " Rendering bestGatesetChoiEvalTable took 0.054203 seconds\n", " Rendering bestGatesetDecompTable took 0.04594 seconds\n", " Rendering bestGatesetEvalTable took 0.052549 seconds\n", " Rendering bestGermsEvalTable took 0.179015 seconds\n", " Rendering bestGatesetVsTargetTable took 0.002305 seconds\n", " Rendering bestGatesVsTargetTable_gv took 0.011405 seconds\n", " Rendering bestGatesVsTargetTable_gvgerms took 0.024074 seconds\n", " Rendering bestGatesVsTargetTable_gi took 0.008997 seconds\n", " Rendering bestGatesVsTargetTable_gigerms took 0.012173 seconds\n", " Rendering bestGatesVsTargetTable_sum took 0.009914 seconds\n", " Rendering bestGatesetErrGenBoxTable took 0.134905 seconds\n", " Rendering metadataTable took 0.008872 seconds\n", " Rendering stdoutBlock took 0.001558 seconds\n", " Rendering profilerTable took 0.004032 seconds\n", " Rendering softwareEnvTable took 0.003016 seconds\n", " Rendering exampleTable took 0.006037 seconds\n", " Rendering metricSwitchboard_gv took 9e-05 seconds\n", " Rendering metricSwitchboard_gi took 6.1e-05 seconds\n", " Rendering singleMetricTable_gv took 0.013462 seconds\n", " Rendering singleMetricTable_gi took 0.00785 seconds\n", " Rendering fiducialListTable took 0.002778 seconds\n", " Rendering prepStrListTable took 0.002255 seconds\n", " Rendering effectStrListTable took 0.002011 seconds\n", " Rendering colorBoxPlotKeyPlot took 0.006833 seconds\n", " Rendering germList2ColTable took 0.003413 seconds\n", " Rendering progressTable took 0.016861 seconds\n", " Rendering gramBarPlot took 0.006237 seconds\n", " Rendering progressBarPlot took 0.005492 seconds\n", " Rendering progressBarPlot_sum took 0.005855 seconds\n", " Rendering finalFitComparePlot took 0.002357 seconds\n", " Rendering bestEstimateColorBoxPlot took 0.146263 seconds\n", " Rendering bestEstimateTVDColorBoxPlot took 0.136855 seconds\n", " Rendering bestEstimateColorScatterPlot took 0.112607 seconds\n", " Rendering bestEstimateColorHistogram took 0.08189 seconds\n", " Rendering progressTable_scl took 0.013337 seconds\n", " Rendering progressBarPlot_scl took 0.005941 seconds\n", " Rendering bestEstimateColorBoxPlot_scl took 0.089555 seconds\n", " Rendering bestEstimateColorScatterPlot_scl took 0.072658 seconds\n", " Rendering bestEstimateColorHistogram_scl took 0.060206 seconds\n", " Rendering dataScalingColorBoxPlot took 0.024509 seconds\n", "Output written to tutorial_files/gettingStartedReport directory\n", "*** Report Generation Complete! Total time 254.7s ***\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": {}, "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": {}, "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.6.5" } }, "nbformat": 4, "nbformat_minor": 1 }