Newcomer of tenpy having an issue with my code
Posted: 17 Jul 2022, 07:44
I have written a code in tenpy to simulate the 1D heisenberg chain, but it looks like finally my code does not create any "dynamic properties" at all(Both my energy and my entanglement entropy does not change at all). Can anyone help me with that? Thank you guys so much!Attached are my codes and my plots.
My codes:
My codes:
Code: Select all
import numpy as np
import tenpy
import time
from tenpy.networks.mps import MPS
from tenpy.models.xxz_chain import XXZChain
from tenpy.algorithms import dmrg
import matplotlib.pyplot as plt
def example_DMRG_heisenberg_infinite_S_xi_scaling(Jz):
model_params = dict(L=20, Jxx=1., Jz=Jz, hz=0, bc_MPS='infinite', conserve='best')
M = XXZChain(model_params)
product_state = ["up"] * M.lat.N_sites
psi = MPS.from_product_state(M.lat.mps_sites(), product_state, bc=M.lat.bc_MPS)
dmrg_params = {
'start_env': 10,
'mixer': False,
# 'mixer_params': {'amplitude': 1.e-3, 'decay': 5., 'disable_after': 50},
'trunc_params': {
'chi_max': 30,
#Dimension of the system
'svd_min': 1.e-10
},
'max_E_err': 1.e-9,
'max_S_err': 1.e-6,
'update_env': 0,
}
chi_list = np.arange(7, 31, 2)
s_list = []
xi_list = []
E_list=[]
eng = dmrg.TwoSiteDMRGEngine(psi, M, dmrg_params)
a=0
for chi in chi_list:
t0 = time.time()
eng.reset_stats(
) # necessary if you for example have a fixed numer of sweeps, if you don't set this you option your simulation stops after initial number of sweeps!
eng.trunc_params['chi_max'] = chi
## DMRG Calculation ##
print("Start IDMRG CALCULATION")
result=eng.run()
eng.options['mixer'] = None
psi.canonical_form()
## Calculating bond entropy and correlation length ##
a+=1
if a==len(chi_list):
print("cnm")
s_list=psi.entanglement_entropy()
# the bond 0 is between MPS unit cells and hence sensible even for 2D lattices.
#xi_list.append(psi.correlation_length())
#print(result)
E_list.append(result[0])
print(chi,
time.time() - t0,
#np.mean(psi.expectation_value(M.H_bond)),
#s_list[-1],
#xi_list[-1],
flush=True)
tenpy.tools.optimization.optimize(3) # quite some speedup for small chi
print("SETTING NEW BOND DIMENSION")
return s_list, xi_list, E_list
if __name__ == "__main__":
import logging
logging.basicConfig(level=logging.INFO)
s_list, xi_list,E_list = example_DMRG_heisenberg_infinite_S_xi_scaling(Jz=1)
length=[i for i in range(0,len(E_list))]
plt.plot(length,E_list)
plt.show()