def testTDVP_SEXPMV(self): N=self.N self.dmrg.__simulateTwoSite__(4,1e-10,1e-6,40,verbose=1,solver='LAN') edmrg=self.dmrg.__simulate__(2,1e-10,1e-10,30,verbose=1,solver='LAN') self.dmrg._mps.__applyOneSiteGate__(np.asarray([[0.0,1.],[0.0,0.0]]),int(self.N/2)) self.dmrg._mps.__position__(self.N) self.dmrg._mps.__position__(0) self.dmrg._mps.resetZ() #don't forget to normalize the state again after application of the gate engine=en.TimeEvolutionEngine(self.dmrg._mps,self.mpo,"TDVP_insert_name_here") Dmax=32 #maximum bond dimension to be used during simulation; the maximally allowed bond dimension of the mps will be #adapted to this value in the TimeEvolutionEngine thresh=1E-16 #truncation threshold SZ=np.zeros((self.Nmax,N)) #container for holding the measurements plt.ion() sz=[np.diag([-0.5,0.5]) for n in range(N)] #a list of local operators to be measured it1=0 #counts the total iteration number it2=0 #counts the total iteration number tw=0 #accumulates the truncated weight (see below) solver='SEXPMV' for n in range(self.Nmax): #measure the operators L=engine.measureLocal(sz) #store result for later use SZ[n,:]=L it1=engine.doTDVP(self.dt,numsteps=self.numsteps,krylov_dim=10,cnterset=it1,solver=solver) print(" : ",np.linalg.norm(SZ-self.Szexact)/(self.Nmax*self.N)) self.assertTrue(np.linalg.norm(SZ-self.Szexact)/(self.Nmax*self.N)<1E-8)
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) dmrg._mps.position(N) dmrg._mps.position(0) #initialize a TEBDEngine 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 engine = en.TimeEvolutionEngine(dmrg._mps, mpo, "insert_name_here") dt = -1j * 0.05 #time step numsteps = 20 #numnber of steps to be taken in between measurements Dmax = 40 #maximum bond dimension to be used during simulation; the maximally allowed bond dimension of the mps will be #adapted to this value in the TEBDEngine thresh = 1E-8 #truncation threshold Nmax = 1000 #number of measurements SZ = np.zeros((Nmax, N)) #container for holding the measurements plt.ion() sz = [np.diag([-0.5, 0.5]) for n in range(N)] #a list of local operators to be measured it = 0 #counts the total iteration number tw = 0 #accumulates the truncated weight (see below) for n in range(Nmax): #measure the operators
def run_sim(dmrgcontainer,solver): dmrgcontainer._mps.__applyOneSiteGate__(np.asarray([[0.0,1.],[0.0,0.0]]),int(self.N/2)) dmrgcontainer._mps.__position__(self.N) dmrgcontainer._mps.__position__(0) engine1=en.TimeEvolutionEngine(dmrgcontainer._mps,self.mpo,"insert_name_here") engine2=en.TimeEvolutionEngine(dmrgcontainer._mps.__copy__(),self.mpo,"TDVP_insert_name_here") engine1._mps.resetZ() engine2._mps.resetZ() Dmax=32 #maximum bond dimension to be used during simulation; the maximally allowed bond dimension of the mps will be #adapted to this value in the TimeEvolutionEngine thresh=1E-16 #truncation threshold SZ1=np.zeros((self.Nmax,N)).astype(complex) #container for holding the measurements SZ2=np.zeros((self.Nmax,N)).astype(complex) #container for holding the measurements SX1=np.zeros((self.Nmax,N)).astype(complex) #container for holding the measurements SX2=np.zeros((self.Nmax,N)).astype(complex) #container for holding the measurements SY1=np.zeros((self.Nmax,N)).astype(complex) #container for holding the measurements SY2=np.zeros((self.Nmax,N)).astype(complex) #container for holding the measurements plt.ion() sz=[np.diag([-0.5,0.5]) for n in range(N)] #a list of local operators to be measured sy=[np.asarray([[0,-0.5j],[0.5j,0]]) for n in range(N)] #a list of local operators to be measured sx=[np.asarray([[0,1.0],[1.0,0]]) for n in range(N)] #a list of local operators to be measured it1=0 #counts the total iteration number it2=0 #counts the total iteration number tw=0 #accumulates the truncated weight (see below) for n in range(self.Nmax): #measure a list of local operators #L=[engine1._mps.measureLocal(np.diag([-0.5,0.5]),site=n).real for n in range(N)] SZ1[n,:],SY1[n,:],SX1[n,:]=engine1.measureLocal(sz),engine1.measureLocal(sy),engine1.measureLocal(sx) #store result for later use #note: when measuring with measureLocal function, one has to update the simulation container after that. #this is because measureLocal shifts the center site of the mps around, and that causes inconsistencies #in the simulation container with the left and right environments #L=[engine2._mps.measureLocal(np.diag([-0.5,0.5]),site=n).real for n in range(N)] #engine2.update() SZ2[n,:],SY2[n,:],SX2[n,:]=engine2.measureLocal(sz),engine2.measureLocal(sy),engine2.measureLocal(sx) tw,it2=engine1.doTEBD(dt=self.dt,numsteps=self.numsteps,Dmax=Dmax,tr_thresh=thresh,\ cnterset=it2,tw=tw) it1=engine2.doTDVP(self.dt,numsteps=self.numsteps,krylov_dim=10,cnterset=it1,solver=solver) plt.figure(1,figsize=(10,8)) plt.clf() plt.subplot(3,3,1) plt.plot(range(self.N),self.Szexact[n,:],range(self.N),np.real(SZ2[n,:]),'rd',range(self.N),np.real(SZ1[n,:]),'ko',Markersize=5) plt.ylim([-0.5,0.5]) plt.xlabel('lattice site n') plt.ylabel(r'$\langle S^z_n\rangle$') plt.legend(['exact','TDVP ('+solver+')','TEBD']) plt.subplot(3,3,4) plt.semilogy(range(self.N),np.abs(self.Szexact[n,:]-np.real(SZ2[n,:]))) plt.xlabel('lattice site n') plt.ylabel(r'$|\langle S^z_n\rangle_{tdvp}-\langle S^z_n\rangle_{exact}|$') plt.subplot(3,3,7) plt.semilogy(range(self.N),np.abs(self.Szexact[n,:]-np.real(SZ1[n,:]))) plt.xlabel('lattice site n') plt.ylabel(r'$|\langle S^z_n\rangle_{tebd}-\langle S^z_n\rangle_{exact}|$') plt.tight_layout() plt.subplot(3,3,2) plt.plot(range(self.N),self.Syexact[n,:],range(self.N),np.real(SY2[n,:]),'rd',range(self.N),np.real(SY1[n,:]),'ko',Markersize=5) plt.ylim([-0.5,0.5]) plt.xlabel('lattice site n') plt.ylabel(r'$\langle S^y_n\rangle$') plt.legend(['exact','TDVP ('+solver+')','TEBD']) plt.subplot(3,3,5) plt.semilogy(range(self.N),np.abs(self.Syexact[n,:]-np.real(SY2[n,:]))) plt.xlabel('lattice site n') plt.ylabel(r'$|\langle S^y_n\rangle_{tdvp}-\langle S^y_n\rangle_{exact}|$') plt.subplot(3,3,8) plt.semilogy(range(self.N),np.abs(self.Syexact[n,:]-np.real(SY1[n,:]))) plt.xlabel('lattice site n') plt.ylabel(r'$|\langle S^y_n\rangle_{tebd}-\langle S^y_n\rangle_{exact}|$') plt.tight_layout() plt.subplot(3,3,3) plt.plot(range(self.N),self.Sxexact[n,:],range(self.N),np.real(SX2[n,:]),'rd',range(self.N),np.real(SX1[n,:]),'ko',Markersize=5) plt.ylim([-0.5,0.5]) plt.xlabel('lattice site n') plt.ylabel(r'$\langle S^x_n\rangle$') plt.legend(['exact','TDVP ('+solver+')','TEBD']) plt.subplot(3,3,6) plt.semilogy(range(self.N),np.abs(self.Sxexact[n,:]-np.real(SX2[n,:]))) plt.xlabel('lattice site n') plt.ylabel(r'$|\langle S^x_n\rangle_{tdvp}-\langle S^x_n\rangle_{exact}|$') plt.subplot(3,3,9) plt.semilogy(range(self.N),np.abs(self.Sxexact[n,:]-np.real(SX1[n,:]))) plt.xlabel('lattice site n') plt.ylabel(r'$|\langle S^x_n\rangle_{tebd}-\langle S^x_n\rangle_{exact}|$') plt.tight_layout() plt.figure(2) plt.clf() plt.subplot(3,1,1) plt.plot(range(self.N),np.imag(SZ2[n,:]),'rd',range(self.N),np.imag(SZ1[n,:]),'ko',Markersize=5) plt.xlabel('lattice site n') plt.ylabel(r'$\Im\langle S^z_n\rangle$') plt.legend(['TDVP ('+solver+')','TEBD']) plt.tight_layout() plt.subplot(3,1,2) plt.plot(range(self.N),np.imag(SY2[n,:]),'rd',range(self.N),np.imag(SY1[n,:]),'ko',Markersize=5) plt.xlabel('lattice site n') plt.ylabel(r'$\Im\langle S^y_n\rangle$') plt.legend(['TDVP ('+solver+')','TEBD']) plt.tight_layout() plt.subplot(3,1,3) plt.plot(range(self.N),np.imag(SX2[n,:]),'rd',range(self.N),np.imag(SX1[n,:]),'ko',Markersize=5) plt.xlabel('lattice site n') plt.ylabel(r'$\Im\langle S^x_n\rangle$') plt.legend(['TDVP ('+solver+')','TEBD']) plt.tight_layout() plt.draw() plt.show() plt.pause(0.01)