{ "cells": [ { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "# $\\star\\star$ Currently in development. This example doesn't work $\\star\\star$\n", "Some parts of `pygsti` are works-in-progress. Here, we investigate how to do the task of \"model selection\" within GST, essentially answering the question \"Can we do a better job of modeling the experiment by changing the assumptions within GST?\"." ] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "## Testing variable-gateset-dimension GST with model selection" ] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "### Setup" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true, "deletable": true, "editable": true }, "outputs": [], "source": [ "from __future__ import print_function" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [], "source": [ "import pygsti\n", "from pygsti.construction import std1Q_XYI" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [], "source": [ "#Load gateset and some string lists\n", "gs_target = std1Q_XYI.gs_target\n", "fiducialList = std1Q_XYI.fiducials\n", "germList = std1Q_XYI.germs\n", "specs = pygsti.construction.build_spam_specs(fiducialList)\n", "expList = [1,2,4]\n" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [], "source": [ "#Create some testing gate string lists\n", "lgstList = pygsti.construction.list_lgst_gatestrings(specs, gs_target.gates.keys())\n", "lsgstLists = [ lgstList[:] ]\n", "for exp in expList:\n", " gsList = pygsti.construction.create_gatestring_list(\n", " \"f0+germ*exp+f1\", f0=fiducialList, f1=fiducialList,\n", " germ=germList, exp=exp, order=['germ','f0','f1'])\n", " lsgstLists.append( lsgstLists[-1] + gsList )\n", " \n", "dsList = pygsti.remove_duplicates( lsgstLists[-1] )" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "odict_keys(['Gi', 'Gx', 'Gy'])\n" ] }, { "ename": "AssertionError", "evalue": "", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mAssertionError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 22\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 23\u001b[0m \u001b[0mdsFake4\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mpygsti\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mconstruction\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgenerate_fake_data\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mgs_dataGen4\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdsList\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnSamples\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m1000000\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msampleError\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"binomial\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mseed\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m1234\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 24\u001b[0;31m \u001b[0mdsFake5\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mpygsti\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mconstruction\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgenerate_fake_data\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mgs_dataGen5\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdsList\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnSamples\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m1000000\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msampleError\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"binomial\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mseed\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m1234\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[0;32m/Users/enielse/research/pyGSTi/packages/pygsti/construction/datasetconstruction.py\u001b[0m in \u001b[0;36mgenerate_fake_data\u001b[0;34m(gatesetOrDataset, gatestring_list, nSamples, sampleError, seed, randState, aliasDict, collisionAction, measurementGates)\u001b[0m\n\u001b[1;32m 152\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;32mbreak\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 153\u001b[0m \u001b[0;31m#TODO: add adjustment if psum < 1?\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 154\u001b[0;31m \u001b[0;32massert\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m1.\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0mTOL\u001b[0m \u001b[0;34m<=\u001b[0m \u001b[0msum\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mall_ps\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvalues\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m<=\u001b[0m \u001b[0;36m1.\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0mTOL\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 155\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 156\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mnSamples\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mNone\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0mdsGen\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;31mAssertionError\u001b[0m: " ] } ], "source": [ "#Test on fake data by depolarizing target set, increasing its dimension,\n", "# and adding leakage to the gates into the new dimension.\n", "\n", "gs_dataGen4 = gs_target.depolarize(gate_noise=0.1)\n", "gs_dataGen5 = gs_dataGen4.increase_dimension(5)\n", "leakGate = pygsti.construction.build_gate( [2,1],[('Q0',),('L0',)] , \"LX(pi/4.0,0,2)\",\"gm\") # X(pi,Q0)*LX(pi,0,2)\n", "\n", "gs_dataGen5['Gx'] = pygsti.objects.compose( gs_dataGen5['Gx'], leakGate, 'gm')\n", "gs_dataGen5['Gy'] = pygsti.objects.compose( gs_dataGen5['Gy'], leakGate, 'gm')\n", "print(gs_dataGen5.gates.keys())\n", "\n", "#Some debugging...\n", "#NOTE: with LX(pi,0,2) above, dim 5 test will choose a dimension 3 gateset, which may be sensible\n", "# looking at the gate matrices in this case... but maybe LX(pi,...) is faulty?\n", "#print(gs_dataGen4)\n", "#print(gs_dataGen5)\n", "\n", "#Jmx = GST.JOps.jamiolkowski_iso(gs_dataGen4['Gx'])\n", "#Jmx = GST.JOps.jamiolkowski_iso(gs_dataGen5['Gx'],dimOrStateSpaceDims=[2,1])\n", "#print(\"J = \\n\",Jmx)\n", "#print(\"evals = \",eigvals(Jmx))\n", "\n", "dsFake4 = pygsti.construction.generate_fake_data(gs_dataGen4, dsList, nSamples=1000000, sampleError=\"binomial\", seed=1234)\n", "dsFake5 = pygsti.construction.generate_fake_data(gs_dataGen5, dsList, nSamples=1000000, sampleError=\"binomial\", seed=1234)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Number of gates = 3\n", "Number of fiducials = 6\n", "Maximum length for a gate string in ds = 30\n", "Number of LGST strings = 92\n", "Number of LSGST strings = \n" ] } ], "source": [ "print(\"Number of gates = \",len(gs_target.gates.keys()))\n", "print(\"Number of fiducials =\",len(fiducialList))\n", "print(\"Maximum length for a gate string in ds =\",max(map(len,dsList)))\n", "print(\"Number of LGST strings = \",len(lgstList))\n", "print(\"Number of LSGST strings = \",map(len,lsgstLists))" ] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "### Test using dimension-4 fake data" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false, "deletable": true, "editable": true, "scrolled": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "--- LGST ---\n", " Singular values of I_tilde (truncating to first 4 of 6) = \n", " 3.00262981818\n", " 0.825857216429\n", " 0.671539150077\n", " 0.664532662258\n", " 0.000838614351546\n", " 0.000292355239716\n", " \n", " Singular values of target I_tilde (truncating to first 4 of 6) = \n", " 3.0\n", " 1.0\n", " 1.0\n", " 1.0\n", " 2.46365884775e-16\n", " 9.80956846773e-17\n", " \n", " Resulting gate set:\n", " \n", " rho0 = 0.7072 -0.0214 0.0213 0.7510\n", " \n", " \n", " E0 = 0.6847 0.0028 -0.0026 -0.6446\n", " \n", " \n", " Gi = \n", " 1.0002 0 0.0003 -0.0001\n", " -0.0042 0.9000 0.0005 -0.0004\n", " 0.0032 -0.0018 0.8995 -0.0009\n", " -0.0030 0.0002 0.0013 0.8999\n", " \n", " \n", " Gx = \n", " 1.0001 -0.0002 0 0\n", " -0.0037 0.8982 0.0055 0.0005\n", " 0.0006 -0.0014 -0.0052 -1.0001\n", " -0.0624 0.0070 0.8104 0.0065\n", " \n", " \n", " Gy = \n", " 1.0003 0.0002 0 -0.0003\n", " -0.0001 -0.0066 0.0002 0.9989\n", " 0.0041 0.0069 0.8989 0\n", " -0.0625 -0.8098 -0.0065 0.0067\n", " \n", " \n", " \n", "--- LGST ---\n", " Singular values of I_tilde (truncating to first 6 of 6) = \n", " 3.00262981818\n", " 0.825857216429\n", " 0.671539150077\n", " 0.664532662258\n", " 0.000838614351546\n", " 0.000292355239716\n", " \n", " Singular values of target I_tilde (truncating to first 4 of 6) = \n", " 3.0\n", " 1.0\n", " 1.0\n", " 1.0\n", " 2.46365884775e-16\n", " 9.80956846773e-17\n", " \n", " LGST: Padding target B with sqrt of low singular values of I_tilde: \n", " \n", " [ 0.00083861 0.00029236]\n", " Resulting gate set:\n", " \n", " rho0 = 0.7072 -0.0214 0.0213 0.7510 0.0022 -0.0087\n", " \n", " \n", " E0 = 0.6847 0.0028 -0.0026 -0.6446 0.0123 0.0050\n", " \n", " \n", " Gi = \n", " 1.0002 0 0.0003 -0.0001 -0.0047 0.0100\n", " -0.0042 0.9000 0.0005 -0.0004 0.0027 0.0341\n", " 0.0032 -0.0018 0.8995 -0.0009 0.0164 -0.0220\n", " -0.0030 0.0002 0.0013 0.8999 0.0359 0.0568\n", " 0.0012 -0.0156 0.0249 -0.0288 0.4451 -0.8206\n", " 0.0168 -0.0497 0.0435 0.0986 -0.8074 -2.7233\n", " \n", " \n", " Gx = \n", " 1.0001 -0.0002 0 0 0.0034 0.0250\n", " -0.0037 0.8982 0.0055 0.0005 -0.0199 0.0606\n", " 0.0006 -0.0014 -0.0052 -1.0001 -0.0254 0.0212\n", " -0.0624 0.0070 0.8104 0.0065 0.0003 0.0024\n", " -0.0076 -0.0219 -0.0256 0.0008 -0.0984 -1.9243\n", " 0.0070 0.0435 0.0193 -0.0007 0.0558 -0.1647\n", " \n", " \n", " Gy = \n", " 1.0003 0.0002 0 -0.0003 0.0115 -0.0010\n", " -0.0001 -0.0066 0.0002 0.9989 0.0597 -0.0196\n", " 0.0041 0.0069 0.8989 0 -0.0091 -0.0682\n", " -0.0625 -0.8098 -0.0065 0.0067 0.0225 -0.0122\n", " 0.0132 0.0329 0.0020 -0.0336 -0.7649 -0.4999\n", " 0.0009 -0.0169 0.0394 0.0067 0.4817 0.5269\n", " \n", " \n", " \n", "LGST dim=4 chiSq = 377.497001528\n", "LGST dim=6 chiSq = 974.596182221\n", "--- Iterative MC2GST: Iter 1 of 4 92 gate strings ---: \n", " --- Minimum Chi^2 GST with model selection (starting dim = 4) ---\n", " Dim 4: chi^2 = 61.7228, nGateStrings=92, nParams=56 (so expected mean = 36)\n", " Rejected dim 3: chi^2 = 5.51525e+06 (+5.51519e+06 w.r.t. expected mean of 92 strings - 33 params = 59) (dChi^2=5515185, 2*dParams=-46)\n", " Rejected dim 5: chi^2 = 38.326 (+31.326 w.r.t. expected mean of 92 strings - 85 params = 7) (dChi^2=-23, 2*dParams=58)\n", "--- Iterative MC2GST: Iter 2 of 4 488 gate strings ---: \n", " --- Minimum Chi^2 GST with model selection (starting dim = 4) ---\n", " Dim 4: chi^2 = 438.344, nGateStrings=488, nParams=56 (so expected mean = 432)\n", " Rejected dim 3: chi^2 = 4.86648e+07 (+4.86644e+07 w.r.t. expected mean of 488 strings - 33 params = 455) (dChi^2=48664372, 2*dParams=-46)\n", " Rejected dim 5: chi^2 = 393.935 (-9.06498 w.r.t. expected mean of 488 strings - 85 params = 403) (dChi^2=-44, 2*dParams=58)\n", "--- Iterative MC2GST: Iter 3 of 4 884 gate strings ---: \n", " --- Minimum Chi^2 GST with model selection (starting dim = 4) ---\n", " Dim 4: chi^2 = 866.447, nGateStrings=884, nParams=56 (so expected mean = 828)\n", " Rejected dim 3: chi^2 = 7.23237e+07 (+7.23228e+07 w.r.t. expected mean of 884 strings - 33 params = 851) (dChi^2=72322819, 2*dParams=-46)\n", " Rejected dim 5: chi^2 = 828.008 (+29.0078 w.r.t. expected mean of 884 strings - 85 params = 799) (dChi^2=-38, 2*dParams=58)\n", "--- Iterative MC2GST: Iter 4 of 4 1280 gate strings ---: \n", " --- Minimum Chi^2 GST with model selection (starting dim = 4) ---\n", " Dim 4: chi^2 = 1258.19, nGateStrings=1280, nParams=56 (so expected mean = 1224)\n", " Rejected dim 3: chi^2 = 8.374e+07 (+8.37388e+07 w.r.t. expected mean of 1280 strings - 33 params = 1247) (dChi^2=83738775, 2*dParams=-46)\n", " Rejected dim 5: chi^2 = 1213.69 (+18.6931 w.r.t. expected mean of 1280 strings - 85 params = 1195) (dChi^2=-44, 2*dParams=58)\n" ] } ], "source": [ "#Run LGST to get an initial estimate for the gates in gs_target based on the data in ds\n", "# NOTE: with nSamples less than 1M (100K, 10K, 1K) this routine will choose a higher-than-4 dimensional gateset\n", "ds = dsFake4\n", "gs_lgst4 = pygsti.do_lgst(ds, specs, targetGateset=gs_target, svdTruncateTo=4, verbosity=3)\n", "gs_lgst6 = pygsti.do_lgst(ds, specs, targetGateset=gs_target, svdTruncateTo=6, verbosity=3)\n", "\n", "#Print chi^2 of 4-dim and 6-dim estimates\n", "chiSq4 = pygsti.chi2(ds, gs_lgst4, lgstList, minProbClipForWeighting=1e-4)\n", "chiSq6 = pygsti.chi2(ds, gs_lgst6, lgstList, minProbClipForWeighting=1e-4)\n", "print(\"LGST dim=4 chiSq = \", chiSq4)\n", "print(\"LGST dim=6 chiSq = \", chiSq6)\n", "\n", "# Least squares GST with model selection\n", "gs_lsgst = pygsti.do_iterative_mc2gst_with_model_selection(ds, gs_lgst4, 1, lsgstLists, verbosity=2,\n", " minProbClipForWeighting=1e-3, probClipInterval=(-1e5,1e5))" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "rho0 = 0.7072 -0.0217 0.0216 0.7511\n", "\n", "\n", "E0 = 0.6849 0.0022 -0.0021 -0.6447\n", "\n", "\n", "Gi = \n", " 1.0000 0 0 0\n", " -0.0035 0.9001 0.0001 0.0003\n", " 0.0035 0 0.8998 0.0002\n", " -0.0034 -0.0001 0.0002 0.9000\n", "\n", "\n", "Gx = \n", " 1.0000 0 0 0\n", " -0.0037 0.8998 0.0060 0.0004\n", " 0.0004 -0.0004 -0.0063 -0.9999\n", " -0.0625 0.0067 0.8101 0.0064\n", "\n", "\n", "Gy = \n", " 1.0000 0 0 0\n", " -0.0002 -0.0065 0 0.9994\n", " 0.0038 0.0072 0.9000 -0.0009\n", " -0.0624 -0.8105 -0.0059 0.0066\n", "\n", "\n", "\n" ] } ], "source": [ "print(gs_lsgst)" ] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "### Test using dimension-5 fake data" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "--- LGST ---\n", " Singular values of I_tilde (truncating to first 4 of 6) = \n", " 3.56525557364\n", " 0.755465956932\n", " 0.496239591347\n", " 0.487203220172\n", " 0.00691003018424\n", " 0.000321987001111\n", " \n", " Singular values of target I_tilde (truncating to first 4 of 6) = \n", " 3.0\n", " 1.0\n", " 1.0\n", " 1.0\n", " 2.46365884775e-16\n", " 9.80956846773e-17\n", " \n", " Resulting gate set:\n", " \n", " rho0 = 0.6961 -0.0307 0.0425 0.7832\n", " \n", " \n", " E0 = 0.7554 0.0111 -0.0141 -0.6685\n", " \n", " \n", " Gi = \n", " 0.9997 -0.0005 0.0007 -0.0063\n", " -0.0064 0.8998 0.0007 -0.0020\n", " 0.0037 -0.0023 0.8991 -0.0002\n", " -0.0080 0.0006 0.0017 0.9024\n", " \n", " \n", " Gx = \n", " 1.0223 0.0007 0.0476 -0.0050\n", " -0.0039 0.8292 0.0241 -0.0040\n", " 0.0070 0.0263 -0.0403 -1.0042\n", " -0.1197 0.0279 0.6526 0.0271\n", " \n", " \n", " Gy = \n", " 1.0221 -0.0478 -0.0009 -0.0034\n", " -0.0182 -0.0538 0.0319 1.0079\n", " 0.0003 0.0110 0.8295 -0.0148\n", " -0.1260 -0.6490 -0.0304 0.0388\n", " \n", " \n", " \n", "--- LGST ---\n", " Singular values of I_tilde (truncating to first 6 of 6) = \n", " 3.56525557364\n", " 0.755465956932\n", " 0.496239591347\n", " 0.487203220172\n", " 0.00691003018424\n", " 0.000321987001111\n", " \n", " Singular values of target I_tilde (truncating to first 4 of 6) = \n", " 3.0\n", " 1.0\n", " 1.0\n", " 1.0\n", " 2.46365884775e-16\n", " 9.80956846773e-17\n", " \n", " LGST: Padding target B with sqrt of low singular values of I_tilde: \n", " \n", " [ 0.00691003 0.00032199]\n", " Resulting gate set:\n", " \n", " rho0 = 0.6961 -0.0307 0.0425 0.7832 0.0374 -0.0007\n", " \n", " \n", " E0 = 0.7554 0.0111 -0.0141 -0.6685 -0.0376 -0.0002\n", " \n", " \n", " Gi = \n", " 0.9997 -0.0005 0.0007 -0.0063 -0.0015 -0.0020\n", " -0.0064 0.8998 0.0007 -0.0020 -0.0171 -0.0049\n", " 0.0037 -0.0023 0.8991 -0.0002 0.0107 -0.0284\n", " -0.0080 0.0006 0.0017 0.9024 -0.0006 -0.0612\n", " -0.0013 0.0107 -0.0129 0.0197 0.9113 -0.3506\n", " 0.0073 -0.0197 0.0143 0.0980 0.2630 1.7004\n", " \n", " \n", " Gx = \n", " 1.0223 0.0007 0.0476 -0.0050 0.0615 -0.0337\n", " -0.0039 0.8292 0.0241 -0.0040 -0.0141 0.0412\n", " 0.0070 0.0263 -0.0403 -1.0042 0.3136 -0.0878\n", " -0.1197 0.0279 0.6526 0.0271 -0.0017 -0.0003\n", " -0.0748 -0.0036 -0.1573 0.0164 0.6755 -0.4246\n", " 0.0038 0.0568 0.0102 -0.0015 -0.2004 -0.2516\n", " \n", " \n", " Gy = \n", " 1.0221 -0.0478 -0.0009 -0.0034 0.0676 -0.0495\n", " -0.0182 -0.0538 0.0319 1.0079 -0.3170 0.0147\n", " 0.0003 0.0110 0.8295 -0.0148 0.0105 0.0349\n", " -0.1260 -0.6490 -0.0304 0.0388 -0.0006 -0.0394\n", " -0.0798 0.1549 -0.0002 0.0193 0.7669 -0.5002\n", " -0.0245 -0.0182 0.0293 0.0340 -0.1267 -1.7344\n", " \n", " \n", " \n", "LGST dim=4 chiSq = 1236262.37706\n", "LGST dim=6 chiSq = 704616.980106\n", "--- Iterative MC2GST: Iter 1 of 4 92 gate strings ---: \n", " --- Minimum Chi^2 GST with model selection (starting dim = 4) ---\n", " Dim 4: chi^2 = 278034, nGateStrings=92, nParams=56 (so expected mean = 36)\n", " Rejected dim 3: chi^2 = 3.17675e+06 (+3.17669e+06 w.r.t. expected mean of 92 strings - 33 params = 59) (dChi^2=2898715, 2*dParams=-46)\n", " Selected dim 5: chi^2 = 44.5421 (+37.5421 w.r.t. expected mean of 92 strings - 85 params = 7) (dChi^2=-277989, 2*dParams=58)\n", "--- Iterative MC2GST: Iter 2 of 4 488 gate strings ---: \n", " --- Minimum Chi^2 GST with model selection (starting dim = 5) ---\n", " Dim 5: chi^2 = 397.086, nGateStrings=488, nParams=85 (so expected mean = 403)\n", " Rejected dim 4: chi^2 = 1.39997e+06 (+1.39953e+06 w.r.t. expected mean of 488 strings - 56 params = 432) (dChi^2=1399568, 2*dParams=-58)\n", " Rejected dim 6: chi^2 = 338.432 (-29.5677 w.r.t. expected mean of 488 strings - 120 params = 368) (dChi^2=-58, 2*dParams=70)\n", "--- Iterative MC2GST: Iter 3 of 4 884 gate strings ---: \n", " --- Minimum Chi^2 GST with model selection (starting dim = 5) ---\n", " Dim 5: chi^2 = 802.805, nGateStrings=884, nParams=85 (so expected mean = 799)\n", " Rejected dim 4: chi^2 = 2.69456e+06 (+2.69373e+06 w.r.t. expected mean of 884 strings - 56 params = 828) (dChi^2=2693755, 2*dParams=-58)\n", " Rejected dim 6: chi^2 = 757.678 (-6.32234 w.r.t. expected mean of 884 strings - 120 params = 764) (dChi^2=-45, 2*dParams=70)\n", "--- Iterative MC2GST: Iter 4 of 4 1280 gate strings ---: \n", " --- Minimum Chi^2 GST with model selection (starting dim = 5) ---\n", " Dim 5: chi^2 = 1197.51, nGateStrings=1280, nParams=85 (so expected mean = 1195)\n", " Rejected dim 4: chi^2 = 4.21903e+06 (+4.2178e+06 w.r.t. expected mean of 1280 strings - 56 params = 1224) (dChi^2=4217830, 2*dParams=-58)\n", " Rejected dim 6: chi^2 = 1146.27 (-13.7322 w.r.t. expected mean of 1280 strings - 120 params = 1160) (dChi^2=-51, 2*dParams=70)\n" ] } ], "source": [ "#Run LGST to get an initial estimate for the gates in gs_target based on the data in ds\n", "ds = dsFake5\n", "gs_lgst4 = pygsti.do_lgst(ds, specs, targetGateset=gs_target, svdTruncateTo=4, verbosity=3)\n", "gs_lgst6 = pygsti.do_lgst(ds, specs, targetGateset=gs_target, svdTruncateTo=6, verbosity=3)\n", "\n", "#Print chi^2 of 4-dim and 6-dim estimates\n", "chiSq4 = pygsti.chi2(ds, gs_lgst4, lgstList, minProbClipForWeighting=1e-2)\n", "chiSq6 = pygsti.chi2(ds, gs_lgst6, lgstList, minProbClipForWeighting=1e-2)\n", "print(\"LGST dim=4 chiSq = \", chiSq4)\n", "print(\"LGST dim=6 chiSq = \", chiSq6)\n", "\n", "# Least squares GST with model selection\n", "gs_lsgst = pygsti.do_iterative_mc2gst_with_model_selection(ds, gs_lgst4, 1, lsgstLists, verbosity=2, minProbClipForWeighting=1e-3, probClipInterval=(-1e5,1e5), useFreqWeightedChiSq=False, regularizeFactor=1.0, check=False, check_jacobian=False)" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "rho0 = 0.7072 -0.0141 0.0218 0.7481 -0.0373\n", "\n", "\n", "E0 = 0.7007 0.0431 -0.0421 -0.6482 0.2446\n", "\n", "\n", "Gi = \n", " 1.0000 0 0 0 0\n", " -0.0042 0.8991 0.0007 0.0014 -0.0073\n", " 0.0023 0.0004 0.8992 -0.0011 0.0078\n", " -0.0091 -0.0002 0.0004 0.9002 -0.0006\n", " -0.0002 0.0092 -0.0090 -0.0138 1.0004\n", "\n", "\n", "Gx = \n", " 1.0000 0 0.0001 -0.0001 0\n", " -0.0210 0.8322 0.0094 -0.0114 0.0043\n", " 0.0199 0.0222 -0.0175 -1.0220 -0.0412\n", " -0.1081 0.0314 0.6711 0.0272 -0.0476\n", " 0.1734 -0.0049 0.0221 -0.0089 0.7705\n", "\n", "\n", "Gy = \n", " 1.0000 -0.0001 0 -0.0002 0\n", " -0.0364 -0.0359 0.0230 1.0195 0.0415\n", " 0.0164 -0.0023 0.8315 -0.0122 -0.0053\n", " -0.1186 -0.6737 -0.0266 0.0465 -0.0455\n", " 0.1732 -0.0227 0.0049 -0.0071 0.7705\n", "\n", "\n", "\n" ] } ], "source": [ "print(gs_lsgst)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "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.5.2" } }, "nbformat": 4, "nbformat_minor": 0 }