def test_global_L(self): config.global_L = 10 test_ops = OrderedDict([ ('sx', do.Sigmax), ('sy', do.Sigmay), ('sz', do.Sigmaz), ('ident', do.Identity), ('zero', do.Zero), ('sum', lambda: do.Sum([do.Sigmax()])), ('product', lambda: do.Product([do.Sigmax()])), ('indexsum', lambda: do.IndexSum(do.Sigmax())), ('indexproduct', lambda: do.IndexProduct(do.Sigmax())), ]) for op, d in test_ops.items(): with self.subTest(op=op): self.assertEqual(d().L, 10) v = build_state() self.assertEqual(v.size, 2**10) config.global_L = None for op, d in test_ops.items(): with self.subTest(op=op): self.assertIs(d().L, None) with self.assertRaises(ValueError): build_state()
def longrange(L): d = do.Sum( do.IndexSum(do.Sigmaz(0) * do.Sigmaz(i)) for i in range(1, L - 1)) d += 0.5 * do.IndexSum(do.Sigmax(0) * do.Sigmax(1)) d += 0.1 * do.Sum( do.IndexSum(s()) for s in (do.Sigmax, do.Sigmay, do.Sigmaz)) d.L = L n = np.zeros((2**L, 2**L), dtype=np.complex128) for j in range(1, L - 1): n += sum( np_sigmaz(i, L).dot(np_sigmaz(i + j, L)) for i in range(L - j)) n += 0.5 * sum( np_sigmax(i, L).dot(np_sigmax(i + 1, L)) for i in range(L - 1)) n += 0.1 * sum(np_sigmai(t, i, L) for i in range(L) for t in 'xyz') return d, n
def XXYY(L): d = do.IndexSum(do.Sum(s(0) * s(1) for s in [do.Sigmax, do.Sigmay])) d.L = L n = np.zeros((2**L, 2**L), dtype=np.complex128) for s in 'xy': n += sum( np_sigmai(s, i, L).dot(np_sigmai(s, i + 1, L)) for i in range(L - 1)) return d, n
def test_generatorSum(self): for name, ol in self.op_lists.items(): with self.subTest(ops=name): d = do.Sum(s() for s in ol[1]) n = ol[0][0](0, config.global_L) for o in ol[0][1:]: n += o(0, config.global_L) r, msg = check_dnm_np(d, n) self.assertTrue(r, msg=msg)
def setUp(self): self.L = 4 self.cuts = [0, 1, 2, 4] self.states = OrderedDict([ ('product0', build_state(L=self.L)), ('product1', build_state(L=self.L, state=int(0.8675309 * (2**self.L)))), ('random', build_state(L=self.L, state='random')) ]) H = do.IndexSum(do.Sum(s(0) * s(1) for s in (do.Sigmax, do.Sigmaz))) H.L = self.L self.states['evolved'] = H.evolve(self.states['product1'], 1.0)
def test_SumofProduct(self): for name, ol in self.op_lists.items(): with self.subTest(ops=name): d = do.Sum(s(0) * s(1) for s in ol[1]) s = ol[0][0](0, config.global_L) n = s.dot(ol[0][0](1, config.global_L)) for o in ol[0][1:]: s = o(0, config.global_L) n += s.dot(o(1, config.global_L)) r, msg = check_dnm_np(d, n) self.assertTrue(r, msg=msg)
def test_indexSumofSum(self): for name, ol in self.op_lists.items(): with self.subTest(ops=name): d = do.IndexSum(do.Sum(s() for s in ol[1])) n = ol[0][0](0, config.global_L) for o in ol[0][1:]: n += o(0, config.global_L) for i in range(1, config.global_L): for o in ol[0]: n += o(i, config.global_L) r, msg = check_dnm_np(d, n) self.assertTrue(r, msg=msg)
def test_recursive(self): s = [do.Sigmax(i) for i in range(3)] s1 = s[0] * s[1] * s[2] s2 = s[0] * (s[1] * s[2]) self.assertEqual(s1, s2) self.assertEqual(len(s1.terms), 3) self.assertEqual(len(s2.terms), 3) s1 = s[0] * s[1] * s[2] * s[0] s2 = (s[0] * s[1]) * (s[2] * s[0]) self.assertEqual(s1, s2) self.assertEqual(len(s1.terms), 4) self.assertEqual(len(s2.terms), 4) with self.assertRaises(ValueError): do.Sum(terms=[])
def test_sum_one(self): d = do.Sum([do.Sigmax()]) self.assertEqual(do.Sigmax(), d)