{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# An overview of Gate Set tomography the function-based way." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This tutorial shows you how to run gate set tomography using the older-style function-centric API. This can be useful in certain scenarios, but most of the time it's easier to use the newer, object-oriented approach outlined in the main [GST overview tutorial](GST-Overview.ipynb). For more details and options for running GST, see the [GST circuits tutorial](../objects/advanced/GSTCircuitConstruction.ipynb) and the [tutorial covering the different pyGSTi functions for running GST](GST-Drivers.ipynb).\n", "\n", "To run GST, we need three inputs:\n", "1. a \"**target model**\" which describes the desired, or ideal, operations we want our experimental hardware to perform. In the example below, we use one of pyGSTi's build-in \"model packs\" (see the [tutorial on model packs](objects/advanced/ModelPacks.ipynb)) - which acts 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 circuits tailored to the target model; essentially a list of what experiments we need to run. Using a standard model makes things especially straightforward here, since the building blocks, called *germ* and *fiducial* circuits, needed to make good GST circuits have already been computed (see the [tutorial on GST circuits](../objects/advanced/GSTCircuitConstruction.ipynb)).\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 model. For more information about `DataSet` objects, see the [tutorial on DataSets](../objects/DataSet.ipynb).\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "#Import the pygsti module (always do this) and the XYI model pack\n", "import pygsti\n", "from pygsti.modelpacks import smq1Q_XYI\n", "\n", "# 1) get the target Model\n", "target_model = smq1Q_XYI.target_model()\n", "\n", "# 2) get the building blocks needed to specify which operation sequences are needed\n", "prep_fiducials, meas_fiducials = smq1Q_XYI.prep_fiducials(), smq1Q_XYI.meas_fiducials()\n", "germs = smq1Q_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 target_model\n", "mdl_datagen = target_model.depolarize(op_noise=0.01, spam_noise=0.001)\n", "listOfExperiments = pygsti.construction.make_lsgst_experiment_list(\n", " target_model, prep_fiducials, meas_fiducials, germs, maxLengths)\n", "ds = pygsti.construction.generate_fake_data(mdl_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 = 0 count, 1 count\")\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` function. For more information about this and related functions, see the [GST methods tutorial](GST-Drivers.ipynb). This returns a `pygsti.report.Results` object (see the [Results tutorial](../objects/advanced/Results.ipynb)), from which we can generate a report giving us a summary of the analysis. " ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "scrolled": true }, "outputs": [], "source": [ "#Run GST and create a report\n", "results = pygsti.do_stdpractice_gst(ds, target_model, prep_fiducials, meas_fiducials, \n", " germs, maxLengths, verbosity=3)\n", "\n", "pygsti.report.construct_standard_report(\n", " results, title=\"GST Overview Tutorial Example Report\", verbosity=2\n", ").write_html(\"../tutorial_files/gettingStartedReport\", 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 (Firefox works best) to view the report. **That's it! You've just run GST!** \n", "\n", "In the cell above, `results` is a `Results` object, which is used to generate a HTML report. For more information see the [Results object tutorial](../objects/advanced/Results.ipynb) and [report generation tutorial](../reporting/ReportGeneration.ipynb)." ] }, { "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.7.0" } }, "nbformat": 4, "nbformat_minor": 1 }