{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "## Steps for running basic GST Algorithms" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Setup" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [], "source": [ "#Step 1: Import the GST module -- you probably want this at the beginning of every notebook\n", "import pygsti\n", "import json" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Loading from cache file: tutorial_files/Example_Dataset.txt.cache\n", "Loading from cache file: tutorial_files/Example_Dataset_LowCnts.txt.cache\n", "Loaded target gateset with gate labels: ['Gi', 'Gx', 'Gy']\n", "Loaded fiducial list of length: 6\n", "Loaded dataset of length: 2737\n" ] } ], "source": [ "#Step 2: Load target gateset, dataset, and list of fiducial gate strings. In this case we load directly from files created in past tutorials\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", "dsLowCounts = pygsti.io.load_dataset(\"tutorial_files/Example_Dataset_LowCnts.txt\", cache=True)\n", "fiducialList = pygsti.io.load_gatestring_list(\"tutorial_files/Example_FiducialList.txt\")\n", "\n", "depol_gateset = gs_target.depolarize(gate_noise=0.1)\n", "\n", "#Could also load a fiducial dictionary file like this:\n", "#fiducialDict = GST.load_gatestring_dict(\"Example_FiducialList.txt\")\n", "#fiducialList = fiducialDict.values() #all we really need are the fiducial strings themselves\n", "\n", "print \"Loaded target gateset with gate labels: \",gs_target.keys()\n", "print \"Loaded fiducial list of length: \",len(fiducialList)\n", "print \"Loaded dataset of length: \",len(ds)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### LGST to get an initial estimate" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [], "source": [ "#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\")" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "rhoVec[0] = 0.7096 0.0234 -0.0264 0.7466\n", "\n", "\n", "EVec[0] = 0.6872 -0.0084 0.0009 -0.6489\n", "\n", "\n", "Gi = \n", " 0.9955 0.0094 -0.0005 -0.0030\n", " -0.0045 0.9273 -0.0507 -0.0053\n", " 0.0160 0.0100 0.8971 0.0237\n", " -0.0009 0.0026 0.0196 0.9062\n", "\n", "\n", "Gx = \n", " 1.0021 0.0017 -0.0021 -0.0004\n", " 0.0097 0.9089 -0.0134 -0.0030\n", " 0.0141 -0.0198 -0.0171 0.9948\n", " -0.0563 -0.0285 -0.8119 0.0049\n", "\n", "\n", "Gy = \n", " 0.9932 0.0041 -0.0154 -0.0084\n", " -0.0427 0.0114 -0.0031 -0.9818\n", " 0.0087 0.0059 0.8893 -0.0201\n", " -0.0624 0.8159 -0.0134 -0.0042\n", "\n", "\n", "\n" ] } ], "source": [ "print gs_lgst" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Extended LGST (eLGST)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "--- Iterative eLGST: Beginning iter 1 of 10 : 3 gate strings ---\n", "--- eLGST (least squares) ---\n", " Sum of minimum least squares error (w/out reg terms) = 7.40069e-32\n", " frobenius distance to target = 0.0573635151888\n", "\n", "--- Iterative eLGST: Beginning iter 2 of 10 : 4 gate strings ---\n", "--- eLGST (least squares) ---\n", " Sum of minimum least squares error (w/out reg terms) = 1.80731e-30\n", " frobenius distance to target = 0.0573635151888\n", "\n", "--- Iterative eLGST: Beginning iter 3 of 10 : 8 gate strings ---\n", "--- eLGST (least squares) ---\n", " Sum of minimum least squares error (w/out reg terms) = 0.0146807\n", " frobenius distance to target = 0.0577479001878\n", "\n", "--- Iterative eLGST: Beginning iter 4 of 10 : 18 gate strings ---\n", "--- eLGST (least squares) ---\n", " Sum of minimum least squares error (w/out reg terms) = 0.0793128\n", " frobenius distance to target = 0.057722007158\n", "\n", "--- Iterative eLGST: Beginning iter 5 of 10 : 29 gate strings ---\n", "--- eLGST (least squares) ---\n", " Sum of minimum least squares error (w/out reg terms) = 0.123323\n", " frobenius distance to target = 0.0579279771484\n", "\n", "--- Iterative eLGST: Beginning iter 6 of 10 : 40 gate strings ---\n", "--- eLGST (least squares) ---\n", " Sum of minimum least squares error (w/out reg terms) = 0.193558\n", " frobenius distance to target = 0.0575583465307\n", "\n", "--- Iterative eLGST: Beginning iter 7 of 10 : 51 gate strings ---\n", "--- eLGST (least squares) ---\n", " Sum of minimum least squares error (w/out reg terms) = 0.271269\n", " frobenius distance to target = 0.0575235722462\n", "\n", "--- Iterative eLGST: Beginning iter 8 of 10 : 62 gate strings ---\n", "--- eLGST (least squares) ---\n", " Sum of minimum least squares error (w/out reg terms) = 0.343526\n", " frobenius distance to target = 0.057539360534\n", "\n", "--- Iterative eLGST: Beginning iter 9 of 10 : 73 gate strings ---\n", "--- eLGST (least squares) ---\n", " Sum of minimum least squares error (w/out reg terms) = 0.400736\n", " frobenius distance to target = 0.0575433931016\n", "\n", "--- Iterative eLGST: Beginning iter 10 of 10 : 84 gate strings ---\n", "--- eLGST (least squares) ---\n", " Sum of minimum least squares error (w/out reg terms) = 0.474292\n", " frobenius distance to target = 0.0575443735376\n" ] } ], "source": [ "#Get rho and E specifiers, needed by LGST\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\"))\n", "elgstListOfLists = [ pygsti.io.load_gatestring_list(\"tutorial_files/Example_eLGSTlist%d.txt\" % l) for l in maxLengthList]\n", " \n", "gs_exlgst = pygsti.do_iterative_exlgst(ds, gs_clgst, specs, elgstListOfLists, targetGateset=gs_target,\n", " svdTruncateTo=4, verbosity=2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Minimum-$\\chi^2$ GST (MC2GST)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": 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 : 168 gate strings ---\n", "--- Least Squares GST ---\n", " Sum of Chi^2 = 130.576 (168 data params - 40 model params = expected mean of 128; p-value = 0.420134)\n", "\n", "--- Iterative LSGST: Beginning iter 4 of 10 : 441 gate strings ---\n", "--- Least Squares GST ---\n", " Sum of Chi^2 = 422.595 (441 data params - 40 model params = expected mean of 401; p-value = 0.219844)\n", "\n", "--- Iterative LSGST: Beginning iter 5 of 10 : 817 gate strings ---\n", "--- Least Squares GST ---\n", " Sum of Chi^2 = 768.626 (817 data params - 40 model params = expected mean of 777; p-value = 0.577799)\n", "\n", "--- Iterative LSGST: Beginning iter 6 of 10 : 1201 gate strings ---\n", "--- Least Squares GST ---\n", " Sum of Chi^2 = 1153.92 (1201 data params - 40 model params = expected mean of 1161; p-value = 0.553056)\n", "\n", "--- Iterative LSGST: Beginning iter 7 of 10 : 1585 gate strings ---\n", "--- Least Squares GST ---\n", " Sum of Chi^2 = 1605.8 (1585 data params - 40 model params = expected mean of 1545; p-value = 0.137498)\n", "\n", "--- Iterative LSGST: Beginning iter 8 of 10 : 1969 gate strings ---\n", "--- Least Squares GST ---\n", " Sum of Chi^2 = 2041.44 (1969 data params - 40 model params = expected mean of 1929; p-value = 0.0369745)\n", "\n", "--- Iterative LSGST: Beginning iter 9 of 10 : 2353 gate strings ---\n", "--- Least Squares GST ---\n", " Sum of Chi^2 = 2430 (2353 data params - 40 model params = expected mean of 2313; p-value = 0.0444016)\n", "\n", "--- Iterative LSGST: Beginning iter 10 of 10 : 2737 gate strings ---\n", "--- Least Squares GST ---\n", " Sum of Chi^2 = 2799.74 (2737 data params - 40 model params = expected mean of 2697; p-value = 0.0821746)\n" ] } ], "source": [ "#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\"))\n", "lsgstListOfLists = [ pygsti.io.load_gatestring_list(\"tutorial_files/Example_LSGSTlist%d.txt\" % l) for l in maxLengthList]\n", " \n", "gs_mc2 = pygsti.do_iterative_mc2gst(ds, gs_clgst, lsgstListOfLists, verbosity=2,\n", " minProbClipForWeighting=1e-6, probClipInterval=(-1e6,1e6) )" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [], "source": [ "pygsti.io.write_gateset(gs_exlgst, \"tutorial_files/Example_eLGST_Gateset.txt\",\"# Example result from running eLGST\")\n", "pygsti.io.write_gateset(gs_mc2, \"tutorial_files/Example_MC2GST_Gateset.txt\",\"# Example result from running MC2GST\")" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": 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 = 71.5877 (92 data params - 40 model params = expected mean of 52; p-value = 0.0371042)\n", "\n", "--- Iterative LSGST: Beginning iter 2 of 10 : 92 gate strings ---\n", "--- Least Squares GST ---\n", " Sum of Chi^2 = 71.5877 (92 data params - 40 model params = expected mean of 52; p-value = 0.0371046)\n", "\n", "--- Iterative LSGST: Beginning iter 3 of 10 : 168 gate strings ---\n", "--- Least Squares GST ---\n", " Sum of Chi^2 = 165.482 (168 data params - 40 model params = expected mean of 128; p-value = 0.0143613)\n", "\n", "--- Iterative LSGST: Beginning iter 4 of 10 : 441 gate strings ---\n", "--- Least Squares GST ---\n", " Sum of Chi^2 = 428.861 (441 data params - 40 model params = expected mean of 401; p-value = 0.162233)\n", "\n", "--- Iterative LSGST: Beginning iter 5 of 10 : 817 gate strings ---\n", "--- Least Squares GST ---\n", " Sum of Chi^2 = 769.85 (817 data params - 40 model params = expected mean of 777; p-value = 0.565529)\n", "\n", "--- Iterative LSGST: Beginning iter 6 of 10 : 1201 gate strings ---\n", "--- Least Squares GST ---\n", " Sum of Chi^2 = 1182.06 (1201 data params - 40 model params = expected mean of 1161; p-value = 0.326984)\n", "\n", "--- Iterative LSGST: Beginning iter 7 of 10 : 1585 gate strings ---\n", "--- Least Squares GST ---\n", " Sum of Chi^2 = 1549.4 (1585 data params - 40 model params = expected mean of 1545; p-value = 0.463693)\n", "\n", "--- Iterative LSGST: Beginning iter 8 of 10 : 1969 gate strings ---\n", "--- Least Squares GST ---\n", " Sum of Chi^2 = 1900.6 (1969 data params - 40 model params = expected mean of 1929; p-value = 0.673166)\n", "\n", "--- Iterative LSGST: Beginning iter 9 of 10 : 2353 gate strings ---\n", "--- Least Squares GST ---\n", " Sum of Chi^2 = 2295.93 (2353 data params - 40 model params = expected mean of 2313; p-value = 0.59553)\n", "\n", "--- Iterative LSGST: Beginning iter 10 of 10 : 2737 gate strings ---\n", "--- Least Squares GST ---\n", " Sum of Chi^2 = 2670.41 (2737 data params - 40 model params = expected mean of 2697; p-value = 0.638414)\n" ] } ], "source": [ "gs_mc2_lowcnts = pygsti.do_iterative_mc2gst(dsLowCounts, gs_clgst, lsgstListOfLists, verbosity=2,\n", " minProbClipForWeighting=1e-6, probClipInterval=(-1e6,1e6) )" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Maximum Likelihood GST (MLGST)" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false, "scrolled": true }, "outputs": [], "source": [ "maxLengthList = json.load(open(\"tutorial_files/Example_maxLengths.json\",\"r\"))\n", "lsgstListOfLists = [ pygsti.io.load_gatestring_list(\"tutorial_files/Example_LSGSTlist%d.txt\" % l) for l in maxLengthList] " ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "--- Iterative MLEGST: 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.623489)\n", " 2*Delta(log(L)) = 48.4602\n", "\n", "--- Iterative MLEGST: 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", " 2*Delta(log(L)) = 48.4603\n", "\n", "--- Iterative MLEGST: Beginning iter 3 of 10 : 168 gate strings ---\n", "--- Least Squares GST ---\n", " Sum of Chi^2 = 130.576 (168 data params - 40 model params = expected mean of 128; p-value = 0.420139)\n", " 2*Delta(log(L)) = 130.935\n", "\n", "--- Iterative MLEGST: Beginning iter 4 of 10 : 441 gate strings ---\n", "--- Least Squares GST ---\n", " Sum of Chi^2 = 422.578 (441 data params - 40 model params = expected mean of 401; p-value = 0.220013)\n", " 2*Delta(log(L)) = 423.427\n", "\n", "--- Iterative MLEGST: Beginning iter 5 of 10 : 817 gate strings ---\n", "--- Least Squares GST ---\n", " Sum of Chi^2 = 768.607 (817 data params - 40 model params = expected mean of 777; p-value = 0.577988)\n", " 2*Delta(log(L)) = 770.358\n", "\n", "--- Iterative MLEGST: Beginning iter 6 of 10 : 1201 gate strings ---\n", "--- Least Squares GST ---\n", " Sum of Chi^2 = 1153.91 (1201 data params - 40 model params = expected mean of 1161; p-value = 0.553172)\n", " 2*Delta(log(L)) = 1156.04\n", "\n", "--- Iterative MLEGST: Beginning iter 7 of 10 : 1585 gate strings ---\n", "--- Least Squares GST ---\n", " Sum of Chi^2 = 1605.78 (1585 data params - 40 model params = expected mean of 1545; p-value = 0.137556)\n", " 2*Delta(log(L)) = 1608.31\n", "\n", "--- Iterative MLEGST: Beginning iter 8 of 10 : 1969 gate strings ---\n", "--- Least Squares GST ---\n", " Sum of Chi^2 = 2041.43 (1969 data params - 40 model params = expected mean of 1929; p-value = 0.0369934)\n", " 2*Delta(log(L)) = 2044.46\n", "\n", "--- Iterative MLEGST: Beginning iter 9 of 10 : 2353 gate strings ---\n", "--- Least Squares GST ---\n", " Sum of Chi^2 = 2429.98 (2353 data params - 40 model params = expected mean of 2313; p-value = 0.0444223)\n", " 2*Delta(log(L)) = 2433.43\n", "\n", "--- Iterative MLEGST: Beginning iter 10 of 10 : 2737 gate strings ---\n", "--- Least Squares GST ---\n", " Sum of Chi^2 = 2799.7 (2737 data params - 40 model params = expected mean of 2697; p-value = 0.082264)\n", " 2*Delta(log(L)) = 2803.55\n", "--- Last Iteration: switching to MLE objective ---\n", "--- MLEGST ---\n", " Maximum log(L) = 1401.43 below upper bound of -4.60013e+06\n", " 2*Delta(log(L)) = 2802.85 (2737 data params - 40 model params = expected mean of 2697; p-value = 0.0760873)\n", " 2*Delta(log(L)) = 2802.85\n" ] } ], "source": [ "gs_mle = pygsti.do_iterative_mlgst(ds, gs_clgst, lsgstListOfLists, probClipInterval=[-1e2,1e2], verbosity=2)" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "collapsed": false, "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "--- Iterative MLEGST: Beginning iter 1 of 10 : 92 gate strings ---\n", "--- Least Squares GST ---\n", " Sum of Chi^2 = 71.5875 (92 data params - 40 model params = expected mean of 52; p-value = 0.0371053)\n", " 2*Delta(log(L)) = 73.4362\n", "\n", "--- Iterative MLEGST: Beginning iter 2 of 10 : 92 gate strings ---\n", "--- Least Squares GST ---\n", " Sum of Chi^2 = 71.5875 (92 data params - 40 model params = expected mean of 52; p-value = 0.0371053)\n", " 2*Delta(log(L)) = 73.4369\n", "\n", "--- Iterative MLEGST: Beginning iter 3 of 10 : 168 gate strings ---\n", "--- Least Squares GST ---\n", " Sum of Chi^2 = 165.482 (168 data params - 40 model params = expected mean of 128; p-value = 0.0143616)\n", " 2*Delta(log(L)) = 169.245\n", "\n", "--- Iterative MLEGST: Beginning iter 4 of 10 : 441 gate strings ---\n", "--- Least Squares GST ---\n", " Sum of Chi^2 = 428.861 (441 data params - 40 model params = expected mean of 401; p-value = 0.162234)\n", " 2*Delta(log(L)) = 440.777\n", "\n", "--- Iterative MLEGST: Beginning iter 5 of 10 : 817 gate strings ---\n", "--- Least Squares GST ---\n", " Sum of Chi^2 = 769.847 (817 data params - 40 model params = expected mean of 777; p-value = 0.565559)\n", " 2*Delta(log(L)) = 789.389\n", "\n", "--- Iterative MLEGST: Beginning iter 6 of 10 : 1201 gate strings ---\n", "--- Least Squares GST ---\n", " Sum of Chi^2 = 1182.06 (1201 data params - 40 model params = expected mean of 1161; p-value = 0.327019)\n", " 2*Delta(log(L)) = 1210.06\n", "\n", "--- Iterative MLEGST: Beginning iter 7 of 10 : 1585 gate strings ---\n", "--- Least Squares GST ---\n", " Sum of Chi^2 = 1549.4 (1585 data params - 40 model params = expected mean of 1545; p-value = 0.463726)\n", " 2*Delta(log(L)) = 1583.82\n", "\n", "--- Iterative MLEGST: Beginning iter 8 of 10 : 1969 gate strings ---\n", "--- Least Squares GST ---\n", " Sum of Chi^2 = 1900.6 (1969 data params - 40 model params = expected mean of 1929; p-value = 0.67319)\n", " 2*Delta(log(L)) = 1941.34\n", "\n", "--- Iterative MLEGST: Beginning iter 9 of 10 : 2353 gate strings ---\n", "--- Least Squares GST ---\n", " Sum of Chi^2 = 2295.93 (2353 data params - 40 model params = expected mean of 2313; p-value = 0.595548)\n", " 2*Delta(log(L)) = 2345.66\n", "\n", "--- Iterative MLEGST: Beginning iter 10 of 10 : 2737 gate strings ---\n", "--- Least Squares GST ---\n", " Sum of Chi^2 = 2670.4 (2737 data params - 40 model params = expected mean of 2697; p-value = 0.638444)\n", " 2*Delta(log(L)) = 2727.55\n", "--- Last Iteration: switching to MLE objective ---\n", "--- MLEGST ---\n", " Maximum log(L) = 1356.67 below upper bound of -228670\n", " 2*Delta(log(L)) = 2713.34 (2737 data params - 40 model params = expected mean of 2697; p-value = 0.408605)\n", " 2*Delta(log(L)) = 2713.34\n" ] } ], "source": [ "gs_mle_lowcnts = pygsti.do_iterative_mlgst(dsLowCounts, gs_clgst, lsgstListOfLists, \n", " probClipInterval=[-1e2,1e2], verbosity=2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##Compare MLE-GST with LS-GST" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "collapsed": false }, "outputs": [], "source": [ "gs_mle = pygsti.optimize_gauge(gs_mle,\"target\",targetGateset=depol_gateset)\n", "gs_mle_lowcnts = pygsti.optimize_gauge(gs_mle_lowcnts,\"target\",targetGateset=depol_gateset)\n", "gs_mc2 = pygsti.optimize_gauge(gs_mc2,\"target\",targetGateset=depol_gateset)\n", "gs_mc2_lowcnts = pygsti.optimize_gauge(gs_mc2_lowcnts,\"target\",targetGateset=depol_gateset)" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Frobenius diff btwn MLE and datagen = 0.0322203458694\n", "Frobenius diff btwn LSGST and datagen = 0.0356528339106\n", "Frobenius diff btwn MLE and LGST = 0.0119897115646\n", "Frobenius diff btwn MLE and LSGST = 0.00671203679081\n", "Chi^2( LSGST ) = 2799.73646204\n", "Chi^2( MLE ) = 2800.58536739\n", "LogL( LSGST ) = -4601531.87\n", "LogL( MLE ) = -4601531.52007\n" ] } ], "source": [ "print \"Frobenius diff btwn MLE and datagen = \",gs_mle.frobeniusdist(depol_gateset)\n", "print \"Frobenius diff btwn LSGST and datagen = \",gs_mc2.frobeniusdist(depol_gateset)\n", "print \"Frobenius diff btwn MLE and LGST = \",gs_mle.frobeniusdist(gs_clgst)\n", "print \"Frobenius diff btwn MLE and LSGST = \",gs_mle.frobeniusdist(gs_mc2)\n", "print \"Chi^2( LSGST ) = \",pygsti.chi2(ds, gs_mc2, lsgstListOfLists[-1])\n", "print \"Chi^2( MLE ) = \",pygsti.chi2(ds, gs_mle, lsgstListOfLists[-1] )\n", "print \"LogL( LSGST ) = \",pygsti.logl(gs_mc2, ds, lsgstListOfLists[-1], probClipInterval=[1e-4,1-1e-4])\n", "print \"LogL( MLE ) = \",pygsti.logl(gs_mle, ds, lsgstListOfLists[-1], probClipInterval=[1e-4,1-1e-4])" ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Frobenius diff btwn MLE and datagen = 0.0330990970595\n", "Frobenius diff btwn LSGST and datagen = 0.035106972596\n", "Frobenius diff btwn MLE and LGST = 0.0184621381202\n", "Frobenius diff btwn MLE and LSGST = 0.00819647089028\n", "Chi^2( LSGST ) = 2670.40472039\n", "Chi^2( MLE ) = 2684.71978217\n", "LogL( LSGST ) = -230034.070762\n", "LogL( MLE ) = -230026.900449\n" ] } ], "source": [ "print \"Frobenius diff btwn MLE and datagen = \",gs_mle_lowcnts.frobeniusdist(depol_gateset)\n", "print \"Frobenius diff btwn LSGST and datagen = \",gs_mc2_lowcnts.frobeniusdist(depol_gateset)\n", "print \"Frobenius diff btwn MLE and LGST = \",gs_mle_lowcnts.frobeniusdist(gs_clgst)\n", "print \"Frobenius diff btwn MLE and LSGST = \",gs_mle_lowcnts.frobeniusdist(gs_mc2_lowcnts)\n", "print \"Chi^2( LSGST ) = \",pygsti.chi2(dsLowCounts, gs_mc2_lowcnts)\n", "print \"Chi^2( MLE ) = \",pygsti.chi2(dsLowCounts, gs_mle_lowcnts)\n", "print \"LogL( LSGST ) = \",pygsti.logl(gs_mc2_lowcnts, dsLowCounts, probClipInterval=[1e-12,1-1e-12])\n", "print \"LogL( MLE ) = \",pygsti.logl(gs_mle_lowcnts, dsLowCounts, probClipInterval=[1e-12,1-1e-12])" ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "collapsed": true }, "outputs": [], "source": [ "#OLD - construct an old-style gateset, which at one point was needed to keep MLEGST running before\n", "# it was updated.\n", "\n", "#Note: could use gateset with (-1,-1) spam label here to be consistent\n", "# with trace preservation of MLE (opt_G0 = opt_SP0 = False).\n", "#bUseM1M1Gateset = False\n", "#if bUseM1M1Gateset:\n", "# gateset_fixTrace = pygsti.construction.build_gateset( [2], [('Q0',)],['Gi','Gx','Gy'], \n", "# [ \"I(Q0)\",\"X(pi/2,Q0)\", \"Y(pi/2,Q0)\"],\n", "# rhoExpressions=[\"0\"], EExpressions=[\"1\"], \n", "# spamLabelDict={'plus': (0,0), 'minus': (-1,-1) }) #basis=\"gm\" )\n", "#\n", "# specs = pygsti.construction.build_spam_specs(fiducialGateStrings=fiducialList)\n", "# gs_lgst_4mle = pygsti.do_lgst(ds, specs, targetGateset=gateset_fixTrace, svdTruncateTo=4, verbosity=1)\n", "#\n", "# #Gauge optimize the result to match the target gateset\n", "# gs_lgst_4mle_after_gauge_opt = pygsti.optimize_gauge(gs_lgst_4mle, \"target\", targetGateset=gs_target)\n", "#\n", "# #Contract the result to CPTP\n", "# gs_clgst_4mle = pygsti.contract(gs_lgst_4mle_after_gauge_opt, \"CPTP\")\n", "#else:\n", "# gs_clgst_4mle = gs_clgst" ] } ], "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 }