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
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 })
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_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
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
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 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_construct_from_map(self): ds = DataSet(self.oli_nonstc[:], self.time_nonstc[:], self.reps_nonstc[:], circuitIndices=self.gstrInds, outcomeLabelIndices=self.olInds)
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])
def test_static_constructor_raises_on_missing_counts(self): with self.assertRaises(ValueError): DataSet(circuits=self.gstrs, outcomeLabels=['0', '1'], bStatic=True)
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)
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
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
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_construct_from_list(self): ds = DataSet(self.oli_nonstc, self.time_nonstc, self.reps_nonstc, circuits=self.gstrs, outcomeLabels=['0', '1'])
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
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}
def test_construct_empty_dataset(self): dsEmpty = DataSet(outcomeLabels=['0', '1']) dsEmpty.done_adding_data()