{ "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": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "from __future__ import print_function" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import pygsti\n", "import json" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "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.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 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": null, "metadata": { "collapsed": false }, "outputs": [], "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": null, "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": null, "metadata": { "collapsed": false, "scrolled": false }, "outputs": [], "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": null, "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": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "#optimize each gateset to the target\n", "gs_lsgst_list = [ pygsti.optimize_gauge(gs, \"target\", targetGateset=gs_target) for gs in gs_lsgst_list ]" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false, "scrolled": true }, "outputs": [], "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": [] }, { "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.11" } }, "nbformat": 4, "nbformat_minor": 0 }