Skip to content

Commit 24c1630

Browse files
authored
Handle diagonal C - ensure TensorKit v0.14 compatibility (#223)
* ensure C is not diagonal * improve entanglement spectrum/entropy
1 parent 19a2cd1 commit 24c1630

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

src/algorithms/changebonds/svdcut.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ function changebonds(ψ::InfiniteMPS, alg::SvdCut)
9191
ψ = if space(ncr, 1) != space(copied[1], 1)
9292
InfiniteMPS(copied)
9393
else
94-
InfiniteMPS(copied, complex(ncr))
94+
C₀ = TensorMap(complex(ncr))
95+
InfiniteMPS(copied, C₀)
9596
end
9697
return normalize!(ψ)
9798
end

src/algorithms/toolbox.jl

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,20 @@ Calculate the Von Neumann entanglement entropy of a given MPS. If an integer `si
55
given, the entropy is across the entanglement cut to the right of site `site`. Otherwise, a
66
vector of entropies is returned, one for each site.
77
"""
8-
entropy(state::InfiniteMPS) = map(c -> -tr(safe_xlogx(c * c')), state.C);
8+
entropy(state::InfiniteMPS) = map(Base.Fix1(entropy, state), 1:length(state))
99
function entropy(state::Union{FiniteMPS,WindowMPS,InfiniteMPS}, loc::Int)
10-
return -tr(safe_xlogx(state.C[loc] * state.C[loc]'))
11-
end;
10+
S = zero(real(scalartype(state)))
11+
tol = eps(typeof(S))
12+
for (c, b) in entanglement_spectrum(state, loc)
13+
s = zero(S)
14+
for x in b
15+
x < tol && break
16+
s += (x * log(x))^2
17+
end
18+
S += oftype(S, dim(c) * s)
19+
end
20+
return S
21+
end
1222

1323
# function infinite_temperature(H::MPOHamiltonian)
1424
# return [permute(isomorphism(storagetype(H[1, 1, 1]), oneunit(sp) * sp,
@@ -84,9 +94,8 @@ matrix to the right of a given site. This is a dictionary mapping the charge to
8494
values.
8595
"""
8696
function entanglement_spectrum(st::Union{InfiniteMPS,FiniteMPS,WindowMPS}, site::Int=0)
87-
@assert site <= length(st)
88-
_, S, = tsvd(st.C[site])
89-
return TensorKit.SectorDict(c => real(diag(b)) for (c, b) in blocks(S))
97+
checkbounds(st, site)
98+
return LinearAlgebra.svdvals(st.C[site])
9099
end
91100

92101
"""

src/utility/utility.jl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,6 @@ function randomize!(a::AbstractBlockTensorMap)
148148
return a
149149
end
150150

151-
function safe_xlogx(t::AbstractTensorMap, eps=eps(real(scalartype(t))))
152-
(U, S, V) = tsvd(t; alg=SVD(), trunc=truncbelow(eps))
153-
return U * S * log(S) * V
154-
end
155-
156151
"""
157152
tensorexpr(name::Symbol, ind_out, [ind_in])
158153

0 commit comments

Comments
 (0)