la.print_diagram() lb.print_diagram() #print(la) #print(lb) ## Evov: Elast = 0 for i in range(10000): A.set_labels([-1,0,-2]) B.set_labels([-3,1,-4]) la.set_labels([-2,-3]) lb.set_labels([-4,-5]) ## contract all X = cytnx.Contract(cytnx.Contract(A,la),cytnx.Contract(B,lb)) #X.print_diagram() lb.set_label(1,new_label=-1) X = cytnx.Contract(lb,X) ## X = # (0) (1) # | | # (-4) --lb-A-la-B-lb-- (-5) # #X.print_diagram() Xt = X.clone() ## calculate norm and energy for this step # Note that X,Xt contract will result a rank-0 tensor, which can use item() toget element
# ----- -----A[0]--- -----A[1]--- # | | | | | # ML---- LR[0]--M----- LR[1]--M----- ...... # | | | | | # ----- -----A*[0]-- -----A*[1]-- # # # L_AMAH.net file is used to contract the LR[i] ##>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> LR = [None for i in range(Nsites + 1)] LR[0] = L0 LR[-1] = R0 for p in range(Nsites - 1): s, A[p], vt = cytnx.linalg.Svd(A[p]) A[p + 1] = cytnx.Contract(cytnx.Contract(s, vt), A[p + 1]) #A[p+1].print_diagram() #A[p].print_diagram() anet = cytnx.Network("L_AMAH.net") anet.PutUniTensors(["L", "A", "A_Conj", "M"], [LR[p], A[p], A[p].Conj(), M], is_clone=False) LR[p + 1] = anet.Launch(optimal=True) _, A[-1] = cytnx.linalg.Svd(A[-1], is_U=True, is_vT=False) ## last one. ## DMRG sweep ## Now we are ready for sweeping procedure! ##>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Ekeep = []
prevlnZ = 0; for i in range(Maxiter): print(i) ## LR: # # 1 4 # | | # 0--cT--2 2--cT2--5 # | | # 3 6 # cT2 = cT.clone() cT2.set_labels([2,4,5,6]) cT = cytnx.Contract(cT,cT2) ## Now, let's check the dimension growth onto a point where truncation is needed: if(cT.shape()[1]*cT.shape()[3]>chi): # * if combined bond dimension > chi then: # 1) Do Hosvd get only U and D, with it's Ls matrices. cT.permute_([1,4,3,6,0,5],by_label=True) U,D,Lu,Ld=cytnx.linalg.Hosvd(cT,[2,2],is_core=False,is_Ls=True) # 2) Using Ls matrix to determine if U is used to truncate or D is used to truncate if(Lu.get_block_()[chi:].Norm().item() < Ld.get_block_()[chi:].Norm().item()): U, D = D,U ## truncate, and permute back to the original form: # chi # |
## gates: eHu = cy.linalg.ExpH(Hu, -tau) eHd = cy.linalg.ExpH(Hd, -tau) ## iterator: Eup_old, Edown_old = 0, 0 cov = False for i in range(maxit): ## first do up >>>>>>>>>>>>>>>>>> Nup = cy.Network("up.net") Nup.PutUniTensors(["A", "B", "C", "L2A", "L2B", "L2C", "eHu", "s1"], [A, B, C, Ls2[0], Ls2[1], Ls2[2], eHu, s1]) T = Nup.Launch(True) Nrm = cy.Contract(T, T).item() T /= np.sqrt(Nrm) #normalize for numerical stability. A, B, C, s1, Ls1[0], Ls1[1], Ls1[2] = cy.linalg.Hosvd( T, [2, 2, 2], True, True, [D, D, D]) ## de-contract Ls' Ls2[0].set_labels([-10, A.labels()[0]]) Ls2[0] = 1. / Ls2[0] Ls2[1].set_labels([-11, B.labels()[0]]) Ls2[1] = 1. / Ls2[1] Ls2[2].set_labels([-12, C.labels()[0]]) Ls2[2] = 1. / Ls2[2] A = cy.Contract(Ls2[0], A) B = cy.Contract(Ls2[1], B) C = cy.Contract(Ls2[2], C)
# 1) Absorb s into A and put it in shape # ------------- # / \ # virt ____| |____ phys # | | # | |____ virt # \ / # ------------- # 2) Do Svd, and get the growing n+1 right site, and the right singular values sR # [Note] we don't need U!! # # --A--s --B-- => --sR--A' --B-- # | | | | # A.set_rowrank(1) sR, _, A = cytnx.linalg.Svd(cytnx.Contract(A, s1)) ## rotate right # 1) Absorb s into B and put it in shape # ------------- # / \ # virt ____| |____ virt # | | # phys ____| | # \ / # ------------- # 2) Do Svd, and get the growing n+1 left site, and the left singular values sL # [Note] we don't need vT!! # # --A-- s--B-- => --A-- B'--sL # | | | |