Commit 748fe497 authored by Jacob August Davison's avatar Jacob August Davison
Browse files

updated 2B to latest tensornetwork version

parent f5020534
......@@ -829,12 +829,12 @@ def calc_mbpt3(f, Gamma, user_data):
# Main program
#------------------------------------------------------------------------------
#@profile
def main(n_holes):
def main(n_holes, g=0.5):
# grab delta and g from the command line
# delta = float(argv[1])
# g = float(argv[2])
delta = 1
g = 0.5
#g = g
particles = n_holes
......@@ -923,6 +923,7 @@ def main(n_holes):
"||eta||", "||fod||", "||Gammaod||"))
# print "-----------------------------------------------------------------------------------------------------------------"
print("-" * 148)
count = 0
while solver.successful() and solver.t < sfinal:
ys = solver.integrate(sfinal, step=True)
......@@ -935,10 +936,15 @@ def main(n_holes):
norm_fod = calc_fod_norm(f, user_data)
norm_Gammaod = calc_Gammaod_norm(Gamma, user_data)
print("%8.5f %14.8f %14.8f %14.8f %14.8f %14.8f %14.8f %14.8f %14.8f"%(
solver.t, E , DE2, DE3, E+DE2+DE3, user_data["dE"], user_data["eta_norm"], norm_fod, norm_Gammaod))
if count % 10 == 0:
print("%8.5f %14.8f %14.8f %14.8f %14.8f %14.8f %14.8f %14.8f %14.8f"%(
solver.t, E , DE2, DE3, E+DE2+DE3, user_data["dE"], user_data["eta_norm"], norm_fod, norm_Gammaod))
count += 1
if abs(DE2/E) < 10e-8: break
return E
# solver.integrate(solver.t + ds)
......@@ -946,7 +952,7 @@ def main(n_holes):
# make executable
#------------------------------------------------------------------------------
if __name__ == "__main__":
main(int(argv[1]))
main(4)
import pytest
......
......@@ -216,22 +216,24 @@ if __name__ == '__main__':
# with open('occE_nonzero.txt', 'a') as fi:
# fi.write('%s %s %s %s %s %s -- %s\n' % (a,b,c,d,e,f,val))
#test_exact('plots_exact_2b/', main)
test_exact('plots_exact_2b/', main)
main(4,4)
bas1B = np.array([0,1,2,3,4,5,6,7])
ref = np.array([1,1,1,1,0,0,0,0],dtype=np.float16)
occt = OccupationTensors(bas1B,ref)
occF = occt.occF
# bas1B = np.array([0,1,2,3,4,5,6,7])
# ref = np.array([1,1,1,1,0,0,0,0],dtype=np.float16)
# occt = OccupationTensors(bas1B,ref)
# occF = occt.occF
test1 = np.einsum('i,j,k,l,m->ijklm',ref,ref,(1-ref),(1-ref),(1-ref))
test1e = np.einsum('ijklm,nopqr->ijklmnopqr',test1,test1)
test2 = np.einsum('i,j,k,l,m->ijklm',(1-ref),(1-ref),ref,ref,ref)
test2e = np.einsum('ijklm,nopqr->ijklmnopqr',test2,test2)
test = test1e + test2e
# test = np.einsum('ijklm,nopqr->ijklmnopqr',test3,test3)
print(occF.dtype, test.dtype)
print(occF.shape, test.shape)
print(np.array_equal(occF, test))
# test1 = np.einsum('i,j,k,l,m->ijklm',ref,ref,(1-ref),(1-ref),(1-ref))
# test1e = np.einsum('ijklm,nopqr->ijklmnopqr',test1,test1)
# test2 = np.einsum('i,j,k,l,m->ijklm',(1-ref),(1-ref),ref,ref,ref)
# test2e = np.einsum('ijklm,nopqr->ijklmnopqr',test2,test2)
# test = test1e + test2e
# # test = np.einsum('ijklm,nopqr->ijklmnopqr',test3,test3)
# print(occF.dtype, test.dtype)
# print(occF.shape, test.shape)
# print(np.array_equal(occF, test))
# for a in bas1B:
# for b in bas1B:
......
#import tensorflow as tf
# tf.enable_v2_behavior()
from tensornetwork import *
import tensornetwork as tn
import numpy as np
from oop_imsrg.hamiltonian import *
from oop_imsrg.occupation_tensors import *
from oop_imsrg.generator import *
tn.set_default_backend("tensorflow")
class Flow(object):
"""Parent class for organization purposes. Ideally, all Flow
......@@ -91,37 +92,37 @@ class Flow_IMSRG2(Flow):
# - Calculate dE/ds
# first term
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()
sum1_0b = tn.ncon([eta1B, occA, f], [(3,4), (3,4,1,2), (2,1)]).numpy()
# sum1_0b_1 = tn.ncon([occA, eta1B], [(0, 1, -1, -2), (0, 1)]).numpy()
# sum1_0b = tn.ncon([sum1_0b_1, f], [(0, 1), (1, 0)]).numpy()
# second term
sum2_0b_1 = np.matmul(eta2B, occD)
sum2_0b = ncon([sum2_0b_1, G], [(0, 1, 2, 3), (2, 3, 0, 1)]).numpy()
sum2_0b = tn.ncon([sum2_0b_1, G], [(1, 2, 3, 4), (3, 4, 1, 2)]).numpy()
dE = sum1_0b + 0.5*sum2_0b
# - Calculate df/ds
# first term
sum1_1b_1 = ncon([eta1B, f], [(-1, 0), (0, -2)]).numpy()
sum1_1b_1 = tn.ncon([eta1B, f], [(-1, 1), (1, -2)]).numpy()
sum1_1b_2 = np.transpose(sum1_1b_1)
sum1_1b = sum1_1b_1 + sum1_1b_2
# second term (might need to fix)
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_1 = tn.ncon([eta1B, occA, G], [(3,4), (3,4,1,2), (2,-1,1,-2)]).numpy()
sum2_1b_2 = tn.ncon([f, occA, eta2B], [(3,4), (3,4,1,2), (2,-1,1,-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_1 = tn.ncon([eta1B, G], [(0, 1), (1, -1, 0, -2)]).numpy()
# sum2_1b_2 = tn.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 = tn.ncon([occA, sum2_1b_3],[(-1, -2, 0, 1), (0,1)]).numpy()
# third term
sum3_1b_1 = ncon([eta2B, occC, G], [(5,-1,3,4), (3,4,5,0,1,2), (0,1,2,-2)]).numpy()
sum3_1b_1 = tn.ncon([eta2B, occC, G], [(6,-1,4,5), (4,5,6,1,2,3), (1,2,3,-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_1 = tn.ncon([occC, G], [(-1, -2, -3, 0, 1, 2), (0, 1, 2, -4)]).numpy()
# sum3_1b_2 = tn.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
......@@ -130,15 +131,15 @@ class Flow_IMSRG2(Flow):
# - Calculate dG/ds
# first term (P_ij piece)
sum1_2b_1 = ncon([eta1B, G], [(-1, 0), (0, -2, -3, -4)]).numpy()
sum1_2b_2 = ncon([f, eta2B], [(-1, 0), (0, -2, -3, -4)]).numpy()
sum1_2b_1 = tn.ncon([eta1B, G], [(-1, 1), (1, -2, -3, -4)]).numpy()
sum1_2b_2 = tn.ncon([f, eta2B], [(-1, 1), (1, -2, -3, -4)]).numpy()
sum1_2b_3 = sum1_2b_1 - sum1_2b_2
sum1_2b_4 = np.transpose(sum1_2b_3, [1, 0, 2, 3])
sum1_2b_5 = sum1_2b_3 - sum1_2b_4
# first term (P_kl piece)
sum1_2b_6 = ncon([eta1B, G], [(0, -3), (-1, -2, 0, -4)]).numpy()
sum1_2b_7 = ncon([f, eta2B], [(0, -3), (-1, -2, 0, -4)]).numpy()
sum1_2b_6 = tn.ncon([eta1B, G], [(1, -3), (-1, -2, 1, -4)]).numpy()
sum1_2b_7 = tn.ncon([f, eta2B], [(1, -3), (-1, -2, 1, -4)]).numpy()
sum1_2b_8 = sum1_2b_6 - sum1_2b_7
sum1_2b_9 = np.transpose(sum1_2b_8, [0, 1, 3, 2])
sum1_2b_10 = sum1_2b_8 - sum1_2b_9
......@@ -146,25 +147,25 @@ class Flow_IMSRG2(Flow):
sum1_2b = sum1_2b_5 - sum1_2b_10
# second term
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_1 = tn.ncon([eta2B, occB, G], [(-1,-2,3,4), (3,4,1,2), (1,2,-3,-4)]).numpy()
sum2_2b_2 = tn.ncon([G, occB, eta2B], [(-1,-2,3,4), (3,4,1,2), (1,2,-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_1 = tn.ncon([occB, G], [(-1, -2, 0, 1), (0, 1, -3, -4)]).numpy()
# sum2_2b_2 = tn.ncon([occB, eta2B], [(-1, -2, 0, 1), (0, 1, -3, -4)]).numpy()
# sum2_2b_3 = tn.ncon([eta2B, sum2_2b_1], [(-1, -2, 0, 1), (0, 1, -3, -4)]).numpy()
# sum2_2b_4 = tn.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, occA, G], [(2,-1,3,-3), (2,3,0,1), (1,-2,0,-4)]).numpy()
sum3_2b_1 = tn.ncon([eta2B, occA, G], [(3,-1,4,-3), (3,4,1,2), (2,-2,1,-4)]).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_1 = tn.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 = tn.ncon([occA, sum3_2b_5], [(0, 1, -1, -2), (0, 1, -3, -4)]).numpy()
dG = sum1_2b + 0.5*sum2_2b + sum3_2b
......@@ -248,33 +249,33 @@ class Flow_IMSRG3(Flow_IMSRG2):
# Calculate 0B flow equation
sum3_0b_1 = np.matmul(eta3B, occE)
sum3_0b = ncon([sum3_0b_1, W], [(0,1,2,3,4,5), (3,4,5,0,1,2)]).numpy()
sum3_0b = tn.ncon([sum3_0b_1, W], [(0,1,2,3,4,5), (3,4,5,0,1,2)]).numpy()
dE += (1/18)*sum3_0b
# Calculate 1B flow equation
# fourth term
sum4_1b_1 = np.matmul(np.transpose(occD,[2,3,0,1]), G)
sum4_1b_2 = np.matmul(np.transpose(occD,[2,3,0,1]), eta2B)
sum4_1b_3 = ncon([eta3B, sum4_1b_1], [(0,1,-1,2,3,-2),(2,3,0,1)]).numpy()
sum4_1b_4 = ncon([W, sum4_1b_2], [(0,1,-1,2,3,-2),(2,3,0,1)]).numpy()
sum4_1b_3 = tn.ncon([eta3B, sum4_1b_1], [(0,1,-1,2,3,-2),(2,3,0,1)]).numpy()
sum4_1b_4 = tn.ncon([W, sum4_1b_2], [(0,1,-1,2,3,-2),(2,3,0,1)]).numpy()
sum4_1b = sum4_1b_3 - sum4_1b_4
# fifth term
sum5_1b_1 = ncon([eta3B, occF, W], [(5,6,-1,7,8,9),
sum5_1b_1 = tn.ncon([eta3B, occF, W], [(5,6,-1,7,8,9),
(5,6,7,8,9,0,1,2,3,4),
(2,3,4,0,1,-2)]).numpy()
sum5_1b_2 = ncon([W, occF, eta3B], [(5,6,-1,7,8,9),
sum5_1b_2 = tn.ncon([W, occF, eta3B], [(5,6,-1,7,8,9),
(5,6,7,8,9,0,1,2,3,4),
(2,3,4,0,1,-2)]).numpy()
sum5_1b = sum5_1b_1 - sum5_1b_2
# sum5_1b_1 = ncon([occF, eta3B.astype(np.float32)],
# sum5_1b_1 = tn.ncon([occF, eta3B.astype(np.float32)],
# [(-1,-3,-4,-5,-6,0,1,2,3,4), (0,1,-2,2,3,4)]).numpy()
# sum5_1b_2 = ncon([occF, W.astype(np.float32)],
# sum5_1b_2 = tn.ncon([occF, W.astype(np.float32)],
# [(-1,-3,-4,-5,-6,0,1,2,3,4), (0,1,-2,2,3,4)]).numpy()
# sum5_1b_3 = ncon([sum5_1b_1, W.astype(np.float32)],
# sum5_1b_3 = tn.ncon([sum5_1b_1, W.astype(np.float32)],
# [(0,1,-1,2,3,4), (2,3,4,0,1,-2)]).numpy()
# sum5_1b_4 = ncon([sum5_1b_2, eta3B.astype(np.float32)],
# sum5_1b_4 = tn.ncon([sum5_1b_2, eta3B.astype(np.float32)],
# [(0,1,-1,2,3,4), (2,3,4,0,1,-2)]).numpy()
# sum5_1b = sum5_1b_3 - sum5_1b_4
......@@ -284,55 +285,55 @@ class Flow_IMSRG3(Flow_IMSRG2):
# fourth term
sum4_2b_1 = np.matmul(-1.0*np.transpose(occA2), f)
sum4_2b_2 = np.matmul(-1.0*np.transpose(occA2), eta1B)
sum4_2b_3 = ncon([eta3B, sum4_2b_1], [(0,-1,-2,1,-3,-4), (1,0)]).numpy()
sum4_2b_4 = ncon([W, sum4_2b_2], [(0,-1,-2,1,-3,-4), (1,0)]).numpy()
sum4_2b_3 = tn.ncon([eta3B, sum4_2b_1], [(0,-1,-2,1,-3,-4), (1,0)]).numpy()
sum4_2b_4 = tn.ncon([W, sum4_2b_2], [(0,-1,-2,1,-3,-4), (1,0)]).numpy()
sum4_2b = sum4_2b_3 - sum4_2b_4
#fifth term
sum5_2b_1 = ncon([eta3B, occG, G], [(3,-1,-2,4,5,-4),
sum5_2b_1 = tn.ncon([eta3B, occG, G], [(3,-1,-2,4,5,-4),
(3,4,5,0,1,2),
(1,2,0,-3)]).numpy()
sum5_2b_2 = ncon([W, occG, eta2B], [(3,-1,-2,4,5,-4),
sum5_2b_2 = tn.ncon([W, occG, eta2B], [(3,-1,-2,4,5,-4),
(3,4,5,0,1,2),
(1,2,0,-3)]).numpy()
sum5_2b = sum5_2b_2 - np.transpose(sum5_2b_2, [3,2,0,1]) - \
np.transpose(sum5_2b_2, [0,1,3,2]) + \
np.transpose(sum5_2b_2, [2,3,0,1])
# sum5_2b_1 = ncon([occG, G], [(-1,-2,-4,0,1,2), (1,2,0,-3)]).numpy()
# sum5_2b_2 = ncon([occG, eta2B], [(-1,-2,-4,0,1,2), (1,2,0,-3)]).numpy()
# sum5_2b_3 = ncon([eta3B, sum5_2b_1], [(0,-1,-2,1,2,-4), (1,2,0,-3)]).numpy()
# sum5_2b_4 = ncon([W, sum5_2b_2], [(0,-1,-2,1,2,-4), (1,2,0,-3)]).numpy()
# sum5_2b_1 = tn.ncon([occG, G], [(-1,-2,-4,0,1,2), (1,2,0,-3)]).numpy()
# sum5_2b_2 = tn.ncon([occG, eta2B], [(-1,-2,-4,0,1,2), (1,2,0,-3)]).numpy()
# sum5_2b_3 = tn.ncon([eta3B, sum5_2b_1], [(0,-1,-2,1,2,-4), (1,2,0,-3)]).numpy()
# sum5_2b_4 = tn.ncon([W, sum5_2b_2], [(0,-1,-2,1,2,-4), (1,2,0,-3)]).numpy()
# sum5_2b_5 = sum5_2b_3 - sum5_2b_4
# sum5_2b = sum5_2b_5 - np.transpose(sum5_2b_5, [3,2,0,1]) - \
# np.transpose(sum5_2b_5, [0,1,3,2]) + \
# np.transpose(sum5_2b_5, [2,3,0,1])
#sixth term
sum6_2b_1 = ncon([eta3B, occH, W], [(4,-1,-2,5,6,7),
sum6_2b_1 = tn.ncon([eta3B, occH, W], [(4,-1,-2,5,6,7),
(4,5,6,7,0,1,2,3),
(1,2,3,0,-3,-4)]).numpy()
sum6_2b_2 = ncon([eta3B, occH, W], [(5,6,7,4,-3,-4),
sum6_2b_2 = tn.ncon([eta3B, occH, W], [(5,6,7,4,-3,-4),
(4,5,6,7,0,1,2,3),
(0,-1,-2,1,2,3)]).numpy()
sum6_2b = sum6_2b_1 - sum6_2b_2
# sum6_2b_1 = ncon([occH, W], [(-1,-2,-3,-4,0,1,2,3),(1,2,3,0,-5,-6)]).numpy()
# sum6_2b_2 = ncon([occH, W], [(-3,-4,-5,-6,0,1,2,3),(0,-1,-2,1,2,3)]).numpy()
# sum6_2b_3 = ncon([eta3B, sum6_2b_1], [(0,-1,-2,1,2,3), (1,2,3,0,-3,-4)]).numpy()
# sum6_2b_4 = ncon([eta3B, sum6_2b_2], [(1,2,3,0,-3,-4), (0,-1,-2,1,2,3)]).numpy()
# sum6_2b_1 = tn.ncon([occH, W], [(-1,-2,-3,-4,0,1,2,3),(1,2,3,0,-5,-6)]).numpy()
# sum6_2b_2 = tn.ncon([occH, W], [(-3,-4,-5,-6,0,1,2,3),(0,-1,-2,1,2,3)]).numpy()
# sum6_2b_3 = tn.ncon([eta3B, sum6_2b_1], [(0,-1,-2,1,2,3), (1,2,3,0,-3,-4)]).numpy()
# sum6_2b_4 = tn.ncon([eta3B, sum6_2b_2], [(1,2,3,0,-3,-4), (0,-1,-2,1,2,3)]).numpy()
# sum6_2b = sum6_2b_3 - sum6_2b_4
#seventh term
sum7_2b_1 = ncon([eta3B, occI, W], [(4,5,-1,6,7,-4),
sum7_2b_1 = tn.ncon([eta3B, occI, W], [(4,5,-1,6,7,-4),
(4,5,6,7,0,1,2,3),
(2,3,-2,0,1,-3)]).numpy()
sum7_2b = sum7_2b_1 - np.transpose(sum7_2b_1,[1,0,2,3]) - \
np.transpose(sum7_2b_1,[0,1,3,2]) + \
np.transpose(sum7_2b_1,[1,0,3,2])
# sum7_2b_1 = ncon([occI, W], [(-1,-2,-3,-4,0,1,2,3), (2,3,-5,0,1,-6)]).numpy()
# sum7_2b_2 = ncon([eta3B, sum7_2b_1], [(0,1,-1,2,3,-4),(2,3,-2,0,1,-3)]).numpy()
# sum7_2b_1 = tn.ncon([occI, W], [(-1,-2,-3,-4,0,1,2,3), (2,3,-5,0,1,-6)]).numpy()
# sum7_2b_2 = tn.ncon([eta3B, sum7_2b_1], [(0,1,-1,2,3,-4),(2,3,-2,0,1,-3)]).numpy()
# sum7_2b = sum7_2b_2 - np.transpose(sum7_2b_2,[1,0,2,3]) - \
# np.transpose(sum7_2b_2,[0,1,3,2]) + \
# np.transpose(sum7_2b_2,[1,0,3,2])
......@@ -343,22 +344,22 @@ class Flow_IMSRG3(Flow_IMSRG2):
#first, second, and third terms (one index contraction)
#terms with P(i/jk) -- line 1 and 2
sum1_3b_1 = ncon([eta1B, W], [(-1,0), (0,-2,-3,-4,-5,-6)]).numpy()
sum1_3b_2 = ncon([f, eta3B], [(-1,0), (0,-2,-3,-4,-5,-6)]).numpy()
sum1_3b_1 = tn.ncon([eta1B, W], [(-1,0), (0,-2,-3,-4,-5,-6)]).numpy()
sum1_3b_2 = tn.ncon([f, eta3B], [(-1,0), (0,-2,-3,-4,-5,-6)]).numpy()
sum1_3b_3 = sum1_3b_1 - sum1_3b_2
sum1_3b_4 = sum1_3b_3 - np.transpose(sum1_3b_3, [1,0,2,3,4,5]) - \
np.transpose(sum1_3b_3, [2,1,0,3,4,5])
#terms with P(l/mn) -- line 1 and 2
sum1_3b_5 = ncon([eta1B, W], [(0,-4), (-1,-2,-3,0,-5,-6)]).numpy()
sum1_3b_6 = ncon([f, eta3B], [(0,-4), (-1,-2,-3,0,-5,-6)]).numpy()
sum1_3b_5 = tn.ncon([eta1B, W], [(0,-4), (-1,-2,-3,0,-5,-6)]).numpy()
sum1_3b_6 = tn.ncon([f, eta3B], [(0,-4), (-1,-2,-3,0,-5,-6)]).numpy()
sum1_3b_7 = sum1_3b_6 - sum1_3b_5
sum1_3b_8 = sum1_3b_7 - np.transpose(sum1_3b_7, [0,1,2,4,3,5]) - \
np.transpose(sum1_3b_7, [0,1,2,5,4,3])
#terms with P(ij/k)P(l/mn) -- line 3
sum1_3b_9 = ncon([eta2B, G], [(-1,-2,-4,0),(0,-3,-5,-6)])
sum1_3b_10 = ncon([G, eta2B], [(-1,-2,-4,0),(0,-3,-5,-6)])
sum1_3b_9 = tn.ncon([eta2B, G], [(-1,-2,-4,0),(0,-3,-5,-6)])
sum1_3b_10 = tn.ncon([G, eta2B], [(-1,-2,-4,0),(0,-3,-5,-6)])
sum1_3b_11 = sum1_3b_9 - sum1_3b_10
sum1_3b_12 = sum1_3b_11 - np.transpose(sum1_3b_11, [0,1,2,4,3,5]) - \
np.transpose(sum1_3b_11, [0,1,2,5,4,3])
......@@ -368,22 +369,22 @@ class Flow_IMSRG3(Flow_IMSRG2):
sum1_3b = sum1_3b_4 + sum1_3b_8 + sum1_3b_13
#fourth term
sum4_3b_1 = ncon([eta2B, occB, W], [(-1,-2,2,3),(2,3,0,1),(0,1,-3,-4,-5,-6)]).numpy()
sum4_3b_2 = ncon([G, occB, eta3B], [(-1,-2,2,3),(2,3,0,1),(0,1,-3,-4,-5,-6)]).numpy()
sum4_3b_1 = tn.ncon([eta2B, occB, W], [(-1,-2,2,3),(2,3,0,1),(0,1,-3,-4,-5,-6)]).numpy()
sum4_3b_2 = tn.ncon([G, occB, eta3B], [(-1,-2,2,3),(2,3,0,1),(0,1,-3,-4,-5,-6)]).numpy()
sum4_3b_3 = sum4_3b_1 - sum4_3b_2
sum4_3b = sum4_3b_3 - np.transpose(sum4_3b_3, [1,0,2,3,4,5]) - \
np.transpose(sum4_3b_3, [2,1,0,3,4,5])
#fifth term
sum5_3b_1 = ncon([eta2B, occB, W], [(2,3,-4,-5),(2,3,0,1),(-1,-2,-3,0,1,-6)]).numpy()
sum5_3b_2 = ncon([G, occB, eta3B], [(2,3,-4,-5),(2,3,0,1),(-1,-2,-3,0,1,-6)]).numpy()
sum5_3b_1 = tn.ncon([eta2B, occB, W], [(2,3,-4,-5),(2,3,0,1),(-1,-2,-3,0,1,-6)]).numpy()
sum5_3b_2 = tn.ncon([G, occB, eta3B], [(2,3,-4,-5),(2,3,0,1),(-1,-2,-3,0,1,-6)]).numpy()
sum5_3b_3 = sum5_3b_1 - sum5_3b_2
sum5_3b = sum5_3b_3 - np.transpose(sum5_3b_3, [0,1,2,5,4,3]) - \
np.transpose(sum5_3b_3, [0,1,2,3,5,4])
#sixth term
sum6_3b_1 = ncon([eta2B, occA, W], [(3,-1,2,-4),(2,3,0,1),(0,-2,-3,1,-5,-6)]).numpy()
sum6_3b_2 = ncon([G, occA, eta3B], [(3,-1,2,-4),(2,3,0,1),(0,-2,-3,1,-5,-6)]).numpy()
sum6_3b_1 = tn.ncon([eta2B, occA, W], [(3,-1,2,-4),(2,3,0,1),(0,-2,-3,1,-5,-6)]).numpy()
sum6_3b_2 = tn.ncon([G, occA, eta3B], [(3,-1,2,-4),(2,3,0,1),(0,-2,-3,1,-5,-6)]).numpy()
sum6_3b_3 = sum6_3b_1 - sum6_3b_2
sum6_3b_4 = sum6_3b_3 - np.transpose(sum6_3b_3, [0,1,2,4,3,5]) - \
np.transpose(sum6_3b_3, [0,1,2,5,4,3])
......@@ -391,13 +392,13 @@ class Flow_IMSRG3(Flow_IMSRG2):
np.transpose(sum6_3b_4, [2,1,0,3,4,5])
#seventh term
sum7_3b_1 = ncon([eta3B, occJ, W], [(-1,-2,-3,3,4,5), (3,4,5,0,1,2), (0,1,2,-4,-5,-6)]).numpy()
sum7_3b_2 = ncon([W, occJ, eta3B], [(-1,-2,-3,3,4,5), (3,4,5,0,1,2), (0,1,2,-4,-5,-6)]).numpy()
sum7_3b_1 = tn.ncon([eta3B, occJ, W], [(-1,-2,-3,3,4,5), (3,4,5,0,1,2), (0,1,2,-4,-5,-6)]).numpy()
sum7_3b_2 = tn.ncon([W, occJ, eta3B], [(-1,-2,-3,3,4,5), (3,4,5,0,1,2), (0,1,2,-4,-5,-6)]).numpy()
sum7_3b = sum7_3b_1 - sum7_3b_2
#eighth term
sum8_3b_1 = ncon([eta3B, occC, W], [(3,4,-3,5,-5,-6), (3,4,5,0,1,2), (2,-1,-2,0,1,-4)]).numpy()
sum8_3b_2 = ncon([eta3B, occC, W], [(5,-2,-3,3,4,-6), (3,4,5,0,1,2), (-1,0,1,-4,-5,2)]).numpy()
sum8_3b_1 = tn.ncon([eta3B, occC, W], [(3,4,-3,5,-5,-6), (3,4,5,0,1,2), (2,-1,-2,0,1,-4)]).numpy()
sum8_3b_2 = tn.ncon([eta3B, occC, W], [(5,-2,-3,3,4,-6), (3,4,5,0,1,2), (-1,0,1,-4,-5,2)]).numpy()
sum8_3b_3 = sum8_3b_1 - sum8_3b_2
sum8_3b_4 = sum8_3b_3 - np.transpose(sum8_3b_3, [0,1,2,4,3,5]) - \
np.transpose(sum8_3b_3, [0,1,2,5,4,3])
......
#import tensorflow as tf
# tf.enable_v2_behavior()
from tensornetwork import *
import tensornetwork as tn
import numpy as np
from oop_imsrg.hamiltonian import *
from oop_imsrg.occupation_tensors import *
tn.set_default_backend("tensorflow")
class Generator(object):
"""Parent class for organization purposes. Ideally, all Generator
......@@ -121,24 +122,24 @@ class WegnerGenerator(Generator):
# - Calculate 1B generator
# first term
sum1_1b_1 = ncon([fd, fod], [(-1, 0), (0, -2)]).numpy()
sum1_1b_1 = tn.ncon([fd, fod], [(-1, 1), (1, -2)]).numpy()
sum1_1b_2 = np.transpose(sum1_1b_1)
sum1_1b = sum1_1b_1 - sum1_1b_2
# second term
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_1 = tn.ncon([fd, occA, God], [(3,4), (3,4,1,2), (2,-1,1,-2)]).numpy()
sum2_1b_2 = tn.ncon([fod, occA, Gd], [(3,4), (3,4,1,2), (2,-1,1,-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_1 = tn.ncon([fd, God], [(0, 1), (1, -1, 0, -2)]).numpy()
# sum2_1b_2 = tn.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 = tn.ncon([occA, sum2_1b_3],[(-1, -2, 0, 1), (0,1)]).numpy()
# third term
sum3_1b_1 = ncon([Gd, occC, God], [(5,-1,3,4), (3,4,5,0,1,2), (0,1,2,-2)]).numpy()
sum3_1b_1 = tn.ncon([Gd, occC, God], [(6,-1,4,5), (4,5,6,1,2,3), (1,2,3,-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_1 = tn.ncon([occC, God], [(-1, -2, -3, 0, 1, 2), (0, 1, 2, -4)]).numpy()
# sum3_1b_2 = tn.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
......@@ -146,15 +147,15 @@ class WegnerGenerator(Generator):
# - Calculate 2B generator
# first term (P_ij piece)
sum1_2b_1 = ncon([fd, God], [(-1, 0), (0, -2, -3, -4)]).numpy()
sum1_2b_2 = ncon([fod, Gd], [(-1, 0), (0, -2, -3, -4)]).numpy()
sum1_2b_1 = tn.ncon([fd, God], [(-1, 1), (1, -2, -3, -4)]).numpy()
sum1_2b_2 = tn.ncon([fod, Gd], [(-1, 1), (1, -2, -3, -4)]).numpy()
sum1_2b_3 = sum1_2b_1 - sum1_2b_2
sum1_2b_4 = np.transpose(sum1_2b_3, [1, 0, 2, 3])
sum1_2b_5 = sum1_2b_3 - sum1_2b_4
# first term (P_kl piece)
sum1_2b_6 = ncon([fd, God], [(0, -3), (-1, -2, 0, -4)]).numpy()
sum1_2b_7 = ncon([fod, Gd], [(0, -3), (-1, -2, 0, -4)]).numpy()
sum1_2b_6 = tn.ncon([fd, God], [(1, -3), (-1, -2, 1, -4)]).numpy()
sum1_2b_7 = tn.ncon([fod, Gd], [(1, -3), (-1, -2, 1, -4)]).numpy()
sum1_2b_8 = sum1_2b_6 - sum1_2b_7
sum1_2b_9 = np.transpose(sum1_2b_8, [0, 1, 3, 2])
sum1_2b_10 = sum1_2b_8 - sum1_2b_9
......@@ -162,25 +163,25 @@ class WegnerGenerator(Generator):
sum1_2b = sum1_2b_5 - sum1_2b_10
# second term
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_1 = tn.ncon([Gd, occB, God], [(-1,-2,3,4), (3,4,1,2), (1,2,-3,-4)]).numpy()
sum2_2b_2 = tn.ncon([God, occB, Gd], [(-1,-2,3,4), (3,4,1,2), (1,2,-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_1 = tn.ncon([occB, God], [(-1, -2, 0, 1), (0, 1, -3, -4)]).numpy()
# sum2_2b_2 = tn.ncon([occB, Gd], [(-1, -2, 0, 1), (0, 1, -3, -4)]).numpy()
# sum2_2b_3 = tn.ncon([Gd, sum2_2b_1], [(-1, -2, 0, 1), (0, 1, -3, -4)]).numpy()
# sum2_2b_4 = tn.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, occA, God], [(2,-1,3,-3), (2,3,0,1), (1,-2,0,-4)]).numpy()
sum3_2b_1 = tn.ncon([Gd, occA, God], [(3,-1,4,-3), (3,4,1,2), (2,-2,1,-4)]).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_1 = tn.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 = tn.ncon([occA, sum3_2b_5], [(0, 1, -1, -2), (0, 1, -3, -4)]).numpy()
eta2B = sum1_2b + 0.5*sum2_2b + sum3_2b
......@@ -309,25 +310,25 @@ class WegnerGenerator3B(WegnerGenerator):
# fourth term
sum4_1b_1 = np.matmul(np.transpose(occD,[2,3,0,1]), God)
sum4_1b_2 = np.matmul(np.transpose(occD,[2,3,0,1]), Gd)
sum4_1b_3 = ncon([Wd, sum4_1b_1], [(0,1,-1,2,3,-2),(2,3,0,1)]).numpy()
sum4_1b_4 = ncon([Wod, sum4_1b_2], [(0,1,-1,2,3,-2),(2,3,0,1)]).numpy()
sum4_1b_3 = tn.ncon([Wd, sum4_1b_1], [(0,1,-1,2,3,-2),(2,3,0,1)]).numpy()
sum4_1b_4 = tn.ncon([Wod, sum4_1b_2], [(0,1,-1,2,3,-2),(2,3,0,1)]).numpy()
sum4_1b = sum4_1b_3 - sum4_1b_4
# fifth term
sum5_1b_1 = ncon([Wd, occF, Wod], [(5,6,-1,7,8,9),
sum5_1b_1 = tn.ncon([Wd, occF, Wod], [(5,6,-1,7,8,9),
(5,6,7,8,9,0,1,2,3,4),
(2,3,4,0,1,-2)]).numpy()
sum5_1b_2 = ncon([Wod, occF, Wd], [(5,6,-1,7,8,9),
sum5_1b_2 = tn.ncon([Wod, occF, Wd], [(5,6,-1,7,8,9),
(5,6,7,8,9,0,1,2,3,4),
(2,3,4,0,1,-2)]).numpy()
sum5_1b = sum5_1b_1 - sum5_1b_2
# sum5_1b_1 = ncon([occF, Wd.astype(np.float32)],
# sum5_1b_1 = tn.ncon([occF, Wd.astype(np.float32)],
# [(-1,-3,-4,-5,-6,0,1,2,3,4), (0,1,-2,2,3,4)]).numpy()
# sum5_1b_2 = ncon([occF, Wod.astype(np.float32)],
# sum5_1b_2 = tn.ncon([occF, Wod.astype(np.float32)],
# [(-1,-3,-4,-5,-6,0,1,2,3,4), (0,1,-2,2,3,4)]).numpy()
# sum5_1b_3 = ncon([sum5_1b_1, Wod.astype(np.float32)],
# sum5_1b_3 = tn.ncon([sum5_1b_1, Wod.astype(np.float32)],
# [(0,1,-1,2,3,4), (2,3,4,0,1,-2)]).numpy()
# sum5_1b_4 = ncon([sum5_1b_2, Wd.astype(np.float32)],
# sum5_1b_4 = tn.ncon([sum5_1b_2, Wd.astype(np.float32)],
# [(0,1,-1,2,3,4), (2,3,4,0,1,-2)]).numpy()
# sum5_1b = sum5_1b_3 - sum5_1b_4
......@@ -337,55 +338,55 @@ class WegnerGenerator3B(WegnerGenerator):
# fourth term
sum4_2b_1 = np.matmul(-1.0*np.transpose(occA2), fod)
sum4_2b_2 = np.matmul(-1.0*np.transpose(occA2), fd)
sum4_2b_3 = ncon([Wd, sum4_2b_1], [(0,-1,-2,1,-3,-4), (1,0)]).numpy()
sum4_2b_4 = ncon([Wod, sum4_2b_2], [(0,-1,-2,1,-3,-4), (1,0)]).numpy()
sum4_2b_3 = tn.ncon([Wd, sum4_2b_1], [(0,-1,-2,1,-3,-4), (1,0)]).numpy()
sum4_2b_4 = tn.ncon([Wod, sum4_2b_2], [(0,-1,-2,1,-3,-4), (1,0)]).numpy()
sum4_2b = sum4_2b_3 - sum4_2b_4
#fifth term
sum5_2b_1 = ncon([Wd, occG, God], [(3,-1,-2,4,5,-4),