Commit dd7b9a11 authored by Davison's avatar Davison
Browse files

rewrote some contractions as 3-node tensornetworks

parent 7cea9ccb
......@@ -428,15 +428,18 @@ if __name__ == '__main__':
# test_exact('plots_exact\\')
# print(ci_matrix.exact_diagonalization(1.0, 0.5, 0.1))
h = PairingHamiltonian2B(4,4)
occt = OccupationTensors(h.sp_basis, h.reference)
wg3b = WegnerGenerator3B(h, occt)
test = wg3b.calc_eta()
eta1B = test[0]
eta2B = test[1]
eta3B = test[2]
print(eta1B)
print(eta2B[0,1,4,5])
print(eta2B[4,5,0,1])
print(eta3B.shape)
test = main(4,4)
# test2 = ci_matrix.exact_diagonalization(1.0,0.5,0.001)
# print(test2)
# h = PairingHamiltonian2B(4,4)
# occt = OccupationTensors(h.sp_basis, h.reference)
# wg3b = WegnerGenerator3B(h, occt)
# test = wg3b.calc_eta()
# eta1B = test[0]
# eta2B = test[1]
# eta3B = test[2]
# print(eta1B)
# print(eta2B[0,1,4,5])
# print(eta2B[4,5,0,1])
# print(eta3B.shape)
......@@ -89,8 +89,9 @@ class Flow_IMSRG2(Flow):
# - Calculate dE/ds
# first term
sum1_0b_1 = ncon([occA, eta1B], [(0, 1, -1, -2), (0, 1)]).numpy()
sum1_0b = ncon([sum1_0b_1, f], [(0, 1), (1, 0)]).numpy()
sum1_0b = ncon([eta1B, occA, f], [(2,3), (2,3,0,1), (1,0)]).numpy()
# sum1_0b_1 = ncon([occA, eta1B], [(0, 1, -1, -2), (0, 1)]).numpy()
# sum1_0b = ncon([sum1_0b_1, f], [(0, 1), (1, 0)]).numpy()
# second term
sum2_0b_1 = np.matmul(eta2B, occD)
......@@ -106,16 +107,21 @@ class Flow_IMSRG2(Flow):
sum1_1b = sum1_1b_1 + sum1_1b_2
# second term (might need to fix)
sum2_1b_1 = ncon([eta1B, G], [(0, 1), (1, -1, 0, -2)]).numpy()
sum2_1b_2 = ncon([f, eta2B], [(0, 1), (1, -1, 0, -2)]).numpy()
sum2_1b_3 = sum2_1b_1 - sum2_1b_2
sum2_1b = ncon([occA, sum2_1b_3],[(-1, -2, 0, 1), (0,1)]).numpy()
sum2_1b_1 = ncon([eta1B, occA, G], [(2,3), (2,3,0,1), (1,-1,0,-2)]).numpy()
sum2_1b_2 = ncon([f, occA, eta2B], [(2,3), (2,3,0,1), (1,-1,0,-2)]).numpy()
sum2_1b = sum2_1b_1 - sum2_1b_2
# sum2_1b_1 = ncon([eta1B, G], [(0, 1), (1, -1, 0, -2)]).numpy()
# sum2_1b_2 = ncon([f, eta2B], [(0, 1), (1, -1, 0, -2)]).numpy()
# sum2_1b_3 = sum2_1b_1 - sum2_1b_2
# sum2_1b = ncon([occA, sum2_1b_3],[(-1, -2, 0, 1), (0,1)]).numpy()
# third term
sum3_1b_1 = ncon([occC, G], [(-1, -2, -3, 0, 1, 2), (0, 1, 2, -4)]).numpy()
sum3_1b_2 = ncon([eta2B, sum3_1b_1], [(2, -1, 0, 1), (0, 1, 2, -2)]).numpy()
sum3_1b_3 = np.transpose(sum3_1b_2)
sum3_1b = sum3_1b_2 + sum3_1b_3
sum3_1b_1 = ncon([eta2B, occC, G], [(5,-1,3,4), (3,4,5,0,1,2), (0,1,2,-2)]).numpy()
sum3_1b = sum3_1b_1 + np.transpose(sum3_1b_1)
# sum3_1b_1 = ncon([occC, G], [(-1, -2, -3, 0, 1, 2), (0, 1, 2, -4)]).numpy()
# sum3_1b_2 = ncon([eta2B, sum3_1b_1], [(2, -1, 0, 1), (0, 1, 2, -2)]).numpy()
# sum3_1b_3 = np.transpose(sum3_1b_2)
# sum3_1b = sum3_1b_2 + sum3_1b_3
df = sum1_1b + sum2_1b + 0.5*sum3_1b
......@@ -138,19 +144,25 @@ class Flow_IMSRG2(Flow):
sum1_2b = sum1_2b_5 - sum1_2b_10
# second term
sum2_2b_1 = ncon([occB, G], [(-1, -2, 0, 1), (0, 1, -3, -4)]).numpy()
sum2_2b_2 = ncon([occB, eta2B], [(-1, -2, 0, 1), (0, 1, -3, -4)]).numpy()
sum2_2b_3 = ncon([eta2B, sum2_2b_1], [(-1, -2, 0, 1), (0, 1, -3, -4)]).numpy()
sum2_2b_4 = ncon([G, sum2_2b_2], [(-1, -2, 0, 1), (0, 1, -3, -4)]).numpy()
sum2_2b = sum2_2b_3 - sum2_2b_4
sum2_2b_1 = ncon([eta2B, occB, G], [(-1,-2,2,3), (2,3,0,1), (0,1,-3,-4)]).numpy()
sum2_2b_2 = ncon([G, occB, eta2B], [(-1,-2,2,3), (2,3,0,1), (0,1,-3,-4)]).numpy()
sum2_2b = sum2_2b_1 - sum2_2b_2
# sum2_2b_1 = ncon([occB, G], [(-1, -2, 0, 1), (0, 1, -3, -4)]).numpy()
# sum2_2b_2 = ncon([occB, eta2B], [(-1, -2, 0, 1), (0, 1, -3, -4)]).numpy()
# sum2_2b_3 = ncon([eta2B, sum2_2b_1], [(-1, -2, 0, 1), (0, 1, -3, -4)]).numpy()
# sum2_2b_4 = ncon([G, sum2_2b_2], [(-1, -2, 0, 1), (0, 1, -3, -4)]).numpy()
# sum2_2b = sum2_2b_3 - sum2_2b_4
# third term
sum3_2b_1 = ncon([eta2B, G], [(0, -1, 1, -3), (1, -2, 0, -4)]).numpy()
sum3_2b_2 = np.transpose(sum3_2b_1, [1, 0, 2, 3])
sum3_2b_3 = np.transpose(sum3_2b_1, [0, 1, 3, 2])
sum3_2b_4 = np.transpose(sum3_2b_1, [1, 0, 3, 2])
sum3_2b_5 = sum3_2b_1 - sum3_2b_2 - sum3_2b_3 + sum3_2b_4
sum3_2b = ncon([occA, sum3_2b_5], [(0, 1, -1, -2), (0, 1, -3, -4)]).numpy()
sum3_2b_1 = ncon([eta2B, occA, G], [(3,-2,2,-4), (2,3,0,1), (0,-1,1,-3)]).numpy()
sum3_2b_2 = sum3_2b_1 - np.transpose(sum3_2b_1, [0,1,3,2])
sum3_2b = sum3_2b_2 - np.transpose(sum3_2b_2, [1,0,2,3])
# sum3_2b_1 = ncon([eta2B, G], [(0, -1, 1, -3), (1, -2, 0, -4)]).numpy()
# sum3_2b_2 = np.transpose(sum3_2b_1, [1, 0, 2, 3])
# sum3_2b_3 = np.transpose(sum3_2b_1, [0, 1, 3, 2])
# sum3_2b_4 = np.transpose(sum3_2b_1, [1, 0, 3, 2])
# sum3_2b_5 = sum3_2b_1 - sum3_2b_2 - sum3_2b_3 + sum3_2b_4
# sum3_2b = ncon([occA, sum3_2b_5], [(0, 1, -1, -2), (0, 1, -3, -4)]).numpy()
dG = sum1_2b + 0.5*sum2_2b + sum3_2b
......
......@@ -124,16 +124,21 @@ class WegnerGenerator(Generator):
sum1_1b = sum1_1b_1 - sum1_1b_2
# second term
sum2_1b_1 = ncon([fd, God], [(0, 1), (1, -1, 0, -2)]).numpy()
sum2_1b_2 = ncon([fod, Gd], [(0, 1), (1, -1, 0, -2)]).numpy()
sum2_1b_3 = sum2_1b_1 - sum2_1b_2
sum2_1b = ncon([occA, sum2_1b_3],[(-1, -2, 0, 1), (0,1)]).numpy()
sum2_1b_1 = ncon([fd, occA, God], [(2,3), (2,3,0,1), (1,-1,0,-2)]).numpy()
sum2_1b_2 = ncon([fod, occA, Gd], [(2,3), (2,3,0,1), (1,-1,0,-2)]).numpy()
sum2_1b = sum2_1b_1 - sum2_1b_2
# sum2_1b_1 = ncon([fd, God], [(0, 1), (1, -1, 0, -2)]).numpy()
# sum2_1b_2 = ncon([fod, Gd], [(0, 1), (1, -1, 0, -2)]).numpy()
# sum2_1b_3 = sum2_1b_1 - sum2_1b_2
# sum2_1b = ncon([occA, sum2_1b_3],[(-1, -2, 0, 1), (0,1)]).numpy()
# third term
sum3_1b_1 = ncon([occC, God], [(-1, -2, -3, 0, 1, 2), (0, 1, 2, -4)]).numpy()
sum3_1b_2 = ncon([Gd, sum3_1b_1], [(2, -1, 0, 1), (0, 1, 2, -2)]).numpy()
sum3_1b_3 = np.transpose(sum3_1b_2)
sum3_1b = sum3_1b_2 - sum3_1b_3
sum3_1b_1 = ncon([Gd, occC, God], [(5,-1,3,4), (3,4,5,0,1,2), (0,1,2,-2)]).numpy()
sum3_1b = sum3_1b_1 - np.transpose(sum3_1b_1)
# sum3_1b_1 = ncon([occC, God], [(-1, -2, -3, 0, 1, 2), (0, 1, 2, -4)]).numpy()
# sum3_1b_2 = ncon([Gd, sum3_1b_1], [(2, -1, 0, 1), (0, 1, 2, -2)]).numpy()
# sum3_1b_3 = np.transpose(sum3_1b_2)
# sum3_1b = sum3_1b_2 - sum3_1b_3
eta1B = sum1_1b + sum2_1b + 0.5*sum3_1b
......@@ -155,19 +160,25 @@ class WegnerGenerator(Generator):
sum1_2b = sum1_2b_5 - sum1_2b_10
# second term
sum2_2b_1 = ncon([occB, God], [(-1, -2, 0, 1), (0, 1, -3, -4)]).numpy()
sum2_2b_2 = ncon([occB, Gd], [(-1, -2, 0, 1), (0, 1, -3, -4)]).numpy()
sum2_2b_3 = ncon([Gd, sum2_2b_1], [(-1, -2, 0, 1), (0, 1, -3, -4)]).numpy()
sum2_2b_4 = ncon([God, sum2_2b_2], [(-1, -2, 0, 1), (0, 1, -3, -4)]).numpy()
sum2_2b = sum2_2b_3 - sum2_2b_4
sum2_2b_1 = ncon([Gd, occB, God], [(-1,-2,2,3), (2,3,0,1), (0,1,-3,-4)]).numpy()
sum2_2b_2 = ncon([God, occB, Gd], [(-1,-2,2,3), (2,3,0,1), (0,1,-3,-4)]).numpy()
sum2_2b = sum2_2b_1 - sum2_2b_2
# sum2_2b_1 = ncon([occB, God], [(-1, -2, 0, 1), (0, 1, -3, -4)]).numpy()
# sum2_2b_2 = ncon([occB, Gd], [(-1, -2, 0, 1), (0, 1, -3, -4)]).numpy()
# sum2_2b_3 = ncon([Gd, sum2_2b_1], [(-1, -2, 0, 1), (0, 1, -3, -4)]).numpy()
# sum2_2b_4 = ncon([God, sum2_2b_2], [(-1, -2, 0, 1), (0, 1, -3, -4)]).numpy()
# sum2_2b = sum2_2b_3 - sum2_2b_4
# third term
sum3_2b_1 = ncon([Gd, God], [(0, -1, 1, -3), (1, -2, 0, -4)]).numpy()
sum3_2b_2 = np.transpose(sum3_2b_1, [1, 0, 2, 3])
sum3_2b_3 = np.transpose(sum3_2b_1, [0, 1, 3, 2])
sum3_2b_4 = np.transpose(sum3_2b_1, [1, 0, 3, 2])
sum3_2b_5 = sum3_2b_1 - sum3_2b_2 - sum3_2b_3 + sum3_2b_4
sum3_2b = ncon([occA, sum3_2b_5], [(0, 1, -1, -2), (0, 1, -3, -4)]).numpy()
sum3_2b_1 = ncon([Gd, occA, God], [(3,-2,2,-4), (2,3,0,1), (0,-1,1,-3)]).numpy()
sum3_2b_2 = sum3_2b_1 - np.transpose(sum3_2b_1, [0,1,3,2])
sum3_2b = sum3_2b_2 - np.transpose(sum3_2b_2, [1,0,2,3])
# sum3_2b_1 = ncon([Gd, God], [(0, -1, 1, -3), (1, -2, 0, -4)]).numpy()
# sum3_2b_2 = np.transpose(sum3_2b_1, [1, 0, 2, 3])
# sum3_2b_3 = np.transpose(sum3_2b_1, [0, 1, 3, 2])
# sum3_2b_4 = np.transpose(sum3_2b_1, [1, 0, 3, 2])
# sum3_2b_5 = sum3_2b_1 - sum3_2b_2 - sum3_2b_3 + sum3_2b_4
# sum3_2b = ncon([occA, sum3_2b_5], [(0, 1, -1, -2), (0, 1, -3, -4)]).numpy()
eta2B = sum1_2b + 0.5*sum2_2b + sum3_2b
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment