Exemplo n.º 1
0
def test_indices_so_canonical():
    a = Indices.make_indices("p0, p1, a0, h0, g4, g1, c1, v2", 'so')
    c, sign = a.canonicalize()
    assert sign == -1
    assert c == IndicesSpinOrbital("g1, g4, p0, p1, h0, v2, c1, a0")
    with pytest.raises(TypeError):
        assert c == Indices("g1, g4, p0, p1, h0, v2, c1, a0")
Exemplo n.º 2
0
def test_eq():
    a = IndicesPair("h1,g0,v4", "c0")
    assert a == IndicesPair(Indices.make_indices("h1, g0, v4", 'so'),
                            Indices.make_indices("c0", 'so'))
    with pytest.raises(TypeError):
        assert a == IndicesPair(Indices.make_indices("h1,g0,v4", 'spin-integrated'),
                                Indices.make_indices("c0", 'spin-integrated'))
Exemplo n.º 3
0
def test_init():
    id_type = 'spin-orbital'
    assert SecondQuantizedOperator([], []).is_empty()
    a = SecondQuantizedOperator("g0,g1,g2", "p0,p1,p2", id_type)
    assert a.cre_ops == Indices.make_indices("g0,g1,g2", id_type)
    assert a.ann_ops == Indices.make_indices("p0,p1,p2", id_type)
    assert a.n_ann == 3
    assert a.n_cre == 3
Exemplo n.º 4
0
def test_init():
    with pytest.raises(TypeError):
        IndicesPair(Indices.make_indices("c0", 'spin-adapted'),
                    Indices.make_indices("V0, h2", 'spin-integrated'))

    a = IndicesPair("A0, a1", "p0, G8", 'spin-integrated')
    assert a.upper_indices == Indices.make_indices("A0, a1", 'spin-integrated')
    assert a.lower_indices == Indices.make_indices("p0, G8", 'spin-integrated')
    assert a.n_upper == 2
    assert a.n_lower == 2
    assert not a.is_empty()
Exemplo n.º 5
0
def test_indices_init():
    with pytest.raises(ValueError):
        Indices("a0 c1, P2, V8")
    with pytest.raises(ValueError):
        Indices(["a0"] * 3)
    a = Indices("a0, P2")
    assert a.indices == [Index("a0"), Index("P2")]
    assert a.size == 2
    assert a.indices_set == {Index("a0"), Index("P2")}

    a = Indices([])
    assert a == Indices("")
    assert a.size == 0
Exemplo n.º 6
0
def test_ele_con_list_4():
    h = SQ("g0, h0", "g1, p0", 'spin-orbital')
    t1d = SQ("h3", "p3")
    t2e = SQ("p1, p2", "h1, h2")
    elementary_contractions = compute_elementary_contractions_list(
        [t1d, h, t2e], max_cu=5)

    ref = set()
    upper_indices = t1d.upper_indices + h.upper_indices + t2e.upper_indices
    lower_indices = t1d.lower_indices + h.lower_indices + t2e.lower_indices
    invalid_contractions = {
        make_tensor('L', 'h3', 'p3'),
        make_tensor('L', 'g0', 'g1'),
        make_tensor('L', 'g0', 'p0'),
        make_tensor('L', 'h0', 'g1'),
        make_tensor('L', 'h0', 'p0'),
        make_tensor('L', 'p1', 'h1'),
        make_tensor('L', 'p1', 'h2'),
        make_tensor('L', 'p2', 'h1'),
        make_tensor('L', 'p2', 'h2'),
        make_tensor('L', 'g0, h0', 'g1, p0'),
        make_tensor('L', 'p1, p2', 'h1, h2'),
        make_tensor('L', 'g0', 'p3'),
        make_tensor('L', 'h0', 'p3'),
        make_tensor('L', 'p1', 'p3'),
        make_tensor('L', 'p2', 'p3'),
        make_tensor('L', 'p1', 'p0'),
        make_tensor('L', 'p2', 'p0'),
        make_tensor('L', 'p1', 'g1'),
        make_tensor('L', 'p2', 'g1')
    }
    for cu in range(1, 6):
        for upper in combinations(upper_indices, cu):
            u_indices = Indices.make_indices(upper, 'so')
            for lower in combinations(lower_indices, cu):
                l_indices = Indices.make_indices(lower, 'so')
                tensor = make_tensor('L', u_indices, l_indices)
                if tensor not in invalid_contractions:
                    ref.add(tensor)
    ref |= {
        make_tensor('C', 'g0', 'p3'),
        make_tensor('C', 'h0', 'p3'),
        make_tensor('C', 'p1', 'p3'),
        make_tensor('C', 'p2', 'p3'),
        make_tensor('C', 'p1', 'p0'),
        make_tensor('C', 'p2', 'p0'),
        make_tensor('C', 'p1', 'g1'),
        make_tensor('C', 'p2', 'g1')
    }

    assert ref == set(elementary_contractions)
Exemplo n.º 7
0
    def __init__(self, upper_indices, lower_indices, indices_type='so'):
        """
        The IndicesPair class to handle upper and lower indices for tensors or second-quantized operators.
        :param upper_indices: a Indices object for upper indices
        :param lower_indices: a Indices object for lower indices
        :param indices_type: the type of indices, used if the indices are not Indices
        """
        upper = upper_indices if isinstance(upper_indices, Indices) else \
            Indices.make_indices(upper_indices, indices_type)
        lower = lower_indices if isinstance(lower_indices, Indices) else \
            Indices.make_indices(lower_indices, indices_type)

        if type(upper_indices) != type(lower_indices):
            raise TypeError(
                f"Inconsistent type for upper_indices ('{upper_indices.__class__.__name__}') "
                f"and lower_indices ('{lower_indices.__class__.__name__}').")

        self._upper_indices = upper
        self._lower_indices = lower
Exemplo n.º 8
0
def test_indices_si_ambit_perm():
    a = IndicesSpinIntegrated(["P0", "P1", "V2", "A3"])
    part = [[Index("V2")], [Index("P0"), Index("P1")], [Index("A3")]]
    ref = {
        "P0,P1,V2,A3", "P0,P1,A3,V2", "P0,A3,P1,V2", "A3,P0,P1,V2",
        "P0,V2,P1,A3", "V2,P0,P1,A3", "P0,A3,V2,P1", "P0,V2,A3,P1",
        "V2,P0,A3,P1", "A3,P0,V2,P1", "A3,V2,P0,P1", "V2,A3,P0,P1"
    }
    for sign, indices_str in a.ambit_permute_format(part):
        assert sign == (-1)**a.count_permutations(Indices(indices_str))
        assert indices_str in ref
        ref.remove(indices_str)
    assert len(ref) == 0

    a = IndicesSpinIntegrated(["P0", "P1", "c2", "A3"])
    with pytest.raises(ValueError):
        list(a.ambit_permute_format(part))
Exemplo n.º 9
0
def test_indices_count_space():
    assert Indices("p0, P1, a2, h0, g4, G1, C1, v2").count_index_space(
        ['p', 'v', 'P', 'V']) == 3
Exemplo n.º 10
0
def test_indices_perm():
    a = Indices("p0, p1, g2, A4")
    assert a.is_permutation(Indices("g2, p1, p0, A4"))
Exemplo n.º 11
0
def test_indices_add():
    a = Indices("a0")
    assert a + Indices("a1") == Indices("a0, a1")
    a += Indices("a1")
    assert a == Indices("a0, a1")
Exemplo n.º 12
0
def test_indices_get():
    with pytest.raises(IndexError):
        assert Indices([])[0]
    assert Indices("p0, p1, a0, h0, g4, g1, c1, v2")[2] == Index("a0")
Exemplo n.º 13
0
def test_indices_ge():
    assert Indices("g0, C2, H8") >= Indices("v2")
    assert Indices("g0, C2, h8") >= Indices("g0, c2, h8")
    assert Indices("g0, c1, V3") >= Indices("g0, c1, V3")
Exemplo n.º 14
0
def test_indices_so_ambit_perm():
    a = IndicesSpinOrbital(["p0", "p1", "v2", "a3"])
    part = [[Index("p0"), Index("p1")], [Index("v2")], [Index("a3")]]
    for sign, indices_str in a.ambit_permute_format(part):
        assert sign == (-1)**a.count_permutations(Indices(indices_str))
Exemplo n.º 15
0
def test_lt():
    a = IndicesPair("G3", "g0, v2", 'spin-integrated')
    assert a < IndicesPair(Indices.make_indices("A0", 'spin-integrated'),
                           Indices.make_indices("c0", 'spin-integrated'))
Exemplo n.º 16
0
def test_indices_le():
    assert Indices("A3") <= Indices("g0, v2")
    assert Indices("g0, c1, V3") <= Indices("c1, V3, g0")
    assert Indices("g0, c1, V3") <= Indices("g0, c1, V3")
Exemplo n.º 17
0
def test_indices_ne():
    assert not Indices("g0, c1, V3") != Indices(["g0", 'c1', "V3"])
Exemplo n.º 18
0
def test_ne():
    a = IndicesPair("v1,G9", "h2,a2", 'spin-adapted')
    assert a != IndicesPair(Indices.make_indices("h1,g0,v4", 'sa'),
                            Indices.make_indices("c0", 'sa'))
Exemplo n.º 19
0
def test_indices_ambit():
    assert Indices(["p0", "p1", "a0", "h0", "g4", "g1", "c1",
                    "v2"]).ambit() == "p0,p1,a0,h0,g4,g1,c1,v2"
Exemplo n.º 20
0
def test_indices_latex():
    assert Indices("g1, g4, p0, h1, v2, c1").latex(
        True) == "${ g_{1} g_{4} p_{0} h_{1} v_{2} c_{1} }$"
Exemplo n.º 21
0
def test_indices_str():
    assert str(Indices(["p0", "p1", "a0", "h0", "g4", "g1", "c1",
                        "v2"])) == "p0, p1, a0, h0, g4, g1, c1, v2"
Exemplo n.º 22
0
def test_any_overlap():
    a = Indices("p0, p1, g2, A4")
    b = Indices("p3, p1, c2, a4")
    assert a.any_overlap(b)
    b = Indices("p3, h1, c2, a4")
    assert not a.any_overlap(b)
Exemplo n.º 23
0
def test_le():
    a = IndicesPair("G3", "g0, v2", 'spin-adapted')
    assert a <= IndicesPair(Indices.make_indices("A0", 'sa'),
                            Indices.make_indices("c0", 'sa'))
    assert a <= IndicesPair(Indices.make_indices("G3", 'spin-adapted'),
                            Indices.make_indices("g0,v2", 'spin-adapted'))
Exemplo n.º 24
0
def test_clone():
    a = Indices("p0, c1, g2, A4")
    b = a.clone()
    assert a == b
    assert a is not b
Exemplo n.º 25
0
def test_indices_gt():
    assert Indices("g0, C2, H8") > Indices("v2")
    assert Indices("g0, C2, h8") > Indices("g0, c2, h8")
Exemplo n.º 26
0
def test_indices_eq():
    assert Indices("g0, c1, V3") == Indices(["g0", 'c1', "V3"])
Exemplo n.º 27
0
def test_indices_so_init():
    with pytest.raises(ValueError):
        Indices.make_indices("p0, V2, A2", 'spin-orbital')