Skip to content

Commit 27fd437

Browse files
authored
Add entanglement entropy to examples (#80)
1 parent 3e633fc commit 27fd437

File tree

5 files changed

+59
-14
lines changed

5 files changed

+59
-14
lines changed

examples/vumps/src/entropy.jl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using ITensors
2+
using ITensorInfiniteMPS
3+
4+
# calculate -\sum_i rho_i log(rho_i)
5+
function entropy(S::ITensor)
6+
@assert order(S) == 2
7+
SvN, norm = 0.0, 0.0
8+
for n in 1:dim(S, 1)
9+
p = S[n, n]^2
10+
SvN -= p * log(p)
11+
norm += p
12+
end
13+
return SvN, norm
14+
end
15+
16+
# calculate von Neumann entropy of a MPS cut between sites b-1 and b
17+
function entropy::MPS, b)
18+
ψ = orthogonalize(ψ, b)
19+
U, S, V = svd(ψ[b], (linkind(ψ, b - 1), siteind(ψ, b)))
20+
SvN, norm = entropy(S)
21+
@assert norm 1.0
22+
return SvN
23+
end
24+
25+
# calculate von Neumann entropy of an infinite MPS at cut b of the unit cell
26+
function entropy::InfiniteCanonicalMPS, b)
27+
#calculate entropy
28+
C = ψ.C[b]
29+
Ũ, S, Ṽ = svd(C, inds(C)[1])
30+
SvN, norm = entropy(S)
31+
@assert norm 1.0
32+
return SvN
33+
end

examples/vumps/vumps_hubbard_extended.jl

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
using ITensors
22
using ITensorInfiniteMPS
33

4-
include(
5-
joinpath(
6-
pkgdir(ITensorInfiniteMPS), "examples", "vumps", "src", "vumps_subspace_expansion.jl"
7-
),
8-
)
4+
base_path = joinpath(pkgdir(ITensorInfiniteMPS), "examples", "vumps", "src")
5+
src_files = ["vumps_subspace_expansion.jl", "entropy.jl"]
6+
for f in src_files
7+
include(joinpath(base_path, f))
8+
end
99

1010
##############################################################################
1111
# VUMPS parameters
@@ -105,7 +105,7 @@ maxdims =
105105
## setcutoff!(sweeps, cutoff)
106106

107107
println("\nRun DMRG on $Nfinite sites")
108-
energy_finite_total, ψfinite = dmrg(Hfinite, ψfinite; nsweeps, maxdims, cutoff)
108+
energy_finite_total, ψfinite = dmrg(Hfinite, ψfinite; nsweeps, maxdim=maxdims, cutoff)
109109
println("\nEnergy density")
110110
@show energy_finite_total / Nfinite
111111

@@ -125,6 +125,9 @@ corr_finite = correlation_matrix(
125125
ψfinite, "Cdagup", "Cup"; sites=Int(Nfinite / 2):Int(Nfinite / 2 + 9)
126126
)
127127

128+
S_finite = [entropy(ψfinite, b) for b in (Nfinite ÷ 2):(Nfinite ÷ 2 + N - 1)]
129+
S_infinite = [entropy(ψ, b) for b in 1:N]
130+
128131
println("\nResults from VUMPS")
129132
@show energy_infinite
130133
@show energy_exact
@@ -133,6 +136,7 @@ println("\nResults from VUMPS")
133136
@show Nup .+ Ndn
134137
@show Sz
135138
@show corr_infinite
139+
@show S_infinite
136140

137141
println("\nResults from DMRG")
138142
@show energy_finite
@@ -141,5 +145,6 @@ println("\nResults from DMRG")
141145
@show Nup_finite .+ Ndn_finite
142146
@show Sz_finite
143147
@show corr_finite
148+
@show S_finite
144149

145150
nothing

examples/vumps/vumps_ising.jl

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
using ITensors
22
using ITensorInfiniteMPS
33

4-
include(
5-
joinpath(
6-
pkgdir(ITensorInfiniteMPS), "examples", "vumps", "src", "vumps_subspace_expansion.jl"
7-
),
8-
)
4+
base_path = joinpath(pkgdir(ITensorInfiniteMPS), "examples", "vumps", "src")
5+
src_files = ["vumps_subspace_expansion.jl", "entropy.jl"]
6+
for f in src_files
7+
include(joinpath(base_path, f))
8+
end
99

1010
##############################################################################
1111
# VUMPS/TDVP parameters
@@ -102,3 +102,10 @@ Sz2_infinite = expect(ψ.AL[2] * ψ.C[2], "Sz")
102102

103103
@show Sz1_finite, Sz2_finite
104104
@show Sz1_infinite, Sz2_infinite
105+
106+
S_finite = [entropy(ψ_finite, b) for b in (nsite_finite ÷ 2):(nsite_finite ÷ 2 + nsite - 1)]
107+
S_infinite = [entropy(ψ, b) for b in 1:nsite]
108+
@show S_finite
109+
@show S_infinite
110+
111+
nothing

test/test_vumps.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ end
3636
ψfinite = randomMPS(sfinite, initstate)
3737
nsweeps = 20
3838
energy_finite_total, ψfinite = dmrg(
39-
Hfinite, ψfinite; nsweeps, maxdims=10, cutoff=1e-10, outputlevel=0
39+
Hfinite, ψfinite; nsweeps, maxdim=10, cutoff=1e-10, outputlevel=0
4040
)
4141

4242
@testset "VUMPS/TDVP with: multisite_update_alg = $multisite_update_alg, conserve_qns = $conserve_qns, nsites = $nsites, time_step = $time_step, localham_type = $localham_type" for multisite_update_alg in
@@ -142,7 +142,7 @@ end
142142
ψfinite = randomMPS(sfinite, initstate)
143143
nsweeps = 20
144144
energy_finite_total, ψfinite = dmrg(
145-
Hfinite, ψfinite; nsweeps, maxdims=10, cutoff=1e-10, outputlevel=0
145+
Hfinite, ψfinite; nsweeps, maxdim=10, cutoff=1e-10, outputlevel=0
146146
)
147147

148148
multisite_update_alg = "sequential"

test/test_vumpsmpo.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ end
105105
ψfinite = randomMPS(sfinite, initstate)
106106
nsweeps = 20
107107
energy_finite_total, ψfinite = dmrg(
108-
Hfinite, ψfinite; nsweeps, maxdims=10, cutoff=1e-10, outputlevel=0
108+
Hfinite, ψfinite; nsweeps, maxdim=10, cutoff=1e-10, outputlevel=0
109109
)
110110
Szs_finite = expect(ψfinite, "Sz")
111111

0 commit comments

Comments
 (0)