I am trying to create a model with periodic boundary conditions, but I am running into an error when using the Nearest Neighbor function calc_H_bond().
Below my code can be seen:
Python: Select all
class Arb_Model( CouplingModel, NearestNeighborModel, MPOModel ):
def __init__(self, model_params):
self.L = model_params.get( 'L' , 2 )
self.bc_MPS = model_params.get( 'bc_MPS' , 'finite' )
self.bc = model_params.get( 'bc' , 'periodic' )
self.J = 1.
site = SpinSite( S = 1 , conserve = None )
lat = Chain( self.L , site , bc = self.bc , bc_MPS = self.bc_MPS )
CouplingModel.__init__( self , lat )
self.add_onsite( strength = - self.J , u = 0 , opname = 'Sz' )
self.add_coupling( strength = self.J , u1 = 0 , op1 = 'Sx' , u2 = 0 , op2 = 'Sx' , dx = [1] )
MPOModel.__init__(self, lat, self.calc_H_MPO())
NearestNeighborModel.__init__(self, lat, self.calc_H_bond())
model = Arb_Model( model_params = { 'L' : 3 , 'bc' : 'periodic' , 'bc_MPS' : 'finite' } )
It seems to me that this should work as due to the periodic boundary conditions the first and last particle are connected.
If I use:
Python: Select all
mps_is , mps_js , _ = self.lat.possible_couplings( u1 = 0 , u2 = 0 , dx = [1] , strength = self.J )
Looking at the calc_H_bond() function it is clear that the error comes from the requirement that i+1=j (as seen in the code hereafter).
Python: Select all
term_list = self.to_TermList()
for term, strength in zip(term_list.terms, term_list.strength):
(--- other code not relevant here ---)
(op_i, i), (op_j, j) = term
if i + 1 != j:
raise ValueError('not nearest neighbor')
My question is then whether this is a bug or I am simply not implementing the boundary conditions (or something else entirely!) correctly.
Secondly, when I only apply the onsite Sz term and analyze the model.H_bond, I get that the bond between the first and last particle is None. It seems that for finite systems, regardless of boundary conditions, the entire weight of the onsite term get distributed to the right (left) for the first (last) term. This again seems a bit odd for periodic boundary conditions as I would expect there to be a nonzero bond between them.
Thanks a lot for any help provided and apologies in advance if this is merely me not understanding how to properly incorporate the boundary conditions in tenpy:)