MPSEnvironment¶
full name: tenpy.networks.mps.MPSEnvironment
parent module:
tenpy.networks.mps
type: class
Inheritance Diagram
Methods

Initialize self. 
Delete stored part strictly to the left of site i. 

Delete storde part scrictly to the right of site i. 


Expectation value 
Calculate the overlap by a full contraction of the network. 


Calculate LP at given site from nearest available one (including i). 
Return number of physical sites in the contractions of get_LP(i). 


Calculate RP at given site from nearest available one (including i). 
Return number of physical sites in the contractions of get_RP(i). 

Build initial left part 

Build initial right part 


Store part to the left of site i. 

Store part to the right of site i. 
Sanity check, raises ValueErrors, if something is wrong. 

class
tenpy.networks.mps.
MPSEnvironment
(bra, ket, init_LP=None, init_RP=None, age_LP=0, age_RP=0)[source]¶ Bases:
object
Stores partial contractions of \(<braOpket>\) for local operators Op.
The network for a contraction \(<braOpket>\) of a local operator Op, say exemplary at sites i, i+1 looks like:
 .M[0] ... M[1]M[2] ... >.             LP[0]   Op  RP[1]             .N[0]* ... N[1]*N[2]* ... <.
Of course, we can also calculate the overlap <braket> by using the special case
Op = Id
.We use the following label convention (where arrows indicate qconj):
 .> vR vL >.     LP 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 partLP[0]
andRP[1]
are trivial and don’t change, but forbc='infinite'
they are might be 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 leftcanonical A to the left parts LP and rightcanonical B to the right parts RP. Thus, the special case
ket=bra
should yield identity matrices for LP and RP. Parameters
bra (
MPS
) – The MPS to project on. Should be given in usual ‘ket’ form; we call conj() on the matrices directly. Stored in place, without making copies. If necessary to match charges, we callgauge_total_charge()
.ket (
MPO
 None) – The MPS on which the local operator acts. Stored in place, without making copies. IfNone
, use bra.init_LP (
None
Array
) – Initial very left partLP
. IfNone
, build trivial one withinit_LP()
.init_RP (
None
Array
) – Initial very right partRP
. IfNone
, build trivial one withinit_RP()
.age_LP (int) – The number of physical sites involved into the contraction yielding firstLP.
age_RP (int) – The number of physical sites involved into the contraction yielding lastRP.

L
¶ Number of physical sites involved into the Environment, i.e. the least common multiple of
bra.L
andket.L
. Type

bra, ket
The two MPS for the contraction.
 Type

_LP
¶ Left parts of the environment, len L.
LP[i]
contains the contraction strictly left of site i (orNone
, if we don’t have it calculated). Type
list of {
None
Array
}

_RP
¶ Right parts of the environment, len L.
RP[i]
contains the contraction strictly right of site i (orNone
, if we don’t have it calculated). Type
list of {
None
Array
}

_LP_age
¶ Used for bookkeeping, how large the DMRG system grew:
_LP_age[i]
stores the number of physical sites invovled into the contraction network which yieldsself._LP[i]
. Type
list of int 
None

_RP_age
¶ Used for bookkeeping, how large the DMRG system grew:
_RP_age[i]
stores the number of physical sites invovled into the contraction network which yieldsself._RP[i]
. Type
list of int 
None

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[i1]> 'vR'      LP[0]        .N[0]* ... N[i1]*< 'vR*'

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[L1].        RP[1]      'vL*' <N[i+1]* ... N[L1]*.

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
.

full_contraction
(i0)[source]¶ Calculate the overlap by a full contraction of the network.
The full contraction of the environments gives the overlap
<braket>
, taking into accountMPS.norm
of both bra and ket. For this purpose, this function contractsget_LP(i0+1, store=False)
andget_RP(i0, store=False)
with appropriate singular values in between. Parameters
i0 (int) – Site index.

expectation_value
(ops, sites=None, axes=None)[source]¶ Expectation value
<braopsket>
of (nsite) operator(s).Calculates nsite expectation values of operators sandwiched between bra and ket. For examples the contraction for a twosite operator on site i would look like:
 .SB[i]B[i+1].           LP[i]  op  RP[i+1]           .SB*[i]B*[i+1].
Here, the B are taken from ket, the B* from bra. The call structure is the same as for
MPS.expectation_value()
. Parameters
ops ((list of) {
Array
 str }) – The operators, for wich the expectation value should be taken, All operators should all have the same number of legs (namely 2 n). If less thanlen(sites)
operators are given, we repeat them periodically. Strings (like'Id', 'Sz'
) are translated into singlesite operators defined bysites
.sites (list) – List of site indices. Expectation values are evaluated there. If
None
(default), the entire chain is taken (clipping for finite b.c.)axes (None  (list of str, list of str)) – Two lists of each n leg labels giving the physical legs of the operator used for contraction. The first n legs are contracted with conjugated B, the second n legs with the nonconjugated B.
None
defaults to(['p'], ['p*'])
for single site (n=1), or(['p0', 'p1', ... 'p{n1}'], ['p0*', 'p1*', .... 'p{n1}*'])
for n > 1.
 Returns
exp_vals – Expectation values,
exp_vals[i] = <braops[i]ket>
, whereops[i]
acts on site(s)j, j+1, ..., j+{n1}
withj=sites[i]
. Return type
1D ndarray
Examples
One site examples (n=1):
>>> env.expectation_value('Sz') [Sz0, Sz1, ..., Sz{L1}] >>> env.expectation_value(['Sz', 'Sx']) [Sz0, Sx1, Sz2, Sx3, ... ] >>> env.expectation_value('Sz', sites=[0, 3, 4]) [Sz0, Sz3, Sz4]
Two site example (n=2), assuming homogeneous sites:
>>> SzSx = npc.outer(psi.sites[0].Sz.replace_labels(['p', 'p*'], ['p0', 'p0*']), psi.sites[1].Sx.replace_labels(['p', 'p*'], ['p1', 'p1*'])) >>> env.expectation_value(SzSx) [Sz0Sx1, Sz1Sx2, Sz2Sx3, ... ] # with len L1 for finite bc, or L for infinite
Example measuring <braSzSxket> on each second site, for inhomogeneous sites:
>>> SzSx_list = [npc.outer(psi.sites[i].Sz.replace_labels(['p', 'p*'], ['p0', 'p0*']), psi.sites[i+1].Sx.replace_labels(['p', 'p*'], ['p1', 'p1*'])) for i in range(0, psi.L1, 2)] >>> env.expectation_value(SzSx_list, range(0, psi.L1, 2)) [Sz0Sx1, Sz2Sx3, Sz4Sx5, ...]