TDVP run time issue
Posted: 31 Dec 2020, 20:21
Hello!!! First, I thank your group for making such a nice TeNPy Package. Here I attached the TDVP of the Bose-Hubbard ladder model.
1. To run this code I face some warnings like that -
I install and upgrade the cython, still, these issues present there .
2. This code is running and results are matched with Exact and openmps results. But problem is that it takes a huge time (4-5 hours or more) to produce the results compared to the Exact and OpenMPS results(5 to 10 min). The same scenario occurs for 2D also. Can you please help me to understand why this is happening?
Code: Select all
import numpy as np
from tenpy.networks.mps import MPS
from tenpy.models.lattice import Ladder
#from tenpy.models.hubbard import BoseHubbardChain
from tenpy.algorithms import dmrg
from tenpy.networks.site import BosonSite
from tenpy.models.model import MultiCouplingModel,CouplingMPOModel
import tenpy.linalg.np_conserved as npc
from mpl_toolkits.axes_grid1 import make_axes_locatable
from tenpy.algorithms import tdvp
import copy
import matplotlib.pyplot as plt
from matplotlib import style
from matplotlib.gridspec import GridSpec
import matplotlib.cm as cm
import matplotlib
class Bose_hubbard_ladder(CouplingMPOModel, MultiCouplingModel):
def init_sites(self, model_params):
n_max = model_params.get('n_max', 3)
filling = model_params.get('filling', 0.5)
conserve = model_params.get('conserve', 'N')
if conserve == 'best':
conserve = 'N'
if self.verbose >= 1.:
print(self.name + ": set conserve to", conserve)
site = BosonSite(Nmax=n_max, conserve=conserve, filling=filling)
return site
def init_lattice(self,model_params):
site = self.init_sites(model_params)
L = model_params.get('L',2)
bc_MPS = model_params.get('bc_MPS','infinite')
bc = 'periodic' if bc_MPS =='infinite' else 'open'
bc = model_params.get('bc',bc)
lat = Ladder(L,site,bc=bc,bc_MPS=bc_MPS)
return lat
def init_terms(self, model_params):
t1 = model_params.get('t1', 1.)
t2 = model_params.get('t2', 1.)
phi = model_params.get('phi', 0.)
U = model_params.get('U', 0.)
#V = model_params.get('V', 0.)
mu = model_params.get('mu', 0)
#for u in range(len(self.lat.unit_cell)):
self.add_onsite(-mu - U / 2., 0, 'N')
self.add_onsite(-mu - U / 2., 1, 'N')
self.add_onsite(U / 2., 0, 'NN')
self.add_onsite(U / 2., 1, 'NN')
self.add_coupling(-t1, 0, 'Bd', 0, 'B', 1)
self.add_coupling(-t1, 0, 'B', 0, 'Bd', 1)
self.add_coupling(-t1, 1, 'Bd', 1, 'B', 1)
self.add_coupling(-t1, 1, 'B', 1, 'Bd', 1)
self.add_coupling(-t2, 0, 'Bd', 1, 'B', 0)
self.add_coupling(-t2, 0, 'B', 1, 'Bd', 0)
def Bose_Hubbard_ladder(L,U,t1,t2,mu,N0,nmax,tmax,dt, verbose,Bond_dmrg):
model_params = dict(L=L,
n_max = nmax,
t1=t1,
t2=t2,
U=U,
mu=mu,
bc_MPS='finite',
conserve='N',
verbose=1)
M = Bose_hubbard_ladder(model_params)
product_state=[0]*M.lat.N_sites
product_state[int(L)] = 1
product_state[int(L-1)] = 1
psi = MPS.from_product_state(M.lat.mps_sites(), product_state, bc=M.lat.bc_MPS)
tdvp_params = {
'start_time': 0,
'dt': dt,
'trunc_params': {
'chi_max': 50,
'svd_min': 1.e-10,
'trunc_cut': None
}
}
tdvp_engine = tdvp.Engine(psi, M, tdvp_params)
times = []
N_list = []
for i in range(int(tmax/dt)):
tdvp_engine.run_two_sites(N_steps=1)
times.append(tdvp_engine.evolved_time)
N_list.append(psi.expectation_value("N"))
Nf_list = []
for k in N_list:
nl = []
nu = []
for i in range(2*L):
if i%2 ==0:
nl.append(k[i])
else:
nu.append(k[i])
Nf = []
for i in range(L):
Nf.append(nu[i]+nl[i])
Nf_list.append(Nf)
print(N_list[0])
L_center = int(L/2)
t_f = tmax
txt_font_size = 20
"""*=*=*=*=*=*=*=*=*=*=*==*=*==*=**=***==***=**=***=*=***=**=**==***=*=***==*==***==*===**"""
cvals = [1.0, 1.4, 3.0]
colors = ["white","red","darkred"]
#colors = ["blue","yellow","red"]
norm=plt.Normalize(min(cvals),max(cvals))
tuples = list(zip(map(norm,cvals), colors))
cmap = matplotlib.colors.LinearSegmentedColormap.from_list("", tuples)
"""*=*=*=*=*=*=*=*=*=*=*==*=*==*=**=***==***=**=***=*=***=**=**==***=*=***==*==***==*===**"""
fig = plt.figure(figsize =(10,10))
ax1=fig.add_subplot(111)
im1 = ax1.imshow(Nf_list,extent=[-L_center,L_center,t_f,0],interpolation='Nearest', aspect='auto',cmap=cmap, vmin=0.,vmax=1.)
ax1.tick_params(axis='x', which='both', direction='out',top='off',labelsize=txt_font_size)
ax1.tick_params(axis='y', which='both', direction='out',right='off',labelsize=txt_font_size)
ax1.set_xlabel('Position (Sites)',fontweight="bold",fontsize=txt_font_size)
ax1.set_ylabel("Time (units of $ J^{-1}$)",fontweight="bold",fontsize=txt_font_size+2)
ax1 = plt.gca()
divider = make_axes_locatable(ax1)
cax = divider.append_axes("right", size="5%", pad=0.1)
cbar=plt.colorbar(im1, cax=cax)
cbar.set_label('$\mathbf{<n>}$', rotation=90)
plt.show()
if __name__ == "__main__":
Bose_Hubbard_ladder(L=20,U=0.0,t1=1,t2=1.0,mu=0.0,N0=2,nmax=2,tmax=7.0,dt=0.01, verbose=True,Bond_dmrg=50)
print("*=" * 100)
Code: Select all
/home/.local/lib/python3.6/site-packages/tenpy/tools/optimization.py:278: UserWarning: Couldn't load compiled cython code. Code will run a bit slower.
warnings.warn("Couldn't load compiled cython code. Code will run a bit slower.")
/home/.local/lib/python3.6/site-packages/tenpy/linalg/svd_robust.py:54: UserWarning: Import problems: the work-around `svd_gesvd` will fail.
warnings.warn("Import problems: the work-around `svd_gesvd` will fail.")
parameter 'verbose'=1 for Bose_hubbard_ladder
/home/.local/lib/python3.6/site-packages/tenpy/tools/params.py:124: UserWarning: unused parameters for Bose_hubbard_ladder:
['L', 'U', 'bc_MPS', 'conserve', 'mu', 'n_max', 'phi', 't1', 't2']
warnings.warn(msg.format(keys=sorted(unused), descr=warn))
2. This code is running and results are matched with Exact and openmps results. But problem is that it takes a huge time (4-5 hours or more) to produce the results compared to the Exact and OpenMPS results(5 to 10 min). The same scenario occurs for 2D also. Can you please help me to understand why this is happening?