/
compressions.jl
98 lines (73 loc) · 2.01 KB
/
compressions.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
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
98
@testset "Canonisation and Compression" begin
D = 10
Dcut = 5
d = 2
sites = 5
T = Float32
ψ = CUDA.randn(CuMPS{T}, sites, D, d)
ϕ = CUDA.randn(CuMPS{T}, sites, D, d)
χ = CUDA.randn(CuMPS{T}, sites, D, d)
Φ = CUDA.randn(CuMPS{T}, sites, D, d)
@testset "Canonisation (left)" begin
canonise!(ψ, :left)
show(ψ)
is_left_normalized = true
for i ∈ 1:length(ψ)
A = ψ[i]
DD = size(A, 3)
@cutensor Id[x, y] := conj(A[α, σ, x]) * A[α, σ, y] order = (α, σ)
is_left_normalized *= I(DD) ≈ Id
end
@test is_left_normalized
@test dot(ψ, ψ) ≈ 1
end
@testset "Canonisation (right)" begin
canonise!(ϕ, :right)
show(ϕ)
is_right_normalized = true
for i ∈ 1:length(ϕ)
B = ϕ[i]
DD = size(B, 1)
@cutensor Id[x, y] := B[x, σ, α] * conj(B[y, σ, α]) order = (α, σ)
is_right_normalized *= I(DD) ≈ Id
end
@test is_right_normalized
@test dot(ϕ, ϕ) ≈ 1
end
@testset "Cauchy-Schwarz inequality (after truncation)" begin
@test abs(dot(ϕ, ψ)) <= norm(ϕ) * norm(ψ)
end
@testset "Canonisation (both)" begin
canonise!(χ)
show(χ)
@test dot(χ, χ) ≈ 1
end
@testset "Truncation (SVD, right)" begin
truncate!(ψ, :right, Dcut)
show(ψ)
@test dot(ψ, ψ) ≈ 1
end
@testset "Truncation (SVD, left)" begin
truncate!(ψ, :left, Dcut)
show(ψ)
@test dot(ψ, ψ) ≈ 1
end
@testset "Variational compression" begin
Dcut = 5
tol = 1E-4
max_sweeps = 5
canonise!(Φ, :right)
@test dot(Φ, Φ) ≈ 1
Ψ = compress(Φ, Dcut, tol, max_sweeps)
show(Ψ)
@test dot(Ψ, Ψ) ≈ 1
println("(Ψ, Ψ) = ", dot(Ψ, Ψ))
println("(Φ, Φ) = ", dot(Φ, Φ))
overlap = dot(Ψ, Φ)
dist1 = 2 - 2 * real(overlap)
dist2 = norm(Ψ)^2 + norm(Φ)^2 - 2 * real(overlap)
@test abs(dist1 - dist2) < 1e-5
println("(Φ, Ψ) = ", overlap)
println("dist(Φ, Ψ)^2 = ", dist2)
end
end