def test_read_model(self, tmp_path): gs1 = stdin.read_model(tmp_path) rotXPiOv2 = pc.build_operation([(4, )], [('Q0', )], "X(pi/2,Q0)") rotYPiOv2 = pc.build_operation([(4, )], [('Q0', )], "Y(pi/2,Q0)") self.assertArraysAlmostEqual(gs1.operations['G1'], rotXPiOv2) self.assertArraysAlmostEqual(gs1.operations['G2'], rotYPiOv2) self.assertArraysAlmostEqual( gs1.preps['rho'], 1 / np.sqrt(2) * np.array([1, 0, 0, 1]).reshape(-1, 1)) self.assertArraysAlmostEqual( gs1.povms['Mdefault']['0'], 1 / np.sqrt(2) * np.array([1, 0, 0, -1]).reshape(-1, 1))
def _test_gateset_writeload(self, tmp_path, param): mdl = std.target_model() mdl.set_all_parameterizations(param) io.write_model(mdl, tmp_path) gs2 = stdin.read_model(tmp_path) self.assertAlmostEqual(mdl.frobeniusdist(gs2), 0.0) for lbl in mdl.operations: self.assertEqual(type(mdl.operations[lbl]), type(gs2.operations[lbl])) for lbl in mdl.preps: self.assertEqual(type(mdl.preps[lbl]), type(gs2.preps[lbl])) for lbl in mdl.povms: self.assertEqual(type(mdl.povms[lbl]), type(gs2.povms[lbl])) for lbl in mdl.instruments: self.assertEqual(type(mdl.instruments[lbl]), type(gs2.instruments[lbl]))
def test_read_model_raises_on_no_basis_dimension(self, tmp_path): with self.assertRaises(ValueError): stdin.read_model(tmp_path)
def test_read_model_raises_on_bad_item_type(self, tmp_path): with self.assertRaises(ValueError): stdin.read_model(tmp_path)
def test_read_model_raises_on_bad_format_spec(self, tmp_path): with self.assertRaises(ValueError): stdin.read_model(tmp_path)
def test_read_model_raises_on_bad_unitarymxexp(self, tmp_path): with self.assertRaises(ValueError): stdin.read_model(tmp_path)
def test_read_model_raises_on_bad_unitarymx(self, tmp_path): with self.assertRaises(AssertionError): stdin.read_model(tmp_path)
def test_read_model_raises_on_bad_densitymx(self, tmp_path): with self.assertRaises(ValueError): stdin.read_model(tmp_path)
def test_read_model_with_instrument_and_povm(self, tmp_path): gs10 = stdin.read_model(tmp_path)
def test_read_model_2q(self, tmp_path): gs8 = stdin.read_model(tmp_path)