Exemple #1
0
 def test_inplace_multiplication(self):
     # Real
     expr_r = c(2, "dn")
     expr_r *= c_dag(1, "up")
     self.assertEqual(str(expr_r), "-1*C+(1,up)C(2,dn)")
     expr_r *= a(0, "x")
     self.assertEqual(str(expr_r), "-1*C+(1,up)C(2,dn)A(0,x)")
     expr_r *= a_dag(0, "y")
     self.assertEqual(str(expr_r), "-1*C+(1,up)C(2,dn)A+(0,y)A(0,x)")
     expr_r *= ExpressionR(2)
     self.assertEqual(str(expr_r), "-2*C+(1,up)C(2,dn)A+(0,y)A(0,x)")
     expr_r *= ExpressionR()
     self.assertEqual(str(expr_r), "0")
     # Complex
     expr_c = make_complex(c(2, "dn"))
     expr_c *= make_complex(c_dag(1, "up"))
     self.assertEqual(str(expr_c), "(-1,0)*C+(1,up)C(2,dn)")
     expr_c *= make_complex(a(0, "x"))
     self.assertEqual(str(expr_c), "(-1,0)*C+(1,up)C(2,dn)A(0,x)")
     expr_c *= make_complex(a_dag(0, "y"))
     self.assertEqual(str(expr_c), "(-1,0)*C+(1,up)C(2,dn)A+(0,y)A(0,x)")
     expr_c *= ExpressionC(2)
     self.assertEqual(str(expr_c), "(-2,0)*C+(1,up)C(2,dn)A+(0,y)A(0,x)")
     expr_c *= ExpressionC()
     self.assertEqual(str(expr_c), "(0,0)")
Exemple #2
0
    def test_holstein_int(self):
        g = np.array([1, 2, 3, 4], dtype=float)
        indices_up = [("up", 0), ("up", 1), ("up", 2), ("up", 3)]
        indices_dn = [("dn", 0), ("dn", 1), ("dn", 2), ("dn", 3)]
        indices_boson = [('a', 0), ('b', 1), ('c', 2), ('d', 3)]

        H1 = holstein_int(g)
        self.assertIsInstance(H1, ExpressionR)
        ref1 = sum(g[i] * (n(i, "up") + n(i, "dn")) * (a_dag(i) + a(i))
                   for i in range(4))
        self.assertEqual(H1, ref1)

        H2 = holstein_int(1j * g)
        self.assertIsInstance(H2, ExpressionC)
        ref2 = 1j * ref1
        self.assertEqual(H2, ref2)

        H3 = holstein_int(g,
                          indices_up=indices_up,
                          indices_dn=indices_dn,
                          indices_boson=indices_boson)
        self.assertIsInstance(H3, ExpressionR)
        ref3 = 1.0 * (n("up", 0) + n("dn", 0)) * (a_dag('a', 0) + a('a', 0))
        ref3 += 2.0 * (n("up", 1) + n("dn", 1)) * (a_dag('b', 1) + a('b', 1))
        ref3 += 3.0 * (n("up", 2) + n("dn", 2)) * (a_dag('c', 2) + a('c', 2))
        ref3 += 4.0 * (n("up", 3) + n("dn", 3)) * (a_dag('d', 3) + a('d', 3))
        self.assertEqual(H3, ref3)
Exemple #3
0
    def test_dispersion(self):
        indices = [("a", 0), ("b", 1), ("c", 2)]
        eps = np.array([1.0, 2.0, 3.0])

        H1 = dispersion(eps)
        self.assertIsInstance(H1, ExpressionR)
        ref1 = c_dag(0) * c(0) + 2 * c_dag(1) * c(1) + 3.0 * c_dag(2) * c(2)
        self.assertEqual(H1, ref1)

        H2 = dispersion(1j * eps)
        self.assertIsInstance(H2, ExpressionC)
        ref2 = 1j * ref1
        self.assertEqual(H2, ref2)

        H3 = dispersion(eps, statistics=FERMION)
        self.assertIsInstance(H3, ExpressionR)
        ref3 = ref1
        self.assertEqual(H3, ref3)

        H4 = dispersion(eps, indices=indices)
        self.assertIsInstance(H4, ExpressionR)
        ref4 = c_dag("a", 0) * c("a", 0) + 2 * c_dag("b", 1) * c("b", 1) \
            + 3.0 * c_dag("c", 2) * c("c", 2)
        self.assertEqual(H4, ref4)

        H5 = dispersion(eps, statistics=BOSON)
        self.assertIsInstance(H5, ExpressionR)
        ref5 = a_dag(0) * a(0) + 2 * a_dag(1) * a(1) + 3.0 * a_dag(2) * a(2)
        self.assertEqual(H5, ref5)
Exemple #4
0
    def test_tight_binding(self):
        indices = [("a", 0), ("b", 1), ("c", 2)]
        t = np.array([[1.0, 0.0, 0.5], [0.0, 2.0, 0.0], [0.5, 0.0, 3.0]])

        H1 = tight_binding(t)
        self.assertIsInstance(H1, ExpressionR)
        ref1 = c_dag(0) * c(0) + 2 * c_dag(1) * c(1) + 3.0 * c_dag(2) * c(2)
        ref1 += 0.5 * c_dag(0) * c(2) + 0.5 * c_dag(2) * c(0)
        self.assertEqual(H1, ref1)

        H2 = tight_binding(1j * t)
        self.assertIsInstance(H2, ExpressionC)
        ref2 = 1j * ref1
        self.assertEqual(H2, ref2)

        H3 = tight_binding(t, statistics=FERMION)
        self.assertIsInstance(H3, ExpressionR)
        ref3 = ref1
        self.assertEqual(H3, ref3)

        H4 = tight_binding(t, indices=indices)
        self.assertIsInstance(H4, ExpressionR)
        ref4 = c_dag("a", 0) * c("a", 0) + 2 * c_dag("b", 1) * c("b", 1) \
            + 3.0 * c_dag("c", 2) * c("c", 2)
        ref4 += 0.5 * c_dag("a", 0) * c("c", 2) \
            + 0.5 * c_dag("c", 2) * c("a", 0)
        self.assertEqual(H4, ref4)

        H5 = tight_binding(t, statistics=BOSON)
        self.assertIsInstance(H5, ExpressionR)
        ref5 = a_dag(0) * a(0) + 2 * a_dag(1) * a(1) + 3.0 * a_dag(2) * a(2)
        ref5 += 0.5 * a_dag(0) * a(2) + 0.5 * a_dag(2) * a(0)
        self.assertEqual(H5, ref5)
Exemple #5
0
    def test_transform(self):
        expr = 4.0 * c_dag(1, "up") * c(2, "dn") + 1.0 \
            + 3.0 * a(0, "x") + 2.0 * a_dag(0, "y")

        # Multiply coefficients in front of bosonic operators by 2j
        def f(m, c):
            if len(m) > 0 and isinstance(m[0], GeneratorBoson):
                return 2 * c
            else:
                return 0

        new_expr = transform(expr, f)
        self.assertEqual(new_expr, 6.0 * a(0, "x") + 4.0 * a_dag(0, "y"))
Exemple #6
0
 def test_real_complex(self):
     # Fermion
     self.check_monomial(c_dag(1, "up"), 1, make_fermion(True, 1, "up"))
     self.check_monomial(c(2, "dn"), 1, make_fermion(False, 2, "dn"))
     self.check_monomial(n(1, "dn"), 1, make_fermion(True, 1, "dn"),
                         make_fermion(False, 1, "dn"))
     # Boson
     self.check_monomial(a_dag(0, "x"), 1, make_boson(True, 0, "x"))
     self.check_monomial(a(0, "y"), 1, make_boson(False, 0, "y"))
     # Spin 1/2
     self.check_monomial(S_p(0, "x"), 1,
                         make_spin(SpinComponent.PLUS, 0, "x"))
     self.check_monomial(S_m(0, "x"), 1,
                         make_spin(SpinComponent.MINUS, 0, "x"))
     self.check_monomial(S_z(0, "x"), 1, make_spin(SpinComponent.Z, 0, "x"))
     # Spin 1
     self.check_monomial(S_p(0, "x", spin=1), 1,
                         make_spin(1.0, SpinComponent.PLUS, 0, "x"))
     self.check_monomial(S_m(0, "x", spin=1), 1,
                         make_spin(1.0, SpinComponent.MINUS, 0, "x"))
     self.check_monomial(S_z(0, "x", spin=1), 1,
                         make_spin(1.0, SpinComponent.Z, 0, "x"))
     # Spin 3/2
     self.check_monomial(S_p(0, "x", spin=3 / 2), 1,
                         make_spin(3 / 2, SpinComponent.PLUS, 0, "x"))
     self.check_monomial(S_m(0, "x", spin=3 / 2), 1,
                         make_spin(3 / 2, SpinComponent.MINUS, 0, "x"))
     self.check_monomial(S_z(0, "x", spin=3 / 2), 1,
                         make_spin(3 / 2, SpinComponent.Z, 0, "x"))
Exemple #7
0
 def test_mixed_indices(self):
     expr = c_dag(0, "up") * c(1, "dn") \
         + a_dag("x") * n() + a("y") * n() + S_p() * S_m()
     self.assertEqual(
         str(expr),
         "0.5 + 1*Sz() + 1*C+(0,up)C(1,dn) + 1*C+()C()A+(x) + 1*C+()C()A(y)"
     )
Exemple #8
0
    def test_from_expression(self):
        expr = 2.0 * S_p("i", 0, spin=3 / 2) * S_m("j", 0, spin=3 / 2) \
            + 5.0 * n("up", 0) * n("dn", 0)

        hs1 = HilbertSpace(expr)
        self.assertEqual(len(hs1), 4)
        self.assertEqual(hs1.total_n_bits, 6)
        self.assertEqual(hs1.dim, 64)
        self.assertTrue(self.es_f_dn in hs1)
        self.assertEqual(hs1.index(self.es_f_dn), 0)
        self.assertEqual(hs1.bit_range(self.es_f_dn), (0, 0))
        self.assertTrue(self.es_f_up in hs1)
        self.assertEqual(hs1.index(self.es_f_up), 1)
        self.assertEqual(hs1.bit_range(self.es_f_up), (1, 1))
        self.assertTrue(self.es_s32_i in hs1)
        self.assertEqual(hs1.index(self.es_s32_i), 2)
        self.assertEqual(hs1.bit_range(self.es_s32_i), (2, 3))
        self.assertTrue(self.es_s32_j in hs1)
        self.assertEqual(hs1.index(self.es_s32_j), 3)
        self.assertEqual(hs1.bit_range(self.es_s32_j), (4, 5))

        # foreach()
        count = 0

        def counter(i):
            nonlocal count
            count += i

        foreach(hs1, counter)
        self.assertEqual(count, 2016)

        expr += a_dag("x", 0) + a("y", 0)

        hs2 = HilbertSpace(expr, bits_per_boson=4)

        self.assertEqual(len(hs2), 6)
        self.assertEqual(hs2.total_n_bits, 14)
        self.assertEqual(hs2.dim, 16384)
        self.assertTrue(self.es_f_dn in hs2)
        self.assertEqual(hs2.index(self.es_f_dn), 0)
        self.assertEqual(hs2.bit_range(self.es_f_dn), (0, 0))
        self.assertTrue(self.es_f_up in hs2)
        self.assertEqual(hs2.index(self.es_f_up), 1)
        self.assertEqual(hs2.bit_range(self.es_f_up), (1, 1))
        self.assertTrue(self.es_b_x in hs2)
        self.assertEqual(hs2.index(self.es_b_x), 2)
        self.assertEqual(hs2.bit_range(self.es_b_x), (2, 5))
        self.assertTrue(self.es_b_y in hs2)
        self.assertEqual(hs2.index(self.es_b_y), 3)
        self.assertEqual(hs2.bit_range(self.es_b_y), (6, 9))
        self.assertTrue(self.es_s32_i in hs2)
        self.assertEqual(hs2.index(self.es_s32_i), 4)
        self.assertEqual(hs2.bit_range(self.es_s32_i), (10, 11))
        self.assertTrue(self.es_s32_j in hs2)
        self.assertEqual(hs2.index(self.es_s32_j), 5)
        self.assertEqual(hs2.bit_range(self.es_s32_j), (12, 13))
Exemple #9
0
    def test_compositions_bosons(self):
        hs = HilbertSpace(a_dag(1) + a_dag(2) + a_dag(3) + a_dag(4), 4)

        O_list = [LOperatorR(a_dag(1), hs),
                  LOperatorR(a_dag(2), hs),
                  LOperatorR(a_dag(3), hs),
                  LOperatorR(a_dag(4), hs)]

        map_size_ref = [1, 4, 10, 20, 35, 56, 84, 120, 165, 220]
        for N in range(10):
            mapper = BasisMapper(O_list, hs, N)
            self.assertEqual(len(mapper), map_size_ref[N])
Exemple #10
0
 def test_iter(self):
     expr0 = ExpressionR()
     self.assertEqual([_ for _ in expr0], [])
     expr = 4.0 * c_dag(1, "up") * c(2, "dn") + 1.0 \
         + 3.0 * a(0, "x") + 2.0 * a_dag(0, "y")
     ref = [(Monomial(), 1.0), (Monomial([make_boson(True, 0, "y")]), 2.0),
            (Monomial([make_boson(False, 0, "x")]), 3.0),
            (Monomial(
                [make_fermion(True, 1, "up"),
                 make_fermion(False, 2, "dn")]), 4.0)]
     self.assertEqual([_ for _ in expr], ref)
Exemple #11
0
    def test_loperator(self):
        M = 5

        hs = HilbertSpace([make_space_boson(2, 0)])
        for i in range(M):
            hs.add(make_space_fermion(i))

        H = (n(0) + n(1) + n(2) + n(3) + n(4)) * (a_dag(0) + a(0))

        for src_type, dst_type, lop_type in [(float, float, LOperatorR),
                                             (float, complex, LOperatorR),
                                             (complex, complex, LOperatorR),
                                             (float, complex, LOperatorC),
                                             (complex, complex, LOperatorC)]:
            src_view_type = NFermionSectorViewR if (src_type == float) \
                else NFermionSectorViewC
            dst_view_type = NFermionSectorViewR if (dst_type == float) \
                else NFermionSectorViewC

            Hop = lop_type(H if lop_type == LOperatorR else make_complex(H),
                           hs)

            for N in range(M + 1):
                src = np.zeros(n_fermion_sector_size(hs, N), dtype=src_type)
                view_src = src_view_type(src, hs, N)
                dst = np.zeros(n_fermion_sector_size(hs, N), dtype=dst_type)
                view_dst = dst_view_type(dst, hs, N)

                # 1 boson, fermions in the first N modes
                index_in_f = sum(2**i for i in range(N))

                src[view_src.map_index(index_in_f + (2**M))] = 1

                Hop(view_src, view_dst)

                ref = np.zeros(n_fermion_sector_size(hs, N), dtype=dst_type)
                # 0 bosons
                ref[view_dst.map_index(index_in_f)] = N
                # 2 bosons
                ref[view_dst.map_index(index_in_f + (2 ** (M + 1)))] = \
                    N * np.sqrt(2)
                assert_allclose(dst, ref)
Exemple #12
0
 def test_conj(self):
     expr = 4.0 * c_dag(1, "up") * c(2, "dn") + 1.0 \
         + 3.0 * a(0, "x") + 2j * a_dag(0, "y")
     ref = 4.0 * c_dag(2, "dn") * c(1, "up") + 1.0 \
         + 3.0 * a_dag(0, "x") + -2j * a(0, "y")
     self.assertEqual(conj(expr), ref)
Exemple #13
0
 def nb(*args):
     return a_dag(*args) * a(*args)
Exemple #14
0
    def test_loperator(self):
        hs = HilbertSpace([make_space_boson(2, 0)])
        for i in range(self.M_total):
            hs.add(make_space_fermion(i))

        sector_a_modes = [1, 2, 6, 7]
        sector_b_modes = [3, 4, 8, 9]

        Ha = (n(1) + n(2) + n(6) + n(7)) * (a_dag(0) + a(0))
        Hb = (n(3) + n(4) + n(8) + n(9)) * (a_dag(0) + a(0))

        for src_type, dst_type, lop_type in [(float, float, LOperatorR),
                                             (float, complex, LOperatorR),
                                             (complex, complex, LOperatorR),
                                             (float, complex, LOperatorC),
                                             (complex, complex, LOperatorC)]:
            src_view_type = NFermionMultiSectorViewR if (src_type == float) \
                else NFermionMultiSectorViewC
            dst_view_type = NFermionMultiSectorViewR if (dst_type == float) \
                else NFermionMultiSectorViewC

            lop_is_real = lop_type == LOperatorR

            Hopa = lop_type(Ha if lop_is_real else make_complex(Ha), hs)
            Hopb = lop_type(Hb if lop_is_real else make_complex(Hb), hs)

            for N1, N2 in product(range(self.Na_max + 1),
                                  range(self.Nb_max + 1)):
                sectors = [self.sda(N1), self.sdb(N2)]

                src = np.zeros(n_fermion_multisector_size(hs, sectors),
                               dtype=src_type)
                view_src = src_view_type(src, hs, sectors)
                dst = np.zeros(n_fermion_multisector_size(hs, sectors),
                               dtype=dst_type)
                view_dst = dst_view_type(dst, hs, sectors)

                # Input:
                # First N1 modes of sector A are occupied
                # First N2 modes of sector B are occupied
                # 1 boson

                index_in_f = sum(2**sector_a_modes[n1] for n1 in range(N1))
                index_in_f += sum(2**sector_b_modes[n2] for n2 in range(N2))

                src[view_src.map_index(index_in_f + (2**self.M_total))] = 1

                Hopa(view_src, view_dst)
                ref = np.zeros(n_fermion_multisector_size(hs, sectors),
                               dtype=dst_type)
                # 0 bosons
                ref[view_dst.map_index(index_in_f)] = N1
                # 2 bosons
                ref[view_dst.map_index(index_in_f + (2 ** (self.M_total + 1)))]\
                    = N1 * np.sqrt(2)
                assert_allclose(dst, ref)

                Hopb(view_src, view_dst)
                ref = np.zeros(n_fermion_multisector_size(hs, sectors),
                               dtype=dst_type)
                # 0 bosons
                ref[view_dst.map_index(index_in_f)] = N2
                # 2 bosons
                ref[view_dst.map_index(index_in_f + (2 ** (self.M_total + 1)))]\
                    = N2 * np.sqrt(2)
                assert_allclose(dst, ref)
Exemple #15
0
    def test_quartic_int(self):
        U = np.zeros((3, 3, 3, 3), dtype=float)
        U[0, 1, 0, 1] = U[1, 0, 1, 0] = 3
        U[0, 1, 1, 0] = U[1, 0, 0, 1] = -3
        U[0, 2, 0, 2] = U[2, 0, 2, 0] = 4
        U[0, 2, 2, 0] = U[2, 0, 0, 2] = -4
        U[1, 2, 1, 2] = U[2, 1, 2, 1] = 5
        U[2, 1, 1, 2] = U[1, 2, 2, 1] = -5
        indices = [('a', 0), ('b', 1), ('c', 2)]

        H1 = quartic_int(U)
        self.assertIsInstance(H1, ExpressionR)
        ref1 = 6.0 * c_dag(0) * c_dag(1) * c(1) * c(0)
        ref1 += 8.0 * c_dag(0) * c_dag(2) * c(2) * c(0)
        ref1 += 10.0 * c_dag(1) * c_dag(2) * c(2) * c(1)
        self.assertEqual(H1, ref1)

        H2 = quartic_int(1j * U)
        self.assertIsInstance(H2, ExpressionC)
        ref2 = 1j * ref1
        self.assertEqual(H2, ref2)

        H3 = quartic_int(U, indices=indices)
        self.assertIsInstance(H3, ExpressionR)
        ref3 = 6.0 * c_dag('a', 0) * c_dag('b', 1) * c('b', 1) * c('a', 0)
        ref3 += 8.0 * c_dag('a', 0) * c_dag('c', 2) * c('c', 2) * c('a', 0)
        ref3 += 10.0 * c_dag('b', 1) * c_dag('c', 2) * c('c', 2) * c('b', 1)
        self.assertEqual(H3, ref3)

        U = 2 * np.array(range(1, 17), dtype=float).reshape((2, 2, 2, 2))
        H4 = quartic_int(U, statistics=BOSON)
        self.assertIsInstance(H4, ExpressionR)
        ref4 = a_dag(0) * a_dag(0) * a(0) * a(0)
        ref4 += 2 * a_dag(0) * a_dag(0) * a(1) * a(0)
        ref4 += 3 * a_dag(0) * a_dag(0) * a(0) * a(1)
        ref4 += 4 * a_dag(0) * a_dag(0) * a(1) * a(1)
        ref4 += 5 * a_dag(0) * a_dag(1) * a(0) * a(0)
        ref4 += 6 * a_dag(0) * a_dag(1) * a(1) * a(0)
        ref4 += 7 * a_dag(0) * a_dag(1) * a(0) * a(1)
        ref4 += 8 * a_dag(0) * a_dag(1) * a(1) * a(1)
        ref4 += 9 * a_dag(1) * a_dag(0) * a(0) * a(0)
        ref4 += 10 * a_dag(1) * a_dag(0) * a(1) * a(0)
        ref4 += 11 * a_dag(1) * a_dag(0) * a(0) * a(1)
        ref4 += 12 * a_dag(1) * a_dag(0) * a(1) * a(1)
        ref4 += 13 * a_dag(1) * a_dag(1) * a(0) * a(0)
        ref4 += 14 * a_dag(1) * a_dag(1) * a(1) * a(0)
        ref4 += 15 * a_dag(1) * a_dag(1) * a(0) * a(1)
        ref4 += 16 * a_dag(1) * a_dag(1) * a(1) * a(1)
        self.assertEqual(H4, ref4)
Exemple #16
0
    def test_spin_boson(self):
        eps = np.array([1, 2, 3], dtype=float)
        delta = np.array([4, 5, 6], dtype=float)
        delta_z = np.zeros((3, ))
        omega = np.array([7, 8], dtype=float)
        lambda_ = np.array([[0.1, 0.2], [0.3, 0.4], [0.5, 0.6]], dtype=float)
        indices_spin = [('a', 0), ('b', 1), ('c', 2)]
        indices_boson = [('x', 0), ('y', 1)]

        self.assertIsInstance(spin_boson(eps, delta, omega, lambda_),
                              ExpressionC)
        self.assertIsInstance(spin_boson(eps, delta_z, omega, lambda_),
                              ExpressionR)
        self.assertIsInstance(spin_boson(1j * eps, delta_z, omega, lambda_),
                              ExpressionC)
        self.assertIsInstance(spin_boson(eps, delta_z, 1j * omega, lambda_),
                              ExpressionC)
        self.assertIsInstance(spin_boson(eps, delta_z, omega, 1j * lambda_),
                              ExpressionC)

        H1 = spin_boson(eps, delta, omega, 1j * lambda_)
        ref1 = -(S_z(0) + 2.0 * S_z(1) + 3.0 * S_z(2))
        ref1 += (4.0 * S_x(0) + 5.0 * S_x(1) + 6.0 * S_x(2))
        ref1 += 7.0 * a_dag(0) * a(0) + 8.0 * a_dag(1) * a(1)
        ref1 += S_z(0) * (0.1j * a_dag(0) - 0.1j * a(0))
        ref1 += S_z(0) * (0.2j * a_dag(1) - 0.2j * a(1))
        ref1 += S_z(1) * (0.3j * a_dag(0) - 0.3j * a(0))
        ref1 += S_z(1) * (0.4j * a_dag(1) - 0.4j * a(1))
        ref1 += S_z(2) * (0.5j * a_dag(0) - 0.5j * a(0))
        ref1 += S_z(2) * (0.6j * a_dag(1) - 0.6j * a(1))
        self.assertEqual(H1, ref1)

        H2 = spin_boson(eps,
                        delta,
                        omega,
                        1j * lambda_,
                        indices_spin=indices_spin,
                        indices_boson=indices_boson)
        ref2 = -(S_z('a', 0) + 2.0 * S_z('b', 1) + 3.0 * S_z('c', 2))
        ref2 += (4.0 * S_x('a', 0) + 5.0 * S_x('b', 1) + 6.0 * S_x('c', 2))
        ref2 += 7 * a_dag('x', 0) * a('x', 0) + 8 * a_dag('y', 1) * a('y', 1)
        ref2 += S_z('a', 0) * (0.1j * a_dag('x', 0) - 0.1j * a('x', 0))
        ref2 += S_z('a', 0) * (0.2j * a_dag('y', 1) - 0.2j * a('y', 1))
        ref2 += S_z('b', 1) * (0.3j * a_dag('x', 0) - 0.3j * a('x', 0))
        ref2 += S_z('b', 1) * (0.4j * a_dag('y', 1) - 0.4j * a('y', 1))
        ref2 += S_z('c', 2) * (0.5j * a_dag('x', 0) - 0.5j * a('x', 0))
        ref2 += S_z('c', 2) * (0.6j * a_dag('y', 1) - 0.6j * a('y', 1))
        self.assertEqual(H2, ref2)

        H3 = spin_boson(eps, delta, omega, 1j * lambda_, spin=1)
        ref3 = -(S1_z(0) + 2.0 * S1_z(1) + 3.0 * S1_z(2))
        ref3 += (4.0 * S1_x(0) + 5.0 * S1_x(1) + 6.0 * S1_x(2))
        ref3 += 7.0 * a_dag(0) * a(0) + 8.0 * a_dag(1) * a(1)
        ref3 += S1_z(0) * (0.1j * a_dag(0) - 0.1j * a(0))
        ref3 += S1_z(0) * (0.2j * a_dag(1) - 0.2j * a(1))
        ref3 += S1_z(1) * (0.3j * a_dag(0) - 0.3j * a(0))
        ref3 += S1_z(1) * (0.4j * a_dag(1) - 0.4j * a(1))
        ref3 += S1_z(2) * (0.5j * a_dag(0) - 0.5j * a(0))
        ref3 += S1_z(2) * (0.6j * a_dag(1) - 0.6j * a(1))
        self.assertEqual(H3, ref3)
Exemple #17
0
    def test_rabi(self):
        eps = np.array([1, 2, 3], dtype=float)
        omega = np.array([4, 5], dtype=float)
        g = np.array([[0.1, 0.2], [0.3, 0.4], [0.5, 0.6]], dtype=float)
        indices_atom = [('a', 0), ('b', 1), ('c', 2)]
        indices_boson = [('x', 0), ('y', 1)]

        self.assertIsInstance(rabi(eps, omega, np.zeros((3, 2))), ExpressionR)
        self.assertIsInstance(rabi(eps, omega, g), ExpressionC)
        self.assertIsInstance(rabi(1j * eps, omega, g), ExpressionC)
        self.assertIsInstance(rabi(eps, 1j * omega, g), ExpressionC)
        self.assertIsInstance(rabi(eps, omega, 1j * g), ExpressionC)

        H1 = rabi(eps, omega, g)
        ref1 = S_z(0) + 2.0 * S_z(1) + 3.0 * S_z(2)
        ref1 += 4.0 * a_dag(0) * a(0) + 5.0 * a_dag(1) * a(1)
        ref1 += 0.1 * S_x(0) * (a_dag(0) + a(0))
        ref1 += 0.2 * S_x(0) * (a_dag(1) + a(1))
        ref1 += 0.3 * S_x(1) * (a_dag(0) + a(0))
        ref1 += 0.4 * S_x(1) * (a_dag(1) + a(1))
        ref1 += 0.5 * S_x(2) * (a_dag(0) + a(0))
        ref1 += 0.6 * S_x(2) * (a_dag(1) + a(1))
        self.assertEqual(H1, ref1)

        H2 = rabi(eps,
                  omega,
                  g,
                  indices_atom=indices_atom,
                  indices_boson=indices_boson)
        ref2 = S_z('a', 0) + 2.0 * S_z('b', 1) + 3.0 * S_z('c', 2)
        ref2 += 4 * a_dag('x', 0) * a('x', 0) + 5 * a_dag('y', 1) * a('y', 1)
        ref2 += 0.1 * S_x('a', 0) * (a_dag('x', 0) + a('x', 0))
        ref2 += 0.2 * S_x('a', 0) * (a_dag('y', 1) + a('y', 1))
        ref2 += 0.3 * S_x('b', 1) * (a_dag('x', 0) + a('x', 0))
        ref2 += 0.4 * S_x('b', 1) * (a_dag('y', 1) + a('y', 1))
        ref2 += 0.5 * S_x('c', 2) * (a_dag('x', 0) + a('x', 0))
        ref2 += 0.6 * S_x('c', 2) * (a_dag('y', 1) + a('y', 1))
        self.assertEqual(H2, ref2)

        H3 = rabi(eps, omega, g, spin=1)
        ref3 = S1_z(0) + 2.0 * S1_z(1) + 3.0 * S1_z(2)
        ref3 += 4.0 * a_dag(0) * a(0) + 5.0 * a_dag(1) * a(1)
        ref3 += 0.1 * S1_x(0) * (a_dag(0) + a(0))
        ref3 += 0.2 * S1_x(0) * (a_dag(1) + a(1))
        ref3 += 0.3 * S1_x(1) * (a_dag(0) + a(0))
        ref3 += 0.4 * S1_x(1) * (a_dag(1) + a(1))
        ref3 += 0.5 * S1_x(2) * (a_dag(0) + a(0))
        ref3 += 0.6 * S1_x(2) * (a_dag(1) + a(1))
        self.assertEqual(H3, ref3)
Exemple #18
0
    def test_jaynes_cummings(self):
        eps = np.array([1, 2, 3], dtype=float)
        omega = np.array([4, 5], dtype=float)
        g = np.array([[0.1, 0.2], [0.3, 0.4], [0.5, 0.6]], dtype=float)
        indices_atom = [('a', 0), ('b', 1), ('c', 2)]
        indices_boson = [('x', 0), ('y', 1)]

        self.assertIsInstance(jaynes_cummings(eps, omega, g), ExpressionR)
        self.assertIsInstance(jaynes_cummings(1j * eps, omega, g), ExpressionC)
        self.assertIsInstance(jaynes_cummings(eps, 1j * omega, g), ExpressionC)
        self.assertIsInstance(jaynes_cummings(eps, omega, 1j * g), ExpressionC)

        H1 = jaynes_cummings(eps, omega, 1j * g)
        ref1 = S_z(0) + 2.0 * S_z(1) + 3.0 * S_z(2)
        ref1 += 4.0 * a_dag(0) * a(0) + 5.0 * a_dag(1) * a(1)
        ref1 += 0.1j * a_dag(0) * S_m(0) - 0.1j * a(0) * S_p(0)
        ref1 += 0.2j * a_dag(1) * S_m(0) - 0.2j * a(1) * S_p(0)
        ref1 += 0.3j * a_dag(0) * S_m(1) - 0.3j * a(0) * S_p(1)
        ref1 += 0.4j * a_dag(1) * S_m(1) - 0.4j * a(1) * S_p(1)
        ref1 += 0.5j * a_dag(0) * S_m(2) - 0.5j * a(0) * S_p(2)
        ref1 += 0.6j * a_dag(1) * S_m(2) - 0.6j * a(1) * S_p(2)
        self.assertEqual(H1, ref1)

        H2 = jaynes_cummings(eps,
                             omega,
                             1j * g,
                             indices_atom=indices_atom,
                             indices_boson=indices_boson)
        ref2 = S_z('a', 0) + 2.0 * S_z('b', 1) + 3.0 * S_z('c', 2)
        ref2 += 4.0 * a_dag('x', 0) * a('x', 0) \
            + 5.0 * a_dag('y', 1) * a('y', 1)
        ref2 += 0.1j * a_dag('x', 0) * S_m('a', 0) \
            - 0.1j * a('x', 0) * S_p('a', 0)
        ref2 += 0.2j * a_dag('y', 1) * S_m('a', 0) \
            - 0.2j * a('y', 1) * S_p('a', 0)
        ref2 += 0.3j * a_dag('x', 0) * S_m('b', 1) \
            - 0.3j * a('x', 0) * S_p('b', 1)
        ref2 += 0.4j * a_dag('y', 1) * S_m('b', 1) \
            - 0.4j * a('y', 1) * S_p('b', 1)
        ref2 += 0.5j * a_dag('x', 0) * S_m('c', 2) \
            - 0.5j * a('x', 0) * S_p('c', 2)
        ref2 += 0.6j * a_dag('y', 1) * S_m('c', 2) \
            - 0.6j * a('y', 1) * S_p('c', 2)
        self.assertEqual(H2, ref2)

        H3 = jaynes_cummings(eps, omega, 1j * g, spin=1)
        ref3 = S1_z(0) + 2.0 * S1_z(1) + 3.0 * S1_z(2)
        ref3 += 4.0 * a_dag(0) * a(0) + 5.0 * a_dag(1) * a(1)
        ref3 += 0.1j * a_dag(0) * S1_m(0) - 0.1j * a(0) * S1_p(0)
        ref3 += 0.2j * a_dag(1) * S1_m(0) - 0.2j * a(1) * S1_p(0)
        ref3 += 0.3j * a_dag(0) * S1_m(1) - 0.3j * a(0) * S1_p(1)
        ref3 += 0.4j * a_dag(1) * S1_m(1) - 0.4j * a(1) * S1_p(1)
        ref3 += 0.5j * a_dag(0) * S1_m(2) - 0.5j * a(0) * S1_p(2)
        ref3 += 0.6j * a_dag(1) * S1_m(2) - 0.6j * a(1) * S1_p(2)
        self.assertEqual(H3, ref3)