def setUp(self): mdl.ExplicitOpModel._strict = False # XXX can these be constructed directly? EGN: yes, some model-construction tests should do it. self.model = build_explicit_model( [('Q0', )], ['Gi', 'Gx', 'Gy'], ["I(Q0)", "X(pi/2,Q0)", "Y(pi/2,Q0)"]) self.gateset_2q = build_explicit_model( [('Q0', 'Q1')], ['GIX', 'GIY', 'GXI', 'GYI', 'GCNOT'], [ "I(Q0):X(pi/2,Q1)", "I(Q0):Y(pi/2,Q1)", "X(pi/2,Q0):I(Q1)", "Y(pi/2,Q0):I(Q1)", "CX(pi,Q0,Q1)" ])
def test_build_basis_gateset(self): modelA = mc.build_explicit_model( [('Q0',)], ['Gi', 'Gx', 'Gy'], ["I(Q0)", "X(pi/2,Q0)", "Y(pi/2,Q0)"] ) modelB = mc.basis_build_explicit_model( [('Q0',)], pygsti.Basis.cast('gm', 4), ['Gi', 'Gx', 'Gy'], ["I(Q0)", "X(pi/2,Q0)", "Y(pi/2,Q0)"] ) self.assertAlmostEqual(modelA.frobeniusdist(modelB), 0)
def test_build_explicit_model(self): model = mc.build_explicit_model([('Q0',)], ['Gi', 'Gx', 'Gy'], ["I(Q0)", "X(pi/2,Q0)", "Y(pi/2,Q0)"]) self.assertEqual(set(model.operations.keys()), set(['Gi', 'Gx', 'Gy'])) self.assertAlmostEqual(sum(model.probs(('Gx', 'Gi', 'Gy')).values()), 1.0) self.assertEqual(model.num_params(), 60) model2 = mc.build_explicit_model([('Q0',)], ['Gi', 'Gx', 'Gy'], ["I(Q0)", "X(pi/2,Q0)", "Y(pi/2,Q0)"]) gateset2b = mc.build_explicit_model([('Q0',)], ['Gi', 'Gx', 'Gy'], ["I(Q0)", "X(pi/2,Q0)", "Y(pi/2,Q0)"], effectLabels=['1', '0']) std_gateset = mc.build_explicit_model([('Q0',)], ['Gi', 'Gx', 'Gy'], ["I(Q0)", "X(pi/8,Q0)", "Y(pi/8,Q0)"], basis="std") pp_gateset = mc.build_explicit_model([('Q0',)], ['Gi', 'Gx', 'Gy'], ["I(Q0)", "X(pi/8,Q0)", "Z(pi/8,Q0)"], basis="pp")
def test_iter_gatesets(self): model = build_explicit_model([('Q0', )], ['Gi', 'Gx', 'Gy'], ["I(Q0)", "X(pi/2,Q0)", "Y(pi/2,Q0)"]) model2 = ExplicitOpModel(['Q0']) for label, gate in model.operations.items(): model2[label] = gate for label, vec in model.preps.items(): model2[label] = vec for label, povm in model.povms.items(): model2[label] = povm self.assertAlmostEqual(model.frobeniusdist(model2), 0.0)
def test_build_explicit_model_raises_on_bad_effect_expression(self): with self.assertRaises(ValueError): mc.build_explicit_model([('Q0',)], ['Gi', 'Gx', 'Gy'], ["I(Q0)", "X(pi/8,Q0)", "Y(pi/8,Q0)"], effectLabels=['0', '1'], effectExpressions=["FooBar", "1"])
def test_build_explicit_model_raises_on_bad_rho_expression(self): with self.assertRaises(ValueError): mc.build_explicit_model([('Q0',)], ['Gi', 'Gx', 'Gy'], ["I(Q0)", "X(pi/8,Q0)", "Y(pi/8,Q0)"], prepLabels=['rho0'], prepExpressions=["FooBar"],)
def test_build_explicit_model_raises_on_bad_basis(self): with self.assertRaises(AssertionError): mc.build_explicit_model([('Q0',)], ['Gi', 'Gx', 'Gy'], ["I(Q0)", "X(pi/8,Q0)", "Y(pi/8,Q0)"], basis="FooBar")
def test_build_explicit_model_raises_on_bad_state(self): with self.assertRaises(ValueError): mc.build_explicit_model([('A0',)], ['Gi', 'Gx', 'Gy'], ["I(Q0)", "X(pi/8,Q0)", "Y(pi/8,Q0)"])