My code is following:

Python: Select all

```
class Heisenberg(MultiCouplingModel, MPOModel):
def __init__(self, model_params):
#
L = model_params.get('L', 10)
self.bc_MPS=bc_MPS = model_params.get('bc_MPS', 'finite')
bc='periodic' if bc_MPS=='infinite' else 'open'
Heisenberg = site.SpinHalfSite(conserve='Sz')
lat = Lattice([L],[Heisenberg],bc=bc,bc_MPS=bc_MPS)
MultiCouplingModel.__init__(self, lat)
#
J = model_params.get('J', 1.)
h = model_params.get('h', 0.)
#self.add_coupling(J, 0,'Sz' ,0,'Sz',1)
for i in range(L):
if(i%2==0):
self.add_local_term(J, [('Sz',[i,0]),( 'Sz', [i+2,0])])
self.add_local_term(J*0.5, [('Sp',[i,0]),( 'Sm', [i+2,0])])
self.add_local_term(J*0.5, [('Sm',[i,0]),( 'Sp', [i+2,0])])
self.add_onsite(-h, 0,'Sz')
MPOModel.__init__(self, lat, self.calc_H_MPO())
```

Python: Select all

```
H=Heisenberg({'L':L,'J':J,'h':h,'bc_MPS':'infinite'})
ni_state = []
for i in range(L):
if(i%2==1):
ini_state.append('up')
else:
ini_state.append('down')
sw_max=50
chi=100
dmrg_params = {'norm_tol': None,"trunc_params": {"chi_max":1000, "svd_min": 1.e-10}}
psi = MPS.from_product_state(H.lat.mps_sites(), ini_state, "infinite")
dmrg_params['trunc_params'] = {'chi_max': chi,'svd_min': 1.e-15}
dmrg_params['max_sweeps'] = sw_max
info = dmrg.run(psi, H, dmrg_params)
```