Possible bug to implement vanishing coupling strength?
Posted: 23 Aug 2020, 17:00
I'm trying to produce a model with spatially-dependent on-site terms and was having some difficulty.
For example to produce a dimerized pattern of Zeeman fields I use the on-site functionality
If amplitudes t1, t2 are non-zero, everything is fine. I can create a CouplingMPOModel, and from there I can create a NearestNeighborModel using fromMPOModel().
But there are times when I actually want the field on a given site to be exactly zero. If either t1 or t2 are zero, creating CouplingMPOMOdel is fine, but creating NearestNeighborModel throws up an exception:
I could hack it by setting the desired zero entry to be very small but non-vanishing, e.g. 0.0000000000001, and the code runs OK, and the physics should be unchanged. But this feels a bit unsatisfactory than actually literally setting the coupling to 0. So, is this a bug?
A minimal working code to showcase the error is as follows:
Conversely if I do it is OK.
For example to produce a dimerized pattern of Zeeman fields I use the on-site functionality
Code: Select all
self.add_onsite(np.array([t1, t2]), 0, 'Sz')
But there are times when I actually want the field on a given site to be exactly zero. If either t1 or t2 are zero, creating CouplingMPOMOdel is fine, but creating NearestNeighborModel throws up an exception:
Code: Select all
Traceback (most recent call last):
File "/Users/physics2/anaconda3/envs/tenpy/lib/python3.8/site-packages/tenpy/linalg/np_conserved.py", line 2483, in _advanced_getitem
iter(i)
TypeError: 'NoneType' object is not iterable
I could hack it by setting the desired zero entry to be very small but non-vanishing, e.g. 0.0000000000001, and the code runs OK, and the physics should be unchanged. But this feels a bit unsatisfactory than actually literally setting the coupling to 0. So, is this a bug?
A minimal working code to showcase the error is as follows:
Code: Select all
import numpy as np
from tenpy.models.model import CouplingMPOModel, NearestNeighborModel
from tenpy.tools.params import asConfig
from tenpy.networks.site import SpinSite
__all__ = ['minimal_example']
class minimal_example(CouplingMPOModel):
def __init__(self,model_params):
model_params = asConfig(model_params, self.__class__.__name__)
model_params.setdefault('lattice',"Chain")
CouplingMPOModel.__init__(self,model_params)
def init_sites(self, model_params):
site = SpinSite(S=0.5,conserve=None)
return site
def init_terms(self, model_params):
self.add_onsite(np.array([1, 0]), 0, 'Sz')
L = 10
model_params = dict(L=L, bc_MPS="finite")
ME = minimal_example(model_params)
ME_TEBD = NearestNeighborModel.from_MPOModel(ME)
Code: Select all
self.add_onsite(np.array([1, 0.0000000000001]), 0, 'Sz')