# MPOEnvironment¶

Inheritance Diagram

Methods

 MPOEnvironment.__init__(bra, H, ket[, cache]) Update short_term_keys for the cache and possibly preload tensors. Delete all partial contractions except the left-most LP and right-most RP. Delete stored part strictly to the left of site i. Delete stored part scrictly to the right of site i. MPOEnvironment.expectation_value(ops[, ...]) (doesn't make sense) 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). 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). Return number of physical sites in the contractions of get_RP(i). Return data for (re-)initialization of the environment. Return True if LP left of site i is stored. 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. (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. Sanity check, raises ValueErrors, if something is wrong.
class tenpy.networks.mpo.MPOEnvironment(bra, H, ket, cache=None, **init_env_data)[source]

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* -<-.


To avoid recalculations of the whole network e.g. in the DMRG sweeps, we store the contractions up to some site index in this class. For bc='finite','segment', the very left and right part LP[0] and RP[-1] are trivial and don’t change in the DMRG algorithm, but for iDMRG (bc='infinite') they are also updated (by inserting another unit cell to the left/right).

The MPS bra and ket have to be in canonical form. All the environments are constructed without the singular values on the open bond. In other words, we contract left-canonical A to the left parts LP and right-canonical B to the right parts RP.

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 initializaiton data, as returned by get_initialization_data(). See initialize_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)[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 two methods:

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.

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, make the assumptions 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[IdL, :, :] just contains the energy for the left part of the Hamiltonian, contributing just a constant we can ignore (since we only look at relative energies) LP[IdR, :, :] = eye(:, :) is just the MPS environment. The remaining part is the harder one: we need to converge $C + CA + CAA + CAAA + …$ sandwiched between the MPS. However, H often has finite range, which makes A nil-potent, such that we only need to contract the environment a few times from the left.

Todo

Right now, for infinite/long range it just limits the number of iterations. In general, we could calculate the exact $X = C + CA + CAA +…$ with the geometric series by solving the set of linear equation $X(1-A) = C$ for X, (and analogously $(1-A)X = B$ for the right environment RP).

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) – Wheter 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 rigth of site i.

• store (bool) – Wheter 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> / (norm(|bra>)*norm(|ket>)), i.e. if bra is ket and normalized, the total energy. For this purpose, this function contracts get_LP(i0+1, store=False) and get_RP(i0, store=False).

Parameters

i0 (int) – Site index.

expectation_value(ops, sites=None, axes=None)[source]

(doesn’t make sense)

Update short_term_keys for the cache and possibly preload tensors.

Parameters
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 scrictly to the right of site i.

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)[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.

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.

Return type

dict

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.

set_LP(i, LP, age)[source]

Store part to the left of site i.

set_RP(i, RP, age)[source]

Store part to the right of site i.