Expectation values#
See examples at Expectation values.
Overlaps and MPO expectation values#
Measurement of the overlap between two MPSs is calculated by contracting a network formed by MPS and conjugate of another or the same MPS. Works also for two MPOs.
- yastn.tn.mps.measure_overlap(bra, ket) Number [source]#
Calculate overlap \(\langle \textrm{bra}|\textrm{ket} \rangle\). Conjugate of MPS
bra
is computed internally.MPSs
bra
andket
must have matching length, physical dimensions, and symmetry.- Parameters:
bra (yastn.tn.mps.MpsMpoOBC) – An MPS which will be conjugated.
ket (yastn.tn.mps.MpsMpoOBC)
While the above allows calculating the norm of MPS or MPO, a dedicated method extracts the norm through canonization. This can be more precise for norms close to zero.
Measurement of MPO’s expectation value is calculated by contracting a network formed by MPS, MPO, and a conjugate of the same or different MPS. Works also for three MPOs.
- yastn.tn.mps.measure_mpo(bra, op: MpsMpoOBC | Sequence[tuple(MpsMpoOBC, number)], ket) Number [source]#
Calculate expectation value \(\langle \textrm{bra}|\textrm{op}|\textrm{ket} \rangle\).
Conjugate of MPS
bra
is computed internally. MPSsbra
,ket
, and MPOop
must have matching length, physical dimensions, and symmetry.- Parameters:
bra (yastn.tn.mps.MpsMpoOBC) – An MPS which will be conjugated.
op (yastn.tn.mps.MpsMpoOBC or Sequence[tuple(MpsMpoOBC,number)]) – Operator written as (sums of) MPO.
ket (yastn.tn.mps.MpsMpoOBC)
Shorthand notation#
The above function can be also executed by
One- and two-point expectation values#
- yastn.tn.mps.measure_1site(bra, O, ket, sites=None) dict[int, number] [source]#
Calculate expectation values \(\langle \textrm{bra}|\textrm{O}_i|\textrm{ket} \rangle\) for local operator
O
at sites i.O
can be provided as a dictionary {site: operator}, limiting the calculation to provided sites.sites
can also be provided in the form of a list.Conjugate of MPS
bra
is computed internally. For fermionic operators, a Jordan-Wigner string related to the operator charge is included in the contraction.- Parameters:
bra (yastn.tn.mps.MpsMpoOBC) – An MPS which will be conjugated.
O (yastn.Tensor | dict[int, yastn.Tensor]) – A rank-2 operator, or a dictionary of such operators {site: operator}. In the second case, all operators need to have the same charge.
ket (yastn.tn.mps.MpsMpoOBC)
sites (int | Sequence[int] | None) – It controls which 1-sites observables to calculate. If int is provided here, compute the expectation value for this single site and return a float. In other cases, a dictionary {site: float} is returned. The default is None, in which case the calculation is done for all sites.
- yastn.tn.mps.measure_2site(bra, O, P, ket, bonds='<') dict[tuple[int, int], float] | float [source]#
Calculate expectation values \(\langle \textrm{bra}|\textrm{O}_i \textrm{P}_j|\textrm{ket} \rangle\) of local operators
O
andP
for pairs of lattice sites \(i, j\).Conjugate of MPS
bra
is computed internally. Fermionic strings are incorporated for fermionic operators by employingyastn.swap_gate()
.- Parameters:
bra (yastn.tn.mps.MpsMpoOBC) – An MPS which will be conjugated.
O, P (yastn.Tensor or dict) – Operators with signature (1, -1). Each can also be a dictionary {site: operator} with all operators of the same charge.
ket (yastn.tn.mps.MpsMpoOBC)
bonds (tuple[int, int] | Sequence[tuple[int, int]] | str) – Which 2-site correlators to calculate. For a single bond, tuple[int, int], return float. Otherwise, return dict[bond, float]. It is possible to provide a string to build a list of bonds as:
‘<’ for all i < j.
‘=’ for all i == j.
‘>’ for all i > j.
‘a’ for all i, j; equivalent to “<=>”.
‘rx’ for all i, i+x with OBC, e.g. “r1” for nearest-neighbours; x can be negative.
‘p’ to include PBC terms in ‘rx’.
The default is ‘<’.
Schmidt values and entropy profile#
The Schmidt values are computed by performing bipartition of the MPS/MPO across each of the bonds. This amounts to SVD decomposition with respect to a bond, where all sites to the left are in left-canonical form and all sites to the right are in right-canonical form.
- MpsMpoOBC.get_Schmidt_values() Sequence[Tensor] [source]#
Schmidt values for bipartition across all bonds along MPS/MPO from the first to the last site, including trivial leftmost and rightmost cuts. This gives a list with N+1 elements. Schmidt values are stored as diagonal tensors and are normalized.
The SVD is used to calculate the entropy at each bond. For \(\alpha \neq 1\), this gives the Renyi entropy, \(S_\alpha(\rho)=\frac{1}{1-\alpha}\log_2 Tr(\rho^\alpha)\), where \(\rho\) indicates a reduced density matrix of the system with all sites to the right of the cut traced out. For \(\alpha=1\) we get von Neumann entropy, \(S_1(\rho)=-Tr(\rho \log_2 \rho)\). The entropy is counted in bits, i.e., using base-2 logarithm.
- MpsMpoOBC.get_entropy(alpha=1) Sequence[Number] [source]#
Entropy of bipartition across each bond, along MPS/MPO from the first to the last site, including trivial leftmost and rightmost cuts. This gives a list with N+1 elements.
- Parameters:
alpha (int) – Order of Renyi entropy.
alpha=1
(the default) is von Neuman entropy: \(-{\rm Tr}(\rho \cdot {\rm log2}(\rho))\) otherwise: \(\frac{1}{1-alpha} {\rm log2}({\rm Tr}(\rho ^{alpha}))\)
Sampling#
- mps.sample(projectors, number=1, return_probabilities=False) ndarray[int] | tuple[ndarray[int], Sequence[float]] #
Sample random configurations from an MPS psi.
Probabilities follow from \(|psi \rangle\langle psi|\). Works also for purification. Output samples as numpy array of integers, where samples[k, n] give a projector’s index in the k-th sample on the n-th MPS site.
It does not check whether projectors sum up to identity; calculated probabilities of provided projectors are normalized to one.
- Parameters:
projectors (Dict[Any, yast.Tensor] | Sequence[yast.Tensor] | Dict[Site, Dict[Any, yast.Tensor]]) – Local vector states (or projectors) to sample from. Their orthogonality or local basis completeness is not checked (normalization is checked). We can provide a dict(key: projector), where the same set of projectors is used at each site. The keys should be integers, to fit into the output samples array. Projectors can also be provided as a list, and then the keys follow from enumeration. Finally, we can provide a dictionary between each site and sets of projectors (to have different projections at various sites).
number (int) – Number of drawn samples.
return_probabilities (bool) – Whether to also return probability to find each sample in the state. If
True
, return: samples, probabilities. IfFalse
(the default), return: samples.
Note
Depending on the basis, sampling might break the symmetry of the state psi. In this case, psi and local states/projectors should first be cast down to dense representation. It is important to make sure that the local basis ordering between state sites and projectors/vectors is maintained
Example
ops = yastn.operators.SpinlessFermions(sym='U1') I = mps.product_mpo(ops.I(), N=8) psi = mps.random_mps(I, n=4, D_total=8) # random state with 8 sites and 4 particles. projectors = [ops.vec_n(0), ops.vec_n(1)] # empty and full local states samples = mps.sample(psi, projectors, number=15)