{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "from __future__ import print_function" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [], "source": [ "#Import relevant modules.\n", "\n", "import pygsti\n", "import numpy as _np\n", "\n", "from pygsti.algorithms import fiducialselection as FS\n", "\n", "import matplotlib.pyplot as plt\n", "%matplotlib inline\n", "\n", "import time" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In this notebook, we'll demonstrate how to select preparation and measurement fiducials for a standard two-qubit gate set. By \"standard\", we mean that a) measurements are made in the computational (Z) basis (and state prep is |00>), and b) gate set consists of independent X pi/2 and Y pi/2 gates on each qubit. Presumably there will be additional entangling gates available; however, we do not want (or need) such gates in our fiducial gate strings. (Two-qubit operations will typically be of lower fidelity, so it is \"safer\" to use single-qubit operations for fiducials.)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [], "source": [ "#Build the gate set. As mentioned above, no entangling operation is included; these results will be general for\n", "#any two-qubit gate set that has access to the Gix, Giy, Gxi, and Gyi gates \n", "#(and prepares in the state |00> and performs measurements in the computational basis).\n", "gs_target = pygsti.construction.build_gateset( [4], [('Q0','Q1')],['Gix','Giy','Gxi','Gyi'], \n", " [\"X(pi/2,Q1)\", \"Y(pi/2,Q1)\", \"X(pi/2,Q0)\", \"Y(pi/2,Q0)\"], \n", " prepLabels = [\"rho0\"], prepExpressions = [\"0\"], \n", " effectLabels = [\"E0\",\"E1\",\"E2\"], effectExpressions = [\"0\",\"1\",\"2\"], \n", " spamdefs={'upup': (0,0), 'updn': (0,1), 'dnup': (0,2), 'dndn': (0,-1) },\n", " basis=\"pp\")" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": true }, "outputs": [], "source": [ "#Let's try to pick out a fiducial set. \n", "\n", "#First, we generate a candidate set which we'll attempt to prune.\n", "#We could look at all gate strings of up to a fixed length (using pygsti.construction.list_all_gatestrings),\n", "#but that grows quite rapidly.\n", "#Instead, we'll look at the tensor product of the standard 1-qubit fiducial set with itself.\n", "#This product set we define below.\n", "\n", "#{} x 1q fid list\n", "emptyList = pygsti.construction.gatestring_list([\n", " (),\n", " ('Gix',),\n", " ('Gix','Gix'),\n", " ('Gix','Gix','Gix'),\n", " ('Giy',),\n", " ('Giy','Giy','Giy')\n", " ])\n", "\n", "#Gx x 1q fid list\n", "XList = pygsti.construction.gatestring_list([\n", " ('Gxi',),\n", " ('Gxi','Gix',),\n", " ('Gxi','Gix','Gix'),\n", " ('Gxi','Gix','Gix','Gix'),\n", " ('Gxi','Giy',),\n", " ('Gxi','Giy','Giy','Giy')\n", " ])\n", "\n", "#GxGx x 1q fid list\n", "XXList = pygsti.construction.gatestring_list([\n", " ('Gxi','Gxi'),\n", " ('Gxi','Gxi','Gix',),\n", " ('Gxi','Gxi','Gix','Gix'),\n", " ('Gxi','Gxi','Gix','Gix','Gix'),\n", " ('Gxi','Gxi','Giy',),\n", " ('Gxi','Gxi','Giy','Giy','Giy')\n", " ])\n", "\n", "#GxGxGx x 1q fid list\n", "XXXList = pygsti.construction.gatestring_list([\n", " ('Gxi','Gxi','Gxi'),\n", " ('Gxi','Gxi','Gxi','Gix',),\n", " ('Gxi','Gxi','Gxi','Gix','Gix'),\n", " ('Gxi','Gxi','Gxi','Gix','Gix','Gix'),\n", " ('Gxi','Gxi','Gxi','Giy',),\n", " ('Gxi','Gxi','Gxi','Giy','Giy','Giy')\n", " ])\n", "\n", "#Gy x 1q fid list\n", "YList = pygsti.construction.gatestring_list([\n", " ('Gyi',),\n", " ('Gyi','Gix',),\n", " ('Gyi','Gix','Gix'),\n", " ('Gyi','Gix','Gix','Gix'),\n", " ('Gyi','Giy',),\n", " ('Gyi','Giy','Giy','Giy')\n", " ])\n", "\n", "#Gy x 1q fid list\n", "YYYList = pygsti.construction.gatestring_list([\n", " ('Gyi','Gyi'),\n", " ('Gyi','Gyi','Gyi','Gix',),\n", " ('Gyi','Gyi','Gyi','Gix','Gix'),\n", " ('Gyi','Gyi','Gyi','Gix','Gix','Gix'),\n", " ('Gyi','Gyi','Gyi','Giy',),\n", " ('Gyi','Gyi','Gyi','Giy','Giy','Giy')\n", " ])\n", "\n", "testFidList = emptyList + XList + XXList + XXXList + YList + YYYList\n" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": true }, "outputs": [], "source": [ "#Don't worry if the optimize_integer_fiducials_slack function below throws a divide by zero warning;\n", "#this just means one of the tested cases was *really* bad." ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false, "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Complete initial fiducial set succeeds.\n", "Now searching for best fiducial set.\n", " Starting fiducial set optimization. Lower score is better.\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Stationary point found!\n", "\n", " score = 1468.8\n", " weights = [1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 1 1 1 1 0 0 0 1 1 1 1 0 0 1 1 1 1]\n", " L1(weights) = 16\n", "Final fiducial set succeeds.\n", "\n", "Fiducial selection completed in 0.13008809089660645 seconds.\n", "{}\n", "GyiGiy\n", "GxiGxiGiy\n", "GyiGixGix\n", "GxiGxiGxiGix\n", "GxiGxiGxiGiy\n", "GyiGixGixGix\n", "GyiGiyGiyGiy\n", "GyiGyiGyiGiy\n", "GxiGxiGixGixGix\n", "GxiGxiGiyGiyGiy\n", "GxiGxiGxiGixGix\n", "GyiGyiGyiGixGix\n", "GxiGxiGxiGixGixGix\n", "GyiGyiGyiGixGixGix\n", "GyiGyiGyiGiyGiyGiy\n" ] } ], "source": [ "#We know that we should be able to find a prep fiducial set that has no more than 16 elements,\n", "#so if we are finding sets that are larger than that, we can always increase slackFrac or fixedSlack\n", "start = time.time()\n", "prepFidList1_all = FS.optimize_integer_fiducials_slack(gs_target,testFidList,prepOrMeas='prep',initialWeights=None,\n", " scoreFunc='all',slackFrac=.275)\n", "end = time.time()\n", "print('')\n", "print(\"Fiducial selection completed in\", end-start, \"seconds.\")\n", "print(\"\\n\".join(map(str,sorted(prepFidList1_all,key=len))))" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false, "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Complete initial fiducial set succeeds.\n", "Now searching for best fiducial set.\n", " Starting fiducial set optimization. Lower score is better.\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Stationary point found!\n", "\n", " score = 249.001323854\n", " weights = [1 0 0 1 1 0 0 0 0 0 0 0 0 1 0 0 0 1 1 0 1 1 0 1 0 0 1 1 0 1 1 1 1 0 1 0]\n", " L1(weights) = 16\n", "Final fiducial set succeeds.\n", "\n", "Fiducial selection completed in 0.12403392791748047 seconds.\n", "{}\n", "Giy\n", "GyiGyi\n", "GixGixGix\n", "GxiGxiGix\n", "GxiGxiGxi\n", "GyiGixGix\n", "GyiGixGixGix\n", "GyiGiyGiyGiy\n", "GyiGyiGyiGix\n", "GyiGyiGyiGiy\n", "GxiGxiGiyGiyGiy\n", "GxiGxiGxiGixGix\n", "GyiGyiGyiGixGix\n", "GxiGxiGxiGixGixGix\n", "GxiGxiGxiGiyGiyGiy\n" ] } ], "source": [ "#We know that we should be able to find a prep fiducial set that has no more than 16 elements,\n", "#so if we are finding sets that are larger than that, we can always increase slackFrac or fixedSlack\n", "start = time.time()\n", "prepFidList1_worst = FS.optimize_integer_fiducials_slack(gs_target,testFidList,prepOrMeas='prep',initialWeights=None,\n", " scoreFunc='worst',slackFrac=.275)\n", "end = time.time()\n", "print('')\n", "print(\"Fiducial selection completed in\", end-start, \"seconds.\")\n", "print(\"\\n\".join(map(str,sorted(prepFidList1_worst,key=len))))" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false, "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Complete initial fiducial set succeeds.\n", "Now searching for best fiducial set.\n", " Starting fiducial set optimization. Lower score is better.\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Stationary point found!\n", "\n", " score = 316.130180659\n", " weights = [1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 0 0 0 0 0 0 1 1 0 0 1]\n", " L1(weights) = 9\n", "Final fiducial set succeeds.\n", "\n", "Fiducial selection completed in 0.17540383338928223 seconds.\n", "{}\n", "GxiGxiGxiGiy\n", "GyiGyiGyiGix\n", "GxiGxiGixGixGix\n", "GxiGxiGiyGiyGiy\n", "GxiGxiGxiGixGix\n", "GyiGyiGyiGixGix\n", "GxiGxiGxiGixGixGix\n", "GyiGyiGyiGiyGiyGiy\n" ] } ], "source": [ "#We know that there might exist a fiducial measurement set with as few as 6 elements (as 6*3=18>16).\n", "#However, repeated attempts to find one to date have failed. We can reliably identify fiducial measurement sets\n", "#with only 9 elements, so 9 should be considered an upper bound. (If you do find a set with fewer than 9 elements,\n", "#the pyGSTi team would love to hear from you!)\n", "start = time.time()\n", "measFidList1_all = FS.optimize_integer_fiducials_slack(gs_target,testFidList,prepOrMeas='meas',initialWeights=None,\n", " scoreFunc='all',slackFrac=1)\n", "end = time.time()\n", "print('')\n", "print(\"Fiducial selection completed in\", end-start, \"seconds.\")\n", "print(\"\\n\".join(map(str,sorted(measFidList1_all,key=len))))" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false, "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Complete initial fiducial set succeeds.\n", "Now searching for best fiducial set.\n", " Starting fiducial set optimization. Lower score is better.\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Moving to better neighbor\n", "\n", " INVALID LEVEL: Stationary point found!\n", "\n", " score = 48.4574110103\n", " weights = [1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 1 0 0 1 0 0 0 0 0 0 0 0 1 1 1 0]\n", " L1(weights) = 9\n", "Final fiducial set succeeds.\n", "\n", "Fiducial selection completed in 0.16562414169311523 seconds.\n", "{}\n", "GxiGxiGxiGix\n", "GyiGyiGyiGiy\n", "GxiGxiGixGixGix\n", "GxiGxiGiyGiyGiy\n", "GxiGxiGxiGixGix\n", "GyiGyiGyiGixGix\n", "GxiGxiGxiGiyGiyGiy\n", "GyiGyiGyiGixGixGix\n" ] } ], "source": [ "#Let's try the same as above, but with \"worst\" instead of \"all\" as the scoreFunc.\n", "start = time.time()\n", "measFidList1_worst = FS.optimize_integer_fiducials_slack(gs_target,testFidList,prepOrMeas='meas',initialWeights=None,\n", " scoreFunc='worst',slackFrac=1)\n", "end = time.time()\n", "print('')\n", "print(\"Fiducial selection completed in\", end-start, \"seconds.\")\n", "print(\"\\n\".join(map(str,sorted(measFidList1_worst,key=len))))" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "(True,\n", " [0.035777874246103299,\n", " 0.094384513594892291,\n", " 0.12472064408484007,\n", " 0.18406325009774385,\n", " 0.21922359359558521,\n", " 0.24878825006702773,\n", " 0.32992842070695416,\n", " 0.50000000000000078,\n", " 0.6010698552873196,\n", " 0.89527809661407387,\n", " 1.0000000000000018,\n", " 1.2601374932937577,\n", " 1.5082401339544396,\n", " 1.9793250220729004,\n", " 2.2807764064044163,\n", " 4.7382864459799467],\n", " Score: 1152.0000000000011, N: 16)" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "FS.test_fiducial_list(gs_target, prepFidList1_all,'prep', scoreFunc='all', returnAll=True)" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "prep fid_all spectrum:\n", " [0.035777874246103299, 0.094384513594892291, 0.12472064408484007, 0.18406325009774385, 0.21922359359558521, 0.24878825006702773, 0.32992842070695416, 0.50000000000000078, 0.6010698552873196, 0.89527809661407387, 1.0000000000000018, 1.2601374932937577, 1.5082401339544396, 1.9793250220729004, 2.2807764064044163, 4.7382864459799467]\n", "prep fid_all 'all-score': 1152.0\n", "prep fid_all 'worst-score': 447.20376314\n" ] } ], "source": [ "print(\"prep fid_all spectrum:\\n\", FS.test_fiducial_list(gs_target, prepFidList1_all, 'prep',\n", " returnAll=True)[1])\n", "print(\"prep fid_all 'all-score':\", FS.compute_composite_score(gs_target, prepFidList1_all, 'prep',\n", " scoreFunc='all').score)\n", "print(\"prep fid_all 'worst-score':\", FS.compute_composite_score(gs_target, prepFidList1_all, 'prep',\n", " scoreFunc='worst').score)" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "prep fid_worst spectrum:\n", " [0.081927275262131879, 0.11388855211719072, 0.13201527829771245, 0.19518521569267214, 0.27205660994856701, 0.29289321881345265, 0.50000000000000011, 0.50000000000000056, 0.50000000000000078, 0.65555661468669446, 0.91892639567648648, 1.1149936429348561, 1.7071067811865479, 2.1841101287185083, 2.1951284422577579, 4.6362118444074252]\n", "prep fid_worst 'all-score': 832.0\n", "prep fid_worst 'worst-score': 195.295155964\n" ] } ], "source": [ "print(\"prep fid_worst spectrum:\\n\", FS.test_fiducial_list(gs_target, prepFidList1_worst, 'prep',\n", " returnAll=True)[1])\n", "print(\"prep fid_worst 'all-score':\", FS.compute_composite_score(gs_target, prepFidList1_worst, 'prep',\n", " scoreFunc='all').score)\n", "print(\"prep fid_worst 'worst-score':\", FS.compute_composite_score(gs_target, prepFidList1_worst, 'prep',\n", " scoreFunc='worst').score)" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "collapsed": true }, "outputs": [], "source": [ "#Interestingly, using the option \"worst\" instead of \"all\" yields a better scoring fiducial set, by both the \"worst\"\n", "#and \"all\"." ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "prep meas_all spectrum:\n", " [0.37146020855667633, 0.500000000000001, 0.5636858449704405, 0.64534972638934451, 0.71248175049995832, 0.71922359359558619, 0.74410254312752222, 0.75000000000000044, 0.75000000000000122, 1.9166803725509389, 2.0000000000000036, 2.1610191647597028, 2.5209138803963604, 2.7710731135452402, 2.7807764064044189, 7.0932333952038338]\n", "prep meas_all 'all-score': 158.065090329\n", "prep meas_all 'worst-score': 24.2287055051\n" ] } ], "source": [ "print(\"prep meas_all spectrum:\\n\", FS.test_fiducial_list(gs_target, measFidList1_all, 'meas',\n", " returnAll=True)[1])\n", "print(\"prep meas_all 'all-score':\", FS.compute_composite_score(gs_target, measFidList1_all, 'meas',\n", " scoreFunc='all').score)\n", "print(\"prep meas_all 'worst-score':\", FS.compute_composite_score(gs_target, measFidList1_all, 'meas',\n", " scoreFunc='worst').score)" ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "prep meas_worst spectrum:\n", " [0.37146020855667539, 0.50000000000000056, 0.56368584497044083, 0.64534972638934596, 0.71248175049995899, 0.71922359359558596, 0.74410254312752333, 0.75000000000000056, 0.75000000000000133, 1.916680372550938, 2.0000000000000031, 2.1610191647597019, 2.5209138803963618, 2.7710731135452407, 2.7807764064044185, 7.093233395203832]\n", "prep meas_worst 'all-score': 158.065090329\n", "prep meas_worst 'worst-score': 24.2287055051\n" ] } ], "source": [ "print(\"prep meas_worst spectrum:\\n\", FS.test_fiducial_list(gs_target, measFidList1_worst, 'meas',\n", " returnAll=True)[1])\n", "print(\"prep meas_worst 'all-score':\", FS.compute_composite_score(gs_target, measFidList1_worst, 'meas',\n", " scoreFunc='all').score)\n", "print(\"prep meas_worst 'worst-score':\", FS.compute_composite_score(gs_target, measFidList1_worst, 'meas',\n", " scoreFunc='worst').score)" ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{} \t {} \t True\n", "GxiGxiGxiGiy \t GxiGxiGxiGix \t False\n", "GyiGyiGyiGix \t GyiGyiGyiGiy \t False\n", "GxiGxiGixGixGix \t GxiGxiGixGixGix \t True\n", "GxiGxiGiyGiyGiy \t GxiGxiGiyGiyGiy \t True\n", "GxiGxiGxiGixGix \t GxiGxiGxiGixGix \t True\n", "GyiGyiGyiGixGix \t GyiGyiGyiGixGix \t True\n", "GxiGxiGxiGixGixGix \t GxiGxiGxiGiyGiyGiy \t False\n", "GyiGyiGyiGiyGiyGiy \t GyiGyiGyiGixGixGix \t False\n" ] } ], "source": [ "for i in range(len(measFidList1_all)):\n", " print(sorted(measFidList1_all,key=len)[i], '\\t', sorted(measFidList1_worst,key=len)[i], '\\t', sorted(measFidList1_all,key=len)[i] == sorted(measFidList1_worst,key=len)[i])" ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "collapsed": true }, "outputs": [], "source": [ "#We have the same scores for \"all\" and \"worst\" for measurement fiducials, even though the fiducial sets themselves\n", "#are not quite the same." ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "collapsed": true }, "outputs": [], "source": [ "#Lastly, let's see if we can find a minimal set of measurement fiducials (size 6), using the same input set as before." ] }, { "cell_type": "code", "execution_count": 19, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Complete initial fiducial set succeeds.\n", "Now searching for best fiducial set.\n", " Starting fiducial set optimization. Lower score is better.\n", " Output set is required to be of size6\n", " Total number of fiducial sets to be checked is324632.0\n", "\n", "WARNING: If this is very large, you may wish to abort.\n", " Switching!\n", " Switching!\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "/Users/jongros/src/python/pyGSTi/packages/pygsti/algorithms/fiducialselection.py:589: VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future\n", " scoreMx[:, colInd:colInd+int(numFids)] = fidArray[:, wtsLoc]\n", "/Users/jongros/src/python/pyGSTi/packages/pygsti/algorithms/scoring.py:38: RuntimeWarning: divide by zero encountered in true_divide\n", " score = sum(1. / _np.abs(input_array))\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ " Switching!\n", "\n", "Fiducial selection completed in 32.74297118186951 seconds.\n", "{}\n", "GxiGxiGxiGix\n", "GyiGyiGyiGiy\n", "GxiGxiGixGixGix\n", "GxiGxiGiyGiyGiy\n", "GxiGxiGxiGixGix\n", "GyiGyiGyiGixGix\n", "GxiGxiGxiGiyGiyGiy\n", "GyiGyiGyiGixGixGix\n" ] } ], "source": [ "start = time.time()\n", "measFidList1_all_force6 = FS.optimize_integer_fiducials_slack(gs_target,testFidList,prepOrMeas='meas',initialWeights=None,fixedNum=6,\n", " scoreFunc='all',slackFrac=1)\n", "end = time.time()\n", "print('')\n", "print(\"Fiducial selection completed in\", end-start, \"seconds.\")\n", "print(\"\\n\".join(map(str,sorted(measFidList1_worst,key=len))))" ] }, { "cell_type": "code", "execution_count": 20, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "(False,\n", " [0.0,\n", " 4.183338548779793e-18,\n", " 7.1381167993949151e-17,\n", " 2.1243389323425814e-16,\n", " 3.192307977368377e-16,\n", " 0.19842366731041428,\n", " 0.4728779036644713,\n", " 0.64193230628110098,\n", " 0.72785899132332788,\n", " 1.0000000000000007,\n", " 1.2630926063270917,\n", " 1.4397252510775762,\n", " 1.7835109688541178,\n", " 2.5529047338745787,\n", " 2.79942773826098,\n", " 5.1202458330263525],\n", " Score: 84.46396396396389, N: 11)" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "FS.test_fiducial_list(gs_target,measFidList1_all_force6,'meas',scoreFunc='all',returnAll=True)" ] }, { "cell_type": "code", "execution_count": 21, "metadata": { "collapsed": true }, "outputs": [], "source": [ "#Sadly, this did not work! However, one could try different input sets (or increasing fixedNum to 7 or 8, which would\n", "#still be better than 9.)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "anaconda-cloud": {}, "kernelspec": { "display_name": "Python [Root]", "language": "python", "name": "Python [Root]" }, "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.1" } }, "nbformat": 4, "nbformat_minor": 0 }