Environment BP#

Belief propagation environments#

class yastn.tn.fpeps.EnvCTM(psi, init='rand', leg=None)[source]#

Environment used in Corner Transfer Matrix Renormalization Group algorithm.

Note:

Index convention for environment tensors:

C--1 0--T--2 0--C
|       |       |
0       1       1
2               0
|               |
T--1         1--T
|               |
0               2
1       1       0
|       |       |
C--0 2--T--0 1--C
  • enlarged corners: anti-clockwise

Parameters:
  • psi (yastn.tn.Peps) – PEPS lattice to be contracted using CTM. If psi has physical legs, a double-layer PEPS with no physical legs is formed.

  • init (str) – None, ‘eye’ or ‘rand’. Initialization scheme, see yastn.tn.fpeps.EnvCTM.reset_().

  • leg (Optional[yastn.Leg]) – Passed to yastn.tn.fpeps.EnvCTM.reset_() to further customize initialization.

bond_metric(Q0, Q1, s0, s1, dirn)[source]#

Calculates Full-Update metric tensor.

If dirn == 'h':

    tl═══t═══════t═══tr
    ║    ║       ║    ║
    l════Q0══  ══Q1═══r
    ║    ║       ║    ║
    bl═══b═══════b═══br


If dirn == 'v':

    tl═══t═══tr
    ║    ║    ║
    l═══0Q0═══r
    ║    ╳    ║
    l═══1Q1═══r
    ║    ║    ║
    bl═══b═══br
iterate_(opts_svd=None, method='2site', max_sweeps=1, iterator_step=None, corner_tol=None, truncation_f: Callable = None, **kwargs)#

Perform CTMRG updates yastn.tn.fpeps.EnvCTM.update_() until convergence. Convergence can be measured based on singular values of CTM environment corner tensors.

Outputs iterator if iterator_step is given, which allows inspecting env, e.g., calculating expectation values, outside of ctmrg_ function after every iterator_step sweeps.

Parameters:
  • opts_svd (dict) – A dictionary of options to pass to SVD truncation algorithm. This sets EnvCTM bond dimension.

  • method (str) – ‘2site’ or ‘1site’. The default is ‘2site’. ‘2site’ uses the standard 4x4 enlarged corners, allowing to enlarge EnvCTM bond dimension. ‘1site’ uses smaller 4x2 corners. It is significantly faster, but is less stable and does not allow to grow EnvCTM bond dimension.

  • max_sweeps (int) – Maximal number of sweeps.

  • iterator_step (int) – If int, ctmrg_ returns a generator that would yield output after every iterator_step sweeps. The default is None, in which case ctmrg_ sweeps are performed immediately.

  • corner_tol (float) – Convergence tolerance for the change of singular values of all corners in a single update. The default is None, in which case convergence is not checked and it is up to user to implement convergence check.

  • truncation_f – Custom projector truncation function with signature truncation_f(S: Tensor)->Tensor, consuming rank-1 tensor with singular values. If provided, truncation parameters passed to SVD decomposition are ignored.

  • checkpoint_move (Union[str, bool]) – Whether to use checkpointing for the CTM updates. The default is False. Otherwise, in case of PyTorch backend it can be set to ‘reentrant’ for reentrant checkpointing or ‘nonreentrant’ for non-reentrant checkpointing, see https://pytorch.org/docs/stable/checkpoint.html.

  • use_qr (bool) – Whether to include intermediate QR decomposition while calculating projectors. The default is True.

Returns:

  • Generator if iterator_step is not None.

  • CTMRG_out(NamedTuple)

    NamedTuple including fields:

    • sweeps number of performed ctmrg updates.

    • max_dsv norm of singular values change in the worst corner in the last sweep.

    • converged whether convergence based on corner_tol has been reached.

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

Calculate local expectation values within CTM environment.

Returns a number if site is provided. If None, returns a dictionary {site: value} for all unique lattice sites.

Parameters:
  • env (EnvCtm) – Class containing CTM 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 CTM 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_(opts_svd, method='2site', **kwargs)[source]#

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

The function performs a CTMRG update for a square lattice using the corner transfer matrix renormalization group (CTMRG) algorithm. The update is performed in two steps: a horizontal move and a vertical move. The projectors for each move are calculated first, and then the tensors in the CTM environment are updated using the projectors. The boundary conditions of the lattice determine whether trivial projectors are needed for the move.

Parameters:
  • opts_svd (dict) – A dictionary of options to pass to SVD truncation algorithm. This sets EnvCTM bond dimension.

  • method (str) – ‘2site’ or ‘1site’. The default is ‘2site’. ‘2site’ uses the standard 4x4 enlarged corners, allowing to enlarge EnvCTM bond dimension. ‘1site’ uses smaller 4x2 corners. It is significantly faster, but is less stable and does not allow to grow EnvCTM bond dimension.

  • checkpoint_move (bool) – Whether to use (reentrant) checkpointing for the move. The default is False

Returns:

proj

Return type:

Peps structure loaded with CTM projectors related to all lattice site.