BaseEnvironment
full name: tenpy.networks.mps.BaseEnvironment
parent module:
tenpy.networks.mpstype: class
Inheritance Diagram

Methods
|
|
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 strictly to the right of site i. |
|
Calculate expectation values for a bunch of terms and sum them up. |
|
Calculate the overlap by a full contraction of the network. |
|
|
Calculate LP at given site from nearest available one. |
Return number of physical sites in the contractions of get_LP(i). |
|
|
Calculate RP at given site from nearest available one. |
Return number of physical sites in the contractions of get_RP(i). |
|
Return data for (re-)initialization of the environment. |
|
Get the i-th site. |
|
Return True if LP left of site i is stored. |
|
Return True if RP right of site i is stored. |
|
|
Build initial left part |
|
Build initial right part |
(Re)initialize first LP and last RP from the given data. |
|
|
Store part to the left of site i. |
|
Store part to the right of site i. |
|
Shift an Array by an integer multiple of unit cells. |
|
Shift a site by an integer multiple of unit cells. |
Shift charges by an integer multiple of unit cells. |
|
Sanity check, raises ValueErrors, if something is wrong. |
Class Attributes and Properties
Number of physical sites; for an iMPS the len of the MPS unit cell. |
|
Number of sites per horizontal lattice spacing. |
|
List of local physical dimensions. |
|
Distinguish MPS vs iMPS. |
|
Slice of the non-trivial bond indices, depending on |
- class tenpy.networks.mps.BaseEnvironment(bra, ket, cache=None, **init_env_data)[source]
Bases:
MPSGeometryBase class for
MPSEnvironmentstoring partial contractions between MPS.When bra and ket are the same, a suitable canonical form simplifies LP and RP tensors to identities, but for different bra and ket, or if we sandwich a whole MPO between the bra and ket (even if they are the same), the partial contractions are non-trivial.
This class stores the partial contractions up to each bond.
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. Thus, the special case
ket=brashould 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.cache (
DictCache| None) – Cache in which the tensors should be saved. IfNone, a new DictCache is generated.**init_env_data – Further keyword arguments with initialization data, as returned by
get_initialization_data(). Seeinitialize_first_LP_last_RP()for details on these parameters.
- 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| }
- _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 book-keeping, how large the DMRG system grew:
_LP_age[i]stores the number of physical sites involved into the contraction network which yieldsself.get_LP(i).- Type:
list of int |
None
- _RP_age
Used for book-keeping, how large the DMRG system grew:
_RP_age[i]stores the number of physical sites involved into the contraction network which yieldsself._RP[i].- Type:
list of int |
None
- init_first_LP_last_RP(init_LP=None, init_RP=None, age_LP=0, age_RP=0, start_env_sites=0)[source]
(Re)initialize first LP and last RP from the given data.
- Parameters:
init_LP (
None|Array) – Initial very left partLP. IfNone, build one withinit_LP().init_RP (
None|Array) – Initial very right partRP. IfNone, build one withinit_RP().age_LP (int) – The number of physical sites involved into the contraction of init_LP.
age_RP (int) – The number of physical sites involved into the contraction of init_RP.
start_env_sites (int) – If init_LP and init_RP are not specified, contract each start_env_sites for them.
- init_LP(i, start_env_sites=0)[source]
Build initial left part
LP.If bra and ket are the same and in left canonical form, this is the environment you get contracting the overlaps from the left infinity up to bond left of site i.
For segment MPS, the
segment_boundariesare read out (if set).
- init_RP(i, start_env_sites=0)[source]
Build initial right part
RPfor an MPS/MPOEnvironment.If bra and ket are the same and in right canonical form, this is the environment you get contracting from the right infinity up to bond right of site i.
For segment MPS, the
segment_boundariesare read out (if set).
- get_LP(i, store=True)[source]
Calculate LP at given site from nearest available one.
The returned
LP_icorresponds 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] | | | | | | | .-------N[0]*-- ... --N[i-1]*--<- 'vR*'
Takes care of shifting as described in Dipole Conservation.
- get_RP(i, store=True)[source]
Calculate RP at given site from nearest available one.
The returned
RP_icorresponds to the following contraction, where the M’s and the N’s are in the ‘B’ form:| 'vL' ->---M[i+1]-- ... --M[L-1]----. | | | | | | | RP[L-1] | | | | | 'vL*' -<---N[i+1]*- ... --N[L-1]*---.
Takes care of shifting as described in Dipole Conservation.
- 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.
- 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.
- 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()andget_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()andget_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()andget_RP()call, respectively, from disk.preload_RP (int | None) – If not None, preload the tensors for the corresponding
get_LP()andget_RP()call, respectively, from disk.
- 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
braandket, respectively.include_ket (bool) – Whether to also return the
braandket, respectively.
- Returns:
init_env_data – A dictionary with the following entries.
- init_LP, init_RP
Array 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, ket
MPS References of
braandket. Only included if include_bra and include_ket are True, respectively.
- init_LP, init_RP
- Return type:
- abstractmethod full_contraction(i0)[source]
Calculate the overlap by a full contraction of the network.
This function contracts
get_LP(i0+1, store=False)andget_RP(i0, store=False)with appropriate singular values in between.Conventions for
MPSEnvironmentandMPOEnvironmentare slightly different: the MPSEnvironment multiplies with taking into accountMPS.normof both bra and ket, the MPOEnvironment not.- Parameters:
i0 (int) – Site index.
- 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 MPSterms_sum = _mpo.expectation_value(self) * self.L
See also
expectation_value_termevaluates a single term.
tenpy.networks.mpo.MPO.expectation_valueexpectation value density of an MPO.
- 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.
- property dim
List of local physical dimensions.
- property finite
Distinguish MPS vs iMPS.
True for an MPS (
bc='finite', 'segment'), False for an iMPS (bc='infinite').
- 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.
- property nontrivial_bonds
Slice of the non-trivial bond indices, depending on
self.bc.
- 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
Land a shift by one unit cell is purely horizontal and shifts byunit_cell_widthlattice spacings.
- 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
Land a shift by one unit cell is purely horizontal and shifts byunit_cell_widthlattice spacings.
- 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
Land a shift by one unit cell is purely horizontal and shifts byunit_cell_widthlattice 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