示例#1
0
    def test_scoring(self):
        eigenvalue_array = np.array([1e-6,1e-4,1.0,2.0])
        s0 = scoring.list_score(eigenvalue_array)
        self.assertEqual(s0, 1010001.5)

        s1 = scoring.list_score(eigenvalue_array, 'all')
        self.assertEqual(s1, 1010001.5)

        s2 = scoring.list_score(eigenvalue_array, 'worst')
        self.assertEqual(s2, 1000000)

        with self.assertRaises(ValueError):
            scoring.list_score(eigenvalue_array, 'foobar')
示例#2
0
    def test_helper_functions(self):
        """ Mostly test boundary cases of helper fns """
        germsToTest = pygsti.construction.list_all_circuits_without_powers_and_cycles(
            list(std.target_model().operations.keys()), 2)

        maxscore = pygsti.alg.calculate_germset_score(germsToTest, std.target_model(),
                                                      neighborhoodSize=5, 
                                                      randomizationStrength=1e-2, scoreFunc='all', 
                                                      opPenalty=0.0, l1Penalty=0.0)

        #Test failures in get_model_params:
        gs1 = std.target_model()
        gs2 = std.target_model()
        gs3 = std.target_model()
        gs4 = std.target_model()
        gs1.set_all_parameterizations("full")
        gs2.set_all_parameterizations("TP")
        gs3.set_all_parameterizations("full")
        gs4.set_all_parameterizations("full")
        gs3.operations['Gi2'] = np.identity(4,'d') #adds non-gauge params but not gauge params
        gs4.operations['Gi2'] = pygsti.obj.StaticDenseOp(np.identity(4,'d')) # keeps param counts the same but adds gate

        with self.assertRaises(ValueError):
            germsel.get_model_params([gs1,gs2]) # different number of gauge params
        with self.assertRaises(ValueError):
            germsel.get_model_params([gs1,gs3]) # different number of non-gauge params
        with self.assertRaises(ValueError):
            germsel.get_model_params([gs1,gs4]) # different number of gates


        self.assertWarns(germsel.setup_model_list, [gs1,gs1], randomize=False, randomizationStrength=0, 
                         numCopies=3, seed=0) # warns b/c list len > 1 and numCopies specified

        scoreFn = lambda x: scoring.list_score(x, scoreFunc="all")
        with self.assertRaises(ValueError):
            germsel.compute_composite_germ_score(scoreFn) #need to provide partialDerivDaggerDeriv or partialGermsList

        germsel.compute_composite_germ_score(scoreFn, model=gs1, partialGermsList=germsToTest,
                                             eps=1e-5, germLengths=np.array([len(g) for g in germsToTest]))
        
        pDDD = np.zeros( (len(germsToTest),gs1.num_params(),gs1.num_params()), 'd')
        with self.assertRaises(ValueError):
            germsel.compute_composite_germ_score(scoreFn, partialDerivDaggerDeriv=pDDD) # must specify model ro numGaugeParams
        with self.assertRaises(ValueError):
            germsel.compute_composite_germ_score(scoreFn, model=gs1, partialDerivDaggerDeriv=pDDD,
                                                 opPenalty=1.0) # must specify partialGermLists or germLengths
        germsel.compute_composite_germ_score(scoreFn, model=gs1, partialDerivDaggerDeriv=pDDD,
                                             partialGermsList=germsToTest, opPenalty=1.0) # OK
示例#3
0
 def test_list_score_worst(self):
     s2 = scoring.list_score(self.eigvals, 'worst')
     self.assertEqual(s2, 1000000)
示例#4
0
 def test_list_score_raises_on_bad_score_function(self):
     with self.assertRaises(ValueError):
         scoring.list_score(self.eigvals, 'foobar')
示例#5
0
 def test_list_score_all(self):
     s1 = scoring.list_score(self.eigvals, 'all')
     self.assertEqual(s1, 1010001.5)