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 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 #3
0
    def testEea2(self):
        bra = braEea2("occ", "vir", "vir")
        ket = ketEea2("occ", "vir", "vir")
        out = apply_wick(bra * ket)
        aout = AExpression(Ex=out)

        i = Idx(0, "occ")
        a = Idx(0, "vir")
        b = Idx(1, "vir")
        k = Idx(2, "occ")
        c = Idx(2, "vir")
        d = Idx(3, "vir")
        tensors = [Tensor([i, a, b], ""), Tensor([c, d, k], "")]
        tr1 = Term(1, [], tensors, [], [Delta(i, k), Delta(a, c), Delta(b, d)])
        tr2 = Term(
            -1, [], tensors, [],
            [Delta(i, k), Delta(a, d), Delta(b, c)])
        ref = Expression([tr1, tr2])
        aref = AExpression(Ex=ref)
        self.assertTrue(aout.pmatch(aref))

        op = Eea2("A", ["occ"], ["vir"])
        out = apply_wick(bra * op)
        out.resolve()
        aout = AExpression(Ex=out)
        ext = Tensor([a, b, i], "")
        ten = Tensor([a, b, i], "A", sym=get_sym_ea2())
        at1 = ATerm(scalar=1, sums=[], tensors=[ext, ten])
        self.assertTrue(len(aout.terms) == 1)
        self.assertTrue(at1.pmatch(aout.terms[0]))
Example #4
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 #5
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 #6
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 #7
0
    def testP1E1(self):
        bra = braP1E1("nm", "occ", "vir")
        ket = ketP1E1("nm", "occ", "vir")
        out = apply_wick(bra * ket)
        aout = AExpression(Ex=out)

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

        op = EPS1("A", ["nm"], ["occ"], ["vir"])
        out = apply_wick(bra * op)
        out.resolve()
        aout = AExpression(Ex=out)
        ext = Tensor([x, a, i], "")
        t1 = Tensor([x, a, i], "A")
        at1 = ATerm(scalar=1, sums=[], tensors=[ext, t1])
        self.assertTrue(at1 == aout.terms[0])
Example #8
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 #9
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 #10
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 #11
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 #12
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 #13
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 #14
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 #15
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)
Example #16
0
    def testP1(self):
        bra = braP1("nm")
        ket = ketP1("nm")
        out = apply_wick(bra * ket)
        aout = AExpression(Ex=out)

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

        op = P1("A", ["nm"])
        out = apply_wick(bra * op)
        out.resolve()
        aout = AExpression(Ex=out)
        ext = Tensor([x], "")
        ten = Tensor([x], "A")
        at1 = ATerm(scalar=1, sums=[], tensors=[ext, ten])
        self.assertTrue(at1 == aout.terms[0])
Example #17
0
    def test_mul(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)
        t2 = t1.copy()
        out = t1 * t2

        k = Idx(2, "occ")
        l = Idx(3, "occ")
        sumsx = [Sigma(i), Sigma(j), Sigma(k), Sigma(l)]
        tensorsx = [Tensor([i, j], 'f'), Tensor([k, l], 'f')]
        tx = ATerm(s, sumsx, tensorsx)
        self.assertTrue(tx == out)
        tx.scalar = 2
        out = 2 * out
        self.assertTrue(tx == out)
        self.assertTrue(4 * tx == out * 4)