Chain¶
full name: tenpy.models.lattice.Chain
parent module:
tenpy.models.lattice
type: class
-
class
tenpy.models.lattice.
Chain
(L, site, **kwargs)[source]¶ Bases:
tenpy.models.lattice.SimpleLattice
A chain of L equal sites.
- Parameters
- Attributes
- nearest_neighbors
- next_nearest_neighbors
- next_next_nearest_neighbors
order
Defines an ordering of the lattice sites, thus mapping the lattice to a 1D chain.
Methods
count_neighbors
(self[, u, key])Count e.g.
coupling_shape
(self, dx)Calculate correct shape of the strengths for a coupling.
lat2mps_idx
(self, lat_idx)Translate lattice indices
(x_0, ..., x_{D-1}, u)
to MPS index i.mps2lat_idx
(self, i)Translate MPS index i to lattice indices
(x_0, ..., x_{dim-1}, u)
.mps2lat_values
(self, A[, axes, u])same as
Lattice.mps2lat_values()
, but ignoreu
, setting it to0
.mps_idx_fix_u
(self[, u])return an index array of MPS indices for which the site within the unit cell is u.
mps_lat_idx_fix_u
(self[, u])Similar as
mps_idx_fix_u()
, but return also the corresponding lattice indices.mps_sites
(self)Return a list of sites for all MPS indices.
multi_coupling_shape
(self, dx)Calculate correct shape of the strengths for a multi_coupling.
number_nearest_neighbors
(self[, u])Deprecated.
number_next_nearest_neighbors
(self[, u])Deprecated.
ordering
(self, order)Provide possible orderings of the N lattice sites.
plot_basis
(self, ax, \*\*kwargs)Plot arrows indicating the basis vectors of the lattice.
plot_bc_identified
(self, ax[, direction, shift])Mark two sites indified by periodic boundary conditions.
plot_coupling
(self, ax[, coupling])Plot lines connecting nearest neighbors of the lattice.
plot_order
(self, ax[, order, textkwargs])Plot a line connecting sites in the specified “order” and text labels enumerating them.
plot_sites
(self, ax[, markers])Plot the sites of the lattice with markers.
position
(self, lat_idx)return ‘space’ position of one or multiple sites.
possible_couplings
(self, u1, u2, dx)Find possible MPS indices for two-site couplings.
possible_multi_couplings
(self, u0, other_us, dx)Generalization of
possible_couplings()
to couplings with more than 2 sites.site
(self, i)return
Site
instance corresponding to an MPS index itest_sanity
(self)Sanity check.
-
ordering
(self, order)[source]¶ Provide possible orderings of the N lattice sites.
The following orders are defined in this method compared to
Lattice.ordering()
:order
Resulting order
'default'
0, 1, 2, 3, 4, ... ,L-1
'folded'
0, L-1, 1, L-2, ... , L//2
. This order might be usefull if you want to consider a ring with periodic boundary conditions with a finite MPS: It avoids the ultra-long range of the coupling from site 0 to L present in the default order.
-
count_neighbors
(self, u=0, key='nearest_neighbors')¶ Count e.g. the number of nearest neighbors for a site in the bulk.
- Parameters
- uint
Specifies the site in the unit cell, for which we should count the number of neighbors (or whatever key specifies).
- keystr
Key of
pairs
to select what to count.
- Returns
- numberint
Number of nearest neighbors (or whatever key specified) for the u-th site in the unit cell, somewhere in the bulk of the lattice. Note that it might not be the correct value at the edges of a lattice with open boundary conditions.
-
coupling_shape
(self, dx)¶ Calculate correct shape of the strengths for a coupling.
- Parameters
- dxtuple of int
Translation vector in the lattice for a coupling of two operators.
- Returns
- coupling_shapetuple of int
Len
dim
. The correct shape for an array specifying the coupling strength. lat_indices has only rows within this shape.- shift_lat_indicesarray
Translation vector from lower left corner of box spanned by dx to the origin.
-
lat2mps_idx
(self, lat_idx)¶ Translate lattice indices
(x_0, ..., x_{D-1}, u)
to MPS index i.- Parameters
- lat_idxarray_like […, dim+1]
The last dimension corresponds to lattice indices
(x_0, ..., x_{D-1}, u)
. All lattice indices should be positive and smaller than the corresponding entry inself.shape
. Exception: for “infinite” bc_MPS, an x_0 outside indicates shifts accross the boundary.
- Returns
- iarray_like
MPS index/indices corresponding to lat_idx. Has the same shape as lat_idx without the last dimension.
-
mps2lat_idx
(self, i)¶ Translate MPS index i to lattice indices
(x_0, ..., x_{dim-1}, u)
.- Parameters
- iint | array_like of int
MPS index/indices.
- Returns
- lat_idxarray
First dimensions like i, last dimension has len dim`+1 and contains the lattice indices ``(x_0, …, x_{dim-1}, u)` corresponding to i. For i accross the MPS unit cell and “infinite” bc_MPS, we shift x_0 accordingly.
-
mps2lat_values
(self, A, axes=0, u=None)¶ same as
Lattice.mps2lat_values()
, but ignoreu
, setting it to0
.
-
mps_idx_fix_u
(self, u=None)¶ return an index array of MPS indices for which the site within the unit cell is u.
If you have multiple sites in your unit-cell, an onsite operator is in general not defined for all sites. This functions returns an index array of the mps indices which belong to sites given by
self.unit_cell[u]
.- Parameters
- uNone | int
Selects a site of the unit cell.
None
(default) means all sites.
- Returns
- mps_idxarray
MPS indices for which
self.site(i) is self.unit_cell[u]
. Ordered ascending.
-
mps_lat_idx_fix_u
(self, u=None)¶ Similar as
mps_idx_fix_u()
, but return also the corresponding lattice indices.- Parameters
- uNone | int
Selects a site of the unit cell.
None
(default) means all sites.
- Returns
- mps_idxarray
MPS indices i for which
self.site(i) is self.unit_cell[u]
.- lat_idx2D array
The row j contains the lattice index (without u) corresponding to
mps_idx[j]
.
-
mps_sites
(self)¶ Return a list of sites for all MPS indices.
Equivalent to
[self.site(i) for i in range(self.N_sites)]
.This should be used for sites of 1D tensor networks (MPS, MPO,…).
-
multi_coupling_shape
(self, dx)¶ Calculate correct shape of the strengths for a multi_coupling.
- Parameters
- dxtuple of int
Translation vector in the lattice for a coupling of two operators.
- Returns
- coupling_shapetuple of int
Len
dim
. The correct shape for an array specifying the coupling strength. lat_indices has only rows within this shape.- shift_lat_indicesarray
Translation vector from lower left corner of box spanned by dx to the origin.
-
number_nearest_neighbors
(self, u=0)¶ Deprecated.
Use
count_neighbors()
instead.
-
number_next_nearest_neighbors
(self, u=0)¶ Deprecated.
Use
count_neighbors()
instead.
-
property
order
¶ Defines an ordering of the lattice sites, thus mapping the lattice to a 1D chain.
This order defines how an MPS/MPO winds through the lattice.
-
plot_basis
(self, ax, **kwargs)¶ Plot arrows indicating the basis vectors of the lattice.
- Parameters
- ax
matplotlib.axes.Axes
The axes on which we should plot.
- **kwargs :
Keyword arguments specifying the “arrowprops” of
ax.annotate
.
- ax
-
plot_bc_identified
(self, ax, direction=-1, shift=None, **kwargs)¶ Mark two sites indified by periodic boundary conditions.
Works only for lattice with a 2-dimensional basis.
- Parameters
- ax
matplotlib.axes.Axes
The axes on which we should plot.
- directionint
The direction of the lattice along which we should mark the idenitified sites. If
None
, mark it along all directions with periodic boundary conditions.- shiftNone | np.ndarray
The origin starting from where we mark the identified sites. Defaults to the first entry of
unit_cell_positions
.- **kwargs :
Keyword arguments for the used
ax.plot
.
- ax
-
plot_coupling
(self, ax, coupling=None, **kwargs)¶ Plot lines connecting nearest neighbors of the lattice.
- Parameters
- ax
matplotlib.axes.Axes
The axes on which we should plot.
- couplinglist of (u1, u2, dx)
By default (
None
), useself.pairs['nearest_neighbors']
. Specifies the connections to be plotted; iteating over lattice indices (i0, i1, …), we plot a connection from the site(i0, i1, ..., u1)
to the site(i0+dx[0], i1+dx[1], ..., u2)
, taking into account the boundary conditions.- **kwargs :
Further keyword arguments given to
ax.plot()
.
- ax
-
plot_order
(self, ax, order=None, textkwargs={}, **kwargs)¶ Plot a line connecting sites in the specified “order” and text labels enumerating them.
- Parameters
- ax
matplotlib.axes.Axes
The axes on which we should plot.
- orderNone | 2D array (self.N_sites, self.dim+1)
The order as returned by
ordering()
; by default (None
) useorder
.- textkwargs: ``None`` | dict
If not
None
, we add text labels enumerating the sites in the plot. The dictionary can contain keyword arguments forax.text()
.- **kwargs :
Further keyword arguments given to
ax.plot()
.
- ax
-
plot_sites
(self, ax, markers=['o', '^', 's', 'p', 'h', 'D'], **kwargs)¶ Plot the sites of the lattice with markers.
- Parameters
- ax
matplotlib.axes.Axes
The axes on which we should plot.
- markerslist
List of values for the keywork marker of
ax.plot()
to distinguish the different sites in the unit cell, a site u in the unit cell is plotted with a markermarkers[u % len(markers)]
.- **kwargs :
Further keyword arguments given to
ax.plot()
.
- ax
-
position
(self, lat_idx)¶ return ‘space’ position of one or multiple sites.
- Parameters
- lat_idxndarray,
(... , dim+1)
Lattice indices.
- lat_idxndarray,
- Returns
- posndarray,
(..., dim)
The position of the lattice sites specified by lat_idx in real-space.
- posndarray,
-
possible_couplings
(self, u1, u2, dx)¶ Find possible MPS indices for two-site couplings.
For periodic boundary conditions (
bc[a] == False
) the indexx_a
is taken moduloLs[a]
and runs throughrange(Ls[a])
. For open boundary conditions,x_a
is limited to0 <= x_a < Ls[a]
and0 <= x_a+dx[a] < lat.Ls[a]
.- Parameters
- u1, u2int
Indices within the unit cell; the u1 and u2 of
add_coupling()
- dxarray
Length
dim
. The translation in terms of basis vectors for the coupling.
- Returns
- mps1, mps2array
For each possible two-site coupling the MPS indices for the u1 and u2.
- lat_indices2D int array
Rows of lat_indices correspond to rows of mps_ijkl and contain the lattice indices of the “lower left corner” of the box containing the coupling.
- coupling_shapetuple of int
Len
dim
. The correct shape for an array specifying the coupling strength. lat_indices has only rows within this shape.
-
possible_multi_couplings
(self, u0, other_us, dx)¶ Generalization of
possible_couplings()
to couplings with more than 2 sites.Given the arguments of
add_coupling()
determine the necessary shape of strength.- Parameters
- u0int
Argument u0 of
add_multi_coupling()
.- other_uslist of int
The u of the other_ops in
add_multi_coupling()
.- dxarray, shape (len(other_us), lat.dim+1)
The dx specifying relative operator positions of the other_ops in
add_multi_coupling()
.
- Returns
- mps_ijkl2D int array
Each row contains MPS indices i,j,k,l,…` for each of the operators positions. The positions are defined by dx (j,k,l,… relative to i) and boundary coundary conditions of self (how much the box for given dx can be shifted around without hitting a boundary - these are the different rows).
- lat_indices2D int array
Rows of lat_indices correspond to rows of mps_ijkl and contain the lattice indices of the “lower left corner” of the box containing the coupling.
- coupling_shapetuple of int
Len
dim
. The correct shape for an array specifying the coupling strength. lat_indices has only rows within this shape.
-
test_sanity
(self)¶ Sanity check.
Raises ValueErrors, if something is wrong.