{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import pygsti\n", "import json" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Loading from cache file: tutorial_files/Example_Dataset.txt.cache\n" ] } ], "source": [ "# Follow Algorithm tutorial to generate LSGST 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.optimize_gauge(gs_lgst, \"target\", targetGateset=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 LSGST 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": 3, "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", " --> Higheset number of amplified parameters was 19\n", "Beginning search for a good set of 2 pairs (630 pair lists to test)\n", " --> Higheset number of amplified parameters was 30\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", "rhoEPairs = pygsti.alg.find_sufficient_fiducial_pairs(gs_target, fiducialList, fiducialList, germList, verbosity=1)\n", "print rhoEPairs" ] }, { "cell_type": "code", "execution_count": 4, "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": 5, "metadata": { "collapsed": false, "scrolled": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "--- Iterative LSGST: Beginning iter 1 of 10 : 92 gate strings ---\n", "--- Least Squares GST ---\n", " Sum of Chi^2 = 48.2156 (92 data params - 40 model params = expected mean of 52; p-value = 0.623488)\n", "\n", "--- Iterative LSGST: Beginning iter 2 of 10 : 92 gate strings ---\n", "--- Least Squares GST ---\n", " Sum of Chi^2 = 48.2156 (92 data params - 40 model params = expected mean of 52; p-value = 0.623489)\n", "\n", "--- Iterative LSGST: Beginning iter 3 of 10 : 95 gate strings ---\n", "--- Least Squares GST ---\n", " Sum of Chi^2 = 51.0054 (95 data params - 40 model params = expected mean of 55; p-value = 0.627974)\n", "\n", "--- Iterative LSGST: Beginning iter 4 of 10 : 114 gate strings ---\n", "--- Least Squares GST ---\n", " Sum of Chi^2 = 76.4723 (114 data params - 40 model params = expected mean of 74; p-value = 0.399098)\n", "\n", "--- Iterative LSGST: Beginning iter 5 of 10 : 146 gate strings ---\n", "--- Least Squares GST ---\n", " Sum of Chi^2 = 117.016 (146 data params - 40 model params = expected mean of 106; p-value = 0.218495)\n", "\n", "--- Iterative LSGST: Beginning iter 6 of 10 : 178 gate strings ---\n", "--- Least Squares GST ---\n", " Sum of Chi^2 = 145.915 (178 data params - 40 model params = expected mean of 138; p-value = 0.305874)\n", "\n", "--- Iterative LSGST: Beginning iter 7 of 10 : 210 gate strings ---\n", "--- Least Squares GST ---\n", " Sum of Chi^2 = 190.552 (210 data params - 40 model params = expected mean of 170; p-value = 0.13384)\n", "\n", "--- Iterative LSGST: Beginning iter 8 of 10 : 242 gate strings ---\n", "--- Least Squares GST ---\n", " Sum of Chi^2 = 233.121 (242 data params - 40 model params = expected mean of 202; p-value = 0.0657696)\n", "\n", "--- Iterative LSGST: Beginning iter 9 of 10 : 274 gate strings ---\n", "--- Least Squares GST ---\n", " Sum of Chi^2 = 267.547 (274 data params - 40 model params = expected mean of 234; p-value = 0.0651749)\n", "\n", "--- Iterative LSGST: Beginning iter 10 of 10 : 306 gate strings ---\n", "--- Least Squares GST ---\n", " Sum of Chi^2 = 291.434 (306 data params - 40 model params = expected mean of 266; p-value = 0.136086)\n" ] } ], "source": [ "lsgstListOfLists = pygsti.construction.make_lsgst_lists(gs_target.keys(), fiducialList, germList,\n", " maxLengthList, rhoEPairs)\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": 6, "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, "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "*** Generating tables ***\n", "Generating targetSpamTable table...\n", "Generating targetGatesTable table...\n", "Generating datasetOverviewTable table...\n", "Generating bestGatesetSpamTable table...\n", "Generating bestGatesetSpamParametersTable table...\n", "Generating bestGatesetGatesTable table...\n", "Generating bestGatesetChoiTable table...\n", "Generating bestGatesetDecompTable table...\n", "Generating bestGatesetRotnAxisTable table...\n", "Generating bestGatesetClosestUnitaryTable table...\n", "Generating bestGatesetVsTargetTable table...\n", "Generating bestGatesetErrorGenTable table...\n", "Generating fiducialListTable table...\n", "Generating rhoStrListTable table...\n", "Generating EStrListTable table...\n", "Generating germListTable table...\n", "Generating chi2ProgressTable table...\n", "*** Generating plots ***\n", " -- Chi2 plots (2): 1 Generating bestEstimateColorBoxPlot figure...\n", "2 Generating invertedBestEstimateColorBoxPlot figure...\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, rhoEPairs)\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": [] }, { "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.3" } }, "nbformat": 4, "nbformat_minor": 0 }