MPO¶
full name: tenpy.networks.mpo.MPO
parent module:
tenpy.networks.mpo
type: class
Inheritance Diagram
Methods

Initialize self. 
Return hermition conjugate copy of self. 


Calculate 

Initialize an MPO from grids. 

Load instance from a HDF5 file. 

Return index of IdL at bond to the left of site i. 

Return index of IdR at bond to the right of site i. 

Return W at site i. 

extract the full Hamiltonian as a 

group each blocklen subsequent tensors and return result as a new MPO. 

Modify self inplace to group sites. 

Check if self and other represent the same MPO to precision eps. 

Check if self is a hermitian MPO. 

Export self into a HDF5 file. 

Set W at site i. 
Sort virtual legs by charges. 

Sanity check, raises ValueErrors, if something is wrong. 
Class Attributes and Properties
Number of physical sites; for an iMPO the len of the MPO unit cell. 

Dimensions of the virtual bonds. 

List of local physical dimensions. 

Distinguish MPO vs iMPO. 

class
tenpy.networks.mpo.
MPO
(sites, Ws, bc='finite', IdL=None, IdR=None, max_range=None)[source]¶ Bases:
object
Matrix product operator, finite (MPO) or infinite (iMPO).
 Parameters
sites (list of
Site
) – Defines the local Hilbert space for each site.Ws (list of
Array
) – The matrices of the MPO. Should have labelswL, wR, p, p*
.bc ({'finite'  'segment'  'infinite'}) – Boundary conditions as described in
mps
.'finite'
requiresWs[0].get_leg('wL').ind_len = 1
.IdL ((iterable of) {int  None}) – Indices on the bonds, which correpond to ‘only identities to the left’. A single entry holds for all bonds.
IdR ((iterable of) {int  None}) – Indices on the bonds, which correpond to ‘only identities to the right’.
max_range (int  np.inf  None) – Maximum range of hopping/interactions (in unit of sites) of the MPO.
None
for unknown.

chinfo
¶ The nature of the charge.
 Type
ChargeInfo

sites
¶ Defines the local Hilbert space for each site.
 Type
list of
Site

bc
¶ Boundary conditions as described in
mps
.'finite'
requiresWs[0].get_leg('wL').ind_len = 1
. Type
{‘finite’  ‘segment’  ‘infinite’}

IdL
¶ Indices on the bonds (length L`+1), which correpond to ‘only identities to the left’. ``None` for bonds where it is not set. In standard form, this is 0 (except for unset bonds in finite case)
 Type
list of {int  None}

IdR
¶ Indices on the bonds (length L`+1), which correpond to ‘only identities to the right’. ``None` for bonds where it is not set. In standard form, this is the last index on the bond (except for unset bonds in finite case).
 Type
list of {int  None}

max_range
¶ Maximum range of hopping/interactions (in unit of sites) of the MPO.
None
for unknown. Type
int  np.inf  None

grouped
¶ Number of sites grouped together, see
group_sites()
. Type

_valid_bc
¶ Class attribute. Valid boundary conditions; the same as for an MPS.
 Type
tuple of str

save_hdf5
(hdf5_saver, h5gr, subpath)[source]¶ Export self into a HDF5 file.
This method saves all the data it needs to reconstruct self with
from_hdf5()
.Specifically, it saves
sites
,chinfo
,max_range
(under these names),_W
as"tensors"
,IdL
as"index_identity_left"
,IdR
as"index_identity_right"
, andbc
as"boundary_condition"
. Moreover, it savesL
, andgrouped
as HDF5 attributes, as well as the maximum ofchi
under the namemax_bond_dimension
.

classmethod
from_hdf5
(hdf5_loader, h5gr, subpath)[source]¶ Load instance from a HDF5 file.
This method reconstructs a class instance from the data saved with
save_hdf5()
. Parameters
hdf5_loader (
Hdf5Loader
) – Instance of the loading engine.h5gr (
Group
) – HDF5 group which is represent the object to be constructed.subpath (str) – The name of h5gr with a
'/'
in the end.
 Returns
obj – Newly generated class instance containing the required data.
 Return type
cls

classmethod
from_grids
(sites, grids, bc='finite', IdL=None, IdR=None, Ws_qtotal=None, leg0=None, max_range=None)[source]¶ Initialize an MPO from grids.
 Parameters
sites (list of
Site
) – Defines the local Hilbert space for each site.grids (list of list of list of entries) – For each site (outermost list) a matrixgrid (corresponding to
wL, wR
) with entries being or representing (seegrid_insert_ops()
) onsiteoperators.bc ({'finite'  'segment'  'infinite'}) – Boundary conditions as described in
mps
.IdL ((iterable of) {int  None}) – Indices on the bonds, which correpond to ‘only identities to the left’. A single entry holds for all bonds.
IdR ((iterable of) {int  None}) – Indices on the bonds, which correpond to ‘only identities to the right’.
Ws_qtotal ((list of) total charge) – The qtotal to be used for each grid. Defaults to zero charges.
leg0 (
LegCharge
) – LegCharge for ‘wL’ of the leftmost W. By default, construct it.max_range (int  np.inf  None) – Maximum range of hopping/interactions (in unit of sites) of the MPO.
None
for unknown.
See also
grid_insert_ops()
used to plug in entries of the grid.
tenpy.linalg.np_conserved.grid_outer()
used for final conversion.

property
L
Number of physical sites; for an iMPO the len of the MPO unit cell.

property
dim
¶ List of local physical dimensions.

property
finite
¶ Distinguish MPO vs iMPO.
True for an MPO (
bc='finite', 'segment'
), False for an iMPO (bc='infinite'
).

property
chi
¶ Dimensions of the virtual bonds.

group_sites
(n=2, grouped_sites=None)[source]¶ Modify self inplace to group sites.
Group each n sites together using the
GroupedSite
. This might allow to do TEBD with a Trotter decomposition, or help the convergence of DMRG (in case of too long range interactions). Parameters
n (int) – Number of sites to be grouped together.
grouped_sites (None  list of
GroupedSite
) – The sites grouped together.

sort_legcharges
()[source]¶ Sort virtual legs by charges. In place.
The MPO seen as matrix of the
wL, wR
legs is usually very sparse. This sparsity is captured by the LegCharges for these bonds not being sorted and bunched. This requires a tensordot to do more blockmultiplications with smaller blocks. This is in general faster for large blocks, but might lead to a larger overhead for small blocks. Therefore, this function allows to sort the virtual legs by charges.

expectation_value
(psi, tol=1e10, max_range=100)[source]¶ Calculate
<psiselfpsi>/<psipsi>
.For a finite MPS, simply contract the network
<psiselfpsi>
. For an infinite MPS, it assumes that self is the a of terms, withIdL
andIdR
defined on each site. Under this assumption, it calculates the expectation value of terms with the leftmost nontrivial operator inside the MPO unit cell and returns the average value per site. Parameters
psi (
MPS
) – State for which the expectation value should be taken.tol (float) – Ignored for finite psi. For infinite MPO containing exponentially decaying longrange terms, stop evaluating further terms if the terms in LP have norm < tol.
max_range (int) – Ignored for finite psi. Contract at most
self.L * max_range
sites, even if tol is not reached. In that case, issue a warning.
 Returns
exp_val – The expectation value of self with respect to the state psi. For an infinite MPS: the density per site.
 Return type
float/complex

is_hermitian
(eps=1e10, max_range=None)[source]¶ Check if self is a hermitian MPO.
Shorthand for
self.is_equal(self.dagger(), eps, max_range)
.

is_equal
(other, eps=1e10, max_range=None)[source]¶ Check if self and other represent the same MPO to precision eps.
To compare them efficiently we view self and other as MPS and compare the overlaps
abs(<selfself> + <otherother>  2 Re(<selfother>)) < eps*(<selfself>+<otherother>)
 Parameters
other (
MPO
) – The MPO to compare to.eps (float) – Precision threshold what counts as zero.
max_range (None  int) – Ignored for finite MPS; for finite MPS we consider only the terms contained in the sites with indices
range(self.L + max_range)
. None defaults tomax_range
(orL
in case this is infinite or None).
 Returns
equal – Whether self equals other to the desired precision.
 Return type