File size: 3,033 Bytes
6288873
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import numpy as np
from scipy.sparse.linalg import LinearOperator, eigs

import jax.numpy as jnp

from varipeps.contractions import apply_contraction_jitted
from varipeps.peps import PEPS_Unit_Cell


def calculate_correlation_length(unitcell: PEPS_Unit_Cell, num_eigvals: int = 8):
    if num_eigvals < 2:
        raise ValueError(
            "Number of eigenvalues must be at least two to compute the correlation length."
        )

    initial_vector_left = apply_contraction_jitted(
        "corrlength_vector_left",
        (unitcell[0, 0][0][0].tensor,),
        (unitcell[0, 0][0][0],),
        (),
    )
    initial_vector_left = initial_vector_left.reshape(-1)

    initial_vector_top = apply_contraction_jitted(
        "corrlength_vector_top",
        (unitcell[0, 0][0][0].tensor,),
        (unitcell[0, 0][0][0],),
        (),
    )
    initial_vector_top = initial_vector_top.reshape(-1)

    def left_matvec(vec):
        vec = jnp.asarray(vec)
        for _, view in unitcell.iter_one_row(0):
            if vec.ndim != 4:
                vec = vec.reshape(
                    view[0, 0][0][0].T1.shape[0],
                    view[0, 0][0][0].tensor.shape[0],
                    view[0, 0][0][0].tensor.shape[0],
                    view[0, 0][0][0].T3.shape[0],
                )
            vec = apply_contraction_jitted(
                "corrlength_absorb_one_column",
                (view[0, 0][0][0].tensor,),
                (view[0, 0][0][0],),
                (vec,),
            )
        return vec.reshape(-1)

    left_lin_op = LinearOperator(
        (initial_vector_left.shape[0], initial_vector_left.shape[0]),
        matvec=left_matvec,
    )

    eig_left, eigvec_left = eigs(
        left_lin_op, k=num_eigvals, v0=initial_vector_left, which="LM"
    )

    eig_left = eig_left[np.argsort(np.abs(eig_left))[::-1]]
    eig_left /= np.abs(eig_left[0])

    corr_len_left = -1 / np.log(np.abs(eig_left[1]))

    def top_matvec(vec):
        vec = jnp.asarray(vec)
        for _, view in unitcell.iter_one_column(0):
            if vec.ndim != 4:
                vec = vec.reshape(
                    view[0, 0][0][0].T4.shape[3],
                    view[0, 0][0][0].tensor.shape[4],
                    view[0, 0][0][0].tensor.shape[4],
                    view[0, 0][0][0].T2.shape[3],
                )
            vec = apply_contraction_jitted(
                "corrlength_absorb_one_row",
                (view[0, 0][0][0].tensor,),
                (view[0, 0][0][0],),
                (vec,),
            )
        return vec.reshape(-1)

    top_lin_op = LinearOperator(
        (initial_vector_top.shape[0], initial_vector_top.shape[0]),
        matvec=top_matvec,
    )

    eig_top, eigvec_top = eigs(
        top_lin_op, k=num_eigvals, v0=initial_vector_top, which="LM"
    )

    eig_top = eig_top[np.argsort(np.abs(eig_top))[::-1]]
    eig_top /= np.abs(eig_top[0])

    corr_len_top = -1 / np.log(np.abs(eig_top[1]))

    return (corr_len_left, eig_left), (corr_len_top, eig_top)