def setUpClass(cls): #OK for these tests, since we test user interface? #Set Model objects to "strict" mode for testing ExplicitOpModel._strict = False cls._model = pc.build_explicit_model( [('Q0', )], ['Gi', 'Gx', 'Gy'], ["I(Q0)", "X(pi/8,Q0)", "Y(pi/8,Q0)"], **cls.build_options) super(ModelBase, cls).setUpClass()
def test_max_gram_rank_and_evals(self): model = pc.build_explicit_model([('Q0',)], ['Gx', 'Gy'], ["X(pi/4,Q0)", "Y(pi/4,Q0)"]) rank, evals, tgt_evals = gm.max_gram_rank_and_evals(self.ds, model) self.assertEqual(rank, 1)
def setUp(self): super(DataSetConstructionTestCase, self).setUp() self.model = pc.build_explicit_model( [('Q0', )], ['Gi', 'Gx', 'Gy'], ["I(Q0)", "X(pi/2,Q0)", "Y(pi/2,Q0)"]) self.depolGateset = self.model.depolarize(op_noise=0.1) def make_lsgst_lists(opLabels, fiducialList, germList, maxLengthList): singleOps = pc.circuit_list([(g, ) for g in opLabels]) lgstStrings = pc.list_lgst_circuits(fiducialList, fiducialList, opLabels) lsgst_list = pc.circuit_list([ () ]) #running list of all strings so far if maxLengthList[0] == 0: lsgst_listOfLists = [lgstStrings] maxLengthList = maxLengthList[1:] else: lsgst_listOfLists = [] for maxLen in maxLengthList: lsgst_list += pc.create_circuit_list( "f0+R(germ,N)+f1", f0=fiducialList, f1=fiducialList, germ=germList, N=maxLen, R=pc.repeat_with_max_length, order=('germ', 'f0', 'f1')) lsgst_listOfLists.append( pygsti.remove_duplicates(lgstStrings + lsgst_list)) print("%d LSGST sets w/lengths" % len(lsgst_listOfLists), map(len, lsgst_listOfLists)) return lsgst_listOfLists gates = ['Gi', 'Gx', 'Gy'] fiducials = pc.circuit_list([(), ('Gx', ), ('Gy', ), ('Gx', 'Gx'), ('Gx', 'Gx', 'Gx'), ('Gy', 'Gy', 'Gy') ]) # fiducials for 1Q MUB germs = pc.circuit_list([('Gx', ), ('Gy', ), ('Gi', ), ( 'Gx', 'Gy', ), ( 'Gx', 'Gy', 'Gi', ), ( 'Gx', 'Gi', 'Gy', ), ( 'Gx', 'Gi', 'Gi', ), ( 'Gy', 'Gi', 'Gi', ), ( 'Gx', 'Gx', 'Gi', 'Gy', ), ( 'Gx', 'Gy', 'Gy', 'Gi', ), ( 'Gx', 'Gx', 'Gy', 'Gx', 'Gy', 'Gy', )]) maxLengths = [0, 1, 2, 4, 8, 16, 32, 64, 128, 256] self.lsgst_lists = make_lsgst_lists(gates, fiducials, germs, maxLengths) self.circuit_list = self.lsgst_lists[-1] self.dataset = pc.generate_fake_data(self.depolGateset, self.circuit_list, nSamples=1000, sampleError='binomial', seed=100)
def setUpClass(cls): # XXX can this be constructed directly instead of taking it from a model instance? EGN: yet, but maybe painful - see model's ._fwdsim() ExplicitOpModel._strict = False cls.model = pc.build_explicit_model( [('Q0', )], ['Gi', 'Gx', 'Gy'], ["I(Q0)", "X(pi/8,Q0)", "Y(pi/8,Q0)"])
def test_explicit(self): model = pc.build_explicit_model( [('Q0',)], ['Gi','Gx','Gy'], [ "I(Q0)","X(pi/2,Q0)", "Y(pi/2,Q0)"]) self.assertEqual(set(model.operations.keys()), set(['Gi','Gx','Gy'])) self.assertAlmostEqual(sum(model.probs( ('Gx','Gi','Gy')).values()), 1.0) self.assertEqual(model.num_params(), 60)
def test_strdiff(self): other = pc.build_explicit_model([('Q0', )], ['Gi', 'Gx', 'Gy'], ["I(Q0)", "X(pi/8,Q0)", "Y(pi/8,Q0)"], parameterization='TP') self.model.strdiff(other)
def test_auto_experiment_design(self): # Let's construct a 1-qubit $X(\pi/2)$, $Y(\pi/2)$, $I$ model for which we will need to find germs and fiducials. target_model = constr.build_explicit_model([('Q0',)], ['Gi', 'Gx', 'Gy'], ["I(Q0)", "X(pi/2,Q0)", "Y(pi/2,Q0)"]) # ## Hands-off # We begin by demonstrating the most hands-off approach. # We can generate a germ set simply by providing the target model. (and seed so it's deterministic) germs = germsel.generate_germs(target_model, seed=2017) # In the same way we can generate preparation and measurement fiducials. prepFiducials, measFiducials = fidsel.generate_fiducials(target_model) #test returnAll - this just prints more info... p,m = fidsel.generate_fiducials(target_model, algorithm_kwargs={'returnAll': True}) #test invalid algorithm with self.assertRaises(ValueError): fidsel.generate_fiducials(target_model, algorithm='foobar') # Now that we have germs and fiducials, we can construct the list of experiments we need to perform in # order to do GST. The only new things to provide at this point are the sizes for the experiments we want # to perform (in this case we want to perform between 0 and 256 gates between fiducial pairs, going up # by a factor of 2 at each stage). maxLengths = [0] + [2**n for n in range(8 + 1)] listOfExperiments = constr.make_lsgst_experiment_list(target_model.operations.keys(), prepFiducials, measFiducials, germs, maxLengths) # The list of `Circuit` that the previous function gave us isn't necessarily the most readable # form to present the information in, so we can write the experiment list out to an empty data # file to be filled in after the experiments are performed. graspGerms = germsel.generate_germs(target_model, algorithm='grasp', seed=2017, numGSCopies=2, candidateGermCounts={3: 'all upto', 4:10, 5:10, 6:10}, candidateSeed=2017, algorithm_kwargs={'iterations': 1}) slackPrepFids, slackMeasFids = fidsel.generate_fiducials(target_model, algorithm='slack', algorithm_kwargs={'slackFrac': 0.25}) fidsel.generate_fiducials(target_model, algorithm='slack') # slacFrac == 1.0 if don't specify either slackFrac or fixedSlack germsMaxLength3 = germsel.generate_germs(target_model, candidateGermCounts={3: 'all upto'}, seed=2017) uniformPrepFids, uniformMeasFids = fidsel.generate_fiducials(target_model, maxFidLength=3, algorithm='grasp', algorithm_kwargs={'iterations': 100}) incompletePrepFids, incompleteMeasFids = fidsel.generate_fiducials(target_model, maxFidLength=1) nonSingletonGerms = germsel.generate_germs(target_model, numGSCopies=2, force=None, candidateGermCounts={4: 'all upto'}, algorithm='grasp', algorithm_kwargs={'iterations': 5}, seed=2017) omitIdentityPrepFids, omitIdentityMeasFids = fidsel.generate_fiducials(target_model, omitIdentity=False, opsToOmit=['Gi'])