Skip to content

Commit e5b33b6

Browse files
authored
Bump compat for TensorKit 0.16 and MatrixAlgebraKit 0.6 (#365)
* Bump TK and MAK compat * remove `_left_orth` and `_right_orth` workarounds * refactor operator orthogonalization to use new orths * ensure positive QR/LQ in IDMRG * fix space sampling * correct for `SectorVector` * update minimum BlockTensorKit requirement
1 parent 48d65b8 commit e5b33b6

File tree

11 files changed

+40
-60
lines changed

11 files changed

+40
-60
lines changed

Project.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "MPSKit"
22
uuid = "bb1c41ca-d63c-52ed-829e-0820dda26502"
3-
authors = "Lukas Devos, Maarten Van Damme and contributors"
43
version = "0.13.8"
4+
authors = "Lukas Devos, Maarten Van Damme and contributors"
55

66
[deps]
77
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
@@ -26,23 +26,23 @@ VectorInterface = "409d34a3-91d5-4945-b6ec-7529ddf182d8"
2626
[compat]
2727
Accessors = "0.1"
2828
Aqua = "0.8.9"
29-
BlockTensorKit = "0.3"
29+
BlockTensorKit = "0.3.4"
3030
Combinatorics = "1"
3131
Compat = "3.47, 4.10"
3232
DocStringExtensions = "0.9.3"
3333
HalfIntegers = "1.6.0"
3434
KrylovKit = "0.8.3, 0.9.2, 0.10"
3535
LinearAlgebra = "1.6"
3636
LoggingExtras = "~1.0"
37-
MatrixAlgebraKit = "0.5.0"
37+
MatrixAlgebraKit = "0.6"
3838
OhMyThreads = "0.7, 0.8"
3939
OptimKit = "0.3.1, 0.4"
4040
Pkg = "1"
4141
Plots = "1.40"
4242
Printf = "1"
4343
Random = "1"
4444
RecipesBase = "1.1"
45-
TensorKit = "0.15.1"
45+
TensorKit = "0.16"
4646
TensorKitManifolds = "0.7"
4747
TensorOperations = "5"
4848
Test = "1"

src/algorithms/changebonds/randexpand.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ Sample basis states within a given `V::VectorSpace` by creating weights for each
8282
are distributed uniformly, and then truncating according to the given `strategy`.
8383
"""
8484
function sample_space(V, strategy)
85-
S = TensorKit.SectorDict(c => Random.rand(dim(V, c)) for c in sectors(V))
85+
S = TensorKit.SectorVector{Float64}(undef, V)
86+
Random.rand!(parent(S))
8687
ind = MatrixAlgebraKit.findtruncated(S, strategy)
8788
return TensorKit.Factorizations.truncate_space(V, ind)
8889
end

src/algorithms/changebonds/svdcut.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,13 @@ function changebonds!(H::FiniteMPOHamiltonian, alg::SvdCut)
120120
end
121121

122122
# swipe right
123+
alg_trunc = MatrixAlgebraKit.TruncatedAlgorithm(alg.alg_svd, alg.trscheme)
123124
for i in 1:(length(H) - 1)
124-
H = left_canonicalize!(H, i; alg = alg.alg_svd, alg.trscheme)
125+
H = left_canonicalize!(H, i; alg = alg_trunc)
125126
end
126127
# swipe left -- TODO: do we really need this double sweep?
127128
for i in length(H):-1:2
128-
H = right_canonicalize!(H, i; alg = alg.alg_svd, alg.trscheme)
129+
H = right_canonicalize!(H, i; alg = alg_trunc)
129130
end
130131

131132
return H

src/algorithms/groundstate/idmrg.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,9 @@ function _localupdate_sweep_idmrg!(ψ, H, envs, alg_eigsolve)
159159
_, ψ.AC[pos] = fixedpoint(h, ψ.AC[pos], :SR, alg_eigsolve)
160160
if pos == length(ψ)
161161
# AC needed in next sweep
162-
ψ.AL[pos], ψ.C[pos] = left_orth.AC[pos])
162+
ψ.AL[pos], ψ.C[pos] = left_orth.AC[pos]; positive = true)
163163
else
164-
ψ.AL[pos], ψ.C[pos] = left_orth!.AC[pos])
164+
ψ.AL[pos], ψ.C[pos] = left_orth!.AC[pos]; positive = true)
165165
end
166166
transfer_leftenv!(envs, ψ, H, ψ, pos + 1)
167167
end
@@ -171,7 +171,7 @@ function _localupdate_sweep_idmrg!(ψ, H, envs, alg_eigsolve)
171171
h = AC_hamiltonian(pos, ψ, H, ψ, envs)
172172
E, ψ.AC[pos] = fixedpoint(h, ψ.AC[pos], :SR, alg_eigsolve)
173173

174-
ψ.C[pos - 1], temp = right_orth!(_transpose_tail.AC[pos]; copy = (pos == 1)))
174+
ψ.C[pos - 1], temp = right_orth!(_transpose_tail.AC[pos]; copy = (pos == 1)); positive = true)
175175
ψ.AR[pos] = _transpose_front(temp)
176176

177177
transfer_rightenv!(envs, ψ, H, ψ, pos - 1)

src/algorithms/toolbox.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ entropy(state::InfiniteMPS) = map(Base.Fix1(entropy, state), 1:length(state))
99
function entropy(state::Union{FiniteMPS, WindowMPS, InfiniteMPS}, loc::Int)
1010
S = zero(real(scalartype(state)))
1111
tol = eps(typeof(S))
12-
for (c, b) in entanglement_spectrum(state, loc)
12+
for (c, b) in pairs(entanglement_spectrum(state, loc))
1313
s = zero(S)
1414
for x in b
1515
x < tol && break

src/operators/ortho.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
function left_canonicalize!(
22
H::FiniteMPOHamiltonian, i::Int;
3-
alg = Defaults.alg_qr(), trscheme::TruncationStrategy = notrunc()
3+
alg::MatrixAlgebraKit.AbstractAlgorithm = Defaults.alg_qr()
44
)
55
1 i < length(H) || throw(ArgumentError("Bounds error in canonicalize"))
66

@@ -19,7 +19,7 @@ function left_canonicalize!(
1919
# QR of second column
2020
if size(W, 1) == 1
2121
tmp = transpose(C′, ((2, 1), (3,)))
22-
Q, R = _left_orth!(tmp; alg, trunc = trscheme)
22+
Q, R = left_orth!(tmp; alg)
2323

2424
if dim(R) == 0 # fully truncated
2525
V = oneunit(S) oneunit(S)
@@ -35,7 +35,7 @@ function left_canonicalize!(
3535
H[i] = JordanMPOTensor(codomain(W) physicalspace(W) V, Q1, W.B, Q2, W.D)
3636
else
3737
tmp = transpose(cat(insertleftunit(C′, 1), W.A; dims = 1), ((3, 1, 2), (4,)))
38-
Q, R = _left_orth!(tmp; alg, trunc = trscheme)
38+
Q, R = left_orth!(tmp; alg)
3939

4040
if dim(R) == 0 # fully truncated
4141
V = oneunit(S) oneunit(S)
@@ -86,7 +86,7 @@ end
8686

8787
function right_canonicalize!(
8888
H::FiniteMPOHamiltonian, i::Int;
89-
alg = Defaults.alg_lq(), trscheme::TruncationStrategy = notrunc()
89+
alg::MatrixAlgebraKit.AbstractAlgorithm = Defaults.alg_lq()
9090
)
9191
1 < i length(H) || throw(ArgumentError("Bounds error in canonicalize"))
9292

@@ -105,7 +105,7 @@ function right_canonicalize!(
105105
# LQ of second row
106106
if size(W, 4) == 1
107107
tmp = transpose(B′, ((1,), (3, 2)))
108-
R, Q = _right_orth!(tmp; alg, trunc = trscheme)
108+
R, Q = right_orth!(tmp; alg)
109109

110110
if dim(R) == 0
111111
V = oneunit(S) oneunit(S)
@@ -121,7 +121,7 @@ function right_canonicalize!(
121121
H[i] = JordanMPOTensor(V physicalspace(W) domain(W), Q1, Q2, W.C, W.D)
122122
else
123123
tmp = transpose(cat(insertleftunit(B′, 4), W.A; dims = 4), ((1,), (3, 4, 2)))
124-
R, Q = _right_orth!(tmp; alg, trunc = trscheme)
124+
R, Q = right_orth!(tmp; alg)
125125
if dim(R) == 0
126126
V = oneunit(S) oneunit(S)
127127
Q1 = typeof(W.A)(undef, SumSpace{S}() physicalspace(W) physicalspace(W) SumSpace{S}())

src/states/abstractmps.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,11 @@ function makefullrank!(A::PeriodicVector{<:GenericMPSTensor}; alg = Defaults.alg
119119
i = findfirst(!isfullrank, A)
120120
isnothing(i) && break
121121
if !isfullrank(A[i]; side = :left)
122-
L, Q = _right_orth!(_transpose_tail(A[i]); alg)
122+
L, Q = right_orth!(_transpose_tail(A[i]); alg)
123123
A[i] = _transpose_front(Q)
124124
A[i - 1] = A[i - 1] * L
125125
else
126-
A[i], R = _left_orth!(A[i]; alg)
126+
A[i], R = left_orth!(A[i]; alg)
127127
A[i + 1] = _transpose_front(R * _transpose_tail(A[i + 1]))
128128
end
129129
end

src/states/ortho.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ regauge!
164164
function regauge!(
165165
AC::GenericMPSTensor, C::MPSBondTensor; alg = Defaults.alg_qr()
166166
)
167-
Q_AC, _ = _left_orth!(AC; alg)
168-
Q_C, _ = _left_orth!(C; alg)
167+
Q_AC, _ = left_orth!(AC; alg)
168+
Q_C, _ = left_orth!(C; alg)
169169
return mul!(AC, Q_AC, Q_C')
170170
end
171171
function regauge!(AC::Vector{<:GenericMPSTensor}, C::Vector{<:MPSBondTensor}; kwargs...)
@@ -178,8 +178,8 @@ function regauge!(
178178
CL::MPSBondTensor, AC::GenericMPSTensor; alg = Defaults.alg_lq()
179179
)
180180
AC_tail = _transpose_tail(AC)
181-
_, Q_AC = _right_orth!(AC_tail; alg)
182-
_, Q_C = _right_orth!(CL; alg)
181+
_, Q_AC = right_orth!(AC_tail; alg)
182+
_, Q_C = right_orth!(CL; alg)
183183
AR_tail = mul!(AC_tail, Q_C', Q_AC)
184184
return repartition!(AC, AR_tail)
185185
end
@@ -240,7 +240,7 @@ function gauge_eigsolve_step!(it::IterativeSolver{LeftCanonical}, state)
240240
if iter it.eig_miniter
241241
alg_eigsolve = updatetol(it.alg_eigsolve, 1, ϵ^2)
242242
_, vec = fixedpoint(flip(TransferMatrix(A, AL)), C[end], :LM, alg_eigsolve)
243-
_, C[end] = _left_orth!(vec; alg = it.alg_orth)
243+
_, C[end] = left_orth!(vec; alg = it.alg_orth)
244244
end
245245
return C[end]
246246
end
@@ -251,7 +251,7 @@ function gauge_orth_step!(it::IterativeSolver{LeftCanonical}, state)
251251
# repartition!(A_tail[i], AL[i])
252252
mul!(CA_tail[i], C[i - 1], A_tail[i])
253253
repartition!(AL[i], CA_tail[i])
254-
AL[i], C[i] = _left_orth!(AL[i]; alg = it.alg_orth)
254+
AL[i], C[i] = left_orth!(AL[i]; alg = it.alg_orth)
255255
end
256256
normalize!(C[end])
257257
return C[end]
@@ -298,7 +298,7 @@ function gauge_eigsolve_step!(it::IterativeSolver{RightCanonical}, state)
298298
if iter it.eig_miniter
299299
alg_eigsolve = updatetol(it.alg_eigsolve, 1, ϵ^2)
300300
_, vec = fixedpoint(TransferMatrix(A, AR), C[end], :LM, alg_eigsolve)
301-
C[end], _ = _right_orth!(vec; alg = it.alg_orth)
301+
C[end], _ = right_orth!(vec; alg = it.alg_orth)
302302
end
303303
return C[end]
304304
end
@@ -308,7 +308,7 @@ function gauge_orth_step!(it::IterativeSolver{RightCanonical}, state)
308308
for i in length(AR):-1:1
309309
AC = mul!(AR[i], A[i], C[i]) # use AR as temporary storage for A * C
310310
tmp = repartition!(AC_tail[i], AC)
311-
C[i - 1], tmp = _right_orth!(tmp; alg = it.alg_orth)
311+
C[i - 1], tmp = right_orth!(tmp; alg = it.alg_orth)
312312
repartition!(AR[i], tmp) # TODO: avoid doing this every iteration
313313
end
314314
normalize!(C[end])

src/utility/plotting.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function entanglementplot end
3636
spectra = entanglement_spectrum(mps, site)
3737
sectors = []
3838
spectrum = []
39-
for (c, b) in spectra
39+
for (c, b) in pairs(spectra)
4040
if expand_symmetry # Duplicate entries according to the quantum dimension.
4141
b′ = repeat(b, dim(c))
4242
sort!(b′; rev = true)

src/utility/utility.jl

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -149,31 +149,3 @@ function check_unambiguous_braiding(V::VectorSpace)
149149
return check_unambiguous_braiding(Bool, V) ||
150150
throw(ArgumentError("cannot unambiguously braid $V"))
151151
end
152-
153-
# temporary workaround for the fact that left_orth and right_orth are poorly designed:
154-
function _left_orth!(t; alg::MatrixAlgebraKit.AbstractAlgorithm, trunc::MatrixAlgebraKit.TruncationStrategy = notrunc())
155-
if alg isa LAPACK_HouseholderQR
156-
return left_orth!(t; kind = :qr, alg_qr = alg, trunc)
157-
elseif alg isa LAPACK_HouseholderLQ
158-
return left_orth!(t; kind = :qr, alg_qr = LAPACK_HouseholderQR(; alg.kwargs...), trunc)
159-
elseif alg isa PolarViaSVD
160-
return left_orth!(t; kind = :polar, alg_polar = alg, trunc)
161-
elseif alg isa LAPACK_SVDAlgorithm
162-
return left_orth!(t; kind = :svd, alg_svd = alg, trunc)
163-
else
164-
error(lazy"unkown algorithm $alg")
165-
end
166-
end
167-
function _right_orth!(t; alg::MatrixAlgebraKit.AbstractAlgorithm, trunc::TruncationStrategy = notrunc())
168-
if alg isa LAPACK_HouseholderLQ
169-
return right_orth!(t; kind = :lq, alg_lq = alg, trunc)
170-
elseif alg isa LAPACK_HouseholderQR
171-
return right_orth!(t; kind = :lq, alg_lq = LAPACK_HouseholderLQ(; alg.kwargs...), trunc)
172-
elseif alg isa PolarViaSVD
173-
return right_orth!(t; kind = :polar, alg_polar = alg, trunc)
174-
elseif alg isa LAPACK_SVDAlgorithm
175-
return right_orth!(t; kind = :svd, alg_svd = alg, trunc)
176-
else
177-
error(lazy"unkown algorithm $alg")
178-
end
179-
end

0 commit comments

Comments
 (0)