File size: 802 Bytes
1c703f0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
The LRM is based on the Lanczos algorithm for tridiagonalizing sparse Hermitian matrices.
The Lanczos algorithm is usually used to obtain extremal eigenvalues and the corresponding eigenstates,
 but it can also be used to calculate spectral property
"""

from .fast_math import op_ket, bra_ket, init_v0, init_vrand
import math


def compute_lanczos(ham, m_limit):
    b1 = 0
    phi_0 = init_v0(ham.shape[1])
    phi_1 = init_vrand(phi_0.shape)
    a_ = []
    b_ = [b1]
    for m in range(1, m_limit):
        psi_m = op_ket(ham, phi_1) - b_[m - 1] * phi_0
        a_m = bra_ket(psi_m, phi_1)
        a_.append(a_m)
        psi_m = psi_m - a_m * phi_1
        b_m1 = math.sqrt(bra_ket(psi_m, psi_m))
        b_.append(b_m1)

        phi_0 = phi_1
        phi_1 = psi_m / b_m1

    return [a_, b_]