def test_Majorana(self): tests = [(1, do.Sigmay()), (2, do.Sigmaz(0) * do.Sigmax(1)), (4, do.Sigmaz(0) * do.Sigmaz(1) * do.Sigmax(2))] for idx, op in tests: X = Majorana(idx) self.assertEqual(X, op)
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_set_L(self): good_Ls = [2] for L in good_Ls: with self.subTest(L=L): s = do.Sigmax(1) s.L = L s.set_length(L) bad_Ls = [0, 'hi', 1] for L in bad_Ls: with self.subTest(L=L): with self.assertRaises(ValueError): s = do.Sigmax(1) s.L = L
def test_length(self): x = do.Sigmax() y = do.Sigmay() x.L = 1 y.L = 2 with self.assertRaises(ValueError): x + y
def test_build(self): s = do.Sigmax() with self.assertRaises(ValueError): s.build_mat() s.L = 1 # just make sure this doesn't throw an # exception s.get_mat(diag_entries=True)
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 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_sum_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)
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_MSC_size(self): # simply an example in which I know the answer s = do.Sigmaz(0) + do.Sigmaz(1) + do.Sigmax(0) self.assertEqual(s.MSC_size, 3)
def test_commutator(self): self.assertEqual(commutator(do.Sigmax(), do.Sigmay()), 2j * do.Sigmaz())
def test_sum_one(self): d = do.Sum([do.Sigmax()]) self.assertEqual(do.Sigmax(), d)
def test_num_sum(self): H = do.Sigmax() with self.assertRaises(TypeError): H + 1
def test_IndexProduct_edgelimits(self): for i in range(self.L): with self.subTest(ind=i): d = do.IndexProduct(do.Sigmax(L=self.L), min_i=i, max_i=i) r, msg = check_dnm_np(d, np_sigmax(i, self.L)) self.assertTrue(r, msg=msg)