{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "The purpose of GST's fiducials is to generate an informationally-complete set of states and measurements. However, it's possible to _reduce_ the number of fiducials necessary to do so.\n", "\n", "In this tutorial, we use the `pygsti.alg.find_sufficient_fiducial_pairs` function to reduce the number of fiducials necessary for GST." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "from __future__ import print_function\n", "import matplotlib\n", "matplotlib.use('Agg')" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import pygsti\n", "import json" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Loading tutorial_files/Example_Dataset.txt: 100%\n", "Writing cache file (to speed future loads): tutorial_files/Example_Dataset.txt.cache\n", "--- LGST ---\n" ] } ], "source": [ "# Follow Algorithm tutorial to generate LGST gatesets\n", "gs_target = pygsti.io.load_gateset(\"tutorial_files/Example_Gateset.txt\")\n", "ds = pygsti.io.load_dataset(\"tutorial_files/Example_Dataset.txt\", cache=True)\n", "fiducialList = pygsti.io.load_gatestring_list(\"tutorial_files/Example_FiducialList.txt\")\n", "\n", "#Run LGST to get an initial estimate for the gates in gs_target based on the data in ds\n", "specs = pygsti.construction.build_spam_specs(fiducialGateStrings=fiducialList)\n", "gs_lgst = pygsti.do_lgst(ds, specs, targetGateset=gs_target, svdTruncateTo=4, verbosity=1)\n", "\n", "#Gauge optimize the result to match the target gateset\n", "gs_lgst_after_gauge_opt = pygsti.gaugeopt_to_target(gs_lgst, gs_target)\n", "\n", "#Contract the result to CPTP\n", "gs_clgst = pygsti.contract(gs_lgst_after_gauge_opt, \"CPTP\")\n", "\n", "#Get lists of gate strings for successive iterations of LGST to use\n", "specs = pygsti.construction.build_spam_specs(fiducialGateStrings=fiducialList)\n", "germList = pygsti.io.load_gatestring_list(\"tutorial_files/Example_GermsList.txt\")\n", "maxLengthList = json.load(open(\"tutorial_files/Example_maxLengths.json\",\"r\"))" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "------ Fiducial Pair Reduction --------\n", "maximum number of amplified parameters = 34\n", "Beginning search for a good set of 1 pairs (36 pair lists to test)\n", "Beginning search for a good set of 2 pairs (630 pair lists to test)\n", "Beginning search for a good set of 3 pairs (7140 pair lists to test)\n", "[(0, 0), (0, 1), (1, 0)]\n" ] } ], "source": [ "#Get sufficient set of fiducial pairs, meaning that with these fidicual pairs and the given set of germs,\n", "# the number of gateset parameters which are amplified when all pairs are used are also amplified when using\n", "# the returned subset.\n", "fidPairs = pygsti.alg.find_sufficient_fiducial_pairs(gs_target, fiducialList, fiducialList, germList, verbosity=1)\n", "print(fidPairs)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false, "scrolled": true }, "outputs": [], "source": [ "#Test a specific set of fiducial pairs: see how many gateset parameter are amplified\n", "#FPR.find_sufficient_fiducial_pairs(gs_target, fiducialList, germList, testPairList=[(0,0),(0,1),(1,0)], verbosity=4)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false, "scrolled": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "--- Iterative MC2GST: Iter 01 of 10 92 gate strings ---: \n", " --- Minimum Chi^2 GST ---\n", " Created evaluation tree with 1 subtrees. Will divide 1 procs into 1 (subtree-processing)\n", " groups of ~1 procs each, to distribute over 56 params (taken as 1 param groups of ~56 params).\n", " Sum of Chi^2 = 40.9238 (92 data params - 40 model params = expected mean of 52; p-value = 0.866034)\n", " Completed in 0.2s\n", " Iteration 1 took 0.2s\n", " \n", "--- Iterative MC2GST: Iter 02 of 10 92 gate strings ---: \n", " --- Minimum Chi^2 GST ---\n", " Created evaluation tree with 1 subtrees. Will divide 1 procs into 1 (subtree-processing)\n", " groups of ~1 procs each, to distribute over 56 params (taken as 1 param groups of ~56 params).\n", " Sum of Chi^2 = 40.9238 (92 data params - 40 model params = expected mean of 52; p-value = 0.866034)\n", " Completed in 0.0s\n", " Iteration 2 took 0.0s\n", " \n", "--- Iterative MC2GST: Iter 03 of 10 95 gate strings ---: \n", " --- Minimum Chi^2 GST ---\n", " Created evaluation tree with 1 subtrees. Will divide 1 procs into 1 (subtree-processing)\n", " groups of ~1 procs each, to distribute over 56 params (taken as 1 param groups of ~56 params).\n", " Sum of Chi^2 = 45.7751 (95 data params - 40 model params = expected mean of 55; p-value = 0.80775)\n", " Completed in 0.2s\n", " Iteration 3 took 0.2s\n", " \n", "--- Iterative MC2GST: Iter 04 of 10 114 gate strings ---: \n", " --- Minimum Chi^2 GST ---\n", " Created evaluation tree with 1 subtrees. Will divide 1 procs into 1 (subtree-processing)\n", " groups of ~1 procs each, to distribute over 56 params (taken as 1 param groups of ~56 params).\n", " Sum of Chi^2 = 71.8674 (114 data params - 40 model params = expected mean of 74; p-value = 0.548568)\n", " Completed in 0.3s\n", " Iteration 4 took 0.3s\n", " \n", "--- Iterative MC2GST: Iter 05 of 10 146 gate strings ---: \n", " --- Minimum Chi^2 GST ---\n", " Created evaluation tree with 1 subtrees. Will divide 1 procs into 1 (subtree-processing)\n", " groups of ~1 procs each, to distribute over 56 params (taken as 1 param groups of ~56 params).\n", " Sum of Chi^2 = 115.418 (146 data params - 40 model params = expected mean of 106; p-value = 0.250138)\n", " Completed in 0.3s\n", " Iteration 5 took 0.3s\n", " \n", "--- Iterative MC2GST: Iter 06 of 10 178 gate strings ---: \n", " --- Minimum Chi^2 GST ---\n", " Created evaluation tree with 1 subtrees. Will divide 1 procs into 1 (subtree-processing)\n", " groups of ~1 procs each, to distribute over 56 params (taken as 1 param groups of ~56 params).\n", " Sum of Chi^2 = 149.112 (178 data params - 40 model params = expected mean of 138; p-value = 0.244594)\n", " Completed in 0.4s\n", " Iteration 6 took 0.5s\n", " \n", "--- Iterative MC2GST: Iter 07 of 10 210 gate strings ---: \n", " --- Minimum Chi^2 GST ---\n", " Created evaluation tree with 1 subtrees. Will divide 1 procs into 1 (subtree-processing)\n", " groups of ~1 procs each, to distribute over 56 params (taken as 1 param groups of ~56 params).\n", " Sum of Chi^2 = 189.135 (210 data params - 40 model params = expected mean of 170; p-value = 0.149864)\n", " Completed in 0.5s\n", " Iteration 7 took 0.5s\n", " \n", "--- Iterative MC2GST: Iter 08 of 10 242 gate strings ---: \n", " --- Minimum Chi^2 GST ---\n", " Created evaluation tree with 1 subtrees. Will divide 1 procs into 1 (subtree-processing)\n", " groups of ~1 procs each, to distribute over 56 params (taken as 1 param groups of ~56 params).\n", " Sum of Chi^2 = 238.689 (242 data params - 40 model params = expected mean of 202; p-value = 0.0393795)\n", " Completed in 0.7s\n", " Iteration 8 took 0.7s\n", " \n", "--- Iterative MC2GST: Iter 09 of 10 274 gate strings ---: \n", " --- Minimum Chi^2 GST ---\n", " Created evaluation tree with 1 subtrees. Will divide 1 procs into 1 (subtree-processing)\n", " groups of ~1 procs each, to distribute over 56 params (taken as 1 param groups of ~56 params).\n", " Sum of Chi^2 = 272.022 (274 data params - 40 model params = expected mean of 234; p-value = 0.0444789)\n", " Completed in 0.8s\n", " Iteration 9 took 0.8s\n", " \n", "--- Iterative MC2GST: Iter 10 of 10 306 gate strings ---: \n", " --- Minimum Chi^2 GST ---\n", " Created evaluation tree with 1 subtrees. Will divide 1 procs into 1 (subtree-processing)\n", " groups of ~1 procs each, to distribute over 56 params (taken as 1 param groups of ~56 params).\n", " Sum of Chi^2 = 295.644 (306 data params - 40 model params = expected mean of 266; p-value = 0.102215)\n", " Completed in 1.1s\n", " Iteration 10 took 1.1s\n", " \n", "Iterative MC2GST Total Time: 4.6s\n" ] } ], "source": [ "lsgstListOfLists = pygsti.construction.make_lsgst_lists(gs_target.gates.keys(), fiducialList, fiducialList,\n", " germList, maxLengthList, fidPairs)\n", "\n", "gs_lsgst_list = pygsti.do_iterative_mc2gst(ds, gs_clgst, lsgstListOfLists, verbosity=2,\n", " minProbClipForWeighting=1e-6, probClipInterval=(-1e6,1e6),\n", " returnAll=True )" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# Compute a few additional quantities needed to generate the report\n", "Ls = maxLengthList\n", "gateStrDict = { (L,germ):pygsti.construction.repeat_with_max_length(germ,L,False) for L in Ls for germ in germList }\n", "\n", "#remove duplicates by replacing duplicate strings with None\n", "runningList = []\n", "for L in Ls:\n", " for germ in germList:\n", " if gateStrDict[(L,germ)] in runningList:\n", " gateStrDict[(L,germ)] = None\n", " else: runningList.append( gateStrDict[(L,germ)] )" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [], "source": [ "#optimize each gateset to the target\n", "gs_lsgst_list = [ pygsti.gaugeopt_to_target(gs, gs_target) for gs in gs_lsgst_list ]" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false, "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "*** Generating tables ***\n", " Iter 01 of 19 : Generating table: targetSpamTable [0.0s]\n", " Iter 02 of 19 : Generating table: targetGatesTable [0.0s]\n", " Iter 03 of 19 : Generating table: datasetOverviewTable [0.1s]\n", " Iter 04 of 19 : Generating table: bestGatesetSpamTable [0.0s]\n", " Iter 05 of 19 : Generating table: bestGatesetSpamParametersTable [0.0s]\n", " Iter 06 of 19 : Generating table: bestGatesetGaugeOptParamsTable [0.0s]\n", " Iter 07 of 19 : Generating table: bestGatesetGatesTable [0.0s]\n", " Iter 08 of 19 : Generating table: bestGatesetChoiTable [0.0s]\n", " Iter 09 of 19 : Generating table: bestGatesetDecompTable [0.0s]\n", " Iter 10 of 19 : Generating table: bestGatesetRotnAxisTable [0.0s]\n", " Iter 11 of 19 : Generating table: bestGatesetVsTargetTable [0.3s]\n", " Iter 12 of 19 : Generating table: bestGatesetErrorGenTable [0.0s]\n", " Iter 13 of 19 : Generating table: metadataTable [0.0s]\n", " Iter 14 of 19 : Generating table: softwareEnvTable [0.3s]\n", " Iter 15 of 19 : Generating table: fiducialListTable [0.0s]\n", " Iter 16 of 19 : Generating table: prepStrListTable [0.0s]\n", " Iter 17 of 19 : Generating table: effectStrListTable [0.0s]\n", " Iter 18 of 19 : Generating table: germListTable [0.0s]\n", " Iter 19 of 19 : Generating table: progressTable [0.3s]\n", "*** Generating plots ***\n", "Chi2 plots (2): \n", " Iter 1 of 3 : Generating figure: colorBoxPlotKeyPlot [2.1s]\n", " Iter 2 of 3 : Generating figure: bestEstimateColorBoxPlot [19.4s]\n", " Iter 3 of 3 : Generating figure: invertedBestEstimateColorBoxPlot [25.6s]\n", "\n", "*** Merging into template file ***\n", "Latex file(s) successfully generated. Attempting to compile with pdflatex...\n", "Initial output PDF tutorial_files/Example_report_FR.pdf successfully generated.\n", "Final output PDF tutorial_files/Example_report_FR.pdf successfully generated. Cleaning up .aux and .log files.\n" ] } ], "source": [ "res = pygsti.report.Results()\n", "res.init_Ls_and_germs(\"chi2\", gs_target, ds, gs_clgst, maxLengthList, germList,\n", " gs_lsgst_list, lsgstListOfLists, fiducialList, fiducialList, \n", " pygsti.construction.repeat_with_max_length, False, fidPairs)\n", "\n", "res.create_full_report_pdf(filename=\"tutorial_files/Example_report_FR.pdf\", verbosity=2)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": 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": 0 }