forked from shifushuimenu/lanczos-julia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lanczos_test.jl
50 lines (42 loc) · 1.26 KB
/
Lanczos_test.jl
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
using Test
include("Lanczos.jl")
@testset "6-site TFIsing" begin
N = 6
J = zeros(N, N)
for i = 1:N-1
J[i,i+1] = 1.0
J[i+1, i] = 1.0
end
J[1, N] = J[N, 1] = 1.0
h = hinit(J, hx=0.1, hz=0.0)
info = LanczosInfo(10, 200, false, 1.0)
gamma = hoperation!(h, ones(2^N), ones(2^N))
@time (Ks, g_out) = lanczos_reortho(h, ones(2^N), gamma, info)
# measure ground state energy
g2 = zeros(2^N)
g2 = hoperation!(h, g_out, g2)
GS_energy = sum(g2 .* g_out) / N
println("info=", info)
println("GS_energy=", GS_energy)
@test isapprox(GS_energy, -1.0025016072757338, atol=1e-8 )
end
@testset "twopass Lanczos 6-site TFIsing" begin
N = 6
J = zeros(N, N)
for i = 1:N-1
J[i,i+1] = 1.0
J[i+1, i] = 1.0
end
J[1, N] = J[N, 1] = 1.0
h = hinit(J, hx=0.1, hz=0.0)
info = LanczosInfo(10, 200, false, 1.0)
gamma = hoperation!(h, ones(2^N), ones(2^N))
@time (Ks, g_out) = lanczos_twopass(h, ones(2^N), gamma, info)
# measure ground state energy
g2 = zeros(2^N)
g2 = hoperation!(h, g_out, g2)
GS_energy = sum(g2 .* g_out) / N
println("info=", info)
println("GS_energy=", GS_energy)
@test isapprox(GS_energy, -1.0025016072757338, atol=1e-8 )
end