def setUp(self): N = 11 dtype = float U = np.zeros(N) U[0] = 0.0 hop_u = (-1.0) * np.ones(N - 1) hop_d = (-1.0) * np.ones(N - 1) mu_u = (-0.1) * np.ones(N) mu_d = (-0.8) * np.ones(N) """ =============================================================== diagonalization of free Hamiltonian """ Ham_up = np.diag(mu_u) + np.diag(-hop_u, 1) + np.diag(-hop_u, -1) eta_up, UNIT_up = np.linalg.eig(Ham_up) eta_up[np.abs(eta_up) < 1E-12] = 0.0 mF_up = np.nonzero(eta_up <= 0.0)[0][-1] UNIT_up_ = np.copy(UNIT_up[:, 0:mF_up + 1]) M_up = UNIT_up_.dot(herm(UNIT_up_)) Ham_down = np.diag(mu_d) + np.diag(-hop_d, 1) + np.diag(-hop_d, -1) eta_down, UNIT_down = np.linalg.eig(Ham_down) eta_down[np.abs(eta_down) < 1E-12] = 0.0 mF_down = np.nonzero(eta_down <= 0.0)[0][-1] UNIT_down_ = np.copy(UNIT_down[:, 0:mF_down + 1]) M_down = UNIT_down_.dot(herm(UNIT_down_)) self.eexact = np.sum(eta_up[eta_up < 0]) + np.sum( eta_down[eta_down < 0]) """ =============================================================== """ mpoobc = H.HubbardChain(U, hop_u, hop_d, mu_u, mu_d, obc=True, dtype=dtype) chi = 10 d = 4 mps = mpslib.MPS.random(N, chi, d, obc=True, dtype=dtype) mps.__position__(N) mps.__position__(0) mps._D = 60 lb = np.ones((1, 1, 1)) rb = np.ones((1, 1, 1)) self.dmrg = en.DMRGengine(mps, mpoobc, 'testSIAM', lb, rb) self.eps = 1E-5
def setUp(self): D = 60 d = 2 self.N = 10 jz = 1.0 jxy = 1.0 Jz = np.ones(self.N) * jz Jxy = np.ones(self.N) * jxy N = self.N #system size Nup = int(self.N / 2) #number of up-spins Z2 = -1 Jzar = [0.0] * N Jxyar = [0.0] * N grid = [None] * N for n in range(N - 1): grid[n] = [n + 1] Jzar[n] = np.asarray([jz]) Jxyar[n] = np.asarray([jxy]) grid[N - 1] = [] Jzar[N - 1] = np.asarray([0.0]) Jxyar[N - 1] = np.asarray([0.0]) np.asarray(Jxyar) Jxyar, Jzar = np.asarray(Jxyar).astype( np.float64), np.asarray(Jzar).astype(np.float64) Hsparse = ed.XXZSparseHam(Jxyar, Jzar, N, Nup, Z2, grid) e, v = sp.sparse.linalg.eigsh(Hsparse, k=1, which='SA', maxiter=1000000, tol=1E-8, v0=None, ncv=40) self.Eexact = e[0] mps = mpslib.MPS.random(self.N, 10, d, obc=True) mps._D = D mps.__position__(self.N) mps.__position__(0) mpoobc = H.XXZ(Jz, Jxy, np.zeros(self.N), True) lb = np.ones((1, 1, 1)) rb = np.ones((1, 1, 1)) self.dmrg = en.DMRGengine(mps, mpoobc, 'testXXZ', lb, rb) self.eps = 1E-5
import numpy as np import scipy as sp import math import lib.mpslib.mpsfunctions as mf import lib.mpslib.engines as en import lib.mpslib.Hamiltonians as H import lib.mpslib.mps as mpslib comm=lambda x,y:np.dot(x,y)-np.dot(y,x) anticomm=lambda x,y:np.dot(x,y)+np.dot(y,x) herm=lambda x:np.conj(np.transpose(x)) if __name__ == "__main__": D=50 d=2 N=2 Jz=np.ones(N) Jxy=np.ones(N) #initialize MPS with bond dimension D dtype=complex mps=mpslib.MPS.random(N=N,D=D,d=d,obc=False,dtype=dtype) mpo=H.XXZ(Jz,Jxy,np.zeros(N),False,dtype=dtype) idmrg=en.IDMRGengine(mps,mpo,'blabla') #idmrg.__simulateTwoSite__(Nmax=1000,NUC=1,Econv=1E-10,tol=1E-4,ncv=10,cp=None,verbose=1,truncation=1E-8,regaugestep=3) #two site idmrg print(idmrg.__doc__) print(idmrg.__simulate__.__doc__) idmrg.simulate(Nmax=100,NUC=2,solver='LOBPCG',Econv=1E-10,tol=1E-6,ncv=20,cp=None,verbose=1,regaugestep=0) #single site idmrg
type=int, default=10) parser.add_argument( '--innermlgmres', help= 'Number of inner GMRES iterations per each outer iteration (from scipy.sparse.linalg.lgmres manual)', type=int, default=30) args = parser.parse_args() d = 2 N = 1 Jz = args.Jz * np.ones(N) Jxy = np.ones(N) B = args.Bz * np.ones(N) mpo = H.XXZ(Jz, Jxy, B, False) if args.dtype == 'complex': dtype = complex elif args.dtype == 'float': dtype = float else: sys.exit('unknown type args.dtype={0}'.format(args.dtype)) mps = mpslib.MPS.random( N=N, D=args.D, d=d, obc=False, dtype=dtype) #initialize a random MPS with bond dimension D'=10 filename = args.filename + 'D{0}_Jx{1}_B{2}'.format( args.D, args.Jz, args.Bz) mps.regauge(gauge='right') iMPS = en.VUMPSengine(mps, mpo, args.filename)
Jz = np.ones(N).astype(float) #Hamiltonian parameters Jxy = np.ones(N).astype(float) mps = mpslib.MPS.random( N=N, D=10, d=d, obc=True, dtype=float) #initialize a random MPS with bond dimension D'=10 mps._D = D #set the mps final bond-dimension parameter to D; mps._D is the maximally allowed dimension of the mps #normalize the state by sweeping the orthogonalizty center once back and forth through the system mps.position(N) mps.position(0) #initialize an MPO (MPOs are defined in lib.mpslib.Hamiltonians) #the MPO class in Hamiltonians implements a routine MPO.twoSiteGate(m,n,dt), which #returns the exponential exp(dt*h(m,n)), where h(m,n) is the local Hamiltonian contribution #acting on sites m and n mpo = H.XXZ(Jz, Jxy, Bz=np.zeros(N), obc=True) #initialize a DMRGEngine with an mps and an mpo dmrg = en.DMRGengine(mps, mpo, 'blabla') #start with a two site simulation with the state with bond dimension D'=10; the bond-dimension will #grow until it reaches mps._D dmrg.simulateTwoSite(2, 1e-10, 1e-6, 40, verbose=1, solver='LAN') #now switch to a single site DMRG (faster) to further converge state state dmrg.simulate(3, 1e-10, 1e-10, 30, verbose=1, solver='LAN') dmrg._mps.position(0) #initialize a TimeEvolutionEngine with an mps and an mpo #you don't have to pass an mpo here; the engine mererly assumes that #the object passed implements the memberfunction object.twoSiteGate(m,n,dt) #which should return an twosite gate dmrg._mps.applyOneSiteGate(np.asarray([[0.0, 1.], [0.0, 0.0]]), 50)
def setUp(self): Jx = -1.0 * np.ones(1) B = np.ones(1) self.mpo = H.TFI(Jx, B, False) self.D = 20
def setUp(self): D=32 d=2 self.N=10 jz=1.0 jxy=1.0 self.Nmax=10 self.dt=-1j*0.05 #time step self.numsteps=10 #numnber of steps to be taken in between measurements Jz=np.ones(self.N)*jz Jxy=np.ones(self.N)*jxy N=self.N #system size Nup=int(self.N/2) #number of up-spins Z2=-10 Jzar=[0.0]*N Jxyar=[0.0]*N grid=[None]*N for n in range(N-1): grid[n]=[n+1] Jzar[n]=np.asarray([jz]) Jxyar[n]=np.asarray([jxy]) grid[N-1]=[] Jzar[N-1]=np.asarray([0.0]) Jxyar[N-1]=np.asarray([0.0]) np.asarray(Jxyar) Jxyar,Jzar=np.asarray(Jxyar).astype(np.float64),np.asarray(Jzar).astype(np.float64) Hsparse1=ed.XXZSparseHam(Jxyar,Jzar,N,Nup,Z2,grid) #get the ground state e,v=sp.sparse.linalg.eigsh(Hsparse1,k=1,which='SA',maxiter=1000000,tol=1E-8,v0=None,ncv=40) #the Hamiltonian in the new sector Hsparse2=ed.XXZSparseHam(Jxyar,Jzar,N,Nup+1,Z2,grid) #flip the spin at the center of the ground state basis1=ed.binarybasisU1(self.N,self.N/2) assert(len(basis1)==Hsparse1.shape[0]) basis2=ed.binarybasisU1(self.N,self.N/2+1) vnew=np.zeros(len(basis2),v.dtype) assert(len(basis2)==Hsparse2.shape[0]) for n in range(len(basis1)): state1=basis1[n] splus=bb.setBit(state1,(N-1)/2) for m in range(len(basis2)): if splus==basis2[m]: vnew[m]=v[n] def matvec(mat,vec): return mat.dot(vec) mv=fct.partial(matvec,*[Hsparse2]) lan=lanEn.LanczosTimeEvolution(mv,np.dot,np.zeros,ncv=20,delta=1E-8) self.Szexact=np.zeros((self.Nmax,self.N)) self.Syexact=np.zeros((self.Nmax,self.N)) vnew/=np.linalg.norm(vnew) for n in range(self.Nmax): self.Szexact[n,:]=measureSz(vnew,basis2,self.N)[::-1] self.Syexact[n,:]=measureSy(vnew,basis2,self.N)[::-1] stdout.write("\rED time evolution at t/T= %4.4f/%4.4f"%(n*self.numsteps*np.abs(self.dt),self.Nmax*self.numsteps*np.abs(self.dt))) stdout.flush() for step in range(self.numsteps): vnew=lan.__doStep__(vnew,self.dt) vnew/=np.linalg.norm(vnew) mps=mpslib.MPS.random(self.N,10,d,obc=True) mps._D=D mps.__position__(self.N) mps.__position__(0) self.mpo=H.XXZ(Jz,Jxy,np.zeros(self.N),True) lb=np.ones((1,1,1)) rb=np.ones((1,1,1)) self.dmrg=en.DMRGengine(mps,self.mpo,'testXXZ',lb,rb) self.eps=1E-5
import lib.mpslib.mps as mpslib comm = lambda x, y: np.dot(x, y) - np.dot(y, x) anticomm = lambda x, y: np.dot(x, y) + np.dot(y, x) herm = lambda x: np.conj(np.transpose(x)) if __name__ == "__main__": D = 32 d = 2 N = 2 Jx = np.ones(N) Bz = 0.5 * np.ones(N) #initialize MPS with bond dimension D dtype = float mps = mpslib.MPS.random(N=N, D=D, d=d, obc=False, dtype=dtype) mpo = H.TFI(Jx, Bz, False) idmrg = en.IDMRGengine(mps, mpo, 'blabla') #idmrg.__simulateTwoSite__(Nmax=1000,NUC=1,Econv=1E-10,tol=1E-4,ncv=10,cp=None,verbose=1,truncation=1E-8,regaugestep=0) #two site idmrg print(idmrg.__doc__) print(idmrg.__simulate__.__doc__) idmrg.__simulate__(Nmax=1000, NUC=2, solver='LAN', Econv=1E-10, tol=1E-6, ncv=20, cp=None, verbose=1, regaugestep=0) #single site idmrg
parser.add_argument('--seed', help='seed for initialization of Q and R matrices',type=int) parser.add_argument('--numeig', help='number of eigenvector in TMeigs (5)',type=int,default=5) parser.add_argument('--ncv', help='number of krylov vectors in TMeigs (20)',type=int,default=20) parser.add_argument('--svd', help='do svd instead of polar decompostion for guage matching',action="store_true") parser.add_argument('--arncv', help='number of Krylov vectors in arnoldi (20)',type=int,default=20) parser.add_argument('--arnumvecs', help='number of exciteds states (1)',type=int,default=1) parser.add_argument('--artol', help='tolerance of the arnoldi sovler (1E-12)',type=float,default=1E-12) parser.add_argument('--Nmaxlgmres', help='Maximum number of lgmres steps (see scipy.sparse.linalg.lgmres help); total number is (Nmaxlgmres+1)*innermlgmres',type=int,default=50) parser.add_argument('--outerklgmres', help='Number of vectors to carry between inner GMRES iterations. According to [R271], good values are in the range of 1...3. However, note that if you want to use the additional vectors to accelerate solving multiple similar problems, larger values may be beneficial (from scipy.sparse.linalg.lgmres manual)',type=int,default=10) parser.add_argument('--innermlgmres', help='Number of inner GMRES iterations per each outer iteration (from scipy.sparse.linalg.lgmres manual)',type=int,default=30) args=parser.parse_args() d=2 N=1 Jx=args.Jx*np.ones(N) B=args.Bz*np.ones(N) mpo=H.TFI(Jx,B,False) if args.dtype=='complex': dtype=complex elif args.dtype=='float': dtype=float else: sys.exit('unknown type args.dtype={0}'.format(args.dtype)) mps=mpslib.MPS.random(N=N,D=args.D,d=d,obc=False,dtype=dtype) #initialize a random MPS with bond dimension D'=10 #normalize the state by sweeping the orthogonalizty center once back and forth through the system filename=args.filename+'D{0}_Jx{1}_B{2}'.format(args.D,args.Jx,args.Bz) mps.regauge(gauge='right') iMPS=en.VUMPSengine(mps,mpo,args.filename) e=iMPS.simulate(args.imax,args.epsilon,args.regaugetol,args.lgmrestol,args.ncv,args.numeig,args.Nmaxlgmres,artol=args.artol,arnumvecs=args.arnumvecs,\ arncv=args.arncv,svd=args.svd,checkpoint=args.cp,solver=args.solver.upper())
parser.add_argument('--dt',help='time step for imaginary time evolution (0.05)',type=float,default=0.005) parser.add_argument('--regaugetol', help='tolerance of eigensolver for finding left and right reduced DM (1E-10)',type=float,default=1E-10) parser.add_argument('--lgmrestol', help='lgmres tolerance for reduced hamiltonians (1E-10)',type=float,default=1E-10) parser.add_argument('--epsilon', help='desired convergence of the state (1E-5)',type=float,default=1E-6) parser.add_argument('--imax', help='maximum number of iterations (20000)',type=int,default=20000) parser.add_argument('--filename', help='filename for output (_cMPSoptnew)',type=str,default='_HeisTDVP') parser.add_argument('--numeig', help='number of eigenvector in TMeigs',type=int,default=5) parser.add_argument('--ncv', help='number of krylov vectors in TMeigs',type=int,default=20) args=parser.parse_args() #run in left mps gauge and left mps-tangent gauge N=2 d=2 Jx=args.Jx*np.ones(N) B=args.B*np.ones(N) mpo=Hams.TFI(Jx,B,obc=True) if args.dtype=='complex': tensor=(np.random.rand(args.D,args.D,d)-0.5)*0.9+1j*(np.random.rand(args.D,args.D,d)-0.5)*0.9 dtype=complex elif args.dtype=='float': tensor=(np.random.rand(args.D,args.D,d)-0.5)*0.9 dtype=float else: sys.exit('unknown type args.dtype={0}'.format(args.dtype)) [gamma,lam]=mf.regauge(tensor,gauge='left',tol=args.regaugetol) A=np.copy(gamma)