def test_canonicalize_2(): # H^{ v_{0} }_{ v_{1} } T^{ v_{1} }_{ c_{1} } T^{ v_{2} }_{ c_{0} } T^{ c_{0} c_{1} }_{ v_{0} v_{2} } indices_type = 'so' list_of_tensors = [ make_tensor('Hamiltonian', "v0", "v1", indices_type), make_tensor('cluster_amplitude', "v1", "c1", indices_type), make_tensor('cluster_amplitude', "v2", "c0", indices_type), make_tensor('cluster_amplitude', "c0,c1", "v0,v2", indices_type) ] sq_op = SecondQuantizedOperator.make_empty(indices_type) a = Term(list_of_tensors, sq_op) # H^{ v_{0} }_{ v_{1} } T^{ c_{0} }_{ v_{2} } T^{ c_{1} }_{ v_{0} } T^{ v_{1} v_{2} }_{ c_{0} c_{1} } list_of_tensors = [ make_tensor('Hamiltonian', "v0", "v1", indices_type), make_tensor('cluster_amplitude', "c0", "v2", indices_type), make_tensor('cluster_amplitude', "c1", "v0", indices_type), make_tensor('cluster_amplitude', "v1,v2", "c0,c1", indices_type) ] b = Term(list_of_tensors, sq_op) ref = Term([ make_tensor('Hamiltonian', "v1", "v0", indices_type), make_tensor('cluster_amplitude', "c0", "v0", indices_type), make_tensor('cluster_amplitude', "c1", "v2", indices_type), make_tensor('cluster_amplitude', "c0,c1", "v1,v2", indices_type) ], sq_op, -1) assert ref == a.canonicalize() == b.canonicalize()
def test_canonicalize_3(): # -1 * H^{g0,g1}_{g2,g3} * T^{h0,h1}_{p0,p1} * L^{p1}_{g2} * L^{p0}_{g3} * a^{g0,g1}_{h0, h1} list_of_tensors = [ make_tensor('H', 'g0, g1', 'g2, g3'), make_tensor('t', 'p0, p1', 'h0, h1'), make_tensor('L', 'p1', 'g2'), make_tensor('L', 'p0', 'g3') ] sq_op = make_sq('g0, g1', 'h0, h1') a = Term(list_of_tensors, sq_op, -1) ref = Term([ make_tensor('H', 'a0, a1', 'g0, g1'), make_tensor('t', 'a2, a3', 'h0, h1'), make_tensor('L', 'a2', 'a0'), make_tensor('L', 'a3', 'a1') ], sq_op, 1) assert a.canonicalize() == ref list_of_tensors = [ make_tensor('H', 'g0, G1', 'g2, G3', 'si'), make_tensor('t', 'P0, p1', 'H0, h1', 'si'), make_tensor('L', 'p1', 'g2', 'si'), make_tensor('L', 'P0', 'G3', 'si') ] a = Term(list_of_tensors, make_sq('g0, G1', 'H0, h1', 'si')) ref = Term([ make_tensor('H', 'a0, A0', 'g0, G0', 'si'), make_tensor('t', 'a1, A1', 'h0, H0', 'si'), make_tensor('L', 'a1', 'a0', 'si'), make_tensor('L', 'A1', 'A0', 'si') ], make_sq('g0, G0', 'h0, H0', 'si'), -1) assert ref == a.canonicalize() list_of_tensors = [ make_tensor('H', 'g0, G1', 'g2, G3', 'sa'), make_tensor('t', 'P0, p1', 'H0, h1', 'sa'), make_tensor('L', 'p1', 'g2', 'sa'), make_tensor('L', 'P0', 'G3', 'sa') ] a = Term(list_of_tensors, make_sq('g0, G1', 'h1, H0', 'sa')) ref = Term([ make_tensor('H', 'a0, A0', 'g0, G0', 'sa'), make_tensor('t', 'a1, A1', 'h0, H0', 'sa'), make_tensor('L', 'a1', 'a0', 'sa'), make_tensor('L', 'A1', 'A0', 'sa') ], make_sq('g0, G0', 'h0, H0', 'sa')) assert ref == a.canonicalize()
def test_canonicalize_1(): list_of_tensors = [ make_tensor('H', "g0", "g0"), make_tensor('t', "h0", "p0"), make_tensor('t', "p1", "c1"), make_tensor('L', 'g0', 'c1'), make_tensor('K', 'p0', 'p1') ] a = Term(list_of_tensors, SecondQuantizedOperator('h0', 'g0')) with pytest.raises(NotImplementedError): assert a.canonicalize()
def test_canonicalize_4(): list_of_tensors = [ make_tensor('Hamiltonian', "g0,g1,c0", "g2,p0,v0"), make_tensor('cluster_amplitude', "p0,p1,g3", "a0,h1,a1"), make_tensor('Kronecker', "v0", "p1"), make_tensor('cumulant', "h1", "c0"), make_tensor('cumulant', "a1", "g3"), make_tensor('cumulant', "g2,a0", "g0,g1") ] a = Term(list_of_tensors, SecondQuantizedOperator.make_empty()) ref = Term([ make_tensor('H', "c0,a1,a2", "p0,v0,a0"), make_tensor('t', "c0,a4,a5", "p0,v0,a3"), make_tensor('L', "a4", "a3"), make_tensor('L', "a1,a2", "a0,a5") ], SecondQuantizedOperator.make_empty()) assert a.canonicalize() == ref
def test_generate_spin_cases_3(): list_of_tensors = [ make_tensor('H', "v0,c0", "v1,c1"), make_tensor('t', "v1", "c2"), make_tensor('t', "v2,v3", "c0,c3"), make_tensor('t', "c2,c3", "v0,v3") ] a = Term(list_of_tensors, make_sq("c1", "v2")) ac = Term([ make_tensor('H', 'v2,c1', 'v1,c0'), make_tensor('t', 'c2', 'v1'), make_tensor('t', 'c1,c3', 'v0,v3'), make_tensor('t', 'c2,c3', 'v2,v3') ], make_sq("c0", "v0")) assert a.canonicalize() == ac i_type = 'si' ref = [ Term([ make_tensor('H', 'v2,c1', 'v1,c0', i_type), make_tensor('t', 'c2', 'v1', i_type), make_tensor('t', 'c1,c3', 'v0,v3', i_type), make_tensor('t', 'c2,c3', 'v2,v3', i_type) ], make_sq("c0", "v0", i_type)), Term([ make_tensor('H', 'v2,c1', 'v1,c0', i_type), make_tensor('t', 'c2', 'v1', i_type), make_tensor('t', 'c1,C3', 'v0,V3', i_type), make_tensor('t', 'c2,C3', 'v2,V3', i_type) ], make_sq("c0", "v0", i_type)).canonicalize(), Term([ make_tensor('H', 'v2,C1', 'V1,c0', i_type), make_tensor('t', 'C2', 'V1', i_type), make_tensor('t', 'C1,c3', 'v0,V3', i_type), make_tensor('t', 'C2,c3', 'v2,V3', i_type) ], make_sq("c0", "v0", i_type)).canonicalize(), Term([ make_tensor('H', 'V2,c1', 'V1,c0', i_type), make_tensor('t', 'C2', 'V1', i_type), make_tensor('t', 'c1,c3', 'v0,v3', i_type), make_tensor('t', 'C2,c3', 'V2,v3', i_type) ], make_sq("c0", "v0", i_type)).canonicalize(), Term([ make_tensor('H', 'V2,c1', 'V1,c0', i_type), make_tensor('t', 'C2', 'V1', i_type), make_tensor('t', 'c1,C3', 'v0,V3', i_type), make_tensor('t', 'C2,C3', 'V2,V3', i_type) ], make_sq("c0", "v0", i_type)).canonicalize(), Term([ make_tensor('H', 'V2,C1', 'V1,C0', i_type), make_tensor('t', 'C2', 'V1', i_type), make_tensor('t', 'C1,C3', 'V0,V3', i_type), make_tensor('t', 'C2,C3', 'V2,V3', i_type) ], make_sq("C0", "V0", i_type)), Term([ make_tensor('H', 'V2,C1', 'V1,C0', i_type), make_tensor('t', 'C2', 'V1', i_type), make_tensor('t', 'C1,c3', 'V0,v3', i_type), make_tensor('t', 'C2,c3', 'V2,v3', i_type) ], make_sq("C0", "V0", i_type)).canonicalize(), Term([ make_tensor('H', 'V2,c1', 'v1,C0', i_type), make_tensor('t', 'c2', 'v1', i_type), make_tensor('t', 'c1,C3', 'V0,v3', i_type), make_tensor('t', 'c2,C3', 'V2,v3', i_type) ], make_sq("C0", "V0", i_type)).canonicalize(), Term([ make_tensor('H', 'v2,C1', 'v1,C0', i_type), make_tensor('t', 'c2', 'v1', i_type), make_tensor('t', 'C1,c3', 'V0,v3', i_type), make_tensor('t', 'c2,c3', 'v2,v3', i_type) ], make_sq("C0", "V0", i_type)).canonicalize(), Term([ make_tensor('H', 'v2,C1', 'v1,C0', i_type), make_tensor('t', 'c2', 'v1', i_type), make_tensor('t', 'C1,C3', 'V0,V3', i_type), make_tensor('t', 'c2,C3', 'v2,V3', i_type) ], make_sq("C0", "V0", i_type)).canonicalize() ] count = 0 for i in ac.generate_spin_cases_naive(): assert i in ref count += 1 assert count == len(ref)