Environment BP#
Belief propagation environments#
- class yastn.tn.fpeps.EnvBP(psi, init='eye', tol_positive=1e-12, which='BP')[source]#
Environment used in belief propagation contraction scheme.
- Parameters:
psi (yastn.tn.Peps) – PEPS lattice to be contracted using BP. If
psihas physical legs, a double-layer PEPS with no physical legs is formed.init (str) – None, ‘eye’. Initialization scheme, see
yastn.tn.fpeps.EnvBP.reset_().which (str) – Type of environment from ‘BP’, ‘NN+BP’, ‘NNN+BP’
- bond_metric(Q0, Q1, s0, s1, dirn)[source]#
Calculates bond metric within BP environment.
If which == 'BP': t t ║ ║ l════Q0══ ══Q1═══r ║ ║ b b If which == 'NN+BP': t t ║ ║ l══(-1 +0)══(-1 +1)══r ║ ║ l═════Q0══ ══Q1════r ║ ║ l══(+1 +0)══(+1 +1)══l ║ ║ b b If which == 'NNN+BP': t t t t ║ ║ ║ ║ l══(-1 -1)=(-1 +0)══(-1 +1)=(-1 +2)══r ║ ║ ║ ║ l══(+0 -1)════Q0══ ══Q1═══(+0 +2)══r ║ ║ ║ ║ l══(+1 -1)=(+1 +0)══(+1 +1)=(+1 +2)══r ║ ║ ║ ║ b b b b
- classmethod from_dict(d, config=None)[source]#
De-serializes EnvBP from the dictionary
d. Seeyastn.Tensor.from_dict()for further description.
- iterate_(max_sweeps=1, iterator=False, diff_tol=None, **kwargs)[source]#
Perform BP updates
yastn.tn.fpeps.EnvBP.update_()until convergence. Convergence can be measured based on maximal difference between old and new tensors.Outputs iterator if
iterator==True, which allows inspectingenv, e.g., calculating expectation values, outside ofiterate_function after each sweeps.- Parameters:
max_sweeps (int) – Maximal number of sweeps.
iterator (bool) – If True,
iterate_returns a generator that would yield output after every sweep. The default is False, in which caseiterate_sweeps are performed immediately.diff_tol (float) – Convergence tolerance for the change of belief tensors in one iteration. The default is None, in which case convergence is not checked and it is up to user to implement convergence check.
- Returns:
Generator if iterator is True.
BP_out(NamedTuple) –
NamedTuple including fields:
sweepsnumber of performed lbp updates.max_diffmaximal difference between old and new belief tensors.convergedwhether convergence based ondiff_tolhas been reached.
- measure_1site(O, site=None) dict[source]#
Calculate local expectation values within BP environment.
Returns a number if
siteis provided. IfNone, returns a dictionary {site: value} for all unique lattice sites.- Parameters:
env (EnvBP) – Class containing BP environment tensors along with lattice structure data.
O (Tensor) – Single-site operator
- measure_nn(O, P, bond=None) dict[source]#
Calculate nearest-neighbor expectation values within BP environment.
Return a number if the nearest-neighbor
bondis provided. IfNone, returns a dictionary {bond: value} for all unique lattice bonds.- Parameters:
O, P (yastn.Tensor) – Calculate <O_s0 P_s1>. P is applied first, which might matter for fermionic operators.
bond (yastn.tn.fpeps.Bond | tuple[tuple[int, int], tuple[int, int]]) – Bond of the form (s0, s1). Sites s0 and s1 should be nearest-neighbors on the lattice.
- to_dict(level=2)[source]#
Serialize EnvBP to a dictionary. Complementary function is
yastn.EnvBP.from_dict()or a generalyastn.from_dict(). Seeyastn.Tensor.to_dict()for further description.
- class yastn.tn.fpeps.envs.EnvBP_local(t: Tensor | None = None, l: Tensor | None = None, b: Tensor | None = None, r: Tensor | None = None, tR: Tensor | None = None, lR: Tensor | None = None, bR: Tensor | None = None, rR: Tensor | None = None)[source]#
Dataclass for BP environment tensors at a single Peps site on square lattice. Contains fields
t,l,b,r