Example #1
0
    def testEP11op(self):
        op = ep11("Hp", ["occ", "vir"], ["nm"], name2="Hq")
        bra = braP1E1("nm", "occ", "vir")
        ex = apply_wick(bra * op)
        ex.resolve()
        out = AExpression(Ex=ex)

        x = Idx(0, "nm", fermion=False)
        a = Idx(0, "vir")
        i = Idx(0, "occ")
        tr1 = ATerm(scalar=1,
                    sums=[],
                    tensors=[Tensor([x, a, i], ""),
                             Tensor([x, a, i], "Hq")])
        ref = AExpression(terms=[tr1])
        self.assertTrue(ref.pmatch(out))

        ket = ketP1E1("nm", "occ", "vir")
        ex = apply_wick(op * ket)
        ex.resolve()
        out = AExpression(Ex=ex)

        tr1 = ATerm(scalar=1,
                    sums=[],
                    tensors=[Tensor([x, i, a], "Hp"),
                             Tensor([x, i, a], "")])
        ref = AExpression(terms=[tr1])
        self.assertTrue(ref.pmatch(out))
Example #2
0
    def test_eq(self):
        s = 1.0
        i = Idx(0, "occ")
        j = Idx(1, "occ")
        sums = [Sigma(i), Sigma(j)]
        tensors = [Tensor([i, j], 'f')]
        t1 = ATerm(s, sums, tensors)
        t0 = t1.copy()
        sums = [Sigma(i), Sigma(j)]
        tensors = [Tensor([j, i], 'f'), Tensor([i, j], 'g')]
        t2 = ATerm(s, sums, tensors)
        sums = [Sigma(i)]
        tensors = [Tensor([i, j], 'f')]
        t3 = ATerm(s, sums, tensors)
        sums = [Sigma(i)]
        tensors = [Tensor([i, j], 'g')]
        t4 = ATerm(s, sums, tensors)

        self.assertTrue(t1 < t2)
        self.assertTrue(t1 != t2)
        self.assertFalse(t0 < t1)
        self.assertTrue(t0 <= t1)
        self.assertTrue(t0 >= t1)
        self.assertTrue(t1 > t3)
        self.assertTrue(t3 < t4)
Example #3
0
    def testE1(self):
        bra = braE1("occ", "vir")
        ket = ketE1("occ", "vir")
        out = apply_wick(bra * ket)
        aout = AExpression(Ex=out)

        i = Idx(0, "occ")
        a = Idx(0, "vir")
        j = Idx(1, "occ")
        b = Idx(1, "vir")
        tr1 = Term(1, [],
                   [Tensor([a, i], ""), Tensor([j, b], "")], [],
                   [Delta(i, j), Delta(a, b)])
        ref = Expression([tr1])
        aref = AExpression(Ex=ref)
        self.assertTrue(aout.pmatch(aref))

        op = E1("A", ["occ"], ["vir"])
        out = apply_wick(bra * op)
        out.resolve()
        aout = AExpression(Ex=out)
        ext = Tensor([a, i], "")
        ten = Tensor([a, i], "A")
        at1 = ATerm(scalar=1, sums=[], tensors=[ext, ten])
        self.assertTrue(len(aout.terms) == 1)
        self.assertTrue(at1 == aout.terms[0])
Example #4
0
    def test_string(self):
        a = Idx(0, "vir")
        b = Idx(1, "vir")
        sums = [Sigma(a), Sigma(b)]
        tensors = [Tensor([a, b], 'f')]
        t1 = ATerm(sums=sums, tensors=tensors)
        out = str(t1)
        ref = "1\\sum_{0}\\sum_{1}f_{01}"
        self.assertTrue(out == ref)

        out = t1._print_str()
        ref = "1.0\\sum_{ab}f_{ab}"
        self.assertTrue(out == ref)

        out = t1._einsum_str()
        ref = "1.0*einsum('ab->', f)"
        self.assertTrue(out == ref)

        a = Idx(0, "vir")
        b = Idx(1, "vir")
        sums = [Sigma(b)]
        tensors = [Tensor([a], ''), Tensor([a, b], 'f')]
        t2 = ATerm(sums=sums, tensors=tensors)
        out = t2._einsum_str()
        ref = "1.0*einsum('ab->a', f)"
        self.assertTrue(out == ref)
Example #5
0
    def testP2(self):
        bra = braP2("nm")
        ket = ketP2("nm")
        out = apply_wick(bra * ket)
        aout = AExpression(Ex=out)

        x = Idx(0, "nm", fermion=False)
        y = Idx(1, "nm", fermion=False)
        u = Idx(2, "nm", fermion=False)
        v = Idx(3, "nm", fermion=False)
        tensors = [Tensor([x, y], ""), Tensor([u, v], "")]
        tr1 = Term(1, [], tensors, [], [Delta(x, u), Delta(y, v)])
        tr2 = Term(1, [], tensors, [], [Delta(x, v), Delta(y, u)])
        ref = Expression([tr1, tr2])
        aref = AExpression(Ex=ref)
        self.assertTrue(aout.pmatch(aref))

        op = P2("A", ["nm"])
        out = apply_wick(bra * op)
        out.resolve()
        aout = AExpression(Ex=out)
        sym = TensorSym([(0, 1), (1, 0)], [1, 1])
        ext = Tensor([x, y], "")
        t1 = Tensor([x, y], "A", sym=sym)
        at1 = ATerm(scalar=1, sums=[], tensors=[ext, t1])
        self.assertTrue(at1 == aout.terms[0])
Example #6
0
    def test_idx(self):
        i = Idx(0, "occ")
        j = Idx(1, "occ")
        a = Idx(0, "vir")
        b = Idx(1, "vir")
        c = Idx(0, "vir")

        self.assertTrue(i != j)
        self.assertTrue(a != b)
        self.assertTrue(c == a)
Example #7
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))
Example #8
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)
Example #9
0
    def test_term_map3(self):
        s = 1
        i = Idx(0, "occ")
        a = Idx(0, "vir")
        sums = [Sigma(i), Sigma(a)]
        tensors = [Tensor([i, a], 'f'), Tensor([a, i], 't')]
        t1 = ATerm(s, sums, tensors)

        sums = [Sigma(i)]
        t2 = ATerm(s, sums, tensors)

        self.assertFalse(t1.match(t2))
Example #10
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)
Example #11
0
 def test_delta(self):
     i = Idx(0, "occ")
     j = Idx(1, "occ")
     a = Idx(0, "vir")
     b = Idx(1, "vir")
     D1 = Delta(i, j)
     D2 = Delta(i, j)
     D3 = Delta(j, i)
     D4 = Delta(a, b)
     self.assertTrue(D1 == D2)
     self.assertTrue(D1 == D3)
     self.assertTrue(D1 != D4)
Example #12
0
    def test_term_map2(self):
        s = 1
        i = Idx(0, "occ")
        j = Idx(1, "occ")
        sums = [Sigma(i), Sigma(j)]
        tensors = [Tensor([i, j], 'f')]
        t1 = ATerm(s, sums, tensors)

        sums = [Sigma(i)]
        tensors = [Tensor([j, i], 'f')]
        t2 = ATerm(s, sums, tensors)

        self.assertFalse(t1.match(t2))
Example #13
0
 def test_boperator(self):
     I = Idx(0, "nm", fermion=False)
     J = Idx(1, "nm", fermion=False)
     O1 = BOperator(I, False)
     O2 = BOperator(I, False)
     O3 = BOperator(J, False)
     O4 = BOperator(J, True)
     self.assertTrue(O1 == O2)
     self.assertTrue(O1 != O3)
     self.assertTrue(O1 != O4)
     self.assertTrue(O2 != O4)
     self.assertTrue(O4.qp_creation())
     self.assertTrue(O1.qp_annihilation())
Example #14
0
 def test_null(self):
     i = Idx(0, "occ")
     j = Idx(1, "occ")
     a = Idx(0, "vir")
     b = Idx(1, "vir")
     L1 = Tensor([i, j, a, b], "L")
     J1 = Tensor([j, b], "J")
     S1j = Sigma(j)
     S1b = Sigma(b)
     T1 = ATerm(scalar=1, sums=[S1j, S1b], tensors=[L1, J1])
     T2 = ATerm(scalar=1, sums=[S1j, S1b], tensors=[L1, J1])
     self.assertTrue(T1.match(T2))
     self.assertTrue(T2.match(T1))
Example #15
0
    def test_idx_eq(self):
        i = Idx(0, "occ")
        j = Idx(1, "occ")
        a = Idx(0, "vir")
        b = Idx(1, "vir")

        self.assertTrue(i < j)
        self.assertTrue(j < a)
        self.assertTrue(a <= b)
        self.assertTrue(b > a)
        self.assertTrue(i <= a)
        self.assertFalse(i < idx_copy(i))
        self.assertTrue(b >= a)
Example #16
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())
Example #17
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)
Example #18
0
 def test_tensor_sort(self):
     i = Idx(0, "occ")
     j = Idx(1, "occ")
     a = Idx(0, "vir")
     tensors = [
         Tensor([j, i], 'f'),
         Tensor([a, i], ''),
         Tensor([a, j], "t")
     ]
     st = [tensors[1], tensors[0], tensors[2]]
     sigmas = [Sigma(j)]
     tt = ATerm(scalar=1.0, sums=sigmas, tensors=tensors)
     tt.sort_tensors()
     for ref, out in zip(st, tt.tensors):
         self.assertTrue(ref == out)
Example #19
0
    def testEdip1(self):
        bra = braEdip1("occ", "occ")
        ket = ketEdip1("occ", "occ")
        out = apply_wick(bra * ket)
        aout = AExpression(Ex=out)

        i = Idx(0, "occ")
        j = Idx(1, "occ")
        k = Idx(2, "occ")
        l = Idx(3, "occ")
        tensors = [Tensor([i, j], ""), Tensor([k, l], "")]
        tr1 = Term(1, [], tensors, [], [Delta(i, k), Delta(j, l)])
        tr2 = Term(-1, [], tensors, [], [Delta(i, l), Delta(j, k)])
        ref = Expression([tr1, tr2])
        aref = AExpression(Ex=ref)
        self.assertTrue(aout.pmatch(aref))
Example #20
0
    def testEdea1(self):
        bra = braEdea1("vir", "vir")
        ket = ketEdea1("vir", "vir")
        out = apply_wick(bra * ket)
        aout = AExpression(Ex=out)

        a = Idx(0, "vir")
        b = Idx(1, "vir")
        c = Idx(2, "vir")
        d = Idx(3, "vir")
        tensors = [Tensor([a, b], ""), Tensor([c, d], "")]
        tr1 = Term(1, [], tensors, [], [Delta(a, c), Delta(b, d)])
        tr2 = Term(-1, [], tensors, [], [Delta(a, d), Delta(b, c)])
        ref = Expression([tr1, tr2])
        aref = AExpression(Ex=ref)
        self.assertTrue(aout.pmatch(aref))
Example #21
0
    def testP2E1(self):
        bra = braP2E1("nm", "nm", "occ", "vir")
        op = EPS2("A", ["nm"], ["occ"], ["vir"])
        out = apply_wick(bra * op)
        out.resolve()

        x = Idx(0, "nm", fermion=False)
        y = Idx(1, "nm", fermion=False)
        a = Idx(0, "vir")
        i = Idx(0, "occ")
        sym = TensorSym([(0, 1, 2, 3), (1, 0, 2, 3)], [1, 1])
        aout = AExpression(Ex=out)
        ext = Tensor([x, y, a, i], "")
        t1 = Tensor([x, y, a, i], "A", sym=sym)
        at1 = ATerm(scalar=1, sums=[], tensors=[ext, t1])
        self.assertTrue(at1 == aout.terms[0])
Example #22
0
    def testP1op(self):
        op = one_p("Hp", name2="Hq")
        bra = braP1("nm")
        ex = apply_wick(bra * op)
        ex.resolve()
        out = AExpression(Ex=ex)

        x = Idx(0, "nm", fermion=False)
        tr1 = ATerm(scalar=1,
                    sums=[],
                    tensors=[Tensor([x], "Hq"),
                             Tensor([x], "")])
        ref = AExpression(terms=[tr1])
        self.assertTrue(ref.pmatch(out))

        ket = ketP1("nm")
        ex = apply_wick(op * ket)
        ex.resolve()
        out = AExpression(Ex=ex)
        tr1 = ATerm(scalar=1,
                    sums=[],
                    tensors=[Tensor([x], "Hp"),
                             Tensor([x], "")])
        ref = AExpression(terms=[tr1])
        self.assertTrue(ref.pmatch(out))
Example #23
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])
Example #24
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)
Example #25
0
 def test_sigma(self):
     i = Idx(0, "occ")
     j = Idx(1, "occ")
     a = Idx(0, "vir")
     S1 = Sigma(i)
     S2 = Sigma(i)
     S3 = Sigma(j)
     S4 = Sigma(a)
     self.assertTrue(S2 == S1)
     self.assertTrue(S2 != S3)
     self.assertTrue(S2 != S4)
     self.assertTrue(S3 != S4)
     self.assertTrue(S1 < S3)
     self.assertTrue(S1 <= S3)
     self.assertTrue(S1 <= S2)
     self.assertTrue(S1 >= S2)
     self.assertTrue(S4 > S2)
Example #26
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)
Example #27
0
    def test_tensor(self):
        i = Idx(0, "occ")
        a = Idx(0, "vir")
        T0 = Tensor([i], "g")
        T1 = Tensor([i, a], "g")
        T2 = Tensor([i, a], "f")
        T3 = Tensor([i, a], "f")
        T4 = Tensor([a, i], "f")
        self.assertTrue(T2 == T3)
        self.assertTrue(T2 != T4)
        self.assertTrue(T1 != T3)
        self.assertTrue(T1 != T4)

        self.assertTrue(T0 < T1)
        self.assertTrue(T2 <= T3)
        self.assertFalse(T2 < T3)
        self.assertTrue(T2 > T0)
        self.assertTrue(T4 >= T3)
Example #28
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)
Example #29
0
    def testP2op(self):
        op = two_p("H")
        bra = braP1("nm")
        ket = ketP1("nm")
        ex = apply_wick(bra * op * ket)
        ex.resolve()
        out = AExpression(Ex=ex)

        x = Idx(0, "nm", fermion=False)
        y = Idx(1, "nm", fermion=False)
        sym = TensorSym([(0, 1), (1, 0)], [1, 1])
        tensors = [
            Tensor([x], ""),
            Tensor([x, y], "H", sym=sym),
            Tensor([y], "")
        ]
        tr1 = ATerm(scalar=1, sums=[], tensors=tensors)
        ref = AExpression(terms=[tr1])
        self.assertTrue(ref.pmatch(out))
Example #30
0
    def test_merge_external(self):
        bra = braE1("occ", "vir")
        ket = ketE1("occ", "vir")
        out = apply_wick(bra * ket)
        aout = AExpression(Ex=out)
        aterm = aout.terms[0]
        aterm.merge_external()

        i = Idx(0, "occ")
        a = Idx(0, "vir")
        j = Idx(1, "occ")
        b = Idx(1, "vir")
        tensors = [
            Tensor([a, i, j, b], ""),
            tensor_from_delta(Delta(i, j)),
            tensor_from_delta(Delta(a, b))
        ]
        aref = ATerm(scalar=1, sums=[], tensors=tensors)
        self.assertTrue(aterm == aref)