Example #1
0
def runMC2GSTAnalysis(myspecs,
                      mygerms,
                      gsTarget,
                      seed,
                      maxLs=[1, 2, 4, 8],
                      nSamples=1000,
                      useFreqWeightedChiSq=False,
                      minProbClipForWeighting=1e-4,
                      fidPairList=None,
                      comm=None):
    rhoStrs, EStrs = pygsti.construction.get_spam_strs(myspecs)
    lgstStrings = pygsti.construction.list_lgst_gatestrings(
        myspecs, gsTarget.gates.keys())
    lsgstStrings = pygsti.construction.make_lsgst_lists(
        gsTarget.gates.keys(), rhoStrs, EStrs, mygerms, maxLs, fidPairList)

    print len(myspecs[0]), " rho specifiers"
    print len(myspecs[1]), " effect specifiers"
    print len(mygerms), " germs"
    print len(lgstStrings), " total LGST gate strings"
    print len(lsgstStrings[-1]), " LSGST strings before thinning"

    lsgstStringsToUse = lsgstStrings
    allRequiredStrs = pygsti.remove_duplicates(lgstStrings + lsgstStrings[-1])

    gs_dataGen = gsTarget.depolarize(gate_noise=0.1)
    dsFake = pygsti.construction.generate_fake_data(gs_dataGen,
                                                    allRequiredStrs,
                                                    nSamples,
                                                    sampleError="multinomial",
                                                    seed=seed)

    #Run LGST to get starting gate set
    gs_lgst = pygsti.do_lgst(dsFake,
                             myspecs,
                             gsTarget,
                             svdTruncateTo=gsTarget.dim,
                             verbosity=3)
    gs_lgst_go = pygsti.optimize_gauge(gs_lgst,
                                       "target",
                                       targetGateset=gs_dataGen)

    #Run full iterative LSGST
    tStart = time.time()
    all_gs_lsgst = pygsti.do_iterative_mc2gst(
        dsFake,
        gs_lgst_go,
        lsgstStringsToUse,
        minProbClipForWeighting=minProbClipForWeighting,
        probClipInterval=(-1e5, 1e5),
        verbosity=1,
        memLimit=3 * (1024)**3,
        returnAll=True,
        useFreqWeightedChiSq=useFreqWeightedChiSq,
        comm=comm)
    tEnd = time.time()
    print "Time = ", (tEnd - tStart) / 3600.0, "hours ( =", (tEnd -
                                                             tStart), " secs)"

    return all_gs_lsgst, gs_dataGen
Example #2
0
def mdl_lsgst(self):
    return pygsti.do_iterative_mc2gst(self.dataset,
                                      self.mdl_clgst,
                                      self.lsgstStrings,
                                      verbosity=0,
                                      minProbClipForWeighting=1e-6,
                                      probClipInterval=(-1e6, 1e6),
                                      memLimit=self.CM + 1024**3)
Example #3
0
def runAnalysis(obj,
                ds,
                myspecs,
                gsTarget,
                lsgstStringsToUse,
                useFreqWeightedChiSq=False,
                minProbClipForWeighting=1e-4,
                fidPairList=None,
                comm=None,
                distributeMethod="gatestrings"):

    #Run LGST to get starting gate set
    assertGatesetsInSync(gsTarget, comm)
    gs_lgst = pygsti.do_lgst(ds,
                             myspecs,
                             gsTarget,
                             svdTruncateTo=gsTarget.dim,
                             verbosity=3)

    assertGatesetsInSync(gs_lgst, comm)
    gs_lgst_go = pygsti.gaugeopt_to_target(gs_lgst, gsTarget)

    assertGatesetsInSync(gs_lgst_go, comm)

    #Run full iterative LSGST
    tStart = time.time()
    if obj == "chi2":
        all_gs_lsgst = pygsti.do_iterative_mc2gst(
            ds,
            gs_lgst_go,
            lsgstStringsToUse,
            minProbClipForWeighting=minProbClipForWeighting,
            probClipInterval=(-1e5, 1e5),
            verbosity=1,
            memLimit=3 * (1024)**3,
            returnAll=True,
            useFreqWeightedChiSq=useFreqWeightedChiSq,
            comm=comm,
            distributeMethod=distributeMethod)
    elif obj == "logl":
        all_gs_lsgst = pygsti.do_iterative_mlgst(
            ds,
            gs_lgst_go,
            lsgstStringsToUse,
            minProbClip=minProbClipForWeighting,
            probClipInterval=(-1e5, 1e5),
            verbosity=1,
            memLimit=3 * (1024)**3,
            returnAll=True,
            useFreqWeightedChiSq=useFreqWeightedChiSq,
            comm=comm,
            distributeMethod=distributeMethod)

    tEnd = time.time()
    print("Time = ", (tEnd - tStart) / 3600.0, "hours")

    return all_gs_lsgst
Example #4
0
def runAnalysis(obj, myspecs, mygerms, gsTarget, seed,
                maxLs = [1,2,4,8],
                nSamples=1000, useFreqWeightedChiSq=False,
                minProbClipForWeighting=1e-4, fidPairList=None,
                comm=None, distributeMethod="gatestrings"):
    rhoStrs, EStrs = pygsti.construction.get_spam_strs(myspecs)
    lgstStrings = pygsti.construction.list_lgst_gatestrings(
        myspecs, gsTarget.gates.keys())
    lsgstStrings = pygsti.construction.make_lsgst_lists(
            gsTarget.gates.keys(), rhoStrs, EStrs, mygerms, maxLs, fidPairList )

    print len(myspecs[0]), " rho specifiers"
    print len(myspecs[1]), " effect specifiers"
    print len(mygerms), " germs"
    print len(lgstStrings), " total LGST gate strings"
    print len(lsgstStrings[-1]), " LSGST strings before thinning"
    
    lsgstStringsToUse = lsgstStrings
    allRequiredStrs = pygsti.remove_duplicates(lgstStrings + lsgstStrings[-1])
     
    
    gs_dataGen = gsTarget.depolarize(gate_noise=0.1)
    dsFake = pygsti.construction.generate_fake_data(
        gs_dataGen, allRequiredStrs, nSamples, sampleError="multinomial",
        seed=seed)

    #Run LGST to get starting gate set
    gs_lgst = pygsti.do_lgst(dsFake, myspecs, gsTarget,
                             svdTruncateTo=gsTarget.dim, verbosity=3)
    gs_lgst_go = pygsti.optimize_gauge(gs_lgst,"target",
                                       targetGateset=gs_dataGen)
    
    #Run full iterative LSGST
    tStart = time.time()
    if obj == "chi2":
        all_gs_lsgst = pygsti.do_iterative_mc2gst(
            dsFake, gs_lgst_go, lsgstStringsToUse,
            minProbClipForWeighting=minProbClipForWeighting,
            probClipInterval=(-1e5,1e5),
            verbosity=1, memLimit=3*(1024)**3, returnAll=True, 
            useFreqWeightedChiSq=useFreqWeightedChiSq, comm=comm,
            distributeMethod=distributeMethod)
    elif obj == "logl":
        all_gs_lsgst = pygsti.do_iterative_mlgst(
            dsFake, gs_lgst_go, lsgstStringsToUse,
            minProbClip=minProbClipForWeighting,
            probClipInterval=(-1e5,1e5),
            verbosity=1, memLimit=3*(1024)**3, returnAll=True, 
            useFreqWeightedChiSq=useFreqWeightedChiSq, comm=comm,
            distributeMethod=distributeMethod)

    tEnd = time.time()
    print "Time = ",(tEnd-tStart)/3600.0,"hours"
    
    return all_gs_lsgst, gs_dataGen
Example #5
0
def runAnalysis(obj, ds, myspecs, gsTarget, lsgstStringsToUse,
                useFreqWeightedChiSq=False,
                minProbClipForWeighting=1e-4, fidPairList=None,
                comm=None, distributeMethod="gatestrings"):

    #Run LGST to get starting gate set
    assertGatesetsInSync(gsTarget, comm)
    gs_lgst = pygsti.do_lgst(ds, myspecs, gsTarget,
                             svdTruncateTo=gsTarget.dim, verbosity=3)

    assertGatesetsInSync(gs_lgst, comm)
    gs_lgst_go = pygsti.optimize_gauge(gs_lgst,"target",
                                       targetGateset=gsTarget)
    assertGatesetsInSync(gs_lgst_go, comm)

    #Run full iterative LSGST
    tStart = time.time()
    if obj == "chi2":
        all_gs_lsgst = pygsti.do_iterative_mc2gst(
            ds, gs_lgst_go, lsgstStringsToUse,
            minProbClipForWeighting=minProbClipForWeighting,
            probClipInterval=(-1e5,1e5),
            verbosity=1, memLimit=3*(1024)**3, returnAll=True,
            useFreqWeightedChiSq=useFreqWeightedChiSq, comm=comm,
            distributeMethod=distributeMethod)
    elif obj == "logl":
        all_gs_lsgst = pygsti.do_iterative_mlgst(
            ds, gs_lgst_go, lsgstStringsToUse,
            minProbClip=minProbClipForWeighting,
            probClipInterval=(-1e5,1e5),
            verbosity=1, memLimit=3*(1024)**3, returnAll=True,
            useFreqWeightedChiSq=useFreqWeightedChiSq, comm=comm,
            distributeMethod=distributeMethod)

    tEnd = time.time()
    print("Time = ",(tEnd-tStart)/3600.0,"hours")

    return all_gs_lsgst
Example #6
0
    def test_MLGST(self):

        ds = self.ds
        #pygsti.construction.generate_fake_data(self.datagen_gateset, self.lsgstStrings[-1],
        #                                            nSamples=1000, sampleError='binomial', seed=100)

        gs_lgst = pygsti.do_lgst(ds, self.specs, self.gateset, svdTruncateTo=4, verbosity=0)
        gs_lgst_go = pygsti.optimize_gauge(gs_lgst,"target",targetGateset=self.gateset, spamWeight=1.0, gateWeight=1.0)
        gs_clgst = pygsti.contract(gs_lgst_go, "CPTP")

        gs_single_mlgst = pygsti.do_mlgst(ds, gs_clgst, self.lsgstStrings[0], minProbClip=1e-6,
                                          probClipInterval=(-1e2,1e2), verbosity=0)

        gs_mlegst = pygsti.do_iterative_mlgst(ds, gs_clgst, self.lsgstStrings, verbosity=0,
                                               minProbClip=1e-6, probClipInterval=(-1e2,1e2),
                                               memLimit=1000*1024**2)
        maxLogL, all_gs_mlegst_tups = pygsti.do_iterative_mlgst(
            ds, gs_clgst, [ [gs.tup for gs in gsList] for gsList in self.lsgstStrings],
            minProbClip=1e-6, probClipInterval=(-1e2,1e2), returnAll=True, returnMaxLogL=True)

        gs_mlegst_verb = self.runSilent(pygsti.do_iterative_mlgst, ds, gs_clgst, self.lsgstStrings, verbosity=10,
                                             minProbClip=1e-6, probClipInterval=(-1e2,1e2),
                                             memLimit=10*1024**2)
        self.assertAlmostEqual(gs_mlegst.frobeniusdist(gs_mlegst_verb),0)
        self.assertAlmostEqual(gs_mlegst.frobeniusdist(all_gs_mlegst_tups[-1]),0)


        #Run internal checks on less max-L values (so it doesn't take forever)
        gs_mlegst_chk = pygsti.do_iterative_mlgst(ds, gs_clgst, self.lsgstStrings[0:2], verbosity=0,
                                                 minProbClip=1e-6, probClipInterval=(-1e2,1e2),
                                                 check=True)

        #Other option variations - just make sure they run at this point
        gs_mlegst_chk_opts = pygsti.do_iterative_mlgst(ds, gs_clgst, self.lsgstStrings[0:2], verbosity=0,
                                                      minProbClip=1e-6, probClipInterval=(-1e2,1e2),
                                                      gateStringSetLabels=["Set1","Set2"], useFreqWeightedChiSq=True )

        aliased_list = [ pygsti.obj.GateString( [ (x if x != "Gx" else "GA1") for x in gs]) for gs in self.lsgstStrings[0] ]
        gs_withA1 = gs_clgst.copy(); gs_withA1.gates["GA1"] = gs_clgst.gates["Gx"]
        gs_mlegst_chk_opts2 = pygsti.do_mlgst(ds, gs_withA1, aliased_list, minProbClip=1e-6,
                                              probClipInterval=(-1e2,1e2), verbosity=0,
                                              gateLabelAliases={ 'GA1': ('Gx',) })

        #Other option variations - just make sure they run at this point
        gs_lsgst_chk_opts = pygsti.do_iterative_mc2gst(ds, gs_clgst, self.lsgstStrings[0:2], verbosity=0,
                                                      minProbClipForWeighting=1e-6, probClipInterval=(-1e6,1e6),
                                                      useFreqWeightedChiSq=True, gateStringSetLabels=["Set1","Set2"],
                                                      gatestringWeightsDict={ ('Gx',): 2.0 } )

        self.runSilent(pygsti.do_mlgst, ds, gs_clgst, self.lsgstStrings[0], minProbClip=1e-6,
                        probClipInterval=(-1e2,1e2), verbosity=4, memLimit=300000) #invoke memory control

        pygsti.do_mlgst(ds, gs_clgst, self.lsgstStrings[0], minProbClip=1e-6,
                        probClipInterval=(-1e2,1e2), verbosity=0, poissonPicture=False)
                       #non-Poisson picture - should use (-1,-1) gateset for consistency?


        #Check errors:
        with self.assertRaises(MemoryError):
            pygsti.do_mlgst(ds, gs_clgst, self.lsgstStrings[0], minProbClip=1e-6,
                            probClipInterval=(-1e2,1e2),verbosity=0, memLimit=1)


        # RUN BELOW LINES TO SEED SAVED GATESET FILES
        #pygsti.io.write_gateset(gs_mlegst,compare_files + "/mle_gst.gateset", "Saved MLE-GST Gateset")

        gs_mle_compare = pygsti.io.load_gateset(compare_files + "/mle_gst.gateset")
        gs_mlegst_go = pygsti.optimize_gauge(gs_mlegst, 'target', targetGateset=gs_mle_compare, spamWeight=1.0)

        self.assertAlmostEqual( gs_mlegst_go.frobeniusdist(gs_mle_compare), 0, places=5)
Example #7
0
    def test_MC2GST(self):

        ds = self.ds
        #pygsti.construction.generate_fake_data(self.datagen_gateset, self.lsgstStrings[-1],
        #                                            nSamples=1000, sampleError='binomial', seed=100)

        gs_lgst = pygsti.do_lgst(ds, self.specs, self.gateset, svdTruncateTo=4, verbosity=0)
        gs_lgst_go = pygsti.optimize_gauge(gs_lgst,"target",targetGateset=self.gateset, spamWeight=1.0, gateWeight=1.0)
        gs_clgst = pygsti.contract(gs_lgst_go, "CPTP")

        gs_single_lsgst = pygsti.do_mc2gst(ds, gs_clgst, self.lsgstStrings[0], minProbClipForWeighting=1e-6,
                                           probClipInterval=(-1e6,1e6), regularizeFactor=1e-3,
                                           verbosity=0)

        gs_lsgst = pygsti.do_iterative_mc2gst(ds, gs_clgst, self.lsgstStrings, verbosity=0,
                                             minProbClipForWeighting=1e-6, probClipInterval=(-1e6,1e6),
                                             memLimit=1000*1024**2)
        all_minErrs, all_gs_lsgst_tups = pygsti.do_iterative_mc2gst(
            ds, gs_clgst, [ [gs.tup for gs in gsList] for gsList in self.lsgstStrings],
            minProbClipForWeighting=1e-6, probClipInterval=(-1e6,1e6), returnAll=True, returnErrorVec=True)
        gs_lsgst_verb = self.runSilent(pygsti.do_iterative_mc2gst, ds, gs_clgst, self.lsgstStrings, verbosity=10,
                                             minProbClipForWeighting=1e-6, probClipInterval=(-1e6,1e6),
                                             memLimit=10*1024**2)
        gs_lsgst_reg = self.runSilent(pygsti.do_iterative_mc2gst,ds, gs_clgst,
                                      self.lsgstStrings, verbosity=10,
                                      minProbClipForWeighting=1e-6,
                                      probClipInterval=(-1e6,1e6),
                                      regularizeFactor=10, memLimit=100*1024**2)
        self.assertAlmostEqual(gs_lsgst.frobeniusdist(gs_lsgst_verb),0)
        self.assertAlmostEqual(gs_lsgst.frobeniusdist(all_gs_lsgst_tups[-1]),0)


        #Run internal checks on less max-L values (so it doesn't take forever)
        gs_lsgst_chk = pygsti.do_iterative_mc2gst(ds, gs_clgst, self.lsgstStrings[0:2], verbosity=0,
                                                 minProbClipForWeighting=1e-6, probClipInterval=(-1e6,1e6),
                                                 check=True, check_jacobian=True)
        gs_lsgst_chk_verb = self.runSilent(pygsti.do_iterative_mc2gst, ds, gs_clgst, self.lsgstStrings[0:2], verbosity=10,
                                                      minProbClipForWeighting=1e-6, probClipInterval=(-1e6,1e6),
                                                      check=True, check_jacobian=True, memLimit=100*1024**2)

        #Other option variations - just make sure they run at this point
        gs_lsgst_chk_opts = pygsti.do_iterative_mc2gst(ds, gs_clgst, self.lsgstStrings[0:2], verbosity=0,
                                                      minProbClipForWeighting=1e-6, probClipInterval=(-1e6,1e6),
                                                      useFreqWeightedChiSq=True, gateStringSetLabels=["Set1","Set2"],
                                                      gatestringWeightsDict={ ('Gx',): 2.0 } )

        #Check with small but ok memlimit
        self.runSilent(pygsti.do_mc2gst,ds, gs_clgst, self.lsgstStrings[0], minProbClipForWeighting=1e-6,
                         probClipInterval=(-1e6,1e6), regularizeFactor=1e-3,
                         verbosity=10, memLimit=300000)


        #Check errors:
        with self.assertRaises(MemoryError):
            pygsti.do_mc2gst(ds, gs_clgst, self.lsgstStrings[0], minProbClipForWeighting=1e-6,
                             probClipInterval=(-1e6,1e6), regularizeFactor=1e-3,
                             verbosity=0, memLimit=1)

        with self.assertRaises(NotImplementedError):
            pygsti.do_mc2gst(ds, gs_clgst, self.lsgstStrings[0], minProbClipForWeighting=1e-6,
                             probClipInterval=(-1e6,1e6), regularizeFactor=1e-3,
                             verbosity=0, cptp_penalty_factor=1.0) #cptp pentalty not implemented yet




        # RUN BELOW LINES TO SEED SAVED GATESET FILES
        #pygsti.io.write_gateset(gs_lsgst,compare_files + "/lsgst.gateset", "Saved LSGST Gateset")
        #pygsti.io.write_gateset(gs_lsgst_reg,compare_files + "/lsgst_reg.gateset", "Saved LSGST Gateset w/Regularization")

        gs_lsgst_compare = pygsti.io.load_gateset(compare_files + "/lsgst.gateset")
        gs_lsgst_reg_compare = pygsti.io.load_gateset(compare_files + "/lsgst_reg.gateset")

        gs_lsgst_go = pygsti.optimize_gauge(gs_lsgst, 'target', targetGateset=gs_lsgst_compare, spamWeight=1.0)
        gs_lsgst_reg_go = pygsti.optimize_gauge(gs_lsgst_reg, 'target', targetGateset=gs_lsgst_reg_compare, spamWeight=1.0)

        self.assertAlmostEqual( gs_lsgst_go.frobeniusdist(gs_lsgst_compare), 0, places=5)
        self.assertAlmostEqual( gs_lsgst_reg_go.frobeniusdist(gs_lsgst_reg_compare), 0, places=5)
Example #8
0
    def test_MC2GST(self):

        ds = self.ds

        mdl_lgst = pygsti.do_lgst(ds,
                                  self.fiducials,
                                  self.fiducials,
                                  self.model,
                                  svdTruncateTo=4,
                                  verbosity=0)
        mdl_lgst_go = pygsti.gaugeopt_to_target(mdl_lgst,
                                                self.model, {
                                                    'spam': 1.0,
                                                    'gates': 1.0
                                                },
                                                checkJac=True)
        mdl_clgst = pygsti.contract(mdl_lgst_go, "CPTP")
        CM = profiler._get_mem_usage()

        mdl_lsgst = pygsti.do_iterative_mc2gst(ds,
                                               mdl_clgst,
                                               self.lsgstStrings,
                                               verbosity=0,
                                               minProbClipForWeighting=1e-6,
                                               probClipInterval=(-1e6, 1e6),
                                               memLimit=CM + 1024**3)
        all_minErrs, all_gs_lsgst_tups = pygsti.do_iterative_mc2gst(
            ds,
            mdl_clgst,
            [[mdl.tup for mdl in gsList] for gsList in self.lsgstStrings],
            minProbClipForWeighting=1e-6,
            probClipInterval=(-1e6, 1e6),
            returnAll=True,
            returnErrorVec=True)
        mdl_lsgst_verb = self.runSilent(pygsti.do_iterative_mc2gst,
                                        ds,
                                        mdl_clgst,
                                        self.lsgstStrings,
                                        verbosity=10,
                                        minProbClipForWeighting=1e-6,
                                        probClipInterval=(-1e6, 1e6),
                                        memLimit=CM + 1024**3)
        mdl_lsgst_reg = self.runSilent(pygsti.do_iterative_mc2gst,
                                       ds,
                                       mdl_clgst,
                                       self.lsgstStrings,
                                       verbosity=10,
                                       minProbClipForWeighting=1e-6,
                                       probClipInterval=(-1e6, 1e6),
                                       regularizeFactor=10,
                                       memLimit=CM + 1024**3)
        self.assertAlmostEqual(mdl_lsgst.frobeniusdist(mdl_lsgst_verb), 0)
        self.assertAlmostEqual(mdl_lsgst.frobeniusdist(all_gs_lsgst_tups[-1]),
                               0)

        # RUN BELOW LINES TO SEED SAVED GATESET FILES
        if regenerate_references():
            pygsti.io.write_model(mdl_lsgst, compare_files + "/lsgst.model",
                                  "Saved LSGST Model")
            pygsti.io.write_model(mdl_lsgst_reg,
                                  compare_files + "/lsgst_reg.model",
                                  "Saved LSGST Model w/Regularization")

        mdl_lsgst_compare = pygsti.io.load_model(compare_files +
                                                 "/lsgst.model")
        mdl_lsgst_reg_compare = pygsti.io.load_model(compare_files +
                                                     "/lsgst_reg.model")

        mdl_lsgst_go = pygsti.gaugeopt_to_target(mdl_lsgst,
                                                 mdl_lsgst_compare,
                                                 {'spam': 1.0},
                                                 checkJac=True)

        mdl_lsgst_reg_go = pygsti.gaugeopt_to_target(mdl_lsgst_reg,
                                                     mdl_lsgst_reg_compare,
                                                     {'spam': 1.0},
                                                     checkJac=True)

        self.assertAlmostEqual(mdl_lsgst_go.frobeniusdist(mdl_lsgst_compare),
                               0,
                               places=4)
        self.assertAlmostEqual(
            mdl_lsgst_reg_go.frobeniusdist(mdl_lsgst_reg_compare), 0, places=4)

        # RUN BELOW LINES TO SEED SAVED GATESET FILES
        if regenerate_references():
            mdl_lsgst_go = pygsti.gaugeopt_to_target(mdl_lsgst, self.model,
                                                     {'spam': 1.0})
            pygsti.io.write_model(mdl_lsgst_go,
                                  compare_files + "/analysis.model",
                                  "Saved LSGST Analysis Model")
            print("DEBUG: analysis.model = ")
            print(mdl_lgst_go)
Example #9
0
    def setUp(self):
        super(ReportBaseCase, self).setUp()

        self.targetGateset = std.gs_target
        datagen_gateset = self.targetGateset.depolarize(gate_noise=0.05,
                                                        spam_noise=0.1)

        self.fiducials = std.fiducials
        self.germs = std.germs

        self.specs = pygsti.construction.build_spam_specs(
            self.fiducials, effect_labels=['E0'])  #only use the first EVec

        self.gateLabels = list(
            self.targetGateset.gates.keys())  # also == std.gates
        self.lgstStrings = pygsti.construction.list_lgst_gatestrings(
            self.specs, self.gateLabels)

        self.maxLengthList = [0, 1, 2, 4, 8]

        self.lsgstStrings = pygsti.construction.make_lsgst_lists(
            self.gateLabels, self.fiducials, self.fiducials, self.germs,
            self.maxLengthList)

        self.ds = pygsti.objects.DataSet(fileToLoadFrom=compare_files +
                                         "/reportgen.dataset")

        # RUN BELOW LINES TO GENERATE ANALYSIS DATASET
        #ds = pygsti.construction.generate_fake_data(datagen_gateset, lsgstStrings[-1], nSamples=1000,
        #                                            sampleError='binomial', seed=100)
        #ds.save(compare_files + "/reportgen.dataset")

        gs_lgst = pygsti.do_lgst(self.ds,
                                 self.specs,
                                 self.targetGateset,
                                 svdTruncateTo=4,
                                 verbosity=0)
        gs_lgst_go = pygsti.optimize_gauge(gs_lgst,
                                           "target",
                                           targetGateset=self.targetGateset,
                                           gateWeight=1.0,
                                           spamWeight=0.0)
        self.gs_clgst = pygsti.contract(gs_lgst_go, "CPTP")
        self.gs_clgst_tp = pygsti.contract(self.gs_clgst, "vSPAM")
        self.gs_clgst_tp.set_all_parameterizations("TP")

        try:
            import pptx
            self.have_python_pptx = True
        except ImportError:
            warnings.warn(
                "**** IMPORT: Cannot import pptx (python-pptx), and so" +
                " Powerpoint slide generation tests have been disabled.")
            self.have_python_pptx = False

        #Compute results for MC2GST
        lsgst_gatesets_prego = pygsti.do_iterative_mc2gst(
            self.ds,
            self.gs_clgst,
            self.lsgstStrings,
            verbosity=0,
            minProbClipForWeighting=1e-6,
            probClipInterval=(-1e6, 1e6),
            returnAll=True)
        lsgst_gatesets = [
            pygsti.optimize_gauge(gs,
                                  "target",
                                  targetGateset=self.targetGateset,
                                  gateWeight=1,
                                  spamWeight=0.001)
            for gs in lsgst_gatesets_prego
        ]

        self.results = pygsti.report.Results()
        self.results.init_Ls_and_germs(
            "chi2", self.targetGateset, self.ds, self.gs_clgst,
            self.maxLengthList, self.germs, lsgst_gatesets, self.lsgstStrings,
            self.fiducials, self.fiducials,
            pygsti.construction.repeat_with_max_length, False, None,
            lsgst_gatesets_prego)
        self.results.parameters.update({
            'minProbClip': 1e-6,
            'minProbClipForWeighting': 1e-4,
            'probClipInterval': (-1e6, 1e6),
            'radius': 1e-4,
            'weights': None,
            'defaultDirectory': temp_files + "",
            'defaultBasename': "MyDefaultReportName"
        })
        self.results.options.precision = 4
        self.results.options.polar_precision = 3

        #Compute results for MLGST with TP constraint
        lsgst_gatesets_TP = pygsti.do_iterative_mlgst(self.ds,
                                                      self.gs_clgst_tp,
                                                      self.lsgstStrings,
                                                      verbosity=0,
                                                      minProbClip=1e-4,
                                                      probClipInterval=(-1e6,
                                                                        1e6),
                                                      returnAll=True)
        lsgst_gatesets_TP = [
            pygsti.optimize_gauge(gs,
                                  "target",
                                  targetGateset=self.targetGateset,
                                  constrainToTP=True,
                                  gateWeight=1,
                                  spamWeight=0.001) for gs in lsgst_gatesets_TP
        ]

        self.results_logL = pygsti.report.Results()
        self.results_logL.init_Ls_and_germs(
            "logl", self.targetGateset, self.ds, self.gs_clgst_tp,
            self.maxLengthList, self.germs, lsgst_gatesets_TP,
            self.lsgstStrings, self.fiducials, self.fiducials,
            pygsti.construction.repeat_with_max_length, True)
        self.results_logL.options.precision = 4
        self.results_logL.options.polar_precision = 3

        try:
            basestring  #Only defined in Python 2
            self.versionsuffix = ""  #Python 2
        except NameError:
            self.versionsuffix = "v3"  #Python 3
Example #10
0
    def test_reports_chi2(self):

        lsgst_gatesets_prego = pygsti.do_iterative_mc2gst(self.ds, self.gs_clgst, self.lsgstStrings, verbosity=0,
                                                          minProbClipForWeighting=1e-6, probClipInterval=(-1e6,1e6),
                                                          returnAll=True)
        lsgst_gatesets = [ pygsti.optimize_gauge(gs, "target", targetGateset=self.targetGateset,
                                                 gateWeight=1,spamWeight=0.001) for gs in lsgst_gatesets_prego]

        self.results = pygsti.report.Results()
        self.results.init_Ls_and_germs("chi2", self.targetGateset, self.ds, self.gs_clgst,
                                       self.maxLengthList, self.germs,
                                       lsgst_gatesets, self.lsgstStrings, self.fiducials, self.fiducials, 
                                       pygsti.construction.repeat_with_max_length, False, None, lsgst_gatesets_prego)
        self.results.parameters.update({'minProbClip': 1e-6, 'minProbClipForWeighting': 1e-4,
                                        'probClipInterval': (-1e6,1e6), 'radius': 1e-4,
                                        'weights': None, 'defaultDirectory': "temp_test_files",
                                        'defaultBasename': "MyDefaultReportName" } )

        #db = lsgst_gatesets[-1]
        #firstElIdentityVec = np.zeros( (db.dim,1) )
        #firstElIdentityVec[0] = db.dim**0.25
        #db.povm_identity = firstElIdentityVec
        #
        #print "Target Identity = ", np.asarray(self.targetGateset.povm_identity)
        #print "Identity = ", np.asarray(db.povm_identity)
        #print "rho0 = ", np.asarray(db.preps['rho0'])
        #for plbl in db.get_prep_labels():
        #    for elbl in db.get_effect_labels():
        #        print "DB: dot(%s,%s) = " % (plbl,elbl), np.dot(np.transpose(db.effects[elbl]),db.preps[plbl])
        #return


        self.results.create_full_report_pdf(filename="temp_test_files/full_reportA.pdf", confidenceLevel=None,
                                         debugAidsAppendix=False, gaugeOptAppendix=False,
                                         pixelPlotAppendix=False, whackamoleAppendix=False)
        self.results.create_brief_report_pdf(filename="temp_test_files/brief_reportA.pdf", confidenceLevel=None)
        self.results.create_presentation_pdf(filename="temp_test_files/slidesA.pdf", confidenceLevel=None,
                                           debugAidsAppendix=False, pixelPlotAppendix=False, whackamoleAppendix=False)
        if self.have_python_pptx:
            self.results.create_presentation_ppt(filename="temp_test_files/slidesA.ppt", confidenceLevel=None,
                                                 debugAidsAppendix=False, pixelPlotAppendix=False, whackamoleAppendix=False)

        #Run again using default filenames
        self.results.create_full_report_pdf(filename="auto", confidenceLevel=None,
                                         debugAidsAppendix=False, gaugeOptAppendix=False,
                                         pixelPlotAppendix=False, whackamoleAppendix=False)
        self.results.create_brief_report_pdf(filename="auto", confidenceLevel=None)
        self.results.create_presentation_pdf(filename="auto", confidenceLevel=None,
                                           debugAidsAppendix=False, pixelPlotAppendix=False, whackamoleAppendix=False)
        if self.have_python_pptx:
            self.results.create_presentation_ppt(filename="auto", confidenceLevel=None,
                                                 debugAidsAppendix=False, pixelPlotAppendix=False, whackamoleAppendix=False)

        #Compare the text files, assume if these match the PDFs are equivalent
        self.checkFile("full_reportA.tex")
        self.checkFile("brief_reportA.tex")
        self.checkFile("slidesA.tex")


        self.results.create_full_report_pdf(filename="temp_test_files/full_reportB.pdf", confidenceLevel=95,
                                         debugAidsAppendix=True, gaugeOptAppendix=True,
                                         pixelPlotAppendix=True, whackamoleAppendix=True,
                                         verbosity=2)
        self.results.create_full_report_pdf(filename="temp_test_files/full_reportB-noGOpt.pdf", confidenceLevel=95,
                                         debugAidsAppendix=True, gaugeOptAppendix=False,
                                         pixelPlotAppendix=True, whackamoleAppendix=True) # to test blank GOpt tables
        self.results.create_brief_report_pdf(filename="temp_test_files/brief_reportB.pdf", confidenceLevel=95, verbosity=2)
        self.results.create_presentation_pdf(filename="temp_test_files/slidesB.pdf", confidenceLevel=95,
                                           debugAidsAppendix=True, pixelPlotAppendix=True, whackamoleAppendix=True,
                                           verbosity=2)
        if self.have_python_pptx:
            self.results.create_presentation_ppt(filename="temp_test_files/slidesB.ppt", confidenceLevel=95,
                                                 debugAidsAppendix=True, pixelPlotAppendix=True, whackamoleAppendix=True,
                                                 verbosity=2)

        #Compare the text files, assume if these match the PDFs are equivalent
        self.checkFile("full_reportB.tex")
        self.checkFile("full_reportB_appendices.tex")
        self.checkFile("brief_reportB.tex")
        self.checkFile("slidesB.tex")


        #Non-markovian error bars (negative confidenceLevel) & tooltips
        self.results.create_full_report_pdf(filename="temp_test_files/full_reportE.pdf", confidenceLevel=-95,
                                         debugAidsAppendix=True, gaugeOptAppendix=True,
                                         pixelPlotAppendix=True, whackamoleAppendix=True,
                                         verbosity=2, tips=True)
        self.results.create_brief_report_pdf(filename="temp_test_files/brief_reportE.pdf", confidenceLevel=-95,
                                             verbosity=2, tips=True)

        #Compare the text files, assume if these match the PDFs are equivalent
        self.checkFile("full_reportE.tex")
        self.checkFile("full_reportE_appendices.tex")
Example #11
0
    def setUp(self):
        #Set GateSet objects to "strict" mode for testing
        pygsti.objects.GateSet._strict = True

        self.targetGateset = std.gs_target
        datagen_gateset = self.targetGateset.depolarize(gate_noise=0.05, spam_noise=0.1)
        
        self.fiducials = std.fiducials
        self.germs = std.germs
        self.specs = pygsti.construction.build_spam_specs(self.fiducials, effect_labels=['E0']) #only use the first EVec

        self.gateLabels = self.targetGateset.gates.keys() # also == std.gates
        self.lgstStrings = pygsti.construction.list_lgst_gatestrings(self.specs, self.gateLabels)

        self.maxLengthList = [0,1,2,4,8]
        
        self.lsgstStrings = pygsti.construction.make_lsgst_lists(
            self.gateLabels, self.fiducials, self.fiducials, self.germs, self.maxLengthList)

        self.ds = pygsti.objects.DataSet(fileToLoadFrom="cmp_chk_files/reportgen.dataset")

        # RUN BELOW LINES TO GENERATE ANALYSIS DATASET
        #ds = pygsti.construction.generate_fake_data(datagen_gateset, lsgstStrings[-1], nSamples=1000,
        #                                            sampleError='binomial', seed=100)
        #ds.save("cmp_chk_files/reportgen.dataset")

        gs_lgst = pygsti.do_lgst(self.ds, self.specs, self.targetGateset, svdTruncateTo=4, verbosity=0)
        gs_lgst_go = pygsti.optimize_gauge(gs_lgst,"target",targetGateset=self.targetGateset)
        self.gs_clgst = pygsti.contract(gs_lgst_go, "CPTP")
        self.gs_clgst_tp = pygsti.contract(self.gs_clgst, "vSPAM")
        self.gs_clgst_tp.set_all_parameterizations("TP")

        try:
            import pptx
            self.have_python_pptx = True
        except ImportError:
            warnings.warn("**** IMPORT: Cannot import pptx (python-pptx), and so" +
                         " Powerpoint slide generation tests have been disabled.")
            self.have_python_pptx = False


        #Compute results for MC2GST
        lsgst_gatesets_prego = pygsti.do_iterative_mc2gst(self.ds, self.gs_clgst, self.lsgstStrings, verbosity=0,
                                                          minProbClipForWeighting=1e-6, probClipInterval=(-1e6,1e6),
                                                          returnAll=True)
        lsgst_gatesets = [ pygsti.optimize_gauge(gs, "target", targetGateset=self.targetGateset,
                                                 gateWeight=1,spamWeight=0.001) for gs in lsgst_gatesets_prego]

        self.results = pygsti.report.Results()
        self.results.init_Ls_and_germs("chi2", self.targetGateset, self.ds, self.gs_clgst,
                                       self.maxLengthList, self.germs,
                                       lsgst_gatesets, self.lsgstStrings, self.fiducials, self.fiducials, 
                                       pygsti.construction.repeat_with_max_length, False, None, lsgst_gatesets_prego)
        self.results.parameters.update({'minProbClip': 1e-6, 'minProbClipForWeighting': 1e-4,
                                        'probClipInterval': (-1e6,1e6), 'radius': 1e-4,
                                        'weights': None, 'defaultDirectory': "temp_test_files",
                                        'defaultBasename': "MyDefaultReportName" } )


        #Compute results for MLGST with TP constraint
        lsgst_gatesets_TP = pygsti.do_iterative_mlgst(self.ds, self.gs_clgst_tp, self.lsgstStrings, verbosity=0,
                                                   minProbClip=1e-4, probClipInterval=(-1e6,1e6),
                                                   returnAll=True)
        lsgst_gatesets_TP = [ pygsti.optimize_gauge(gs, "target", targetGateset=self.targetGateset, constrainToTP=True,
                                                 gateWeight=1,spamWeight=0.001) for gs in lsgst_gatesets_TP]

        self.results_logL = pygsti.report.Results()
        self.results_logL.init_Ls_and_germs("logl", self.targetGateset, self.ds, self.gs_clgst_tp, self.maxLengthList, self.germs,
                                     lsgst_gatesets_TP, self.lsgstStrings, self.fiducials, self.fiducials, 
                                     pygsti.construction.repeat_with_max_length, True)
Example #12
0
    def test_MC2GST(self):

        ds = self.ds
        #pygsti.construction.generate_fake_data(self.datagen_gateset, self.lsgstStrings[-1],
        #                                            nSamples=1000, sampleError='binomial', seed=100)

        mdl_lgst = pygsti.do_lgst(ds, self.fiducials, self.fiducials, self.model, svdTruncateTo=4, verbosity=0)
        mdl_lgst_go = pygsti.gaugeopt_to_target(mdl_lgst,self.model, {'spam':1.0, 'gates': 1.0}, checkJac=True)
        mdl_clgst = pygsti.contract(mdl_lgst_go, "CPTP")
        CM = pygsti.baseobjs.profiler._get_mem_usage()

        mdl_single_lsgst = pygsti.do_mc2gst(ds, mdl_clgst, self.lsgstStrings[0], minProbClipForWeighting=1e-4,
                                           probClipInterval=(-1e6,1e6), regularizeFactor=1e-3,
                                           verbosity=0) #uses regularizeFactor

        mdl_single_lsgst_cp = pygsti.do_mc2gst(ds, mdl_clgst, self.lsgstStrings[0], minProbClipForWeighting=1e-4,
                                           probClipInterval=(-1e6,1e6), cptp_penalty_factor=1.0,
                                           verbosity=0) #uses cptp_penalty_factor

        mdl_single_lsgst_sp = pygsti.do_mc2gst(ds, mdl_clgst, self.lsgstStrings[0], minProbClipForWeighting=1e-4,
                                              probClipInterval=(-1e6,1e6), spam_penalty_factor=1.0,
                                              verbosity=0) #uses spam_penalty_factor

        mdl_single_lsgst_cpsp = pygsti.do_mc2gst(ds, mdl_clgst, self.lsgstStrings[0], minProbClipForWeighting=1e-4,
                                                probClipInterval=(-1e6,1e6), cptp_penalty_factor=1.0,
                                                spam_penalty_factor=1.0, verbosity=0) #uses both penalty factors

        mdl_single_lsgst_cpsp = self.runSilent(pygsti.do_mc2gst, ds, mdl_clgst, self.lsgstStrings[0], minProbClipForWeighting=1e-4,
                                              probClipInterval=(-1e6,1e6), cptp_penalty_factor=1.0,
                                              spam_penalty_factor=1.0, verbosity=10) #uses both penalty factors w/verbosity high
        mdl_single_lsgst_cp = self.runSilent(pygsti.do_mc2gst, ds, mdl_clgst, self.lsgstStrings[0], minProbClipForWeighting=1e-4,
                                            probClipInterval=(-1e6,1e6), cptp_penalty_factor=1.0,
                                            verbosity=10) #uses cptp_penalty_factor w/verbosity high
        mdl_single_lsgst_sp = self.runSilent(pygsti.do_mc2gst, ds, mdl_clgst, self.lsgstStrings[0], minProbClipForWeighting=1e-4,
                                            probClipInterval=(-1e6,1e6), spam_penalty_factor=1.0,
                                            verbosity=10) #uses spam_penalty_factor w/verbosity high


        
        mdl_lsgst = pygsti.do_iterative_mc2gst(ds, mdl_clgst, self.lsgstStrings, verbosity=0,
                                             minProbClipForWeighting=1e-6, probClipInterval=(-1e6,1e6),
                                             memLimit=CM + 1024**3)
        all_minErrs, all_gs_lsgst_tups = pygsti.do_iterative_mc2gst(
            ds, mdl_clgst, [ [mdl.tup for mdl in gsList] for gsList in self.lsgstStrings],
            minProbClipForWeighting=1e-6, probClipInterval=(-1e6,1e6), returnAll=True, returnErrorVec=True)
        mdl_lsgst_verb = self.runSilent(pygsti.do_iterative_mc2gst, ds, mdl_clgst, self.lsgstStrings, verbosity=10,
                                             minProbClipForWeighting=1e-6, probClipInterval=(-1e6,1e6),
                                             memLimit=CM + 1024**3)
        mdl_lsgst_reg = self.runSilent(pygsti.do_iterative_mc2gst,ds, mdl_clgst,
                                      self.lsgstStrings, verbosity=10,
                                      minProbClipForWeighting=1e-6,
                                      probClipInterval=(-1e6,1e6),
                                      regularizeFactor=10, memLimit=CM + 1024**3)
        self.assertAlmostEqual(mdl_lsgst.frobeniusdist(mdl_lsgst_verb),0)
        self.assertAlmostEqual(mdl_lsgst.frobeniusdist(all_gs_lsgst_tups[-1]),0)


        #Run internal checks on less max-L values (so it doesn't take forever)
        mdl_lsgst_chk = pygsti.do_iterative_mc2gst(ds, mdl_clgst, self.lsgstStrings[0:2], verbosity=0,
                                                 minProbClipForWeighting=1e-6, probClipInterval=(-1e6,1e6),
                                                 check=True, check_jacobian=True)
        mdl_lsgst_chk_verb = self.runSilent(pygsti.do_iterative_mc2gst, ds, mdl_clgst, self.lsgstStrings[0:2], verbosity=10,
                                                      minProbClipForWeighting=1e-6, probClipInterval=(-1e6,1e6),
                                                      check=True, check_jacobian=True, memLimit=CM + 1024**3)

        #Other option variations - just make sure they run at this point
        mdl_lsgst_chk_opts = pygsti.do_iterative_mc2gst(ds, mdl_clgst, self.lsgstStrings[0:2], verbosity=0,
                                                      minProbClipForWeighting=1e-6, probClipInterval=(-1e6,1e6),
                                                      useFreqWeightedChiSq=True, circuitSetLabels=["Set1","Set2"],
                                                      circuitWeightsDict={ ('Gx',): 2.0 } )

        aliased_list = [ pygsti.obj.Circuit( [ (x if x != L("Gx") else L("GA1")) for x in mdl]) for mdl in self.lsgstStrings[0] ]
        mdl_withA1 = mdl_clgst.copy(); mdl_withA1.operations["GA1"] = mdl_clgst.operations["Gx"]
        del mdl_withA1.operations["Gx"] # otherwise mdl_withA1 will have Gx params that we have no knowledge of!
        mdl_lsgst_chk_opts2 = pygsti.do_mc2gst(ds, mdl_withA1, aliased_list, minProbClipForWeighting=1e-6,
                                              probClipInterval=(-1e2,1e2), verbosity=10,
                                              opLabelAliases={ L('GA1'): (L('Gx'),) })

        
        #Check with small but ok memlimit -- not anymore since new mem estimation uses current memory, making this non-robust
        #self.runSilent(pygsti.do_mc2gst,ds, mdl_clgst, self.lsgstStrings[0], minProbClipForWeighting=1e-6,
        #                 probClipInterval=(-1e6,1e6), regularizeFactor=1e-3,
        #                 verbosity=10, memLimit=CM + 1024**3)


        #Check errors:
        with self.assertRaises(MemoryError):
            pygsti.do_mc2gst(ds, mdl_clgst, self.lsgstStrings[0], minProbClipForWeighting=1e-6,
                             probClipInterval=(-1e6,1e6), regularizeFactor=1e-3,
                             verbosity=0, memLimit=1)

        with self.assertRaises(AssertionError):
            pygsti.do_mc2gst(ds, mdl_clgst, self.lsgstStrings[0], minProbClipForWeighting=1e-6,
                             probClipInterval=(-1e6,1e6), regularizeFactor=1e-3,
                             verbosity=0, cptp_penalty_factor=1.0) #can't specify both cptp_penalty_factor and regularizeFactor


        # RUN BELOW LINES TO SEED SAVED GATESET FILES
        if os.environ.get('PYGSTI_REGEN_REF_FILES','no').lower() in ("yes","1","true"):
            pygsti.io.write_model(mdl_lsgst,compare_files + "/lsgst.model", "Saved LSGST Model")
            pygsti.io.write_model(mdl_lsgst_reg,compare_files + "/lsgst_reg.model", "Saved LSGST Model w/Regularization")

        mdl_lsgst_compare = pygsti.io.load_model(compare_files + "/lsgst.model")
        mdl_lsgst_reg_compare = pygsti.io.load_model(compare_files + "/lsgst_reg.model")

        mdl_lsgst_go = pygsti.gaugeopt_to_target(mdl_lsgst, mdl_lsgst_compare, {'spam':1.0}, checkJac=True)

        mdl_lsgst_reg_go = pygsti.gaugeopt_to_target(mdl_lsgst_reg, mdl_lsgst_reg_compare, {'spam':1.0}, checkJac=True)

        self.assertAlmostEqual( mdl_lsgst_go.frobeniusdist(mdl_lsgst_compare), 0, places=4)
        self.assertAlmostEqual( mdl_lsgst_reg_go.frobeniusdist(mdl_lsgst_reg_compare), 0, places=4)

        # RUN BELOW LINES TO SEED SAVED GATESET FILES
        if os.environ.get('PYGSTI_REGEN_REF_FILES','no').lower() in ("yes","1","true"):
            mdl_lsgst_go = pygsti.gaugeopt_to_target(mdl_lsgst, self.model, {'spam':1.0})
            pygsti.io.write_model(mdl_lsgst_go,compare_files + "/analysis.model", "Saved LSGST Analysis Model")
            print("DEBUG: analysis.model = "); print(mdl_lgst_go)
Example #13
0
    def test_MC2GST(self):

        ds = self.ds
        #pygsti.construction.generate_fake_data(self.datagen_gateset, self.lsgstStrings[-1],
        #                                            nSamples=1000, sampleError='binomial', seed=100)

        gs_lgst = pygsti.do_lgst(ds, self.fiducials, self.fiducials, self.gateset, svdTruncateTo=4, verbosity=0)
        gs_lgst_go = pygsti.gaugeopt_to_target(gs_lgst,self.gateset, {'spam':1.0, 'gates': 1.0}, checkJac=True)
        gs_clgst = pygsti.contract(gs_lgst_go, "CPTP")
        CM = pygsti.baseobjs.profiler._get_mem_usage()

        gs_single_lsgst = pygsti.do_mc2gst(ds, gs_clgst, self.lsgstStrings[0], minProbClipForWeighting=1e-4,
                                           probClipInterval=(-1e6,1e6), regularizeFactor=1e-3,
                                           verbosity=0) #uses regularizeFactor

        gs_single_lsgst_cp = pygsti.do_mc2gst(ds, gs_clgst, self.lsgstStrings[0], minProbClipForWeighting=1e-4,
                                           probClipInterval=(-1e6,1e6), cptp_penalty_factor=1.0,
                                           verbosity=0) #uses cptp_penalty_factor

        gs_single_lsgst_sp = pygsti.do_mc2gst(ds, gs_clgst, self.lsgstStrings[0], minProbClipForWeighting=1e-4,
                                              probClipInterval=(-1e6,1e6), spam_penalty_factor=1.0,
                                              verbosity=0) #uses spam_penalty_factor

        gs_single_lsgst_cpsp = pygsti.do_mc2gst(ds, gs_clgst, self.lsgstStrings[0], minProbClipForWeighting=1e-4,
                                                probClipInterval=(-1e6,1e6), cptp_penalty_factor=1.0,
                                                spam_penalty_factor=1.0, verbosity=0) #uses both penalty factors

        gs_single_lsgst_cpsp = self.runSilent(pygsti.do_mc2gst, ds, gs_clgst, self.lsgstStrings[0], minProbClipForWeighting=1e-4,
                                              probClipInterval=(-1e6,1e6), cptp_penalty_factor=1.0,
                                              spam_penalty_factor=1.0, verbosity=10) #uses both penalty factors w/verbosity high
        gs_single_lsgst_cp = self.runSilent(pygsti.do_mc2gst, ds, gs_clgst, self.lsgstStrings[0], minProbClipForWeighting=1e-4,
                                            probClipInterval=(-1e6,1e6), cptp_penalty_factor=1.0,
                                            verbosity=10) #uses cptp_penalty_factor w/verbosity high
        gs_single_lsgst_sp = self.runSilent(pygsti.do_mc2gst, ds, gs_clgst, self.lsgstStrings[0], minProbClipForWeighting=1e-4,
                                            probClipInterval=(-1e6,1e6), spam_penalty_factor=1.0,
                                            verbosity=10) #uses spam_penalty_factor w/verbosity high


        
        gs_lsgst = pygsti.do_iterative_mc2gst(ds, gs_clgst, self.lsgstStrings, verbosity=0,
                                             minProbClipForWeighting=1e-6, probClipInterval=(-1e6,1e6),
                                             memLimit=CM + 1024**3)
        all_minErrs, all_gs_lsgst_tups = pygsti.do_iterative_mc2gst(
            ds, gs_clgst, [ [gs.tup for gs in gsList] for gsList in self.lsgstStrings],
            minProbClipForWeighting=1e-6, probClipInterval=(-1e6,1e6), returnAll=True, returnErrorVec=True)
        gs_lsgst_verb = self.runSilent(pygsti.do_iterative_mc2gst, ds, gs_clgst, self.lsgstStrings, verbosity=10,
                                             minProbClipForWeighting=1e-6, probClipInterval=(-1e6,1e6),
                                             memLimit=CM + 1024**3)
        gs_lsgst_reg = self.runSilent(pygsti.do_iterative_mc2gst,ds, gs_clgst,
                                      self.lsgstStrings, verbosity=10,
                                      minProbClipForWeighting=1e-6,
                                      probClipInterval=(-1e6,1e6),
                                      regularizeFactor=10, memLimit=CM + 1024**3)
        self.assertAlmostEqual(gs_lsgst.frobeniusdist(gs_lsgst_verb),0)
        self.assertAlmostEqual(gs_lsgst.frobeniusdist(all_gs_lsgst_tups[-1]),0)


        #Run internal checks on less max-L values (so it doesn't take forever)
        gs_lsgst_chk = pygsti.do_iterative_mc2gst(ds, gs_clgst, self.lsgstStrings[0:2], verbosity=0,
                                                 minProbClipForWeighting=1e-6, probClipInterval=(-1e6,1e6),
                                                 check=True, check_jacobian=True)
        gs_lsgst_chk_verb = self.runSilent(pygsti.do_iterative_mc2gst, ds, gs_clgst, self.lsgstStrings[0:2], verbosity=10,
                                                      minProbClipForWeighting=1e-6, probClipInterval=(-1e6,1e6),
                                                      check=True, check_jacobian=True, memLimit=CM + 1024**3)

        #Other option variations - just make sure they run at this point
        gs_lsgst_chk_opts = pygsti.do_iterative_mc2gst(ds, gs_clgst, self.lsgstStrings[0:2], verbosity=0,
                                                      minProbClipForWeighting=1e-6, probClipInterval=(-1e6,1e6),
                                                      useFreqWeightedChiSq=True, gateStringSetLabels=["Set1","Set2"],
                                                      gatestringWeightsDict={ ('Gx',): 2.0 } )

        aliased_list = [ pygsti.obj.GateString( [ (x if x != "Gx" else "GA1") for x in gs]) for gs in self.lsgstStrings[0] ]
        gs_withA1 = gs_clgst.copy(); gs_withA1.gates["GA1"] = gs_clgst.gates["Gx"]
        del gs_withA1.gates["Gx"] # otherwise gs_withA1 will have Gx params that we have no knowledge of!
        gs_lsgst_chk_opts2 = pygsti.do_mc2gst(ds, gs_withA1, aliased_list, minProbClipForWeighting=1e-6,
                                              probClipInterval=(-1e2,1e2), verbosity=10,
                                              gateLabelAliases={ 'GA1': ('Gx',) })

        
        #Check with small but ok memlimit -- not anymore since new mem estimation uses current memory, making this non-robust
        #self.runSilent(pygsti.do_mc2gst,ds, gs_clgst, self.lsgstStrings[0], minProbClipForWeighting=1e-6,
        #                 probClipInterval=(-1e6,1e6), regularizeFactor=1e-3,
        #                 verbosity=10, memLimit=CM + 1024**3)


        #Check errors:
        with self.assertRaises(MemoryError):
            pygsti.do_mc2gst(ds, gs_clgst, self.lsgstStrings[0], minProbClipForWeighting=1e-6,
                             probClipInterval=(-1e6,1e6), regularizeFactor=1e-3,
                             verbosity=0, memLimit=1)

        with self.assertRaises(AssertionError):
            pygsti.do_mc2gst(ds, gs_clgst, self.lsgstStrings[0], minProbClipForWeighting=1e-6,
                             probClipInterval=(-1e6,1e6), regularizeFactor=1e-3,
                             verbosity=0, cptp_penalty_factor=1.0) #can't specify both cptp_penalty_factor and regularizeFactor


        # RUN BELOW LINES TO SEED SAVED GATESET FILES
        #pygsti.io.write_gateset(gs_lsgst,compare_files + "/lsgst.gateset", "Saved LSGST Gateset")
        #pygsti.io.write_gateset(gs_lsgst_reg,compare_files + "/lsgst_reg.gateset", "Saved LSGST Gateset w/Regularization")

        gs_lsgst_compare = pygsti.io.load_gateset(compare_files + "/lsgst.gateset")
        gs_lsgst_reg_compare = pygsti.io.load_gateset(compare_files + "/lsgst_reg.gateset")

        gs_lsgst_go = pygsti.gaugeopt_to_target(gs_lsgst, gs_lsgst_compare, {'spam':1.0}, checkJac=True)

        gs_lsgst_reg_go = pygsti.gaugeopt_to_target(gs_lsgst_reg, gs_lsgst_reg_compare, {'spam':1.0}, checkJac=True)

        self.assertAlmostEqual( gs_lsgst_go.frobeniusdist(gs_lsgst_compare), 0, places=4)
        self.assertAlmostEqual( gs_lsgst_reg_go.frobeniusdist(gs_lsgst_reg_compare), 0, places=4)
Example #14
0
    def setUpClass(cls):
        """ 
        Handle all once-per-class (slow) computation and loading,
         to avoid calling it for each test (like setUp).  Store
         results in class variable for use within setUp.
        """
        super(ReportBaseCase, cls).setUpClass()

        orig_cwd = os.getcwd()
        os.chdir(os.path.abspath(os.path.dirname(__file__)))
        os.chdir('..')  # The test_packages directory

        targetGateset = std.gs_target
        datagen_gateset = targetGateset.depolarize(gate_noise=0.05,
                                                   spam_noise=0.1)
        datagen_gateset2 = targetGateset.depolarize(gate_noise=0.1,
                                                    spam_noise=0.05).rotate(
                                                        (0.15, -0.03, 0.03))

        #cls.specs = pygsti.construction.build_spam_specs(std.fiducials, effect_labels=['E0'])
        #  #only use the first EVec

        gateLabels = std.gates
        cls.lgstStrings = pygsti.construction.list_lgst_gatestrings(
            std.fiducials, std.fiducials, gateLabels)
        cls.maxLengthList = [1, 2, 4, 8]

        cls.lsgstStrings = pygsti.construction.make_lsgst_lists(
            gateLabels, std.fiducials, std.fiducials, std.germs,
            cls.maxLengthList)
        cls.lsgstStructs = pygsti.construction.make_lsgst_structs(
            gateLabels, std.fiducials, std.fiducials, std.germs,
            cls.maxLengthList)

        try:
            basestring  #Only defined in Python 2
            cls.versionsuffix = ""  #Python 2
        except NameError:
            cls.versionsuffix = "v3"  #Python 3

        # RUN BELOW LINES TO GENERATE ANALYSIS DATASET
        #ds = pygsti.construction.generate_fake_data(datagen_gateset, cls.lsgstStrings[-1], nSamples=1000,
        #                                            sampleError='binomial', seed=100)
        #ds.save(compare_files + "/reportgen.dataset%s" % cls.versionsuffix)
        #ds2 = pygsti.construction.generate_fake_data(datagen_gateset2, cls.lsgstStrings[-1], nSamples=1000,
        #                                            sampleError='binomial', seed=100)
        #ds2.save(compare_files + "/reportgen2.dataset%s" % cls.versionsuffix)

        cls.ds = pygsti.objects.DataSet(
            fileToLoadFrom=compare_files +
            "/reportgen.dataset%s" % cls.versionsuffix)
        cls.ds2 = pygsti.objects.DataSet(
            fileToLoadFrom=compare_files +
            "/reportgen2.dataset%s" % cls.versionsuffix)

        gs_lgst = pygsti.do_lgst(cls.ds,
                                 std.fiducials,
                                 std.fiducials,
                                 targetGateset,
                                 svdTruncateTo=4,
                                 verbosity=0)
        gs_lgst_go = pygsti.gaugeopt_to_target(gs_lgst, targetGateset, {
            'gates': 1.0,
            'spam': 0.0
        })
        cls.gs_clgst = pygsti.contract(gs_lgst_go, "CPTP")
        cls.gs_clgst_tp = pygsti.contract(cls.gs_clgst, "vSPAM")
        cls.gs_clgst_tp.set_all_parameterizations("TP")

        #Compute results for MC2GST
        lsgst_gatesets_prego = pygsti.do_iterative_mc2gst(
            cls.ds,
            cls.gs_clgst,
            cls.lsgstStrings,
            verbosity=0,
            minProbClipForWeighting=1e-6,
            probClipInterval=(-1e6, 1e6),
            returnAll=True)

        cls.results = pygsti.objects.Results()
        cls.results.init_dataset(cls.ds)
        cls.results.init_gatestrings(cls.lsgstStructs)
        cls.results.add_estimate(
            targetGateset, cls.gs_clgst, lsgst_gatesets_prego, {
                'objective': "chi2",
                'minProbClipForWeighting': 1e-4,
                'probClipInterval': (-1e6, 1e6),
                'radius': 1e-4,
                'weights': None,
                'defaultDirectory': temp_files + "",
                'defaultBasename': "MyDefaultReportName"
            })

        gaugeOptParams = collections.OrderedDict([
            ('gateset', lsgst_gatesets_prego[-1]),  #so can gauge-propagate CIs
            ('targetGateset', targetGateset),  #so can gauge-propagate CIs
            ('cptp_penalty_factor', 0),
            ('gatesMetric', "frobenius"),
            ('spamMetric', "frobenius"),
            ('itemWeights', {
                'gates': 1.0,
                'spam': 0.001
            }),
            ('returnAll', True)
        ])

        _, gaugeEl, go_final_gateset = pygsti.gaugeopt_to_target(
            **gaugeOptParams)
        gaugeOptParams['_gaugeGroupEl'] = gaugeEl  #so can gauge-propagate CIs
        cls.results.estimates['default'].add_gaugeoptimized(
            gaugeOptParams, go_final_gateset)
        cls.results.estimates['default'].add_gaugeoptimized(
            gaugeOptParams, go_final_gateset, "go_dup")

        #Compute results for MLGST with TP constraint
        # Use do_long_sequence_gst with a non-mark dataset to trigger data scaling
        tp_target = targetGateset.copy()
        tp_target.set_all_parameterizations("TP")

        cls.ds3 = cls.ds.copy_nonstatic()
        cls.ds3.add_counts_from_dataset(cls.ds2)
        cls.ds3.done_adding_data()

        cls.results_logL = pygsti.do_long_sequence_gst(
            cls.ds3,
            tp_target,
            std.fiducials,
            std.fiducials,
            std.germs,
            cls.maxLengthList,
            verbosity=0,
            advancedOptions={
                'tolerance': 1e-6,
                'starting point': 'LGST',
                'onBadFit': ["robust", "Robust", "robust+", "Robust+"],
                'badFitThreshold': -1.0,
                'germLengthLimits': {
                    ('Gx', 'Gi', 'Gi'): 2
                }
            })
        #OLD
        #lsgst_gatesets_TP = pygsti.do_iterative_mlgst(cls.ds, cls.gs_clgst_tp, cls.lsgstStrings, verbosity=0,
        #                                           minProbClip=1e-4, probClipInterval=(-1e6,1e6),
        #                                           returnAll=True) #TP initial gateset => TP output gatesets
        #cls.results_logL = pygsti.objects.Results()
        #cls.results_logL.init_dataset(cls.ds)
        #cls.results_logL.init_gatestrings(cls.lsgstStructs)
        #cls.results_logL.add_estimate(targetGateset, cls.gs_clgst_tp,
        #                         lsgst_gatesets_TP,
        #                         {'objective': "logl",
        #                          'minProbClip': 1e-4,
        #                          'probClipInterval': (-1e6,1e6), 'radius': 1e-4,
        #                          'weights': None, 'defaultDirectory': temp_files + "",
        #                          'defaultBasename': "MyDefaultReportName"})
        #
        #tp_target = targetGateset.copy(); tp_target.set_all_parameterizations("TP")
        #gaugeOptParams = gaugeOptParams.copy() #just to be safe
        #gaugeOptParams['gateset'] = lsgst_gatesets_TP[-1]  #so can gauge-propagate CIs
        #gaugeOptParams['targetGateset'] = tp_target  #so can gauge-propagate CIs
        #_, gaugeEl, go_final_gateset = pygsti.gaugeopt_to_target(**gaugeOptParams)
        #gaugeOptParams['_gaugeGroupEl'] = gaugeEl #so can gauge-propagate CIs
        #cls.results_logL.estimates['default'].add_gaugeoptimized(gaugeOptParams, go_final_gateset)
        #
        ##self.results_logL.options.precision = 3
        ##self.results_logL.options.polar_precision = 2

        os.chdir(orig_cwd)
Example #15
0
    def test_MLGST(self):

        ds = self.ds
        #pygsti.construction.generate_fake_data(self.datagen_gateset, self.lsgstStrings[-1],
        #                                            nSamples=1000, sampleError='binomial', seed=100)

        gs_lgst = pygsti.do_lgst(ds,
                                 self.specs,
                                 self.gateset,
                                 svdTruncateTo=4,
                                 verbosity=0)
        gs_lgst_go = pygsti.optimize_gauge(gs_lgst,
                                           "target",
                                           targetGateset=self.gateset,
                                           spamWeight=1.0,
                                           gateWeight=1.0)
        gs_clgst = pygsti.contract(gs_lgst_go, "CPTP")

        gs_single_mlgst = pygsti.do_mlgst(ds,
                                          gs_clgst,
                                          self.lsgstStrings[0],
                                          minProbClip=1e-6,
                                          probClipInterval=(-1e2, 1e2),
                                          verbosity=0)

        gs_mlegst = pygsti.do_iterative_mlgst(ds,
                                              gs_clgst,
                                              self.lsgstStrings,
                                              verbosity=0,
                                              minProbClip=1e-6,
                                              probClipInterval=(-1e2, 1e2),
                                              memLimit=1000 * 1024**2)
        maxLogL, all_gs_mlegst_tups = pygsti.do_iterative_mlgst(
            ds,
            gs_clgst,
            [[gs.tup for gs in gsList] for gsList in self.lsgstStrings],
            minProbClip=1e-6,
            probClipInterval=(-1e2, 1e2),
            returnAll=True,
            returnMaxLogL=True)

        gs_mlegst_verb = self.runSilent(pygsti.do_iterative_mlgst,
                                        ds,
                                        gs_clgst,
                                        self.lsgstStrings,
                                        verbosity=10,
                                        minProbClip=1e-6,
                                        probClipInterval=(-1e2, 1e2),
                                        memLimit=10 * 1024**2)
        self.assertAlmostEqual(gs_mlegst.frobeniusdist(gs_mlegst_verb), 0)
        self.assertAlmostEqual(gs_mlegst.frobeniusdist(all_gs_mlegst_tups[-1]),
                               0)

        #Run internal checks on less max-L values (so it doesn't take forever)
        gs_mlegst_chk = pygsti.do_iterative_mlgst(ds,
                                                  gs_clgst,
                                                  self.lsgstStrings[0:2],
                                                  verbosity=0,
                                                  minProbClip=1e-6,
                                                  probClipInterval=(-1e2, 1e2),
                                                  check=True)

        #Other option variations - just make sure they run at this point
        gs_mlegst_chk_opts = pygsti.do_iterative_mlgst(
            ds,
            gs_clgst,
            self.lsgstStrings[0:2],
            verbosity=0,
            minProbClip=1e-6,
            probClipInterval=(-1e2, 1e2),
            gateStringSetLabels=["Set1", "Set2"],
            useFreqWeightedChiSq=True)

        aliased_list = [
            pygsti.obj.GateString([(x if x != "Gx" else "GA1") for x in gs])
            for gs in self.lsgstStrings[0]
        ]
        gs_withA1 = gs_clgst.copy()
        gs_withA1.gates["GA1"] = gs_clgst.gates["Gx"]
        gs_mlegst_chk_opts2 = pygsti.do_mlgst(
            ds,
            gs_withA1,
            aliased_list,
            minProbClip=1e-6,
            probClipInterval=(-1e2, 1e2),
            verbosity=0,
            gateLabelAliases={'GA1': ('Gx', )})

        #Other option variations - just make sure they run at this point
        gs_lsgst_chk_opts = pygsti.do_iterative_mc2gst(
            ds,
            gs_clgst,
            self.lsgstStrings[0:2],
            verbosity=0,
            minProbClipForWeighting=1e-6,
            probClipInterval=(-1e6, 1e6),
            useFreqWeightedChiSq=True,
            gateStringSetLabels=["Set1", "Set2"],
            gatestringWeightsDict={('Gx', ): 2.0})

        self.runSilent(pygsti.do_mlgst,
                       ds,
                       gs_clgst,
                       self.lsgstStrings[0],
                       minProbClip=1e-6,
                       probClipInterval=(-1e2, 1e2),
                       verbosity=4,
                       memLimit=300000)  #invoke memory control

        pygsti.do_mlgst(ds,
                        gs_clgst,
                        self.lsgstStrings[0],
                        minProbClip=1e-6,
                        probClipInterval=(-1e2, 1e2),
                        verbosity=0,
                        poissonPicture=False)
        #non-Poisson picture - should use (-1,-1) gateset for consistency?

        #Check errors:
        with self.assertRaises(MemoryError):
            pygsti.do_mlgst(ds,
                            gs_clgst,
                            self.lsgstStrings[0],
                            minProbClip=1e-6,
                            probClipInterval=(-1e2, 1e2),
                            verbosity=0,
                            memLimit=1)

        # RUN BELOW LINES TO SEED SAVED GATESET FILES
        #pygsti.io.write_gateset(gs_mlegst,compare_files + "/mle_gst.gateset", "Saved MLE-GST Gateset")

        gs_mle_compare = pygsti.io.load_gateset(compare_files +
                                                "/mle_gst.gateset")
        gs_mlegst_go = pygsti.optimize_gauge(gs_mlegst,
                                             'target',
                                             targetGateset=gs_mle_compare,
                                             spamWeight=1.0)

        self.assertAlmostEqual(gs_mlegst_go.frobeniusdist(gs_mle_compare),
                               0,
                               places=5)
Example #16
0
    def test_MC2GST(self):

        ds = self.ds
        #pygsti.construction.generate_fake_data(self.datagen_gateset, self.lsgstStrings[-1],
        #                                            nSamples=1000, sampleError='binomial', seed=100)

        gs_lgst = pygsti.do_lgst(ds,
                                 self.specs,
                                 self.gateset,
                                 svdTruncateTo=4,
                                 verbosity=0)
        gs_lgst_go = pygsti.optimize_gauge(gs_lgst,
                                           "target",
                                           targetGateset=self.gateset,
                                           spamWeight=1.0,
                                           gateWeight=1.0)
        gs_clgst = pygsti.contract(gs_lgst_go, "CPTP")

        gs_single_lsgst = pygsti.do_mc2gst(ds,
                                           gs_clgst,
                                           self.lsgstStrings[0],
                                           minProbClipForWeighting=1e-6,
                                           probClipInterval=(-1e6, 1e6),
                                           regularizeFactor=1e-3,
                                           verbosity=0)

        gs_lsgst = pygsti.do_iterative_mc2gst(ds,
                                              gs_clgst,
                                              self.lsgstStrings,
                                              verbosity=0,
                                              minProbClipForWeighting=1e-6,
                                              probClipInterval=(-1e6, 1e6),
                                              memLimit=1000 * 1024**2)
        all_minErrs, all_gs_lsgst_tups = pygsti.do_iterative_mc2gst(
            ds,
            gs_clgst,
            [[gs.tup for gs in gsList] for gsList in self.lsgstStrings],
            minProbClipForWeighting=1e-6,
            probClipInterval=(-1e6, 1e6),
            returnAll=True,
            returnErrorVec=True)
        gs_lsgst_verb = self.runSilent(pygsti.do_iterative_mc2gst,
                                       ds,
                                       gs_clgst,
                                       self.lsgstStrings,
                                       verbosity=10,
                                       minProbClipForWeighting=1e-6,
                                       probClipInterval=(-1e6, 1e6),
                                       memLimit=10 * 1024**2)
        gs_lsgst_reg = self.runSilent(pygsti.do_iterative_mc2gst,
                                      ds,
                                      gs_clgst,
                                      self.lsgstStrings,
                                      verbosity=10,
                                      minProbClipForWeighting=1e-6,
                                      probClipInterval=(-1e6, 1e6),
                                      regularizeFactor=10,
                                      memLimit=100 * 1024**2)
        self.assertAlmostEqual(gs_lsgst.frobeniusdist(gs_lsgst_verb), 0)
        self.assertAlmostEqual(gs_lsgst.frobeniusdist(all_gs_lsgst_tups[-1]),
                               0)

        #Run internal checks on less max-L values (so it doesn't take forever)
        gs_lsgst_chk = pygsti.do_iterative_mc2gst(ds,
                                                  gs_clgst,
                                                  self.lsgstStrings[0:2],
                                                  verbosity=0,
                                                  minProbClipForWeighting=1e-6,
                                                  probClipInterval=(-1e6, 1e6),
                                                  check=True,
                                                  check_jacobian=True)
        gs_lsgst_chk_verb = self.runSilent(pygsti.do_iterative_mc2gst,
                                           ds,
                                           gs_clgst,
                                           self.lsgstStrings[0:2],
                                           verbosity=10,
                                           minProbClipForWeighting=1e-6,
                                           probClipInterval=(-1e6, 1e6),
                                           check=True,
                                           check_jacobian=True,
                                           memLimit=100 * 1024**2)

        #Other option variations - just make sure they run at this point
        gs_lsgst_chk_opts = pygsti.do_iterative_mc2gst(
            ds,
            gs_clgst,
            self.lsgstStrings[0:2],
            verbosity=0,
            minProbClipForWeighting=1e-6,
            probClipInterval=(-1e6, 1e6),
            useFreqWeightedChiSq=True,
            gateStringSetLabels=["Set1", "Set2"],
            gatestringWeightsDict={('Gx', ): 2.0})

        #Check with small but ok memlimit
        self.runSilent(pygsti.do_mc2gst,
                       ds,
                       gs_clgst,
                       self.lsgstStrings[0],
                       minProbClipForWeighting=1e-6,
                       probClipInterval=(-1e6, 1e6),
                       regularizeFactor=1e-3,
                       verbosity=10,
                       memLimit=300000)

        #Check errors:
        with self.assertRaises(MemoryError):
            pygsti.do_mc2gst(ds,
                             gs_clgst,
                             self.lsgstStrings[0],
                             minProbClipForWeighting=1e-6,
                             probClipInterval=(-1e6, 1e6),
                             regularizeFactor=1e-3,
                             verbosity=0,
                             memLimit=1)

        with self.assertRaises(NotImplementedError):
            pygsti.do_mc2gst(
                ds,
                gs_clgst,
                self.lsgstStrings[0],
                minProbClipForWeighting=1e-6,
                probClipInterval=(-1e6, 1e6),
                regularizeFactor=1e-3,
                verbosity=0,
                cptp_penalty_factor=1.0)  #cptp pentalty not implemented yet

        # RUN BELOW LINES TO SEED SAVED GATESET FILES
        #pygsti.io.write_gateset(gs_lsgst,compare_files + "/lsgst.gateset", "Saved LSGST Gateset")
        #pygsti.io.write_gateset(gs_lsgst_reg,compare_files + "/lsgst_reg.gateset", "Saved LSGST Gateset w/Regularization")

        gs_lsgst_compare = pygsti.io.load_gateset(compare_files +
                                                  "/lsgst.gateset")
        gs_lsgst_reg_compare = pygsti.io.load_gateset(compare_files +
                                                      "/lsgst_reg.gateset")

        gs_lsgst_go = pygsti.optimize_gauge(gs_lsgst,
                                            'target',
                                            targetGateset=gs_lsgst_compare,
                                            spamWeight=1.0)
        gs_lsgst_reg_go = pygsti.optimize_gauge(
            gs_lsgst_reg,
            'target',
            targetGateset=gs_lsgst_reg_compare,
            spamWeight=1.0)

        self.assertAlmostEqual(gs_lsgst_go.frobeniusdist(gs_lsgst_compare),
                               0,
                               places=5)
        self.assertAlmostEqual(
            gs_lsgst_reg_go.frobeniusdist(gs_lsgst_reg_compare), 0, places=5)