def compute_time_dependent_G0(H, myrank, Nkx, Nky, ARPES, kpp, k2p, k2i, tmax, nt, beta, ntau, norb, pump): # check how much slower this is than computing G0 using U(t,t') norb = np.shape(H(0,0,0))[0] def H0(kx, ky, t): return np.zeros([norb,norb]) constants = (myrank, Nkx, Nky, ARPES, kpp, k2p, k2i, tmax, nt, beta, ntau, norb, pump) UksR, UksI, eks, fks, Rs, Ht = init_Uks(H0, dt_fine, *constants, version='higher order') G0M_ref = compute_G0M(0, 0, UksI, eks, fks, Rs, *constants) G0_ref = compute_G0R(0, 0, UksR, UksI, eks, fks, Rs, *constants) dt = 1.0*tmax/(nt-1) G0M = compute_G00M(0, 0, *constants) G0 = compute_G00R(0, 0, *constants) print('test G00') differences(G0_ref, G0) ''' G00M = compute_G00M(0, 0, *constants) G00 = compute_G00R(0, 0, G0M, *constants) print('shpae G0M', np.shape(G0M.M)) print('shape G00M', np.shape(G00M.M)) #for (i,j) in product(range(norb), repeat=2): # plt(np.linspace(0,beta,ntau), [G0M.M[:,i,j].imag, G00M.M[:,i,j].imag], 'G00M %d %d'%(i,j)) # plt(np.linspace(0,beta,ntau), [G0M.M[:,i,j].real, G00M.M[:,i,j].real], 'G00M %d %d'%(i,j)) print('diffs') print(dist(G0M.M, G00M.M)) print(dist(G0.R, G00.R)) print(dist(G0.L, G00.L)) print(dist(G0.IR, G00.IR)) exit() ''' GM = matsubara(beta, ntau, norb, -1) SigmaM = matsubara(beta, ntau, norb, -1) SigmaM.deltaM = H(0, 0, 0) integrator.dyson_matsubara(G0M, SigmaM, GM) # check if SigmaM is the same as before G = langreth(norb, nt, tmax, ntau, beta, -1) Sigma = langreth(norb, nt, tmax, ntau, beta, -1) for it in range(nt): Sigma.deltaR[it] = H(0, 0, it*dt) integrator.dyson_langreth(G0M, SigmaM, G0, Sigma, G) return GM, G
def dyson_langreth(self, G0M, SigmaM, G0, Sigma, G): # IS G0*Sigma still fermionic? A.sig=-1? # yes I think so because it worked for Matsubara... GM = matsubara(G0M.beta, G0M.ntau, G0M.norb, G0M.sig) self.dyson_matsubara(G0M, SigmaM, GM) A = langreth(G.norb, G.nt, G.tmax, G.ntau, G.beta, G.sig) A.RI = self.RxRI(G0, Sigma) + self.RIxM(G0, SigmaM) A.R = self.RxR(G0, Sigma) A.L = self.LxA(G0, Sigma) + self.RxL(G0, Sigma) + self.RIxIR(G0, Sigma) #A.M = self.MxM(G0, Sigma) nt = G0.nt norb = G0.norb ntau = G0.ntau # solve RxR = R G0R = np.reshape(G0.R, [nt * norb, nt * norb]) G.R = np.zeros([nt * norb, nt * norb], dtype=np.complex128) for j in range(nt): X = np.diag(np.ones(nt * norb)) - self.prep_RxR([A], j)[0] for b in range(norb): n = j * norb + b lhs, rhs = X[n:, n:], G0R[n:, n] - X[n:, :n] @ G.R[:n, n] G.R[n:, n] = np.linalg.solve(lhs, rhs) G.R[n, n:] = -np.conj(G.R[n:, n]) G.R = np.reshape(G.R, [nt, norb, nt, norb]) # solve A_M x B_IR = C_IR - A_IR x B_A # note minus sign on A because of I-A #rhs = np.reshape(G0.IR + self.IRxA(A, G), [ntau*norb, nt*norb]) #sol = np.linalg.solve(np.diag(np.ones(ntau*norb)) - self.prep_MxIR(A), rhs) #G.IR = np.reshape(sol, [ntau,norb,nt,norb]) # solve A_R x B_RI = C_RI - A_RI x B_M # note minus sign on A because of I-A rhs = np.reshape(G0.RI + self.RIxM(A, GM), [nt * norb, ntau * norb]) sol = np.linalg.solve( np.diag(np.ones(nt * norb)) - self.prep_Rxr(A), rhs) G.RI = np.reshape(sol, [nt, norb, ntau, norb]) # solve A_R x B_L = C_L - A_L x B_A - A_RI x B_IR # A_R x G_L = G0_L - A_L x G_A - A_RI x G_IR # note minus sign on A because of I-A rhs = np.reshape(G0.L + self.LxA(A, G) + self.RIxIR(A, G), [nt * norb, nt * norb]) sol = np.linalg.solve( np.diag(np.ones(nt * norb)) - self.prep_Rxr(A), rhs) G.L = np.reshape(sol, [nt, norb, nt, norb])
def compute_time_dependent_G0(H, myrank, Nkx, Nky, ARPES, kpp, k2p, k2i, tmax, nt, beta, ntau, norb, pump): # check how much slower this is than computing G0 using U(t,t') dt = 1.0 * tmax / (nt - 1) G0M = compute_G00M(0, 0, *constants) GM = matsubara(beta, ntau, norb, -1) SigmaM = matsubara(beta, ntau, norb, -1) SigmaM.deltaM = H(0, 0, 0) integrator.dyson_matsubara(G0M, SigmaM, GM) # check if SigmaM is the same as before G = langreth(nt, tmax, GM) Sigma = langreth(nt, tmax, SigmaM) for it in range(nt): Sigma.deltaR[it] = H(0, 0, it * dt) integrator.dyson_langreth(G0, Sigma, G) return GM, G
def main(): if myrank == 0: time0 = time.time() if myrank == 0: print(' ') print('nprocs = ', nprocs) assert not os.path.exists(savedir + 'Sigma') and not os.path.exists( savedir + 'Gloc'), 'Cannot overwrite existing data' volume = Nkx * Nky k2p, k2i, i2k = init_k2p_k2i_i2k(Nkx, Nky, nprocs, myrank) kpp = np.count_nonzero(k2p == myrank) integrator = integration.integrator(6, nt, beta, ntau) def H(kx, ky, t): return -2.0 * np.cos(kx) * np.ones([norb, norb]) constants = (myrank, Nkx, Nky, ARPES, kpp, k2p, k2i, tmax, nt, beta, ntau, norb, pump) UksR, UksI, eks, fks, Rs, Ht = init_Uks(H, dt_fine, *constants, version='higher order') print('Done initializing Us') SigmaM = matsubara(0, 0, 0, 0) SigmaM.load(savedir, 'SigmaM') # Solve real axis part xo #--------------------------------------------------------- D = compute_D0R(norb, omega, nt, tmax, ntau, beta, +1) print('Done initializing D') Sigma0 = langreth(norb, nt, tmax, ntau, beta, -1) Sigma = langreth(norb, nt, tmax, ntau, beta, -1) iter_selfconsistency = 4 change = 0.0 for i in range(iter_selfconsistency): print('iteration : %d' % i) Sigma0.copy(Sigma) Gloc = langreth(norb, nt, tmax, ntau, beta, -1) for ik in range(kpp): ik1, ik2 = i2k[ik] G0M = compute_G0M(ik1, ik2, UksI, eks, fks, Rs, *constants) G0 = compute_G0R(ik1, ik2, UksR, UksI, eks, fks, Rs, *constants) if i == 0: G = G0 else: G = langreth(norb, nt, tmax, ntau, beta, -1) integrator.dyson_langreth(G0M, SigmaM, G0, Sigma, G) Gloc.add(G) Sigma = langreth(norb, nt, tmax, ntau, beta, -1) if nprocs == 1: Sigma.copy(Gloc) else: comm.Allreduce(Gloc.L, Sigma.L, op=MPI.SUM) comm.Allreduce(Gloc.R, Sigma.R, op=MPI.SUM) comm.Allreduce(Gloc.RI, Sigma.RI, op=MPI.SUM) comm.Allreduce(Gloc.deltaR, Sigma.deltaR, op=MPI.SUM) Sigma.multiply(D) Sigma.scale(1j * g2 / volume) print('Done computing Sigma') print('sigma size') print(np.mean(np.abs(Sigma.R))) print(np.mean(np.abs(Sigma.RI))) print(np.mean(np.abs(Sigma.L))) change = max([np.mean(abs(Sigma0.R-Sigma.R)), \ np.mean(abs(Sigma0.L-Sigma.L)), \ np.mean(abs(Sigma0.RI-Sigma.RI)), \ np.mean(abs(Sigma0.deltaR-Sigma.deltaR))]) print('change = %1.3e' % change) Sigma.save(savedir, 'Sigma') Gloc.save(savedir, 'Gloc') saveparams(savedir) if 'MPI' in sys.modules: MPI.Finalize()
def main(): if myrank == 0: time0 = time.time() print(' ') print('nprocs = ', nprocs) Nkx = 1 Nky = 1 k2p, k2i, i2k = init_k2p_k2i_i2k(Nkx, Nky, nprocs, myrank) kpp = np.count_nonzero(k2p == myrank) beta = 2.0 ARPES = False pump = 0 g2 = None omega = None tmax = 5.0 dim_embedding = 2 order = 6 ntau = 200 #nts = [400,800,1000] #nts = [10, 50, 100, 500] #nts = [50, 100, 500] #nts = [50, 100, 500] nts = [10, 50, 100, 500] diffs = {} diffs['nts'] = nts diffs['M'] = [] diffs['RI'] = [] diffs['R'] = [] diffs['L'] = [] # random H np.random.seed(1) norb = 4 Hmat = 0.1 * np.random.randn(norb, norb) + 0.1 * 1j * np.random.randn( norb, norb) Hmat += np.conj(Hmat).T Tmat = 0.1 * np.random.randn(norb, norb) + 0.1 * 1j * np.random.randn( norb, norb) Tmat += np.conj(Tmat).T # example H ''' norb = 3 e0 = -0.2 e1 = -0.1 e2 = 0.2 lamb1 = 1.0 lamb2 = 1.2 Hmat = np.array([[e0, lamb1, lamb2], [np.conj(lamb1), e1, 0], [np.conj(lamb2), 0, e2]], dtype=complex) ''' print('\nH : ') print(Hmat) print('') #def f(t): return np.cos(0.01*t) def f(t): return 1.0 for nt in nts: dt_fine = 0.1 * tmax / (nt - 1) #--------------------------------------------------------- # compute non-interacting G for the norb x norb problem norb = np.shape(Hmat)[0] def H(kx, ky, t): return Hmat + Tmat * np.cos(0.2 * t) #return np.array([[e0, lamb1, lamb2], # [np.conj(lamb1), e1, 0], # [np.conj(lamb2), 0, e2]], # dtype=complex) constants = (myrank, Nkx, Nky, ARPES, kpp, k2p, k2i, tmax, nt, beta, ntau, norb, pump) UksR, UksI, eks, fks, Rs, Ht = init_Uks(H, dt_fine, *constants, version='higher order') GexactM = compute_G0M(0, 0, UksI, eks, fks, Rs, *constants) Gexact = compute_G0R(0, 0, UksR, UksI, eks, fks, Rs, *constants) #------------------------------------------------------ # compute Sigma_embedding # Sigma = sum_{i,j} H0i(t) Gij(t,t') Hj0(t') norb = np.shape(Hmat)[0] - dim_embedding SigmaM = matsubara(beta, ntau, norb, -1) def H(kx, ky, t): return Hmat[dim_embedding:, dim_embedding:] + Tmat[ dim_embedding:, dim_embedding:] * np.cos(0.2 * t) constants = (myrank, Nkx, Nky, ARPES, kpp, k2p, k2i, tmax, nt, beta, ntau, norb, pump) UksR, UksI, eks, fks, Rs, _ = init_Uks(H, dt_fine, *constants, version='higher order') SM = compute_G0M(0, 0, UksI, eks, fks, Rs, *constants) SM.M = np.einsum('hi,mij,jk->mhk', Ht[0, 0, :dim_embedding, dim_embedding:], SM.M, Ht[0, 0, dim_embedding:, :dim_embedding]) #taus = np.linspace(0, beta, ntau) #plt(taus, [SM.M[:,0,0].real, SM.M[:,0,0].imag], 'SM') #exit() S = compute_G0R(0, 0, UksR, UksI, eks, fks, Rs, *constants) S.R = np.einsum('mhi,minj,njk->mhnk', Ht[0, :, :dim_embedding, dim_embedding:], S.R, Ht[0, :, dim_embedding:, :dim_embedding]) S.L = np.einsum('mhi,minj,njk->mhnk', Ht[0, :, :dim_embedding, dim_embedding:], S.L, Ht[0, :, dim_embedding:, :dim_embedding]) S.RI = np.einsum('mhi,minj,jk->mhnk', Ht[0, :, :dim_embedding, dim_embedding:], S.RI, Ht[0, 0, dim_embedding:, :dim_embedding]) #dt = 1.0*tmax/(nt-1) #ts = np.linspace(0, tmax, nt) SigmaM = matsubara(beta, ntau, dim_embedding, -1) SigmaM.M = SM.M Sigma = langreth(norb, nt, tmax, ntau, beta, -1) Sigma.L = S.L Sigma.R = S.R Sigma.RI = S.RI #------------------------------------------------------ # solve the embedding problem norb = dim_embedding def H(kx, ky, t): return Hmat[:dim_embedding, : dim_embedding] + Tmat[:dim_embedding, : dim_embedding] * np.cos(0.2 * t) constants = (myrank, Nkx, Nky, ARPES, kpp, k2p, k2i, tmax, nt, beta, ntau, norb, pump) #Ht = init_Ht(H, *constants) UksR, UksI, eks, fks, Rs, _ = init_Uks(H, dt_fine, *constants, version='higher order') G0M = compute_G0M(0, 0, UksI, eks, fks, Rs, *constants) G0 = compute_G0R(0, 0, UksR, UksI, eks, fks, Rs, *constants) integrator = integration.integrator(6, nt, beta, ntau) GM = matsubara(beta, ntau, norb, -1) integrator.dyson_matsubara(G0M, SigmaM, GM) print('differences Matsubara') diff = np.mean(abs(GM.M - GexactM.M[:, :dim_embedding, :dim_embedding])) print('diff = %1.3e' % diff) G = langreth(norb, nt, tmax, ntau, beta, -1) integrator.dyson_langreth(G0M, SigmaM, G0, Sigma, G) #------------------------------------------------------ # compute differences diff = np.mean(abs(GM.M - GexactM.M[:, :dim_embedding, :dim_embedding])) print('diff = %1.3e' % diff) diffs['M'].append(diff) diff = np.mean( abs(G.R - Gexact.R[:, :dim_embedding, :, :dim_embedding])) print('diff langreth R = %1.3e' % diff) diffs['R'].append(diff) diff = np.mean( abs(G.RI - Gexact.RI[:, :dim_embedding, :, :dim_embedding])) print('diff langreth RI = %1.3e' % diff) diffs['RI'].append(diff) diff = np.mean( abs(G.L - Gexact.L[:, :dim_embedding, :, :dim_embedding])) print('diff langreth L = %1.3e' % diff) diffs['L'].append(diff) #------------------------------------------------------ plt_diffs(diffs) if 'MPI' in sys.modules: MPI.Finalize()
def main(): if myrank == 0: time0 = time.time() if myrank == 0: print(' ') print('nprocs = ', nprocs) if not os.path.exists(savedir): os.mkdir(savedir) assert not os.path.exists(savedir + 'SigmaM') and not os.path.exists( savedir + 'GlocM'), 'Cannot overwrite existing data' volume = Nkx * Nky k2p, k2i, i2k = init_k2p_k2i_i2k(Nkx, Nky, nprocs, myrank) kpp = np.count_nonzero(k2p == myrank) integrator = integration.integrator(6, nt, beta, ntau) def H(kx, ky): return -2.0 * np.cos(kx) * np.ones([norb, norb]) constants = (myrank, Nkx, Nky, ARPES, kpp, k2p, k2i, tmax, nt, beta, ntau, norb, pump) UksI, eks, fks, Rs = init_UksM(H, dt_fine, *constants, version='higher order') print('Done initializing Us') # Solve Matsubara problem #--------------------------------------------------------- DM = compute_D0M(omega, beta, ntau, norb) SigmaM = matsubara(beta, ntau, norb, -1) iter_selfconsistency = 8 change = 0.0 for i in range(iter_selfconsistency): print('iteration : %d' % i) SigmaM0 = SigmaM.M.copy() GlocM = matsubara(beta, ntau, norb, -1) for ik in range(kpp): ik1, ik2 = i2k[ik] G0M = compute_G0M(ik1, ik2, UksI, eks, fks, Rs, *constants) if i == 0: GM = G0M else: GM = matsubara(beta, ntau, norb, -1) integrator.dyson_matsubara(G0M, SigmaM, GM) GlocM.add(GM) SigmaM = matsubara(beta, ntau, norb, -1) if nprocs == 1: SigmaM.M = GlocM.M else: comm.Allreduce(GlocM.M, SigmaM.M, op=MPI.SUM) SigmaM.multiply(DM) SigmaM.scale(1j * g2 / volume) print('Done computing SigmaM') change = np.mean(abs(SigmaM0 - SigmaM.M)) print('change = %1.3e' % change) print('Done computing GlocM') SigmaM.save(savedir, 'SigmaM') GlocM.save(savedir, 'GlocM') saveparams(savedir) if 'MPI' in sys.modules: MPI.Finalize()
def main(): beta = 2.0 ARPES = False pump = 0 g2 = None omega = None tmax = 1.0 nt = 10 e1 = -0.1 e2 = 0.1 lamb = 1.0 diffs_vs_ntau = [] ntaus = [200] for ntau in ntaus: #--------------------------------------------------------- # compute non-interacting G for the 2x2 problem (exact solution) norb = 2 def H(kx, ky): return np.array([[e1, lamb], [np.conj(lamb), e2]], dtype=complex) constants = (myrank, Nkx, Nky, ARPES, kpp, k2p, k2i, tmax, nt, beta, ntau, norb, pump) UksR, UksI, eks, fks, Rs = init_Uks(H, *constants) G2x2 = compute_G0M(0, 0, UksR, UksI, eks, fks, Rs, *constants) #------------------------------------------------------ # compute Sigma_embedding # Sigma = |lambda|^2 * g22(t,t') norb = 1 def H(kx, ky): return e2*np.ones([1,1]) constants = (myrank, Nkx, Nky, ARPES, kpp, k2p, k2i, tmax, nt, beta, ntau, norb, pump) UksR, UksI, eks, fks, Rs = init_Uks(H, *constants) Sigma = compute_G0M(0, 0, UksR, UksI, eks, fks, Rs, *constants) Sigma.scale(lamb*np.conj(lamb)) # solve the embedding problem norb = 1 def H(kx, ky): return e1*np.ones([1,1]) constants = (myrank, Nkx, Nky, ARPES, kpp, k2p, k2i, tmax, nt, beta, ntau, norb, pump) UksR, UksI, eks, fks, Rs = init_Uks(H, *constants) G0 = compute_G0M(0, 0, UksR, UksI, eks, fks, Rs, *constants) G = matsubara(beta, ntau, norb, -1) integrator = integration.integrator(6, nt, beta, ntau, norb) integrator.dyson_matsubara(G0, Sigma, G) #plt(linspace(0,beta,ntau), [G.M[:,0].imag, G2x2M[:,0,0].imag], 'Gsol and G2x2') print('diff = %1.3e'%np.amax(abs(G.M[:,0,0]-G2x2.M[:,0,0]))) #------------------------------------------------------ #np.save(savedir+'diffs', diffs_vs_deltat) #np.save(savedir+'dts', dts) if 'MPI' in sys.modules: MPI.Finalize()