Defining a New Operator when Inheriting CouplingMPOModel

Discussing the best way to implement feature X
Post Reply
stephenjnaus
Posts: 2
Joined: 15 Jul 2023, 01:04

Defining a New Operator when Inheriting CouplingMPOModel

Post by stephenjnaus »

I'm new at TeNPy and am trying to create a model that is a CouplingMPOModel, with a new operator Nj.

Code: Select all

class myTFLIMModel(CouplingMPOModel):
    def init_sites(self, model_params):
        site = SpinHalfSite(conserve=None)
        Nj = np.array([[1,0],[0,0]])
        site.add_op('Nj', Nj)
        return site
    
    def init_terms(self, model_params):
    	U = model_params.get('U',1.)
        self.add_coupling(U, 0, 'Nj',1,'Nj',np.array([0]))
 
However, when I try to create an object of this class by doing the following:

Code: Select all

model_params = dict(lattice = Ladder(L = 20, site = SpinHalfSite(conserve=None)), L=20, U=1.,bc_MPS='finite', conserve='None') 
M = myTFLIMModel(model_params)
I keep receiving an error that claims it has no knowledge of the Nj operator. In particular it says:

Code: Select all

"ValueError: unknown onsite operator 'Nj' for u=0
SpinHalfSite('None')"
I don't understand why Nj has not been recognized. Interestingly, I have run a similar code without specifying a particular lattice and it has run without any errors, so I'm assuming something went wrong there. Any help would be much appreciated.
User avatar
Johannes
Site Admin
Posts: 456
Joined: 21 Jul 2018, 12:52
Location: TU Munich

Re: Defining a New Operator when Inheriting CouplingMPOModel

Post by Johannes »

The issue here is that you directly pass the full Ladder instance in the model_params, which already has the site defined - hence the model doesn't call init_sites anymore.
Try to use

Python: Select all

model_params = dict(
    lattice='Ladder',
    L=20,
    U=1.,
    bc_MPS='finite'
)
and overwrite init_lattice if you need to adjust creating the lattice in a specialized way.
Post Reply