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 psi has 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
iterate_(max_sweeps=1, iterator_step=None, diff_tol=None)[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_step is given, which allows inspecting env, e.g., calculating expectation values, outside of iterate_ function after every iterator_step sweeps.

Parameters:
  • max_sweeps (int) – Maximal number of sweeps.

  • iterator_step (int) – If int, iterate_ returns a generator that would yield output after every iterator_step sweeps. The default is None, in which case iterate_ 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_step is not None.

  • BP_out(NamedTuple)

    NamedTuple including fields:

    • sweeps number of performed lbp updates.

    • max_diff maximal difference between old and new belief tensors.

    • converged whether convergence based on diff_tol has been reached.

measure_1site(O, site=None) dict[source]#

Calculate local expectation values within BP environment.

Returns a number if site is provided. If None, 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 bond is provided. If None, 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.

update_() float[source]#

Perform one step of BP update. Environment tensors are updated in place.

Returns:

diff

Return type:

maximal difference between belief tensors befor and after the update.

class yastn.tn.fpeps.EnvBP_local(t: Tensor | None = None, l: Tensor | None = None, b: Tensor | None = None, r: Tensor | None = None)[source]#

Dataclass for BP environment tensors at a single Peps site on square lattice.

Contains fields t, l, b, r