Thanks!
Another thing, now I am trying to calculate the spectrum function, for which I need to do tebd on the ladder model. However, it raises error when I try to calculate H_bond. When I try to get H_bond with calc_H_bond(), it says
Code: Select all
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-128-2c765ae31cee> in <module>()
----> 1 TestModel.calc_H_bond()
1 frames
/usr/local/lib/python3.7/dist-packages/tenpy/models/model.py in calc_H_bond(self, tol_zero)
1482 ct = self.all_coupling_terms()
1483 ct.remove_zeros(tol_zero)
-> 1484 H_bond = ct.to_nn_bond_Arrays(sites)
1485
1486 ot = self.all_onsite_terms()
/usr/local/lib/python3.7/dist-packages/tenpy/networks/terms.py in to_nn_bond_Arrays(self, sites)
725 if j2 != i + 1:
726 msg = "Can't give nearest neighbor H_bond for long-range {i:d}-{j:d}"
--> 727 raise ValueError(msg.format(i=i, j=j2))
728 for op2, strength in d3.items():
729 if isinstance(op2, tuple):
ValueError: Can't give nearest neighbor H_bond for long-range 0-2
when I try calc_H_bond_from_MPO, it says
Code: Select all
ValueError Traceback (most recent call last)
<ipython-input-129-3992d8e6b876> in <module>()
1 TestModel.calc_H_MPO()
----> 2 TestModel.calc_H_bond_from_MPO()
/usr/local/lib/python3.7/dist-packages/tenpy/models/model.py in calc_H_bond_from_MPO(self, tol_zero)
588 for W in Ws:
589 if npc.norm(W) > tol_zero:
--> 590 raise ValueError("Bond couplings didn't capture everything. "
591 "Either H is long range or IdL/IdR is wrong!")
592 # now merge the onsite terms to H_bond
ValueError: Bond couplings didn't capture everything. Either H is long range or IdL/IdR is wrong!
The definition of the model class is
Code: Select all
class GroupedBosonImpModel(CouplingMPOModel):
default_lattice = "Ladder"
force_default_lattice = True
# this requires TeNPy v0.8.0
def init_sites(self, model_params):
conserve_F = model_params.get('conserve_F', 'N')
filling_F = model_params.get('filling_F',0.5)
conserve_B = model_params.get('conserve_B', 'N')
filling_B = model_params.get('filling_B',0)
Nmax = model_params.get('Nmax',1)
model_label = model_params.get('label',None)
model_charges = model_params.get('charges','independent')
HostSite = FermionSite(conserve_F,filling_F)
ImpSite = BosonSite(Nmax,conserve_B,filling_B)
set_common_charges([HostSite, ImpSite], model_charges)
return [HostSite, ImpSite]
def init_terms(self, model_params):
#confirm that the input lattice is a chain
if not isinstance(self.lat, tenpy.models.lattice.Ladder):
raise ValueError("The input lattice is not a Ladder")
#get the coupling constants, t*c_{i+1}^\dagger c_i,
# h*x_{i+1}^\dagger x_i
# V*n_e*n_e and g*n_x*n_e
# mue, mux the potential for particle number conservation
t = model_params.get('t', 1.)
h = model_params.get('h', 1.)
V = model_params.get('V', 0.)
g = model_params.get('g', 0.)
mue = model_params.get('mue', 1.)
mux = model_params.get('mux', 1.)
#implement chemical potential
self.add_onsite(-mue,0,'N') # `u=0` = HostSite
self.add_onsite(-mux,1,'N') # `u=1` = ImpSite
#implement e-imp interaction
self.add_coupling(g, 0, 'N', 1, 'N', dx=[0],plus_hc=False)
#implement e-e interaction
self.add_coupling(V,0,'dN',0,'dN',dx=[1],plus_hc=False)
#implement kinetic energy
self.add_coupling(-t,0,'Cd',0,'C',1,plus_hc=True)
self.add_coupling(-h,1,'Bd',1,'B',1,plus_hc=True)
def bond_energies(self, psi):
"""Calculate bond energies <psi|H_bond|psi>.
Parameters
----------
psi : :class:`~tenpy.networks.mps.MPS`
The MPS for which the bond energies should be calculated.
Returns
-------
E_bond : 1D ndarray
List of bond energies: for finite bc, ``E_Bond[i]`` is the energy of bond ``i, i+1``.
(i.e. we omit bond 0 between sites L-1 and 0);
for infinite bc ``E_bond[i]`` is the energy of bond ``i-1, i``.
"""
if self.lat.bc_MPS == 'infinite':
return psi.expectation_value(self.H_bond, axes=(['p0', 'p1'], ['p0*', 'p1*']))
# else
return psi.expectation_value(self.H_bond[1:], axes=(['p0', 'p1'], ['p0*', 'p1*']))
Do I need to rebuild another model with GroupedSite or could I do tebd with this class?