def test_upgrade_dataset(self): #Test upgrade of 2Q dataset ds = DataSet(outcomeLabels=('00', '01', '10', '11')) ds.get_outcome_labels() ds.add_count_dict(('Gix', ), {'00': 90, '10': 10}) ds.add_count_dict(('Giy', ), {'00': 80, '10': 20}) ds.add_count_dict(('Gxi', ), {'00': 55, '10': 45}) ds.add_count_dict(('Gyi', ), {'00': 40, '10': 60}) from pygsti.objects import Circuit as C ds2 = ds.copy() newmod = nc.stdmodule_to_smqmodule(self.std) newmod.upgrade_dataset(ds2) qlbls = (0, 1) # qubit labels self.assertEqual(ds2[C((('Gx', 0), ), qlbls)].counts, { ('00', ): 55, ('10', ): 45 }) self.assertEqual(ds2[C((('Gy', 0), ), qlbls)].counts, { ('00', ): 40, ('10', ): 60 }) self.assertEqual(ds2[C((('Gx', 1), ), qlbls)].counts, { ('00', ): 90, ('10', ): 10 }) self.assertEqual(ds2[C((('Gy', 1), ), qlbls)].counts, { ('00', ): 80, ('10', ): 20 })
class DataSetInstance(object): def setUp(self): super(DataSetInstance, self).setUp() self.ds = DataSet(outcomeLabels=[('0',), ('1',)]) self.ds.add_count_dict(('Gx', 'Gx'), {('0',): 40, ('1',): 60}) self.ds.add_count_dict(('Gx', 'Gy'), {('0',): 40, ('1',): 60}) self.ds.add_count_dict(('Gy', 'Gx'), {('0',): 40, ('1',): 60}) self.ds.add_count_dict(('Gy', 'Gy'), {('0',): 40, ('1',): 60}) self.ds.done_adding_data()
def test_construct_keep_separate_on_collision(self): ds = DataSet(outcomeLabels=['0', '1'], collisionAction="keepseparate") ds.add_count_dict(('Gx', 'Gx'), {'0': 10, '1': 90}) ds.add_count_dict(('Gx', 'Gy'), {'0': 20, '1': 80}) ds.add_count_dict(('Gx', 'Gx'), {'0': 30, '1': 70}) # a duplicate self.assertEqual(ds.keys(), [('Gx', 'Gx'), ('Gx', 'Gy'), ('Gx', 'Gx', '#1')]) self.assertEqual(ds.keys(stripOccurrenceTags=True), [('Gx', 'Gx'), ('Gx', 'Gy'), ('Gx', 'Gx')]) # TODO set_row test separately ds.set_row(('Gx', 'Gx'), {'0': 5, '1': 95}, occurrence=1) # test set_row with occurrence arg
class DefaultDataSetInstance(object): def setUp(self): super(DefaultDataSetInstance, self).setUp() self.ds = DataSet(outcomeLabels=['0', '1'], collisionAction='aggregate') # adds counts at next available integer timestep self.ds.add_count_dict(('Gx',), {'0': 10, '1': 90}) self.ds.add_count_dict(('Gy', 'Gy'), {'1': 90}) self.ds.add_count_dict(('Gy', 'Gy'), ld.OutcomeLabelDict([('0', 10), ('1', 90)])) def test_construction(self): self.assertEqual(self.ds[('Gx',)]['0'], 10) self.assertEqual(self.ds[('Gx',)]['1'], 90) self.assertAlmostEqual(self.ds[('Gx',)].fraction('0'), 0.1) def test_raise_on_new_outcome_label(self): with self.assertRaises(NotImplementedError): self.ds[('Gx',)]['new'] = 20 # assignment can't create *new* outcome labels (yet)
def test_construction_raises_on_op_sequence_mismatch(self): DS_bad = DataSet(outcomeLabels=['0', '1']) # order ok... DS_bad.add_count_dict(('Gx',), {'0': 10, '1': 90}) DS_bad.done_adding_data() with self.assertRaises(ValueError): dc.DataComparator([self.DS_0, DS_bad])
class StdListTester(BaseCase): def setUp(self): self.opLabels = [Label('Gx'), Label('Gy')] self.strs = cc.circuit_list([('Gx', ), ('Gy', ), ('Gx', 'Gx')]) self.germs = cc.circuit_list([('Gx', 'Gy'), ('Gy', 'Gy')]) self.testFidPairs = [(0, 1)] self.testFidPairsDict = { (Label('Gx'), Label('Gy')): [(0, 0), (0, 1)], (Label('Gy'), Label('Gy')): [(0, 0)] } self.ds = DataSet(outcomeLabels=['0', '1']) # a dataset that is missing self.ds.add_count_dict(('Gx', ), { '0': 10, '1': 90 }) # almost all our strings... self.ds.done_adding_data() def test_lsgst_lists_structs(self): maxLens = [1, 2] lsgstLists = stdlists.make_lsgst_lists( std1Q_XY.target_model(), self.strs, self.strs, self.germs, maxLens, fidPairs=None, truncScheme="whole germ powers") # also try a Model as first arg lsgstStructs = stdlists.make_lsgst_structs( std1Q_XY.target_model(), self.strs, self.strs, self.germs, maxLens, fidPairs=None, truncScheme="whole germ powers") # also try a Model as first arg self.assertEqual(set(lsgstLists[-1]), set(lsgstStructs[-1].allstrs)) lsgstLists2 = stdlists.make_lsgst_lists( self.opLabels, self.strs, self.strs, self.germs, maxLens, fidPairs=None, truncScheme="truncated germ powers") lsgstStructs2 = stdlists.make_lsgst_structs( self.opLabels, self.strs, self.strs, self.germs, maxLens, fidPairs=None, truncScheme="truncated germ powers") self.assertEqual(set(lsgstLists2[-1]), set(lsgstStructs2[-1].allstrs)) lsgstLists3 = stdlists.make_lsgst_lists( self.opLabels, self.strs, self.strs, self.germs, maxLens, fidPairs=None, truncScheme="length as exponent") lsgstStructs3 = stdlists.make_lsgst_structs( self.opLabels, self.strs, self.strs, self.germs, maxLens, fidPairs=None, truncScheme="length as exponent") self.assertEqual(set(lsgstLists3[-1]), set(lsgstStructs3[-1].allstrs)) maxLens = [1, 2] lsgstLists4 = stdlists.make_lsgst_lists( self.opLabels, self.strs, self.strs, self.germs, maxLens, fidPairs=None, truncScheme="whole germ powers", nest=False) lsgstStructs4 = stdlists.make_lsgst_structs( self.opLabels, self.strs, self.strs, self.germs, maxLens, fidPairs=None, truncScheme="whole germ powers", nest=False) self.assertEqual(set(lsgstLists4[-1]), set(lsgstStructs4[-1].allstrs)) lsgstLists5 = stdlists.make_lsgst_lists( self.opLabels, self.strs, self.strs, self.germs, maxLens, fidPairs=self.testFidPairs, truncScheme="whole germ powers") lsgstStructs5 = stdlists.make_lsgst_structs( self.opLabels, self.strs, self.strs, self.germs, maxLens, fidPairs=self.testFidPairs, truncScheme="whole germ powers") self.assertEqual(set(lsgstLists5[-1]), set(lsgstStructs5[-1].allstrs)) lsgstLists6 = stdlists.make_lsgst_lists( self.opLabels, self.strs, self.strs, self.germs, maxLens, fidPairs=self.testFidPairsDict, truncScheme="whole germ powers") lsgstStructs6 = stdlists.make_lsgst_structs( self.opLabels, self.strs, self.strs, self.germs, maxLens, fidPairs=self.testFidPairsDict, truncScheme="whole germ powers") self.assertEqual(set(lsgstLists6[-1]), set(lsgstStructs6[-1].allstrs)) lsgstLists7 = stdlists.make_lsgst_lists( self.opLabels, self.strs, self.strs, self.germs, maxLens, fidPairs=None, truncScheme="whole germ powers", keepFraction=0.5, keepSeed=1234) lsgstStructs7 = stdlists.make_lsgst_structs( self.opLabels, self.strs, self.strs, self.germs, maxLens, fidPairs=None, truncScheme="whole germ powers", keepFraction=0.5, keepSeed=1234) self.assertEqual(set(lsgstLists7[-1]), set(lsgstStructs7[-1].allstrs)) lsgstLists8 = stdlists.make_lsgst_lists( self.opLabels, self.strs, self.strs, self.germs, maxLens, fidPairs=self.testFidPairs, truncScheme="whole germ powers", keepFraction=0.7, keepSeed=1234) lsgstStructs8 = stdlists.make_lsgst_structs( self.opLabels, self.strs, self.strs, self.germs, maxLens, fidPairs=self.testFidPairs, truncScheme="whole germ powers", keepFraction=0.7, keepSeed=1234) self.assertEqual(set(lsgstLists8[-1]), set(lsgstStructs8[-1].allstrs)) # TODO assert correctness # empty max-lengths ==> no output lsgstStructs9 = stdlists.make_lsgst_structs(self.opLabels, self.strs, self.strs, self.germs, []) self.assertEqual(len(lsgstStructs9), 0) # checks against datasets lgst_strings = cc.list_lgst_circuits(self.strs, self.strs, self.opLabels) lsgstStructs10 = stdlists.make_lsgst_structs(self.opLabels, self.strs, self.strs, self.germs, maxLens, dscheck=self.ds, actionIfMissing="drop", verbosity=4) self.assertEqual([Circuit(('Gx', ))], lsgstStructs10[-1].allstrs) def test_lsgst_experiment_list(self): maxLens = [1, 2] lsgstExpList = stdlists.make_lsgst_experiment_list( self.opLabels, self.strs, self.strs, self.germs, maxLens, fidPairs=None, truncScheme="whole germ powers") lsgstExpListb = stdlists.make_lsgst_experiment_list( std1Q_XY.target_model(), self.strs, self.strs, self.germs, maxLens, fidPairs=None, truncScheme="whole germ powers") # with Model as first arg # TODO assert correctness def test_lsgst_lists_structs_raises_on_bad_scheme(self): maxLens = [1, 2] with self.assertRaises(ValueError): stdlists.make_lsgst_lists(self.opLabels, self.strs, self.strs, self.germs, maxLens, fidPairs=None, truncScheme="foobar") with self.assertRaises(ValueError): stdlists.make_lsgst_structs(self.opLabels, self.strs, self.strs, self.germs, maxLens, fidPairs=None, truncScheme="foobar") with self.assertRaises(ValueError): stdlists.make_lsgst_structs(self.opLabels, self.strs, self.strs, self.germs, maxLens, dscheck=self.ds, actionIfMissing="foobar") def test_lsgst_lists_structs_raises_on_missing_ds_sequence(self): with self.assertRaises(ValueError): stdlists.make_lsgst_structs(self.opLabels, self.strs, self.strs, self.germs, [1, 2], dscheck=self.ds) # missing sequences def test_elgst_lists_structs(self): # ELGST maxLens = [1, 2] elgstLists = stdlists.make_elgst_lists(self.opLabels, self.germs, maxLens, truncScheme="whole germ powers") maxLens = [1, 2] elgstLists2 = stdlists.make_elgst_lists( self.opLabels, self.germs, maxLens, truncScheme="whole germ powers", nest=False, includeLGST=False) elgstLists2b = stdlists.make_elgst_lists( std1Q_XY.target_model(), self.germs, maxLens, truncScheme="whole germ powers", nest=False, includeLGST=False) # with a Model as first arg # TODO assert correctness def test_elgst_experiment_list(self): elgstExpLists = stdlists.make_elgst_experiment_list( self.opLabels, self.germs, [1, 2], truncScheme="whole germ powers") # TODO assert correctness def test_elgst_lists_structs_raises_on_bad_scheme(self): with self.assertRaises(ValueError): stdlists.make_elgst_lists(self.opLabels, self.germs, [1, 2], truncScheme="foobar")
def test_initialize_by_index(self): ds1 = DataSet(outcomeLabels=['0', '1']) ds1.add_count_dict(('Gx',), {'0': 10, '1': 90}) ds2 = DataSet(outcomeLabels=['0', '1']) ds2[('Gx',)] = {'0': 10, '1': 90}