Ejemplo n.º 1
0
 def test_scalar_mul(self):
     s = 1.0
     i = Idx(0, "occ")
     j = Idx(1, "occ")
     sums = [Sigma(i), Sigma(j)]
     tensors = [Tensor([i, j], 'f')]
     operators = [FOperator(i, True), FOperator(j, False)]
     t = Term(s, sums, tensors, operators, [])
     t1 = 3.14 * t
     t2 = t * 3.14
     self.assertTrue(t1 == t2)
Ejemplo n.º 2
0
 def test_ilist(self):
     s = 1.0
     i = Idx("i", "occ")
     j = Idx("j", "occ")
     sums = [Sigma(i), Sigma(j)]
     tensors = [Tensor([i, j], 'f')]
     operators = [FOperator(i, True), FOperator(j, False)]
     t1 = Term(s, sums, tensors, operators, [])
     ilist = t1.ilist()
     iref = [i, j]
     self.assertTrue(set(iref) == set(ilist))
Ejemplo n.º 3
0
    def test_split_operators(self):
        i = Idx(0, "occ")
        j = Idx(1, "occ")
        k = Idx(3, "occ")
        l = Idx(4, "occ")
        O1 = FOperator(i, False)
        O2 = FOperator(j, False)
        O3 = FOperator(k, False)
        O4 = FOperator(l, True)
        P = Projector()

        ops = [O1, O2, P, O3, P, O4]
        olists = split_operators(ops)
        self.assertTrue(len(olists) == 3)
        self.assertTrue(olists[0] == [O1, O2])
        self.assertTrue(olists[1] == [O3])
        self.assertTrue(olists[2] == [O4])
Ejemplo n.º 4
0
    def test_resolve3(self):
        I1 = Idx(0, "o1")
        I2 = Idx(1, "o1")
        operators = [FOperator(I1, True), FOperator(I2, False)]
        out = Term(
            1, [Sigma(I1), Sigma(I2)],
            [Tensor([I1, I2], "T")],
            operators, [Delta(I1, I2)])
        out.resolve()

        roperators = [FOperator(I1, True), FOperator(I1, False)]
        ref = Term(
            1, [Sigma(I1)],
            [Tensor([I1, I1], "T")],
            roperators, [])

        self.assertTrue(ref == out)
Ejemplo n.º 5
0
    def test_pair_list(self):
        i = Idx(0, "occ")
        j = Idx(1, "occ")
        k = Idx(2, "occ")
        l = Idx(3, "occ")
        O1 = FOperator(i, False)
        O2 = FOperator(j, True)
        O3 = FOperator(k, False)
        O4 = FOperator(l, True)

        os = [O2, O4, O1, O3]
        pl = pair_list(os)
        self.assertTrue(len(pl) == 2)

        os = [O2, O1, O4, O3]
        pl = pair_list(os)
        self.assertTrue(len(pl) == 1)
Ejemplo n.º 6
0
    def test_resolve0(self):
        I1 = Idx(0, "o1")
        I2 = Idx(1, "o1")
        I3 = Idx(0, "o2")
        operators = [FOperator(I1, True), FOperator(I3, False)]
        out = Term(
            1, [Sigma(I3)],
            [Tensor([I1, I3], "T")],
            operators, [Delta(I1, I2)])

        out.resolve()

        ref = Term(
            1, [Sigma(I3)],
            [Tensor([I1, I3], "T")],
            operators, [Delta(I1, I2)])

        self.assertTrue(ref == out)
Ejemplo n.º 7
0
 def test_foperator(self):
     i = Idx(0, "occ")
     j = Idx(1, "occ")
     O1 = FOperator(i, False)
     O2 = FOperator(i, False)
     O3 = FOperator(j, False)
     O4 = FOperator(j, True)
     self.assertTrue(O1 == O2)
     self.assertTrue(O1 != O3)
     self.assertTrue(O1 != O4)
     self.assertTrue(O2 != O4)
     self.assertTrue(O1.qp_creation())
     self.assertTrue(O4.qp_annihilation())
Ejemplo n.º 8
0
    def test_mul(self):
        i = Idx(0, "occ")
        j = Idx(1, "occ")
        a = Idx(0, "vir")
        b = Idx(1, "vir")
        sum1 = [Sigma(i), Sigma(j)]
        ten1 = [Tensor([i, j], 'f')]
        ops1 = [FOperator(i, True), FOperator(j, False)]
        t1 = Term(1.0, sum1, ten1, ops1, [])
        sum2 = [Sigma(a), Sigma(b)]
        ten2 = [Tensor([a, b], 'f')]
        ops2 = [FOperator(a, True), FOperator(b, False)]
        t2 = Term(1.0, sum2, ten2, ops2, [])

        sum3 = sum2 + sum1
        ten3 = ten1 + ten2
        ops3 = ops1 + ops2
        ref = Term(1.0, sum3, ten3, ops3, [])

        out = t1 * t2
        self.assertTrue(ref == out)
Ejemplo n.º 9
0
    def test_string(self):
        P1 = Projector()
        self.assertTrue(str(P1) == "P")

        i = Idx(0, "occ")
        a = Idx(0, "vir")
        O1 = FOperator(i, False)
        O2 = FOperator(i, True)
        O3 = FOperator(a, False)
        O4 = FOperator(a, True)
        so1 = "a_0(occ)"
        so2 = "a^{\\dagger}_0(occ)"
        so3 = "a_0(vir)"
        so4 = "a^{\\dagger}_0(vir)"
        self.assertTrue(str(O1) == so1)
        self.assertTrue(str(O2) == so2)
        self.assertTrue(str(O3) == so3)
        self.assertTrue(str(O4) == so4)

        x = Idx(0, "nm", fermion=False)
        Ob1 = BOperator(x, False)
        Ob2 = BOperator(x, True)
        sob1 = "b_0(nm)"
        sob2 = "b^{\\dagger}_0(nm)"
        self.assertTrue(str(Ob1) == sob1)
        self.assertTrue(str(Ob2) == sob2)

        T1 = Tensor([i, a], "g")
        st1 = "g_{00}"
        self.assertTrue(str(T1) == st1)

        S1 = Sigma(i)
        ss1 = "\\sum_{0}"
        self.assertTrue(str(S1) == ss1)

        j = Idx(1, "occ")
        D1 = Delta(i, j)
        sd1 = "\\delta_{0,1}"
        self.assertTrue(str(D1) == sd1)
Ejemplo n.º 10
0
    def test_valid_contraction(self):
        i = Idx(0, "occ")
        j = Idx(1, "occ")
        a = Idx(0, "vir")
        b = Idx(1, "vir")
        O1 = FOperator(i, False)
        O2 = FOperator(j, True)
        O3 = FOperator(a, False)
        O4 = FOperator(b, True)
        self.assertTrue(valid_contraction(O2, O1))
        self.assertTrue(not valid_contraction(O1, O2))
        self.assertTrue(valid_contraction(O3, O4))
        self.assertTrue(not valid_contraction(O4, O3))
        self.assertTrue(not valid_contraction(O1, O3))

        x = Idx(0, "nm", fermion=False)
        y = Idx(1, "nm", fermion=False)
        Ob1 = BOperator(x, False)
        Ob2 = BOperator(y, True)
        self.assertTrue(not valid_contraction(Ob2, Ob1))
        self.assertTrue(valid_contraction(Ob1, Ob2))
        self.assertTrue(not valid_contraction(Ob2, O1))
Ejemplo n.º 11
0
    def test_str(self):
        i = Idx(0, "occ")
        j = Idx(1, "occ")
        sums = [Sigma(i)]
        tensors = [Tensor([i, j], "X")]
        operators = [FOperator(i, False)]
        e1 = Term(1, sums, tensors, operators, [Delta(i, j)])
        ex = Expression([e1])
        out = str(ex)
        ref = "1\\sum_{0}\\delta_{0,1}X_{01}a_0(occ)"
        self.assertTrue(ref == out)

        out = ex._print_str()
        ref = " + 1\\sum_{i}\\delta_{ij}X_{ij}a_i"
        self.assertTrue(ref == out)
Ejemplo n.º 12
0
    def test_dagger(self):
        i = Idx(0, "occ")
        O1 = FOperator(i, False)
        O2 = FOperator(i, True)
        self.assertTrue(O1.dagger() == O2)
        self.assertTrue(O2.dagger() == O1)

        x = Idx(0, "nm", fermion=False)
        Ob1 = BOperator(x, False)
        Ob2 = BOperator(x, True)
        self.assertTrue(Ob1.dagger() == Ob2)
        self.assertTrue(Ob2.dagger() == Ob1)
Ejemplo n.º 13
0
    def test_resolve_chain(self):
        I1 = Idx(0, "v1")
        I2 = Idx(0, "o1")
        I3 = Idx(1, "v1")
        I4 = Idx(1, "o1")
        operators = [
            FOperator(I1, True), FOperator(I2, True),
            FOperator(I4, False), FOperator(I3, False)]
        out = Term(
            1, [Sigma(I2), Sigma(I3), Sigma(I4)],
            [Tensor([I1, I2, I3, I4], "T")],
            operators, [Delta(I1, I3), Delta(I2, I4)])
        out.resolve()

        roperators = [
            FOperator(I1, True), FOperator(I2, True),
            FOperator(I2, False), FOperator(I1, False)]
        ref = Term(
            1, [Sigma(I2)],
            [Tensor([I1, I2, I1, I2], "T")],
            roperators, [])

        self.assertTrue(ref == out)
Ejemplo n.º 14
0
    def test_inc(self):
        i = Idx(0, "occ")
        j = Idx(1, "occ")
        a = Idx(0, "vir")
        I = Idx(0, "nm", fermion=False)
        J = Idx(1, "nm", fermion=False)

        iii = 3

        # Fermion operator
        O1 = FOperator(i, False)._inc(iii)
        self.assertTrue(O1.idx.index == iii)

        # Boson operator
        O2 = BOperator(I, False)._inc(iii)
        O3 = BOperator(J, True)._inc(iii)
        self.assertTrue(O2.idx.index == iii)
        self.assertTrue(O3.idx.index == iii + 1)

        # Projector
        P1 = Projector()
        P2 = P1._inc(iii)
        self.assertTrue(P1 == P2)

        # tensor
        T1 = Tensor([i, a], "g")._inc(iii)
        self.assertTrue(T1.indices[0].index == iii)
        self.assertTrue(T1.indices[1].index == iii)

        # sigma
        S3 = Sigma(j)._inc(iii)
        self.assertTrue(S3.idx.index == iii + 1)

        # delta
        D1 = Delta(i, j)._inc(iii)
        self.assertTrue(D1.i1.index == iii)
        self.assertTrue(D1.i2.index == iii + 1)
Ejemplo n.º 15
0
    def test_mul2(self):
        s = 1.0
        i = Idx(0, "occ")
        j = Idx(1, "occ")
        sums = [Sigma(i), Sigma(j)]
        tensors = [Tensor([i, j], 'f')]
        operators = [FOperator(i, True), FOperator(j, False)]
        t1 = Term(s, sums, tensors, operators, [])

        t3 = t1 * t1
        k = Idx(2, "occ")
        l = Idx(3, "occ")
        sums = [Sigma(i), Sigma(j), Sigma(k), Sigma(l)]
        tensors = [Tensor([i, j], 'f'), Tensor([k, l], 'f')]
        operators = [
            FOperator(i, True),
            FOperator(j, False),
            FOperator(k, True),
            FOperator(l, False)
        ]
        ttest = Term(s, sums, tensors, operators, [])
        self.assertTrue(t3 == ttest)
Ejemplo n.º 16
0
i = Idx(0, "occ")
a = Idx(0, "vir")
j = Idx(1, "occ")
b = Idx(1, "vir")

T1 = E1("t", ["occ"], ["vir"])
T2 = E2("t", ["occ"], ["vir"])
T = T1 + T2

L1 = E1("L", ["vir"], ["occ"])
L2 = E2("L", ["vir"], ["occ"])
L = L1 + L2

# ov block
operators = [FOperator(a, True), FOperator(i, False)]
pvo = Expression([Term(1, [], [Tensor([i, a], "")], operators, [])])

PT = commute(pvo, T)
PTT = commute(PT, T)
mid = pvo + PT + Fraction('1/2') * PTT
full = L * mid
out = apply_wick(full)
out.resolve()
final = AExpression(Ex=out)
print("P_{ov} = ")
print(final)

# vv block
operators = [FOperator(a, True), FOperator(b, False)]
pvv = Expression([Term(1, [], [Tensor([b, a], "")], operators, [])])