MPOEnvironment¶
full name: tenpy.networks.mpo.MPOEnvironment
parent module:
tenpy.networks.mpo
type: class
-
class
tenpy.networks.mpo.
MPOEnvironment
(bra, H, ket, init_LP=None, init_RP=None, age_LP=0, age_RP=0)[source]¶ Bases:
tenpy.networks.mps.MPSEnvironment
Stores partial contractions of \(<bra|H|ket>\) for an MPO H.
The network for a contraction \(<bra|H|ket>\) of an MPO H bewteen 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 partLP[0]
andRP[-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_LP
None
|Array
Initial very left part
LP
. IfNone
, build trivial one with :meth`init_LP`.- init_RP
None
|Array
Initial very right part
RP
. IfNone
, build trivial one withinit_RP()
.- age_LPint
The number of physical sites involved into the contraction yielding firstLP.
- age_RPint
The number of physical sites involved into the contraction yielding lastRP.
- bra
- Attributes
- H
MPO
The MPO sandwiched between bra and ket.
- H
Methods
del_LP
(self, i)Delete stored part strictly to the left of site i.
del_RP
(self, i)Delete storde part scrictly to the right of site i.
expectation_value
(self, ops[, sites, axes])Expectation value
<bra|ops|ket>
of (n-site) operator(s).full_contraction
(self, i0)Calculate the energy by a full contraction of the network.
get_LP
(self, i[, store])Calculate LP at given site from nearest available one (including i).
get_LP_age
(self, i)Return number of physical sites in the contractions of get_LP(i).
get_RP
(self, i[, store])Calculate RP at given site from nearest available one (including i).
get_RP_age
(self, i)Return number of physical sites in the contractions of get_RP(i).
init_LP
(self, i)Build initial left part
LP
.init_RP
(self, i)Build initial right part
RP
for an MPS/MPOEnvironment.set_LP
(self, i, LP, age)Store part to the left of site i.
set_RP
(self, i, RP, age)Store part to the right of site i.
test_sanity
(self)Sanity check, raises ValueErrors, if something is wrong.
-
init_LP
(self, i)[source]¶ Build initial left part
LP
.- Parameters
- iint
Build
LP
left of site i.
- Returns
- init_LP
Array
Identity contractible with the vL leg of
.ket.get_B(i)
, multiplied with a unit vector nonzero inH.IdL[i]
, with labels'vR*', 'wR', 'vR'
.
- init_LP
-
init_RP
(self, i)[source]¶ Build initial right part
RP
for an MPS/MPOEnvironment.- Parameters
- iint
Build
RP
right of site i.
- Returns
- init_RP
Array
Identity contractible with the vR leg of
self.get_B(i)
, multiplied with a unit vector nonzero inH.IdR[i]
, with labels'vL*', 'wL', 'vL'
.
- init_RP
-
get_LP
(self, 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
- iint
The returned LP will contain the contraction strictly left of site i.
- storebool
Wheter to store the calculated LP in self (
True
) or discard them (False
).
- Returns
- LP_i
Array
Contraction of everything left of site i, with labels
'vR*', 'wR', 'vR'
for bra, H, ket.
- LP_i
-
get_RP
(self, 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
- iint
The returned RP will contain the contraction strictly rigth of site i.
- storebool
Wheter to store the calculated RP in self (
True
) or discard them (False
).
- Returns
- RP_i
Array
Contraction of everything right of site i, with labels
'vL*', 'wL', 'vL'
for bra, H, ket.
- RP_i
-
full_contraction
(self, 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 contractsget_LP(i0+1, store=False)
andget_RP(i0, store=False)
.- Parameters
- i0int
Site index.
-
del_LP
(self, i)¶ Delete stored part strictly to the left of site i.
-
del_RP
(self, i)¶ Delete storde part scrictly to the right of site i.
-
expectation_value
(self, ops, sites=None, axes=None)¶ Expectation value
<bra|ops|ket>
of (n-site) operator(s).Calculates n-site expectation values of operators sandwiched between bra and ket. For examples the contraction for a two-site operator on site i would look like:
| .--S--B[i]--B[i+1]--. | | | | | | | |-----| | | LP[i] | op | RP[i+1] | | |-----| | | | | | | | .--S--B*[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 than
len(sites)
operators are given, we repeat them periodically. Strings (like'Id', 'Sz'
) are translated into single-site operators defined bysites
.- siteslist
List of site indices. Expectation values are evaluated there. If
None
(default), the entire chain is taken (clipping for finite b.c.)- axesNone | (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 non-conjugated B.
None
defaults to(['p'], ['p*'])
for single site (n=1), or(['p0', 'p1', ... 'p{n-1}'], ['p0*', 'p1*', .... 'p{n-1}*'])
for n > 1.
- ops(list of) {
- Returns
- exp_vals1D ndarray
Expectation values,
exp_vals[i] = <bra|ops[i]|ket>
, whereops[i]
acts on site(s)j, j+1, ..., j+{n-1}
withj=sites[i]
.
Examples
One site examples (n=1):
>>> env.expectation_value('Sz') [Sz0, Sz1, ..., Sz{L-1}] >>> 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 L-1 for finite bc, or L for infinite
Example measuring <bra|SzSx|ket> 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.L-1, 2)] >>> env.expectation_value(SzSx_list, range(0, psi.L-1, 2)) [Sz0Sx1, Sz2Sx3, Sz4Sx5, ...]
-
get_LP_age
(self, i)¶ Return number of physical sites in the contractions of get_LP(i).
Might be
None
.
-
get_RP_age
(self, i)¶ Return number of physical sites in the contractions of get_RP(i).
Might be
None
.
-
set_LP
(self, i, LP, age)¶ Store part to the left of site i.
-
set_RP
(self, i, RP, age)¶ Store part to the right of site i.