# Chain¶

Inheritance Diagram

Methods

 Chain.__init__(L, site, **kwargs) Initialize self. Chain.count_neighbors([u, key]) Count e.g. Calculate correct shape of the strengths for a coupling. Chain.from_hdf5(hdf5_loader, h5gr, subpath) Load instance from a HDF5 file. Chain.lat2mps_idx(lat_idx) Translate lattice indices (x_0, ..., x_{D-1}, u) to MPS index i. Translate MPS index i to lattice indices (x_0, ..., x_{dim-1}, u). Chain.mps2lat_values(A[, axes, u]) same as Lattice.mps2lat_values(), but ignore u, setting it to 0. return an index array of MPS indices for which the site within the unit cell is u. Similar as mps_idx_fix_u(), but return also the corresponding lattice indices. Return a list of sites for all MPS indices. Calculate correct shape of the strengths for a multi_coupling. Deprecated. Deprecated. Chain.ordering(order) Provide possible orderings of the N lattice sites. Chain.plot_basis(ax, **kwargs) Plot arrows indicating the basis vectors of the lattice. Chain.plot_bc_identified(ax[, direction, shift]) Mark two sites indified by periodic boundary conditions. Chain.plot_coupling(ax[, coupling]) Plot lines connecting nearest neighbors of the lattice. Chain.plot_order(ax[, order, textkwargs]) Plot a line connecting sites in the specified “order” and text labels enumerating them. Chain.plot_sites(ax[, markers]) Plot the sites of the lattice with markers. Chain.position(lat_idx) return ‘space’ position of one or multiple sites. Chain.possible_couplings(u1, u2, dx) Find possible MPS indices for two-site couplings. Chain.possible_multi_couplings(u0, other_us, dx) Generalization of possible_couplings() to couplings with more than 2 sites. Chain.save_hdf5(hdf5_saver, h5gr, subpath) Export self into a HDF5 file. return Site instance corresponding to an MPS index i Sanity check.

Class Attributes and Properties

 Chain.boundary_conditions Human-readable list of boundary conditions from bc and bc_shift. Chain.dim Chain.nearest_neighbors Chain.next_nearest_neighbors Chain.next_next_nearest_neighbors Chain.order Defines an ordering of the lattice sites, thus mapping the lattice to a 1D chain.
class tenpy.models.lattice.Chain(L, site, **kwargs)[source]

A chain of L equal sites.

Parameters
• L (int) – The lenght of the chain.

• site (Site) – The local lattice site. The unit_cell of the Lattice is just [site].

• **kwargs – Additional keyword arguments given to the Lattice. pairs are initialize with [next_]next_]nearest_neighbors. positions can be specified as a single vector.

ordering(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.

property boundary_conditions

Human-readable list of boundary conditions from bc and bc_shift.

Returns

boundary_conditions – List of "open" or "periodic", one entry for each direction of the lattice.

Return type

list of str

count_neighbors(u=0, key='nearest_neighbors')[source]

Count e.g. the number of nearest neighbors for a site in the bulk.

Parameters
• u (int) – Specifies the site in the unit cell, for which we should count the number of neighbors (or whatever key specifies).

• key (str) – Key of pairs to select what to count.

Returns

number – 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.

Return type

int

coupling_shape(dx)[source]

Calculate correct shape of the strengths for a coupling.

Parameters

dx (tuple of int) – Translation vector in the lattice for a coupling of two operators.

Returns

• coupling_shape (tuple of int) – Len dim. The correct shape for an array specifying the coupling strength. lat_indices has only rows within this shape.

• shift_lat_indices (array) – Translation vector from lower left corner of box spanned by dx to the origin.

classmethod from_hdf5(hdf5_loader, h5gr, subpath)[source]

Load instance from a HDF5 file.

This method reconstructs a class instance from the data saved with save_hdf5().

Parameters
• hdf5_loader (Hdf5Loader) – Instance of the loading engine.

• h5gr (Group) – HDF5 group which is represent the object to be constructed.

• subpath (str) – The name of h5gr with a '/' in the end.

Returns

obj – Newly generated class instance containing the required data.

Return type

cls

lat2mps_idx(lat_idx)[source]

Translate lattice indices (x_0, ..., x_{D-1}, u) to MPS index i.

Parameters

lat_idx (array_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 in self.shape. Exception: for “infinite” bc_MPS, an x_0 outside indicates shifts accross the boundary.

Returns

i – MPS index/indices corresponding to lat_idx. Has the same shape as lat_idx without the last dimension.

Return type

array_like

mps2lat_idx(i)[source]

Translate MPS index i to lattice indices (x_0, ..., x_{dim-1}, u).

Parameters

i (int | array_like of int) – MPS index/indices.

Returns

lat_idx – 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.

Return type

array

mps2lat_values(A, axes=0, u=None)[source]

same as Lattice.mps2lat_values(), but ignore u, setting it to 0.

mps_idx_fix_u(u=None)[source]

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

u (None | int) – Selects a site of the unit cell. None (default) means all sites.

Returns

mps_idx – MPS indices for which self.site(i) is self.unit_cell[u]. Ordered ascending.

Return type

array

mps_lat_idx_fix_u(u=None)[source]

Similar as mps_idx_fix_u(), but return also the corresponding lattice indices.

Parameters

u (None | int) – Selects a site of the unit cell. None (default) means all sites.

Returns

• mps_idx (array) – MPS indices i for which self.site(i) is self.unit_cell[u].

• lat_idx (2D array) – The row j contains the lattice index (without u) corresponding to mps_idx[j].

mps_sites()[source]

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(dx)[source]

Calculate correct shape of the strengths for a multi_coupling.

Parameters

dx (tuple of int) – Translation vector in the lattice for a coupling of two operators.

Returns

• coupling_shape (tuple of int) – Len dim. The correct shape for an array specifying the coupling strength. lat_indices has only rows within this shape.

• shift_lat_indices (array) – Translation vector from lower left corner of box spanned by dx to the origin.

number_nearest_neighbors(u=0)[source]

Deprecated.

number_next_nearest_neighbors(u=0)[source]

Deprecated.

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(ax, **kwargs)[source]

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.

plot_bc_identified(ax, direction=-1, shift=None, **kwargs)[source]

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.

• direction (int) – The direction of the lattice along which we should mark the idenitified sites. If None, mark it along all directions with periodic boundary conditions.

• shift (None | 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.

plot_coupling(ax, coupling=None, **kwargs)[source]

Plot lines connecting nearest neighbors of the lattice.

Parameters
• ax (matplotlib.axes.Axes) – The axes on which we should plot.

• coupling (list of (u1, u2, dx)) – By default (None), use self.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().

plot_order(ax, order=None, textkwargs={}, **kwargs)[source]

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.

• order (None | 2D array (self.N_sites, self.dim+1)) – The order as returned by ordering(); by default (None) use order.

• textkwargs (None | dict) – If not None, we add text labels enumerating the sites in the plot. The dictionary can contain keyword arguments for ax.text().

• **kwargs – Further keyword arguments given to ax.plot().

plot_sites(ax, markers=['o', '^', 's', 'p', 'h', 'D'], **kwargs)[source]

Plot the sites of the lattice with markers.

Parameters
• ax (matplotlib.axes.Axes) – The axes on which we should plot.

• markers (list) – 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 marker markers[u % len(markers)].

• **kwargs – Further keyword arguments given to ax.plot().

position(lat_idx)[source]

return ‘space’ position of one or multiple sites.

Parameters

lat_idx (ndarray, (... , dim+1)) – Lattice indices.

Returns

pos – The position of the lattice sites specified by lat_idx in real-space.

Return type

ndarray, (..., dim)

possible_couplings(u1, u2, dx)[source]

Find possible MPS indices for two-site couplings.

For periodic boundary conditions (bc[a] == False) the index x_a is taken modulo Ls[a] and runs through range(Ls[a]). For open boundary conditions, x_a is limited to 0 <= x_a < Ls[a] and 0 <= x_a+dx[a] < lat.Ls[a].

Parameters
• u2 (u1,) – Indices within the unit cell; the u1 and u2 of add_coupling()

• dx (array) – Length dim. The translation in terms of basis vectors for the coupling.

Returns

• mps1, mps2 (array) – For each possible two-site coupling the MPS indices for the u1 and u2.

• lat_indices (2D 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_shape (tuple 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(u0, other_us, dx)[source]

Generalization of possible_couplings() to couplings with more than 2 sites.

Given the arguments of add_coupling() determine the necessary shape of strength.

Parameters
Returns

• mps_ijkl (2D 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_indices (2D 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_shape (tuple of int) – Len dim. The correct shape for an array specifying the coupling strength. lat_indices has only rows within this shape.

save_hdf5(hdf5_saver, h5gr, subpath)[source]

Export self into a HDF5 file.

This method saves all the data it needs to reconstruct self with from_hdf5().

Specifically, it saves unit_cell, Ls, unit_cell_positions, basis, boundary_conditions, pairs under their name, bc_MPS as "boundary_conditions_MPS", and bc_MPS as "order_for_MPS". Moreover, it saves dim and N_sites as HDF5 attributes.

Parameters
• hdf5_saver (Hdf5Saver) – Instance of the saving engine.

• h5gr (:classGroup) – HDF5 group which is supposed to represent self.

• subpath (str) – The name of h5gr with a '/' in the end.

site(i)[source]

return Site instance corresponding to an MPS index i

test_sanity`()[source]

Sanity check.

Raises ValueErrors, if something is wrong.