class Modelpack1QTester(ModelpackBase, BaseCase): modelpack = smq1Q_XYZI expected_fiducials_default = circuit_list( [(), (('Gxpi2', 0), ), (('Gypi2', 0), ), (('Gxpi2', 0), ('Gxpi2', 0)), (('Gxpi2', 0), ('Gxpi2', 0), ('Gxpi2', 0)), (('Gypi2', 0), ('Gypi2', 0), ('Gypi2', 0))], line_labels=[0] ) expected_fiducials_new_idx = circuit_list( [(), (('Gxpi2', 10), ), (('Gypi2', 10), ), (('Gxpi2', 10), ('Gxpi2', 10)), (('Gxpi2', 10), ('Gxpi2', 10), ('Gxpi2', 10)), (('Gypi2', 10), ('Gypi2', 10), ('Gypi2', 10))], line_labels=[10] )
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()
class Modelpack2QTester(ModelpackBase, BaseCase): modelpack = smq2Q_XYICPHASE expected_fiducials_default = circuit_list( [(), (('Gxpi2', 1), ), (('Gypi2', 1), ), (('Gxpi2', 1), ('Gxpi2', 1)), (('Gxpi2', 0), ), (('Gxpi2', 0), ('Gxpi2', 1)), (('Gxpi2', 0), ('Gypi2', 1)), (('Gxpi2', 0), ('Gxpi2', 1), ('Gxpi2', 1)), (('Gypi2', 0), ), (('Gypi2', 0), ('Gxpi2', 1)), (('Gypi2', 0), ('Gypi2', 1)), (('Gypi2', 0), ('Gxpi2', 1), ('Gxpi2', 1)), (('Gxpi2', 0), ('Gxpi2', 0)), (('Gxpi2', 0), ('Gxpi2', 0), ('Gxpi2', 1)), (('Gxpi2', 0), ('Gxpi2', 0), ('Gypi2', 1)), (('Gxpi2', 0), ('Gxpi2', 0), ('Gxpi2', 1), ('Gxpi2', 1))], line_labels=[0, 1] ) expected_fiducials_new_idx = circuit_list( [(), (('Gxpi2', 11), ), (('Gypi2', 11), ), (('Gxpi2', 11), ('Gxpi2', 11)), (('Gxpi2', 10), ), (('Gxpi2', 10), ('Gxpi2', 11)), (('Gxpi2', 10), ('Gypi2', 11)), (('Gxpi2', 10), ('Gxpi2', 11), ('Gxpi2', 11)), (('Gypi2', 10), ), (('Gypi2', 10), ('Gxpi2', 11)), (('Gypi2', 10), ('Gypi2', 11)), (('Gypi2', 10), ('Gxpi2', 11), ('Gxpi2', 11)), (('Gxpi2', 10), ('Gxpi2', 10)), (('Gxpi2', 10), ('Gxpi2', 10), ('Gxpi2', 11)), (('Gxpi2', 10), ('Gxpi2', 10), ('Gypi2', 11)), (('Gxpi2', 10), ('Gxpi2', 10), ('Gxpi2', 11), ('Gxpi2', 11))], line_labels=[10, 11] )
def test_fiducials_germ_gatestrings(self): fids = cc.circuit_list([('Gf0', ), ('Gf1', )]) germs = cc.circuit_list([('G0', ), ('G1a', 'G1b')]) gateStrings1 = cc.create_circuit_list("f0+germ*e+f1", f0=fids, f1=fids, germ=germs, e=2, order=["germ", "f0", "f1"]) expected1 = [ "Gf0(G0)^2Gf0", "Gf0(G0)^2Gf1", "Gf1(G0)^2Gf0", "Gf1(G0)^2Gf1", "Gf0(G1aG1b)^2Gf0", "Gf0(G1aG1b)^2Gf1", "Gf1(G1aG1b)^2Gf0", "Gf1(G1aG1b)^2Gf1" ] self.assertEqual([x.str for x in gateStrings1], expected1) gateStrings2 = cc.create_circuit_list("f0+T(germ,N)+f1", f0=fids, f1=fids, germ=germs, N=3, T=cc.repeat_and_truncate, order=["germ", "f0", "f1"]) expected2 = [ "Gf0G0G0G0Gf0", "Gf0G0G0G0Gf1", "Gf1G0G0G0Gf0", "Gf1G0G0G0Gf1", "Gf0G1aG1bG1aGf0", "Gf0G1aG1bG1aGf1", "Gf1G1aG1bG1aGf0", "Gf1G1aG1bG1aGf1" ] self.assertEqual([x.str for x in gateStrings2], expected2) gateStrings3 = cc.create_circuit_list("f0+T(germ,N)+f1", f0=fids, f1=fids, germ=germs, N=3, T=cc.repeat_with_max_length, order=["germ", "f0", "f1"]) expected3 = [ "Gf0(G0)^3Gf0", "Gf0(G0)^3Gf1", "Gf1(G0)^3Gf0", "Gf1(G0)^3Gf1", "Gf0(G1aG1b)Gf0", "Gf0(G1aG1b)Gf1", "Gf1(G1aG1b)Gf0", "Gf1(G1aG1b)Gf1" ] self.assertEqual([x.str for x in gateStrings3], expected3)
def test_translate_circuit_list(self): orig_list = cc.circuit_list([('Gx', 'Gx'), ('Gx', 'Gy'), ('Gx', 'Gx', 'Gx'), ('Gy', 'Gy'), ('Gi', )]) list0 = cc.translate_circuit_list(orig_list, None) self.assertEqual(list0, orig_list) list1 = cc.translate_circuit_list(orig_list, { Label('Gx'): (Label('Gx2'), ), Label('Gy'): (Label('Gy'), ) }) expected_list1 = cc.circuit_list([('Gx2', 'Gx2'), ('Gx2', 'Gy'), ('Gx2', 'Gx2', 'Gx2'), ('Gy', 'Gy'), ('Gi', )]) self.assertEqual(list1, expected_list1) list2 = cc.translate_circuit_list(orig_list, { Label('Gi'): (Label('Gx'), Label('Gx'), Label('Gx'), Label('Gx')) }) expected_list2 = cc.circuit_list([('Gx', 'Gx'), ('Gx', 'Gy'), ('Gx', 'Gx', 'Gx'), ('Gy', 'Gy'), ('Gx', 'Gx', 'Gx', 'Gx')]) self.assertEqual(list2, expected_list2)
def test_circuit_list_accessors(self): expected_allStrs = set( cc.circuit_list([(), ('Gx', ), ('Gy', ), ('Gx', 'Gx'), ('Gx', 'Gy'), ('Gy', 'Gx'), ('Gy', 'Gy')])) allStrs = cc.list_all_circuits(('Gx', 'Gy'), 0, 2) self.assertEqual(set(allStrs), expected_allStrs) allStrs = list(cc.gen_all_circuits(('Gx', 'Gy'), 0, 2)) self.assertEqual(set(allStrs), expected_allStrs) expected_onelenStrs = set( cc.circuit_list([('Gx', 'Gx'), ('Gx', 'Gy'), ('Gy', 'Gx'), ('Gy', 'Gy')])) onelenStrs = cc.list_all_circuits_onelen(('Gx', 'Gy'), 2) self.assertEqual(set(onelenStrs), expected_onelenStrs) randStrs = cc.list_random_circuits_onelen(('Gx', 'Gy', 'Gz'), 2, 3) self.assertEqual(len(randStrs), 3) self.assertTrue(all([len(s) == 2 for s in randStrs])) # TODO should assert correctness beyond this partialStrs = cc.list_partial_strings(('G1', 'G2', 'G3')) self.assertEqual(partialStrs, [(), ('G1', ), ('G1', 'G2'), ('G1', 'G2', 'G3')])
def test_simple_gatestrings(self): #The workhorse function is cc.create_circuit_list, which executes its positional arguments within a nested #loop given by iterable keyword arguments. That's a mouthful, so let's look at a few examples: As = [('a1', ), ('a2', )] Bs = [('b1', ), ('b2', )] def rep2(x): return x + x def asserter(x): assert (False) def samestr(x): return "Gx" # to test string processing def sametup(x): return "Gx" # to test string processing list0 = cc.create_circuit_list("") self.assertEqual(list0, cc.circuit_list([ () ])) # special case: get the empty operation sequence list1 = cc.create_circuit_list("a", a=As) self.assertEqual(list1, cc.circuit_list(As)) list2 = cc.create_circuit_list("a+b", a=As, b=Bs, order=['a', 'b']) self.assertEqual( list2, cc.circuit_list([('a1', 'b1'), ('a1', 'b2'), ('a2', 'b1'), ('a2', 'b2')])) list3 = cc.create_circuit_list("a+b", a=As, b=Bs, order=['b', 'a']) self.assertEqual( list3, cc.circuit_list([('a1', 'b1'), ('a2', 'b1'), ('a1', 'b2'), ('a2', 'b2')])) list4 = cc.create_circuit_list("R(a)+c", a=As, c=[('c', )], R=rep2, order=['a', 'c']) self.assertEqual( list4, cc.circuit_list([('a1', 'a1', 'c'), ('a2', 'a2', 'c')])) list5 = cc.create_circuit_list("Ast(a)", a=As, Ast=asserter) self.assertEqual(list5, []) # failed assertions cause item to be skipped list6 = cc.create_circuit_list("SS(a)", a=As, SS=samestr) self.assertEqual(list6, cc.circuit_list([ ('Gx', ), ('Gx', ) ])) # strs => parser => Circuits list7 = cc.circuit_list(list1) self.assertEqual(list7, list1) with self.assertRaises(ValueError): cc.circuit_list([{ 'foo': "Bar" }]) # cannot convert dicts to Circuits...