Exemple #1
0
 def setUp(self):
     super(RawSeriesDataSetInstance, self).setUp()
     self.ds = DataSet(outcome_labels=['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(outcome_labels=[('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_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, outcome_labels=['0', '1'])
     ds2.add_counts_from_dataset(self.ds)
 def test_add_dataset(self):
     expected_length = len(self.mds) + 1
     expected_keys = self.mds.keys() + ['newDS']
     ds = DataSet(outcome_labels=['0', '1'])
     ds.add_count_dict(('Gx', ), {'0': 10, '1': 90})
     ds.add_count_dict(('Gx', 'Gy'), {'0': 20, '1': 80})
     ds.add_count_dict(('Gy', ), {'0': 20, '1': 80})
     ds.done_adding_data()
     self.mds['newDS'] = ds
     self.assertTrue('newDS' in self.mds)
     self.assertEqual(len(self.mds), expected_length)
     self.assertEqual(self.mds.keys(), expected_keys)
Exemple #5
0
 def setUp(self):
     self.opLabels = [Label('Gx'), Label('Gy')]
     self.strs = cc.to_circuits([('Gx', ), ('Gy', ), ('Gx', 'Gx')])
     self.germs = cc.to_circuits([('Gx', ), ('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(outcome_labels=['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_upgrade_dataset(self):
        #Test upgrade of 2Q dataset
        ds = DataSet(outcome_labels=('00', '01', '10', '11'))
        ds.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.circuits import Circuit as C
        ds2 = ds.copy()
        newmod = stdtarget.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 #7
0
 def test_construct_keep_separate_on_collision(self):
     ds = DataSet(outcome_labels=['0', '1'], collision_action="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(list(ds.keys()), [('Gx', 'Gx'), ('Gx', 'Gy'), ('Gx', 'Gx')])
     self.assertEqual(list(ds.keys())[2].occurrence, 1)
 def test_add_dataset_raises_on_gate_mismatch(self):
     ds = DataSet(outcome_labels=['0',
                                  '1'])  # different operation sequences
     ds.add_count_dict(('Gx', ), {'0': 10, '1': 90})
     ds.done_adding_data()
     with self.assertRaises(ValueError):
         self.mds['newDS'] = ds
Exemple #9
0
 def test_initialize_from_series_data(self):
     ds = DataSet(outcome_labels=['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 #10
0
class DefaultDataSetInstance(object):
    def setUp(self):
        super(DefaultDataSetInstance, self).setUp()
        self.ds = DataSet(outcome_labels=['0', '1'], collision_action='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',)].fractions['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 #11
0
    def test_load_ignore_zero_count_lines4(self, pth):
        c1 = Circuit('Gc1')
        c2 = Circuit('Gc2')
        c3 = Circuit('Gc3')

        ds = DataSet()

        ds.add_count_dict(c1, {}, aux={'test': 1})
        ds.add_count_dict(c2, {'0': 1}, aux={'test': 1})
        ds.add_count_dict(c3, {}, aux={'test': 1})
        #print(ds)

        io.write_dataset(pth, ds, fixed_column_mode=False)
        ds = io.read_dataset(pth, ignore_zero_count_lines=False)

        self.assertEqual(ds[c1]['0'], 0)
        self.assertEqual(ds[c2]['0'], 1)
        self.assertEqual(
            ds[c3]['0'],
            0)  # especially make sure last line is read in properly!

        self.assertEqual(ds[c1].aux['test'], 1)
        self.assertEqual(ds[c2].aux['test'], 1)
        self.assertEqual(ds[c3].aux['test'], 1)
Exemple #12
0
 def test_static_constructor_raises_on_missing_counts(self):
     with self.assertRaises(ValueError):
         DataSet(circuits=self.gstrs, outcome_labels=['0', '1'], static=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,
                 outcome_labels=['0', '1'], static=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 test_construct_static(self):
     ds = DataSet(self.oli_nonstc, self.time_nonstc, self.reps_nonstc,
                  circuit_indices=self.gstrInds_static, outcome_labels=['0', '1'], static=True)
     with self.assertRaises(ValueError):
         ds.add_counts_from_dataset(ds)  # can't add to static DataSet
Exemple #16
0
 def test_construct_from_map(self):
     ds = DataSet(self.oli_nonstc[:], self.time_nonstc[:], self.reps_nonstc[:],
                  circuit_indices=self.gstrInds, outcome_label_indices=self.olInds)
Exemple #17
0
class StdListTester(BaseCase):
    def setUp(self):
        self.opLabels = [Label('Gx'), Label('Gy')]
        self.strs = cc.to_circuits([('Gx', ), ('Gy', ), ('Gx', 'Gx')])
        self.germs = cc.to_circuits([('Gx', ), ('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(outcome_labels=['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 = gstcircuits.create_lsgst_circuit_lists(
            std1Q_XY.target_model(),
            self.strs,
            self.strs,
            self.germs,
            maxLens,
            fid_pairs=None,
            trunc_scheme="whole germ powers")  # also try a Model as first arg
        self.assertEqual(
            lsgstLists[-1][26]._str, 'GxGx(Gx)^2GxGx'
        )  # ensure that (.)^2 appears in string (*not* expanded)

        lsgstLists2 = gstcircuits.create_lsgst_circuit_lists(
            self.opLabels,
            self.strs,
            self.strs,
            self.germs,
            maxLens,
            fid_pairs=None,
            trunc_scheme="truncated germ powers")
        self.assertEqual(set(lsgstLists[-1]), set(lsgstLists2[-1]))

        lsgstLists3 = gstcircuits.create_lsgst_circuit_lists(
            self.opLabels,
            self.strs,
            self.strs,
            self.germs,
            maxLens,
            fid_pairs=None,
            trunc_scheme="length as exponent")
        lsgstStructs3 = gstcircuits.make_lsgst_structs(
            self.opLabels,
            self.strs,
            self.strs,
            self.germs,
            maxLens,
            fid_pairs=None,
            trunc_scheme="length as exponent")
        self.assertEqual(set(lsgstLists3[-1]), set(lsgstStructs3[-1]))

        maxLens = [1, 2]
        lsgstLists4 = gstcircuits.create_lsgst_circuit_lists(
            self.opLabels,
            self.strs,
            self.strs,
            self.germs,
            maxLens,
            fid_pairs=None,
            trunc_scheme="whole germ powers",
            nest=False)
        lsgstStructs4 = gstcircuits.make_lsgst_structs(
            self.opLabels,
            self.strs,
            self.strs,
            self.germs,
            maxLens,
            fid_pairs=None,
            trunc_scheme="whole germ powers",
            nest=False)
        self.assertEqual(set(lsgstLists4[-1]), set(lsgstStructs4[-1]))

        lsgstLists5 = gstcircuits.create_lsgst_circuit_lists(
            self.opLabels,
            self.strs,
            self.strs,
            self.germs,
            maxLens,
            fid_pairs=self.testFidPairs,
            trunc_scheme="whole germ powers")
        lsgstStructs5 = gstcircuits.make_lsgst_structs(
            self.opLabels,
            self.strs,
            self.strs,
            self.germs,
            maxLens,
            fid_pairs=self.testFidPairs,
            trunc_scheme="whole germ powers")
        self.assertEqual(set(lsgstLists5[-1]), set(lsgstStructs5[-1]))

        lsgstLists6 = gstcircuits.create_lsgst_circuit_lists(
            self.opLabels,
            self.strs,
            self.strs,
            self.germs,
            maxLens,
            fid_pairs=self.testFidPairsDict,
            trunc_scheme="whole germ powers")
        lsgstStructs6 = gstcircuits.make_lsgst_structs(
            self.opLabels,
            self.strs,
            self.strs,
            self.germs,
            maxLens,
            fid_pairs=self.testFidPairsDict,
            trunc_scheme="whole germ powers")
        self.assertEqual(set(lsgstLists6[-1]), set(lsgstStructs6[-1]))

        lsgstLists7 = gstcircuits.create_lsgst_circuit_lists(
            self.opLabels,
            self.strs,
            self.strs,
            self.germs,
            maxLens,
            fid_pairs=None,
            trunc_scheme="whole germ powers",
            keep_fraction=0.5,
            keep_seed=1234)
        lsgstStructs7 = gstcircuits.make_lsgst_structs(
            self.opLabels,
            self.strs,
            self.strs,
            self.germs,
            maxLens,
            fid_pairs=None,
            trunc_scheme="whole germ powers",
            keep_fraction=0.5,
            keep_seed=1234)
        self.assertEqual(set(lsgstLists7[-1]), set(lsgstStructs7[-1]))

        lsgstLists8 = gstcircuits.create_lsgst_circuit_lists(
            self.opLabels,
            self.strs,
            self.strs,
            self.germs,
            maxLens,
            fid_pairs=self.testFidPairs,
            trunc_scheme="whole germ powers",
            keep_fraction=0.7,
            keep_seed=1234)
        lsgstStructs8 = gstcircuits.make_lsgst_structs(
            self.opLabels,
            self.strs,
            self.strs,
            self.germs,
            maxLens,
            fid_pairs=self.testFidPairs,
            trunc_scheme="whole germ powers",
            keep_fraction=0.7,
            keep_seed=1234)
        self.assertEqual(set(lsgstLists8[-1]), set(lsgstStructs8[-1]))

        # empty max-lengths ==> no output
        lsgstStructs9 = gstcircuits.make_lsgst_structs(self.opLabels,
                                                       self.strs,
                                                       self.strs,
                                                       self.germs, [],
                                                       include_lgst=False)
        self.assertEqual(len(lsgstStructs9), 0)

        # checks against data
        lgst_strings = cc.create_lgst_circuits(self.strs, self.strs,
                                               self.opLabels)
        lsgstStructs10 = gstcircuits.make_lsgst_structs(
            self.opLabels,
            self.strs,
            self.strs,
            self.germs,
            maxLens,
            dscheck=self.ds,
            action_if_missing="drop",
            verbosity=4)
        self.assertEqual([Circuit(('Gx', ))], list(lsgstStructs10[-1]))

    def test_lsgst_experiment_list(self):
        maxLens = [1, 2]
        lsgstExpList = gstcircuits.create_lsgst_circuits(
            self.opLabels,
            self.strs,
            self.strs,
            self.germs,
            maxLens,
            fid_pairs=None,
            trunc_scheme="whole germ powers")
        lsgstExpListb = gstcircuits.create_lsgst_circuits(
            std1Q_XY.target_model(),
            self.strs,
            self.strs,
            self.germs,
            maxLens,
            fid_pairs=None,
            trunc_scheme="whole germ powers")  # with Model as first arg
        self.assertEqual(set(lsgstExpList), set(lsgstExpListb))

    def test_lsgst_lists_structs_raises_on_bad_scheme(self):
        maxLens = [1, 2]
        with self.assertRaises(ValueError):
            gstcircuits.create_lsgst_circuit_lists(self.opLabels,
                                                   self.strs,
                                                   self.strs,
                                                   self.germs,
                                                   maxLens,
                                                   fid_pairs=None,
                                                   trunc_scheme="foobar")

        # make_lsgst_structs deprecated
        # with self.assertRaises(ValueError):
        #     stdlists.make_lsgst_structs(
        #         self.opLabels, self.strs, self.strs, self.germs, maxLens, fid_pairs=None,
        #         trunc_scheme="foobar")
        # with self.assertRaises(ValueError):
        #     stdlists.make_lsgst_structs(
        #         self.opLabels, self.strs, self.strs, self.germs, maxLens, dscheck=self.ds,
        #         action_if_missing="foobar")

    def test_lsgst_lists_structs_raises_on_missing_ds_sequence(self):
        with self.assertRaises(ValueError):
            gstcircuits.make_lsgst_structs(
                self.opLabels,
                self.strs,
                self.strs,
                self.germs, [1, 2],
                dscheck=self.ds)  # missing sequences

    @unittest.skip("Skipping due to deprecation of eLGST")
    def test_elgst_lists_structs(self):
        # ELGST
        maxLens = [1, 2]
        elgstLists = gstcircuits.create_elgst_lists(
            self.opLabels,
            self.germs,
            maxLens,
            trunc_scheme="whole germ powers")

        maxLens = [1, 2]
        elgstLists2 = gstcircuits.create_elgst_lists(
            self.opLabels,
            self.germs,
            maxLens,
            trunc_scheme="whole germ powers",
            nest=False,
            include_lgst=False)
        elgstLists2b = gstcircuits.create_elgst_lists(
            std1Q_XY.target_model(),
            self.germs,
            maxLens,
            trunc_scheme="whole germ powers",
            nest=False,
            include_lgst=False)  # with a Model as first arg

    @unittest.skip("Skipping due to deprecation of eLGST")
    def test_elgst_experiment_list(self):
        elgstExpLists = gstcircuits.create_elgst_experiment_list(
            self.opLabels,
            self.germs, [1, 2],
            trunc_scheme="whole germ powers")

    @unittest.skip("Skipping due to deprecation of eLGST")
    def test_elgst_lists_structs_raises_on_bad_scheme(self):
        with self.assertRaises(ValueError):
            gstcircuits.create_elgst_lists(self.opLabels,
                                           self.germs, [1, 2],
                                           trunc_scheme="foobar")
Exemple #18
0
 def test_initialize_from_raw_series_data(self):
     ds = DataSet(outcome_label_indices=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(outcome_labels=['0', '1'])
     ds1.add_count_dict(('Gx',), {'0': 10, '1': 90})
     ds2 = DataSet(outcome_labels=['0', '1'])
     ds2[('Gx',)] = {'0': 10, '1': 90}
Exemple #20
0
 def test_construct_empty_dataset(self):
     dsEmpty = DataSet(outcome_labels=['0', '1'])
     dsEmpty.done_adding_data()
Exemple #21
0
 def setUp(self):
     super(DefaultDataSetInstance, self).setUp()
     self.ds = DataSet(outcome_labels=['0', '1'], collision_action='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 #22
0
 def test_construction_raises_on_op_sequence_mismatch(self):
     DS_bad = DataSet(outcome_labels=['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 #23
0
 def test_construct_from_list(self):
     ds = DataSet(self.oli_nonstc, self.time_nonstc, self.reps_nonstc,
                  circuits=self.gstrs, outcome_labels=['0', '1'])