Skip to content

Commit

Permalink
fix IrregularLattice with infinte MPS bc.
Browse files Browse the repository at this point in the history
  • Loading branch information
jhauschild committed Jun 9, 2020
1 parent 7cb4545 commit 037ad76
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
10 changes: 6 additions & 4 deletions tenpy/models/lattice.py
Expand Up @@ -857,7 +857,6 @@ def possible_couplings(self, u1, u2, dx):
if any([s == 0 for s in coupling_shape]):
return [], [], np.zeros([0, self.dim]), coupling_shape
Ls = np.array(self.Ls)
N_sites_per_ring = self.N_sites_per_ring
mps_i, lat_i = self.mps_lat_idx_fix_u(u1)
lat_j_shifted = lat_i + dx
lat_j = np.mod(lat_j_shifted, Ls) # assuming PBC
Expand All @@ -874,7 +873,8 @@ def possible_couplings(self, u1, u2, dx):
mps_j = self.lat2mps_idx(np.concatenate([lat_j, [[u2]] * len(lat_j)], axis=1))
if self.bc_MPS == 'infinite':
# shift j by whole MPS unit cells for couplings along the infinite direction
mps_j_shift = (lat_j_shifted[:, 0] - lat_j[:, 0]) * N_sites_per_ring
# N_sites_per_ring might not be set for IrregularLattice
mps_j_shift = (lat_j_shifted[:, 0] - lat_j[:, 0]) * self.N_sites // self.N_rings
mps_j += mps_j_shift
# finally, ensure 0 <= min(i, j) < N_sites.
mps_ij_shift = np.where(mps_j_shift < 0, -mps_j_shift, 0)
Expand Down Expand Up @@ -967,7 +967,9 @@ def possible_multi_couplings(self, ops):
u = np.broadcast_to(u, lat_ijkl.shape[:2] + (1, ))
mps_ijkl = self.lat2mps_idx(np.concatenate([lat_ijkl, u], axis=2))
if self.bc_MPS == 'infinite':
mps_ijkl += (lat_ijkl_shifted[keep, :, 0] - lat_ijkl[:, :, 0]) * self.N_sites_per_ring
# N_sites_per_ring might not be set for IrregularLattice
mps_ijkl += ((lat_ijkl_shifted[keep, :, 0] - lat_ijkl[:, :, 0]) * self.N_sites //
self.N_rings)
return mps_ijkl, lat_indices, coupling_shape

def _keep_possible_multi_couplings(self, lat_ijkl, lat_ijkl_shifted, u_ijkl):
Expand Down Expand Up @@ -1433,7 +1435,7 @@ def _keep_possible_multi_couplings(self, lat_ijkl, lat_ijkl_shifted, u_ijkl):
def _set_Ls(self, Ls):
super()._set_Ls(Ls)
# N_sites, N_sites_per_ring set by order setter
self.N_sites = None
# self.N_sites = None
self.N_sites_per_ring = None


Expand Down
11 changes: 8 additions & 3 deletions tests/test_lattice.py
Expand Up @@ -104,8 +104,9 @@ def test_IrregularLattice():

ops = [(None, dx, u1), (None, [0, 0], u0)]
m_ji, m_lat_indices, m_coupling_shape = ir.possible_multi_couplings(ops)
# npt.assert_equal(m_ji[1, :], np.array(expect['i']))
# npt.assert_equal(m_ji[0, :], np.array(expect['j']))
sort = np.lexsort(m_lat_indices.T)
npt.assert_equal(m_ji[sort, 1], np.array(expect['i']))
npt.assert_equal(m_ji[sort, 0], np.array(expect['j']))


def test_number_nn():
Expand Down Expand Up @@ -175,7 +176,11 @@ def test_lattice_order():


def test_possible_couplings():
lat_reg = lattice.Honeycomb(2, 3, [None, None], order="snake", bc="periodic")
lat_reg = lattice.Honeycomb(2,
3, [None, None],
order="snake",
bc="periodic",
bc_MPS="infinite")
lat_irreg = lattice.IrregularLattice(lat_reg, remove=[[0, 0, 0]])
u0, u1 = 0, 1
for lat in [lat_reg, lat_irreg]:
Expand Down

0 comments on commit 037ad76

Please sign in to comment.