def test_IndexSum_wrap(self): d0, n0 = dnm_np_operator('x', L=self.L, index=0) d1, n1 = dnm_np_operator('x', L=self.L, index=1) # just to make sure this doesn't throw any exceptions d0.L = None d1.L = None d = do.IndexSum(d0 * d1, wrap=True) d.L = self.L d.get_MSC() d0.L = self.L d1.L = self.L d = do.IndexSum(d0 * d1, wrap=True) d.L = self.L n = n0.dot(n1) for i in range(1, self.L - 1): s = np_sigmai('x', index=i, L=self.L) n += s.dot(np_sigmai('x', index=i + 1, L=self.L)) s = np_sigmai('x', index=self.L - 1, L=self.L) n += s.dot(np_sigmai('x', index=0, L=self.L)) r, msg = check_dnm_np(d, n) self.assertTrue(r, msg=msg)
def ising(L): d = do.IndexSum( do.Sigmaz(0) * do.Sigmaz(1)) + 0.2 * do.IndexSum(do.Sigmax()) d.L = L n = np.zeros((2**L, 2**L), dtype=np.complex128) n += sum(np_sigmaz(i, L).dot(np_sigmaz(i + 1, L)) for i in range(L - 1)) n += 0.2 * sum(np_sigmax(i, L) for i in range(L)) return d, n
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 test_IndexSum_edgelimits(self): for i in range(self.L): with self.subTest(ind=i): d = do.IndexSum(do.Sigmay(L=self.L), min_i=i, max_i=i) n = np_sigmay(i, self.L) r, msg = check_dnm_np(d, n) self.assertTrue(r, msg=msg)
def test_IndexSum(self): for s in ['x', 'y', 'z']: with self.subTest(s=s): d, n = dnm_np_operator(s, index=0, L=self.L) d = do.IndexSum(d) for i in range(1, self.L): n = n + np_sigmai(s, index=i, L=self.L) r, msg = check_dnm_np(d, n) self.assertTrue(r, msg=msg)
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 test_IndexSum_limits(self): for low, high in [(1, 1), (1, 3), (0, 3), (0, 0)]: with self.subTest(low=low, high=high): d = do.Sigmay(L=self.L) d = do.IndexSum(d, min_i=low, max_i=high) n = np_sigmay(low, self.L) for i in range(low + 1, high + 1): n += np_sigmay(i, self.L) r, msg = check_dnm_np(d, n) self.assertTrue(r, msg=msg)
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 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_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_indexSumofProd(self): for name, ol in self.op_lists.items(): with self.subTest(ops=name): d = do.IndexSum(do.Product(s() for s in ol[1])) n = ol[0][0](0, config.global_L) for o in ol[0][1:]: n = n.dot(o(0, config.global_L)) for i in range(1, config.global_L): n_tmp = ol[0][0](i, config.global_L) for o in ol[0][1:]: n_tmp = n_tmp.dot(o(i, config.global_L)) n += n_tmp r, msg = check_dnm_np(d, n) self.assertTrue(r, msg=msg)
def test_indexSumofSumofProduct(self): for name, ol in self.op_lists.items(): with self.subTest(ops=name): d = do.IndexSum(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)) for i in range(1, config.global_L - 1): for o in ol[0]: s = o(i, config.global_L) n += s.dot(o(i + 1, config.global_L)) r, msg = check_dnm_np(d, n) self.assertTrue(r, msg=msg)
def test_IndexSum_exceptions(self): for low, high in [(1, 0), (0, self.L + 1), (-1, 0)]: with self.subTest(low=low, high=high): d = do.Sigmay(L=self.L) with self.assertRaises(ValueError): do.IndexSum(d, min_i=low, max_i=high)