forked from wangleiphy/TRG
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtrg.jl
81 lines (70 loc) · 2.13 KB
/
trg.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
using LinearAlgebra:svd, Diagonal
using TensorOperations
function TRG(K::Float64, Dcut::Int, no_iter::Int)
D = 2
inds = collect(1:D)
T = zeros(Float64, D, D, D, D)
M = [[sqrt(cosh(K)) sqrt(sinh(K))];
[sqrt(cosh(K)) -sqrt(sinh(K))];
]
for i in inds, j in inds, k in inds, l in inds
for a in inds
T[i, j, k, l] += M[a, i] * M[a, j] * M[a, k] * M[a, l]
end
end
lnZ = 0.0
for n in collect(1:no_iter)
#println(n, " ", maximum(T), " ", minimum(T))
maxval = maximum(T)
T = T/maxval
lnZ += 2^(no_iter-n+1)*log(maxval)
D_new = min(D^2, Dcut)
Ma = reshape(permutedims(T, (3, 2, 1, 4)), (D^2, D^2))
Mb = reshape(permutedims(T, (4, 3, 2, 1)), (D^2, D^2))
F = svd(Ma)
<<<<<<< HEAD
for x in inds, y in inds, m in inds_new
S1[x, y, m] = sqrt(F.S[m]) * F.U[x+D*(y-1), m]
S3[x, y, m] = sqrt(F.S[m]) * F.Vt[m, x+D*(y-1)]
end
F = svd(Mb)
for x in inds, y in inds, m in inds_new
S2[x, y, m] = sqrt(F.S[m]) * F.U[x+D*(y-1), m]
S4[x, y, m] = sqrt(F.S[m]) * F.Vt[m, x+D*(y-1)]
end
=======
S1 = reshape(F.U[:,1:D_new]*Diagonal(sqrt.(F.S[1:D_new])), (D, D, D_new))
S3 = reshape(Diagonal(sqrt.(F.S[1:D_new]))*F.Vt[1:D_new, :], (D_new, D, D))
F = svd(Mb)
S2 = reshape(F.U[:,1:D_new]*Diagonal(sqrt.(F.S[1:D_new])), (D, D, D_new))
S4 = reshape(Diagonal(sqrt.(F.S[1:D_new]))*F.Vt[1:D_new, :], (D_new, D, D))
>>>>>>> 3fe5a29dfdf36f08b9fbb60c3d56b2961aea197e
@tensor T_new[r, u, l, d] := S1[w, a, r] * S2[a, b, u] * S3[l, b, g] * S4[d, g, w]
D = D_new
<<<<<<< HEAD
inds = inds_new
=======
>>>>>>> 3fe5a29dfdf36f08b9fbb60c3d56b2961aea197e
T = T_new
end
trace = 0.0
for i in collect(1:D)
trace += T[i, i, i, i]
end
lnZ += log(trace)
end
Dcut = 10
n = 30
ts = 0.1:0.1:3;
β = inv.(ts);
@show "=====TRG======"
lnZ = []
for K in β
t = 1.0/K
#T = Ising( K )
y = TRG(K, Dcut, n);
#@show lnZ
println(1/K, " ", y/2^n)
push!(lnZ,y/2^n)
end
F = - ts.* lnZ