Exemple #1
0
 def setUp(self):
     super(RawSeriesDataSetInstance, self).setUp()
     self.ds = DataSet(outcomeLabels=['0', '1'])
     self.ds.add_raw_series_data(('Gx',),
                                 ['0', '0', '1', '0', '1', '0', '1', '1', '1', '0'],
                                 [0.0, 0.2, 0.5, 0.6, 0.7, 0.9, 1.1, 1.3, 1.35, 1.5], None)
     self.ds[('Gy', 'Gy')] = (['0', '1'], [0.0, 1.0])  # add via spam-labels, times
Exemple #2
0
 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()
Exemple #3
0
 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
Exemple #4
0
 def test_add_counts_from_dataset(self):
     gstrs = [('Gx',), ('Gx', 'Gy'), ('Gy',)]
     oli = np.array([0, 1], 'i')
     oli_nonstc = [oli, oli, oli]
     time_nonstc = [np.zeros(2, 'd'), np.zeros(2, 'd'), np.zeros(2, 'd')]
     reps_nonstc = [10 * np.ones(2, 'i'), 10 * np.ones(2, 'i'), 10 * np.ones(2, 'i')]
     ds2 = DataSet(oli_nonstc, time_nonstc, reps_nonstc,
                   circuits=gstrs, outcomeLabels=['0', '1'])
     ds2.add_counts_from_dataset(self.ds)
    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
        })
Exemple #6
0
 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()
Exemple #7
0
 def test_initialize_from_series_data(self):
     ds = DataSet(outcomeLabels=['0', '1'])
     ds.add_series_data(('Gy', 'Gy'), [{'0': 2, '1': 8}, {'0': 6, '1': 4}, {'1': 10}],
                        [0.0, 1.2, 2.4])
     ds.add_series_data(('Gy', 'Gy', 'Gy'),
                        [OrderedDict([('0', 2), ('1', 8)]),
                         OrderedDict([('0', 6), ('1', 4)]),
                         OrderedDict([('1', 10)])],
                        [0.0, 1.2, 2.4])  # add with ordered dicts
Exemple #8
0
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)
Exemple #9
0
 def test_construct_from_map(self):
     ds = DataSet(self.oli_nonstc[:], self.time_nonstc[:], self.reps_nonstc[:],
                  circuitIndices=self.gstrInds, outcomeLabelIndices=self.olInds)
Exemple #10
0
 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])
Exemple #11
0
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")
Exemple #12
0
 def test_static_constructor_raises_on_missing_counts(self):
     with self.assertRaises(ValueError):
         DataSet(circuits=self.gstrs, outcomeLabels=['0', '1'], bStatic=True)
Exemple #13
0
 def test_static_constructor_raises_on_missing_oplabels(self):
     with self.assertRaises(ValueError):
         DataSet(self.oli_static, self.time_static, self.reps_static,
                 outcomeLabels=['0', '1'], bStatic=True)
Exemple #14
0
 def test_constructor_raises_on_missing_spam_labels(self):
     gstrs = [('Gx',), ('Gx', 'Gy'), ('Gy',)]
     with self.assertRaises(AssertionError):
         DataSet(circuits=gstrs)  # no spam labels specified
Exemple #15
0
 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)]))  
Exemple #16
0
 def test_construct_static(self):
     ds = DataSet(self.oli_nonstc, self.time_nonstc, self.reps_nonstc,
                  circuitIndices=self.gstrInds_static, outcomeLabels=['0', '1'], bStatic=True)
     with self.assertRaises(ValueError):
         ds.add_counts_from_dataset(ds)  # can't add to static DataSet
Exemple #17
0
 def test_construct_from_list(self):
     ds = DataSet(self.oli_nonstc, self.time_nonstc, self.reps_nonstc,
                  circuits=self.gstrs, outcomeLabels=['0', '1'])
Exemple #18
0
 def test_initialize_from_raw_series_data(self):
     ds = DataSet(outcomeLabelIndices=self.olInds)
     ds.add_raw_series_data(('Gy',),  # gate sequence
                            ['0', '1'],  # spam labels
                            [0.0, 1.0],  # time stamps
                            [3, 7])  # repeats
Exemple #19
0
 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}
Exemple #20
0
 def test_construct_empty_dataset(self):
     dsEmpty = DataSet(outcomeLabels=['0', '1'])
     dsEmpty.done_adding_data()