I am sorry for posting question in "Papers using TeNPy", I don't remember how did I posted it there.

I tried to use Irregular Lattice for Toric Code model by removing those sites which do not belong to any Plaquette of the original square lattice. I am getting an unusual error. Can you help me in this regard?

I am attaching the Full Code below.

Code: Select all

```
# Copyright 2018-2020 TeNPy Developers, GNU GPLv3
import numpy as np
from tenpy.networks.mps import MPS
from tenpy.algorithms import dmrg
from tenpy.models.toric_code import ToricCode
def example_run_TC():
model_params = dict(Lx=3, Ly=3, Jv=1, Jp=1, bc_MPS="infinite", verbose= 1)
Lx = model_params['Lx']
Ly = model_params['Ly']
M = ToricCode(model_params)
product_state=[0]*((2*Ly*Lx)-Ly)
psi = MPS.from_product_state(M.lat.mps_sites(), product_state, bc = "infinite")
dmrg_params = {
'mixer': True, # setting this to True helps to escape local minima
'trunc_params': {
'chi_max': 100,
'svd_min': 1.e-10,
},
'max_E_err': 1.e-10,
'verbose': 1,
}
results = dmrg.run(psi, M, dmrg_params)
print("Energy per site: ", results['E'])
if __name__ == "__main__":
example_run_TC()
```

Code: Select all

```
# Copyright 2018-2020 TeNPy Developers, GNU GPLv3
import numpy as np
from .lattice import Lattice, get_order, _parse_sites,IrregularLattice
from ..networks.site import SpinHalfSite
from .model import MultiCouplingModel, CouplingMPOModel
from ..tools.params import asConfig
from ..tools.misc import any_nonzero
__all__ = ['DualSquare', 'ToricCode']
class DualSquare(Lattice):
def __init__(self, Lx, Ly, sites, **kwargs):
sites = _parse_sites(sites, 2)
basis = np.eye(2)
pos = np.array([[0., 0.5], [0.5, 0.]])
kwargs.setdefault('basis', basis)
kwargs.setdefault('positions', pos)
NN = [(1, 0, np.array([0, 0])), (1, 0, np.array([1, 0])), (0, 1, np.array([-1, 1])),
(0, 1, np.array([0, 1]))]
nNN = [(i, i, dx) for i in [0, 1] for dx in [np.array([1, 0]), np.array([0, 1])]]
nnNN = [(i, i, dx) for i in [0, 1] for dx in [np.array([1, 1]), np.array([-1, 1])]]
kwargs.setdefault('pairs', {})
kwargs['pairs'].setdefault('nearest_neighbors', NN)
kwargs['pairs'].setdefault('next_nearest_neighbors', nNN)
kwargs['pairs'].setdefault('next_next_nearest_neighbors', nnNN)
super().__init__([Lx, Ly], sites, **kwargs)
def ordering(self, order):
if isinstance(order, str):
if order == "default":
priority = (0, 2, 1)
snake_winding = (False, False, False)
return get_order(self.shape, snake_winding, priority)
return super().ordering(order)
class ToricCode(CouplingMPOModel, MultiCouplingModel):
def init_sites(self, model_params):
conserve = model_params.get('conserve', 'parity')
site = SpinHalfSite(conserve)
return site
def init_lattice(self, model_params):
site = self.init_sites(model_params)
Lx = model_params.get('Lx', 2)
Ly = model_params.get('Ly', 2)
order = model_params.get('order', 'default')
bc_MPS = model_params.get('bc_MPS', 'infinite')
bc_x = 'periodic' if bc_MPS == 'infinite' else 'open'
bc_x = model_params.get('bc_x', bc_x)
bc_y = model_params.get('bc_y', 'periodic')
assert bc_y in ['open', 'periodic']
bc = [bc_x, bc_y]
lat=IrregularLattice(DualSquare(Lx, Ly, site, order=order, bc=bc,bc_MPS=bc_MPS),
remove=[[Lx-1, y, 1] for y in range(Ly)])
return lat
def init_terms(self, model_params):
Jv = model_params.get('Jv', 1.)
Jp = model_params.get('Jp', 1.)
# vertex/star term
self.add_multi_coupling(Jv, [('Sigmax', [0, 0], 1), ('Sigmax', [0, 0], 0),
('Sigmax', [-1, 0], 1), ('Sigmax', [0, -1], 0)],category='spins')
# plaquette term
self.add_multi_coupling(Jp, [('Sigmaz', [0, 0], 1), ('Sigmaz', [0, 0], 0),
('Sigmaz', [0, 1], 1), ('Sigmaz', [1, 0], 0)],category='spins')
# done
69,1 Bot
```