MPOEnvironment

  • full name: tenpy.networks.mpo.MPOEnvironment

  • parent module: tenpy.networks.mpo

  • type: class

Inheritance Diagram

Inheritance diagram of tenpy.networks.mpo.MPOEnvironment

Methods

MPOEnvironment.__init__(bra, H, ket[, cache])

MPOEnvironment.cache_optimize([...])

Update short_term_keys for the cache and possibly preload tensors.

MPOEnvironment.clear()

Delete all partial contractions except the left-most LP and right-most RP.

MPOEnvironment.del_LP(i)

Delete stored part strictly to the left of site i.

MPOEnvironment.del_RP(i)

Delete stored part strictly to the right of site i.

MPOEnvironment.expectation_value_terms_sum(...)

Calculate expectation values for a bunch of terms and sum them up.

MPOEnvironment.full_contraction(i0)

Calculate the energy by a full contraction of the network.

MPOEnvironment.get_LP(i[, store])

Calculate LP at given site from nearest available one (including i).

MPOEnvironment.get_LP_age(i)

Return number of physical sites in the contractions of get_LP(i).

MPOEnvironment.get_RP(i[, store])

Calculate RP at given site from nearest available one (including i).

MPOEnvironment.get_RP_age(i)

Return number of physical sites in the contractions of get_RP(i).

MPOEnvironment.get_initialization_data([...])

Return data for (re-)initialization of the environment.

MPOEnvironment.get_site(i)

Get the i-th site.

MPOEnvironment.has_LP(i)

Return True if LP left of site i is stored.

MPOEnvironment.has_RP(i)

Return True if RP right of site i is stored.

MPOEnvironment.init_LP(i[, start_env_sites])

Build an initial left part LP.

MPOEnvironment.init_RP(i[, start_env_sites])

Build initial right part RP for an MPS/MPOEnvironment.

MPOEnvironment.init_first_LP_last_RP([...])

(Re)initialize first LP and last RP from the given data.

MPOEnvironment.set_LP(i, LP, age)

Store part to the left of site i.

MPOEnvironment.set_RP(i, RP, age)

Store part to the right of site i.

MPOEnvironment.shift_Array_unit_cells(arr, ...)

Shift an Array by an integer multiple of unit cells.

MPOEnvironment.shift_Site_unit_cells(site, ...)

Shift a site by an integer multiple of unit cells.

MPOEnvironment.shift_charges_unit_cells(...)

Shift charges by an integer multiple of unit cells.

MPOEnvironment.test_sanity()

Sanity check, raises ValueErrors, if something is wrong.

Class Attributes and Properties

MPOEnvironment.L

Number of physical sites; for an iMPS the len of the MPS unit cell.

MPOEnvironment.N_sites_per_hor_spacing

Number of sites per horizontal lattice spacing.

MPOEnvironment.dim

List of local physical dimensions.

MPOEnvironment.finite

Distinguish MPS vs iMPS.

MPOEnvironment.nontrivial_bonds

Slice of the non-trivial bond indices, depending on self.bc.

class tenpy.networks.mpo.MPOEnvironment(bra, H, ket, cache=None, **init_env_data)[source]

Bases: BaseEnvironment

Stores partial contractions of \(<bra|H|ket>\) for an MPO H.

The network for a contraction \(<bra|H|ket>\) of an MPO H between two MPS looks like:

|     .------>-M[0]-->-M[1]-->-M[2]-->- ...  ->--.
|     |        |       |       |                 |
|     |        ^       ^       ^                 |
|     |        |       |       |                 |
|     LP[0] ->-W[0]-->-W[1]-->-W[2]-->- ...  ->- RP[-1]
|     |        |       |       |                 |
|     |        ^       ^       ^                 |
|     |        |       |       |                 |
|     .------<-N[0]*-<-N[1]*-<-N[2]*-<- ...  -<--.

We use the following label convention (where arrows indicate qconj):

|    .-->- vR           vL ->-.
|    |                        |
|    LP->- wR           wL ->-RP
|    |                        |
|    .--<- vR*         vL* -<-.

See BaseEnvironment for further details.

Parameters:
  • bra (MPS) – The MPS to project on. Should be given in usual ‘ket’ form; we call conj() on the matrices directly.

  • H (MPO) – The MPO sandwiched between bra and ket. Should have ‘IdL’ and ‘IdR’ set on the first and last bond.

  • ket (MPS) – The MPS on which H acts. May be identical with bra.

  • **init_env_data – Further keyword arguments with initialization data, as returned by get_initialization_data(). See init_first_LP_last_RP() for details on these parameters.

H

The MPO sandwiched between bra and ket.

Type:

MPO

init_first_LP_last_RP(init_LP=None, init_RP=None, age_LP=0, age_RP=0, start_env_sites=None, force_init_method='iter', gmres_options=None)[source]

(Re)initialize first LP and last RP from the given data.

If init_LP and init_RP are not given, we try to find sensible initial values. Dummy environments can by built with init_LP() and init_RP(), especially for finite MPS.

For infinite MPS, we try to converge the environments with one of three methods:

  • If start_env_sites is given as an integer, contract that many sites into the environment from the given init_LP and init_RP or new trivial environments built with init_LP() / init_RP().

  • If start_env_sites is None, and bra is ket, get init_LP and init_RP using one of two methods:

    ‘iter’: MPOEnvironmentBuilder.init_LP_RP_iterative()
    • Recommended for general use

    ‘TM’: MPOTransferMatrix.find_init_LP_RP()
    • In case ‘iter’ cannot be applied

    • Faster for small bond dimension (chi < 150)

Parameters:
  • init_LP (None | Array) – Initial very left part LP and very right part RP. If None, try to build (and converge) them as described above.

  • init_RP (None | Array) – Initial very left part LP and very right part RP. If None, try to build (and converge) them as described above.

  • age_LP (int) – The number of physical sites involved into the contraction of init_LP and init_RP.

  • age_RP (int) – The number of physical sites involved into the contraction of init_LP and init_RP.

  • start_env_sites (int | None) – Number of sites over which to converge the environment for infinite systems. See above.

  • force_init_method ({None, 'iter', 'TM'}) – Force method ‘TM’ or ‘iter’ as described above for infinite MPS.

  • gmres_options (dict) – Further optional parameters for tenpy.linalg.krylov_based.GMRES. Only relevant for infinite MPS if method ‘iter’ is used to get init_LP/init_RP.

test_sanity()[source]

Sanity check, raises ValueErrors, if something is wrong.

init_LP(i, start_env_sites=0)[source]

Build an initial left part LP.

For start_env_sites > 0, assume that bra is the same as ket and in canonical form, and that H is a Hamiltonian with the following block-form (up to a permutation of MPO indices; this is the case for any model defined in TeNPy),

\[\begin{split}W = \begin{pmatrix} 1 & C & D \\ 0 & A & B \\ 0 & 0 & 1 \end{pmatrix}\end{split}\]

Given that, we can converge the environment even in the thermodynamic limit: LP[IdR, :, :] contains the extensive energy contribution for the left part of the Hamiltonian, which we can ignore (since we only look at relative energies) LP[IdL, :, :] = eye(:, :) is just the MPS environment.

For the remaining part we need to converge $C + CA + CAA + CAAA + … $ sandwiched between the MPS. If H has finite range, A is nil-potent, and it is sufficient to contract the environment a few times from the left.

For infinite/long range interactions it just limits the number of iterations. In this case, the exact environment can still be obtained by solving the geometric series.

Note

For start_env_sites > 0, this function provides a fast approximation of the environment. In general, we recommend using MPOEnvironmentBuilder.init_LP_RP_iterative() which solves the geometric series exactly.

Parameters:
  • i (int) – Build LP left of site i.

  • start_env_sites (int) – How many sites to contract to converge the init_LP; the initial age_LP.

Returns:

init_LP – Environment left of site i with labels 'vR*', 'wR', 'vR'.

Return type:

Array

init_RP(i, start_env_sites=0)[source]

Build initial right part RP for an MPS/MPOEnvironment.

Parameters:
  • i (int) – Build RP right of site i.

  • start_env_sites (int) – How many sites to contract to converge the init_RP; the initial age_RP.

Returns:

init_RP – Environment right of site i with labels 'vL*', 'wL', 'vL'.

Return type:

Array

get_LP(i, store=True)[source]

Calculate LP at given site from nearest available one (including i).

The returned LP_i corresponds to the following contraction, where the M’s and the N’s are in the ‘A’ form:

|     .-------M[0]--- ... --M[i-1]--->-   'vR'
|     |       |             |
|     LP[0]---W[0]--- ... --W[i-1]--->-   'wR'
|     |       |             |
|     .-------N[0]*-- ... --N[i-1]*--<-   'vR*'
Parameters:
  • i (int) – The returned LP will contain the contraction strictly left of site i.

  • store (bool) – Whether to store the calculated LP in self (True) or discard them (False).

Returns:

LP_i – Contraction of everything left of site i, with labels 'vR*', 'wR', 'vR' for bra, H, ket.

Return type:

Array

get_RP(i, store=True)[source]

Calculate RP at given site from nearest available one (including i).

The returned RP_i corresponds to the following contraction, where the M’s and the N’s are in the ‘B’ form:

|     'vL'  ->---M[i+1]-- ... --M[L-1]----.
|                |              |         |
|     'wL'  ->---W[i+1]-- ... --W[L-1]----RP[-1]
|                |              |         |
|     'vL*' -<---N[i+1]*- ... --N[L-1]*---.
Parameters:
  • i (int) – The returned RP will contain the contraction strictly right of site i.

  • store (bool) – Whether to store the calculated RP in self (True) or discard them (False).

Returns:

RP_i – Contraction of everything right of site i, with labels 'vL*', 'wL', 'vL' for bra, H, ket.

Return type:

Array

full_contraction(i0)[source]

Calculate the energy by a full contraction of the network.

The full contraction of the environments gives the value <bra|H|ket> `` ignoring the :attr:`~tenpy.networks.mps.MPS.norm` of the `bra` and `ket`, i.e. the total energy (even if bra and ket are not normalized). For this purpose, this function contracts ``get_LP(i0+1, store=False) and get_RP(i0, store=False) with appropriate singular values in between.

Parameters:

i0 (int) – Site index.

property L

Number of physical sites; for an iMPS the len of the MPS unit cell.

property N_sites_per_hor_spacing

Number of sites per horizontal lattice spacing.

This is the number of MPS sites one has to traverse to travel one lattice spacing in the first dimension, such that self.unit_cell_width * N_sites_per_hor_spacing == self.L.

cache_optimize(short_term_LP=[], short_term_RP=[], preload_LP=None, preload_RP=None)[source]

Update short_term_keys for the cache and possibly preload tensors.

Parameters:
  • short_term_LP (list of int) – i indices for get_LP() and get_RP(), respectively, for which a repeated look-up could happen, i.e., for which tensors should be kept in RAM until the next call to this function.

  • short_term_RP (list of int) – i indices for get_LP() and get_RP(), respectively, for which a repeated look-up could happen, i.e., for which tensors should be kept in RAM until the next call to this function.

  • preload_LP (int | None) – If not None, preload the tensors for the corresponding get_LP() and get_RP() call, respectively, from disk.

  • preload_RP (int | None) – If not None, preload the tensors for the corresponding get_LP() and get_RP() call, respectively, from disk.

clear()[source]

Delete all partial contractions except the left-most LP and right-most RP.

del_LP(i)[source]

Delete stored part strictly to the left of site i.

del_RP(i)[source]

Delete stored part strictly to the right of site i.

property dim

List of local physical dimensions.

expectation_value_terms_sum(term_list)[source]

Calculate expectation values for a bunch of terms and sum them up.

This is equivalent to the following expression:

sum([self.expectation_value_term(term) * strength for term, strength in term_list])

However, for efficiency, the term_list is converted to an MPO and the expectation value of the MPO is evaluated.

Warning

This function works only for finite bra and ket and does not include normalization factors.

Parameters:

term_list (TermList) – The terms and prefactors (strength) to be summed up.

Returns:

  • terms_sum ((complex) float) – Equivalent to the expression sum([self.expectation_value_term(term)*strength for term, strength in term_list]).

  • _mpo – Intermediate results: the generated MPO. For a finite MPS, terms_sum = _mpo.expectation_value(self), for an infinite MPS terms_sum = _mpo.expectation_value(self) * self.L

See also

expectation_value_term

evaluates a single term.

tenpy.networks.mpo.MPO.expectation_value

expectation value density of an MPO.

property finite

Distinguish MPS vs iMPS.

True for an MPS (bc='finite', 'segment'), False for an iMPS (bc='infinite').

get_LP_age(i)[source]

Return number of physical sites in the contractions of get_LP(i).

Might be None.

get_RP_age(i)[source]

Return number of physical sites in the contractions of get_RP(i).

Might be None.

get_initialization_data(first=0, last=None, include_bra=False, include_ket=False)[source]

Return data for (re-)initialization of the environment.

Parameters:
  • first (int) – The first and last site, to the left and right of which we should return the environments. Defaults to 0 and L - 1.

  • last (int) – The first and last site, to the left and right of which we should return the environments. Defaults to 0 and L - 1.

  • include_bra (bool) – Whether to also return the bra and ket, respectively.

  • include_ket (bool) – Whether to also return the bra and ket, respectively.

Returns:

init_env_data – A dictionary with the following entries.

init_LP, init_RPArray

LP on the left of site first and RP on the right of site last, which can be used as init_LP and init_RP for the initialization of a new environment.

age_LP, age_RPint

The number of physical sites involved into the contraction yielding init_LP and init_RP, respectively.

bra, ketMPS

References of bra and ket. Only included if include_bra and include_ket are True, respectively.

Return type:

dict

get_site(i)[source]

Get the i-th site.

This is self.sites[i] if i is in the unit cell and takes care of shifting the charges otherwise.

has_LP(i)[source]

Return True if LP left of site i is stored.

has_RP(i)[source]

Return True if RP right of site i is stored.

property nontrivial_bonds

Slice of the non-trivial bond indices, depending on self.bc.

set_LP(i, LP, age)[source]

Store part to the left of site i. No copy is made!

Takes care of shifting as described in Dipole Conservation.

set_RP(i, RP, age)[source]

Store part to the right of site i. No copy is made!

Takes care of shifting as described in Dipole Conservation.

shift_Array_unit_cells(arr, num_unit_cells, inplace: bool = False)[source]

Shift an Array by an integer multiple of unit cells.

See the notes on Dipole Conservation.

A unit cell has length L and a shift by one unit cell is purely horizontal and shifts by unit_cell_width lattice spacings.

Parameters:
  • arr (Array) – The site to shift.

  • num_unit_cells (int) – The number of unit cells.

  • inplace (bool) – If the array (its legs, qtotal) can be modified in-place. Otherwise (default) we make a shallow copy.

Returns:

The shifted array.

Return type:

Array

shift_Site_unit_cells(site, num_unit_cells)[source]

Shift a site by an integer multiple of unit cells.

See the notes on Dipole Conservation.

A unit cell has length L and a shift by one unit cell is purely horizontal and shifts by unit_cell_width lattice spacings.

Parameters:
  • site (Site) – The site to shift.

  • num_unit_cells (int) – The number of unit cells.

Returns:

A new site with shifted charges, or the unmodified input site if the shift is trivial.

Return type:

Site

shift_charges_unit_cells(charges, num_unit_cells)[source]

Shift charges by an integer multiple of unit cells.

See the notes on Dipole Conservation.

A unit cell has length L and a shift by one unit cell is purely horizontal and shifts by unit_cell_width lattice spacings.

Essentially, this is a convenience wrapper around \(tenpy.linalg.charges.ChargeInfo.shift_charges_horizontal\).

Parameters:
  • charges (2D ndarray of dtype QTYPE) – The charges to shift.

  • num_unit_cells (int) – The number of unit cells.

Returns:

The shifted charges.

Return type:

2D ndarray of dtype QTYPE