Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add entanglement entropy examples #80

Merged
merged 8 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions examples/vumps/src/entropy.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using ITensors
using ITensorInfiniteMPS

# calculate -\sum_i rho_i log(rho_i)
function calc_vN_entropy(S)
ryanlevy marked this conversation as resolved.
Show resolved Hide resolved
SvN, norm = 0.0, 0.0
for n in 1:dim(S, 1)
p = S[n, n]^2
SvN -= p * log(p)
norm += p
end
return SvN, norm
end

# calculate von Neumann entropy of a MPS cut between sites b-1 and b
function entropy(ψ::MPS, b)
ψ = orthogonalize(ψ, b)
U, S, V = svd(ψ[b], (linkind(ψ, b - 1), siteind(ψ, b)))
SvN, norm = calc_vN_entropy(S)
@assert norm ≈ 1.0
return SvN
end

# calculate von Neumann entropy of an infinite MPS at cut b of the unit cell
function entropy(ψ::InfiniteCanonicalMPS, b)
#calculate entropy
C = ψ.C[b]
Ũ, S, Ṽ = svd(C, inds(C)[1])
SvN, norm = calc_vN_entropy(S)
@assert norm ≈ 1.0
return SvN
end
19 changes: 13 additions & 6 deletions examples/vumps/vumps_hubbard_extended.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using ITensors
using ITensorInfiniteMPS

include(
joinpath(
pkgdir(ITensorInfiniteMPS), "examples", "vumps", "src", "vumps_subspace_expansion.jl"
),
)
base_path = joinpath(pkgdir(ITensorInfiniteMPS), "examples", "vumps", "src")
src_files = [
joinpath(base_path, "vumps_subspace_expansion.jl"), joinpath(base_path, "entropy.jl")
]
for f in src_files
include(f)
end
ryanlevy marked this conversation as resolved.
Show resolved Hide resolved

##############################################################################
# VUMPS parameters
Expand Down Expand Up @@ -105,7 +107,7 @@ maxdims =
## setcutoff!(sweeps, cutoff)

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

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

S_finite = [entropy(ψfinite, b) for b in (Nfinite ÷ 2):(Nfinite ÷ 2 + N - 1)]
S_infinite = [entropy(ψ, b) for b in 1:N]

println("\nResults from VUMPS")
@show energy_infinite
@show energy_exact
Expand All @@ -133,6 +138,7 @@ println("\nResults from VUMPS")
@show Nup .+ Ndn
@show Sz
@show corr_infinite
@show S_infinite

println("\nResults from DMRG")
@show energy_finite
Expand All @@ -141,5 +147,6 @@ println("\nResults from DMRG")
@show Nup_finite .+ Ndn_finite
@show Sz_finite
@show corr_finite
@show S_finite

nothing
19 changes: 14 additions & 5 deletions examples/vumps/vumps_ising.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using ITensors
using ITensorInfiniteMPS

include(
joinpath(
pkgdir(ITensorInfiniteMPS), "examples", "vumps", "src", "vumps_subspace_expansion.jl"
),
)
base_path = joinpath(pkgdir(ITensorInfiniteMPS), "examples", "vumps", "src")
src_files = [
joinpath(base_path, "vumps_subspace_expansion.jl"), joinpath(base_path, "entropy.jl")
]
for f in src_files
include(f)
end

##############################################################################
# VUMPS/TDVP parameters
Expand Down Expand Up @@ -102,3 +104,10 @@ Sz2_infinite = expect(ψ.AL[2] * ψ.C[2], "Sz")

@show Sz1_finite, Sz2_finite
@show Sz1_infinite, Sz2_infinite

S_finite = [entropy(ψ_finite, b) for b in (nsite_finite ÷ 2):(nsite_finite ÷ 2 + nsite - 1)]
S_infinite = [entropy(ψ, b) for b in 1:nsite]
@show S_finite
@show S_infinite

nothing
4 changes: 2 additions & 2 deletions test/test_vumps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ end
ψfinite = randomMPS(sfinite, initstate)
nsweeps = 20
energy_finite_total, ψfinite = dmrg(
Hfinite, ψfinite; nsweeps, maxdims=10, cutoff=1e-10, outputlevel=0
Hfinite, ψfinite; nsweeps, maxdim=10, cutoff=1e-10, outputlevel=0
)

@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
Expand Down Expand Up @@ -142,7 +142,7 @@ end
ψfinite = randomMPS(sfinite, initstate)
nsweeps = 20
energy_finite_total, ψfinite = dmrg(
Hfinite, ψfinite; nsweeps, maxdims=10, cutoff=1e-10, outputlevel=0
Hfinite, ψfinite; nsweeps, maxdim=10, cutoff=1e-10, outputlevel=0
)

multisite_update_alg = "sequential"
Expand Down
2 changes: 1 addition & 1 deletion test/test_vumpsmpo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ end
ψfinite = randomMPS(sfinite, initstate)
nsweeps = 20
energy_finite_total, ψfinite = dmrg(
Hfinite, ψfinite; nsweeps, maxdims=10, cutoff=1e-10, outputlevel=0
Hfinite, ψfinite; nsweeps, maxdim=10, cutoff=1e-10, outputlevel=0
)
Szs_finite = expect(ψfinite, "Sz")

Expand Down
Loading