Skip to content

Commit 2e05e6c

Browse files
committed
update algorithms
1 parent 3b931dc commit 2e05e6c

File tree

16 files changed

+80
-82
lines changed

16 files changed

+80
-82
lines changed

src/algorithms/approximate/fvomps.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function approximate!(ψ::AbstractFiniteMPS, Oϕ, alg::DMRG2, envs = environment
88
ϵ = 0.0
99
for pos in [1:(length(ψ) - 1); (length(ψ) - 2):-1:1]
1010
AC2′ = AC2_projection(pos, ψ, Oϕ, envs)
11-
al, c, ar, = tsvd!(AC2′; trunc = alg.trscheme, alg = alg.alg_svd)
11+
al, c, ar = svd_trunc!(AC2′; trunc = alg.trscheme, alg = alg.alg_svd)
1212

1313
AC2 = ψ.AC[pos] * _transpose_tail.AR[pos + 1])
1414
ϵ = max(ϵ, norm(al * c * ar - AC2) / norm(AC2))

src/algorithms/approximate/idmrg.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ function approximate!(
8282
CartesianIndex(row, site), ψ, toapprox, envs;
8383
kind = :ACAR
8484
)
85-
al, c, ar, = tsvd!(AC2′; trunc = alg.trscheme, alg = alg.alg_svd)
85+
al, c, ar = svd_trunc!(AC2′; trunc = alg.trscheme, alg = alg.alg_svd)
8686
normalize!(c)
8787

8888
ψ.AL[row + 1, site] = al
@@ -104,7 +104,7 @@ function approximate!(
104104
CartesianIndex(row, site), ψ, toapprox, envs;
105105
kind = :ALAC
106106
)
107-
al, c, ar, = tsvd!(AC2′; trunc = alg.trscheme, alg = alg.alg_svd)
107+
al, c, ar = svd_trunc!(AC2′; trunc = alg.trscheme, alg = alg.alg_svd)
108108
normalize!(c)
109109

110110
ψ.AL[row + 1, site] = al

src/algorithms/approximate/vomps.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ end
6565
function localupdate_step!(
6666
::IterativeSolver{<:VOMPS}, state::VOMPSState{<:Any, <:Tuple}, ::SerialScheduler
6767
)
68-
alg_orth = QRpos()
68+
alg_orth = Defaults.alg_qr()
6969

7070
ACs = similar(state.mps.AC)
7171
dst_ACs = state.mps isa Multiline ? eachcol(ACs) : ACs
@@ -88,7 +88,7 @@ end
8888
function localupdate_step!(
8989
::IterativeSolver{<:VOMPS}, state::VOMPSState{<:Any, <:Tuple}, scheduler
9090
)
91-
alg_orth = QRpos()
91+
alg_orth = Defaults.alg_qr()
9292

9393
ACs = similar(state.mps.AC)
9494
dst_ACs = state.mps isa Multiline ? eachcol(ACs) : ACs

src/algorithms/changebonds/optimalexpand.jl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ $(TYPEDFIELDS)
1414
alg_svd::S = Defaults.alg_svd()
1515

1616
"algorithm used for truncating the expanded space"
17-
trscheme::TruncationScheme
17+
trscheme::TruncationStrategy
1818
end
1919

2020
function changebonds(
@@ -30,13 +30,13 @@ function changebonds(
3030
AC2 = AC2_hamiltonian(i, ψ, H, ψ, envs) * AC2
3131

3232
# Use the nullspaces and SVD decomposition to determine the optimal expansion space
33-
VL = leftnull.AL[i])
34-
VR = rightnull!(_transpose_tail.AR[i + 1]))
33+
VL = left_null.AL[i])
34+
VR = right_null!(_transpose_tail.AR[i + 1]))
3535
intermediate = normalize!(adjoint(VL) * AC2 * adjoint(VR))
36-
U, _, V, = tsvd!(intermediate; trunc = alg.trscheme, alg = alg.alg_svd)
36+
U, _, Vᴴ = svd_trunc!(intermediate; trunc = alg.trscheme, alg = alg.alg_svd)
3737

3838
AL′[i] = VL * U
39-
AR′[i + 1] = V * VR
39+
AR′[i + 1] = Vᴴ * VR
4040
end
4141

4242
newψ = _expand(ψ, AL′, AR′)
@@ -56,13 +56,13 @@ function changebonds(ψ::MultilineMPS, H, alg::OptimalExpand, envs = environment
5656
AC2 = AC2_hamiltonian(CartesianIndex(i - 1, j), ψ, H, ψ, envs) * AC2
5757

5858
# Use the nullspaces and SVD decomposition to determine the optimal expansion space
59-
VL = leftnull.AL[i, j])
60-
VR = rightnull!(_transpose_tail.AR[i, j + 1]))
59+
VL = left_null.AL[i, j])
60+
VR = right_null!(_transpose_tail.AR[i, j + 1]))
6161
intermediate = normalize!(adjoint(VL) * AC2 * adjoint(VR))
62-
U, _, V, = tsvd!(intermediate; trunc = alg.trscheme, alg = alg.alg_svd)
62+
U, _, Vᴴ = svd_trunc!(intermediate; trunc = alg.trscheme, alg = alg.alg_svd)
6363

6464
AL′[i, j] = VL * U
65-
AR′[i, j + 1] = V * VR
65+
AR′[i, j + 1] = Vᴴ * VR
6666
end
6767

6868
newψ = _expand(ψ, AL′, AR′)
@@ -85,17 +85,17 @@ function changebonds!(ψ::AbstractFiniteMPS, H, alg::OptimalExpand, envs = envir
8585
AC2 = AC2_hamiltonian(i, ψ, H, ψ, envs) * AC2
8686

8787
#Calculate nullspaces for left and right
88-
NL = leftnull.AC[i])
89-
NR = rightnull!(_transpose_tail.AR[i + 1]))
88+
NL = left_null.AC[i])
89+
NR = right_null!(_transpose_tail.AR[i + 1]))
9090

9191
#Use this nullspaces and SVD decomposition to determine the optimal expansion space
9292
intermediate = normalize!(adjoint(NL) * AC2 * adjoint(NR))
93-
_, _, V, = tsvd!(intermediate; trunc = alg.trscheme, alg = alg.alg_svd)
93+
_, _, V, = svd_trunc!(intermediate; trunc = alg.trscheme, alg = alg.alg_svd)
9494

9595
ar_re = V * NR
9696
ar_le = zerovector!(similar(ar_re, codomain.AC[i]) space(V, 1)))
9797

98-
nal, nc = leftorth!(catdomain.AC[i], ar_le); alg = QRpos())
98+
nal, nc = qr_compact!(catdomain.AC[i], ar_le))
9999
nar = _transpose_front(catcodomain(_transpose_tail.AR[i + 1]), ar_re))
100100

101101
ψ.AC[i] = (nal, nc)

src/algorithms/changebonds/randexpand.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ $(TYPEDFIELDS)
1313
"algorithm used for the singular value decomposition"
1414
alg_svd::S = Defaults.alg_svd()
1515

16-
"algorithm used for [truncation](@extref TensorKit.tsvd] the expanded space"
17-
trscheme::TruncationScheme
16+
"algorithm used for [truncation](@extref MatrixAlgebraKit.TruncationStrategy] the expanded space"
17+
trscheme::TruncationStrategy
1818
end
1919

2020
function changebonds::InfiniteMPS, alg::RandExpand)
@@ -26,13 +26,13 @@ function changebonds(ψ::InfiniteMPS, alg::RandExpand)
2626
AC2 = randomize!(_transpose_front.AC[i]) * _transpose_tail.AR[i + 1]))
2727

2828
# Use the nullspaces and SVD decomposition to determine the optimal expansion space
29-
VL = leftnull.AL[i])
30-
VR = rightnull!(_transpose_tail.AR[i + 1]))
29+
VL = left_null.AL[i])
30+
VR = right_null!(_transpose_tail.AR[i + 1]))
3131
intermediate = normalize!(adjoint(VL) * AC2 * adjoint(VR))
32-
U, _, V, = tsvd!(intermediate; trunc = alg.trscheme, alg = alg.alg_svd)
32+
U, _, Vᴴ = svd_trunc!(intermediate; trunc = alg.trscheme, alg = alg.alg_svd)
3333

3434
AL′[i] = VL * U
35-
AR′[i + 1] = V * VR
35+
AR′[i + 1] = Vᴴ * VR
3636
end
3737

3838
return _expand(ψ, AL′, AR′)
@@ -48,17 +48,17 @@ function changebonds!(ψ::AbstractFiniteMPS, alg::RandExpand)
4848
AC2 = randomize!(_transpose_front.AC[i]) * _transpose_tail.AR[i + 1]))
4949

5050
#Calculate nullspaces for left and right
51-
NL = leftnull.AC[i])
52-
NR = rightnull!(_transpose_tail.AR[i + 1]))
51+
NL = left_null.AC[i])
52+
NR = right_null!(_transpose_tail.AR[i + 1]))
5353

5454
#Use this nullspaces and SVD decomposition to determine the optimal expansion space
5555
intermediate = normalize!(adjoint(NL) * AC2 * adjoint(NR))
56-
_, _, V, = tsvd!(intermediate; trunc = alg.trscheme, alg = alg.alg_svd)
56+
_, _, Vᴴ = svd_trunc!(intermediate; trunc = alg.trscheme, alg = alg.alg_svd)
5757

58-
ar_re = V * NR
59-
ar_le = zerovector!(similar(ar_re, codomain.AC[i]) space(V, 1)))
58+
ar_re = Vᴴ * NR
59+
ar_le = zerovector!(similar(ar_re, codomain.AC[i]) space(Vᴴ, 1)))
6060

61-
(nal, nc) = leftorth!(catdomain.AC[i], ar_le); alg = QRpos())
61+
nal, nc = qr_compact!(catdomain.AC[i], ar_le))
6262
nar = _transpose_front(catcodomain(_transpose_tail.AR[i + 1]), ar_re))
6363

6464
ψ.AC[i] = (nal, nc)

src/algorithms/changebonds/svdcut.jl

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@ $(TYPEDFIELDS)
1818
"algorithm used for the singular value decomposition"
1919
alg_svd::S = Defaults.alg_svd()
2020

21-
"algorithm used for [truncation][@extref TensorKit.tsvd] of the gauge tensors"
22-
trscheme::TruncationScheme
21+
"algorithm used for [truncation][@extref MatrixAlgebraKit.TruncationStrategy] of the gauge tensors"
22+
trscheme::TruncationStrategy
2323
end
2424

2525
function changebonds::AbstractFiniteMPS, alg::SvdCut; kwargs...)
2626
return changebonds!(copy(ψ), alg; kwargs...)
2727
end
2828
function changebonds!::AbstractFiniteMPS, alg::SvdCut; normalize::Bool = true)
2929
for i in (length(ψ) - 1):-1:1
30-
U, S, V, = tsvd.C[i]; trunc = alg.trscheme, alg = alg.alg_svd)
30+
U, S, Vᴴ = svd_trunc.C[i]; trunc = alg.trscheme, alg = alg.alg_svd)
3131
AL′ = ψ.AL[i] * U
3232
ψ.AC[i] = (AL′, S)
33-
AR′ = _transpose_front(V * _transpose_tail.AR[i + 1]))
33+
AR′ = _transpose_front(Vᴴ * _transpose_tail.AR[i + 1]))
3434
ψ.AC[i + 1] = (S, AR′)
3535
end
3636
return normalize ? normalize!(ψ) : ψ
@@ -51,24 +51,23 @@ function changebonds!(mpo::FiniteMPO, alg::SvdCut)
5151
O_left = transpose(mpo[1], ((3, 1, 2), (4,)))
5252
local O_right
5353
for i in 2:length(mpo)
54-
U, S, V, = tsvd!(O_left; trunc = alg.trscheme, alg = alg.alg_svd)
54+
U, S, Vᴴ = svd_trunc!(O_left; trunc = alg.trscheme, alg = alg.alg_svd)
5555
@inbounds mpo[i - 1] = transpose(U, ((2, 3), (1, 4)))
5656
if i < length(mpo)
57-
@plansor O_left[-3 -1 -2; -4] := S[-1; 1] * V[1; 2] * mpo[i][2 -2; -3 -4]
57+
@plansor O_left[-3 -1 -2; -4] := S[-1; 1] * Vᴴ[1; 2] * mpo[i][2 -2; -3 -4]
5858
else
59-
@plansor O_right[-1; -3 -4 -2] := S[-1; 1] * V[1; 2] * mpo[end][2 -2; -3 -4]
59+
@plansor O_right[-1; -3 -4 -2] := S[-1; 1] * Vᴴ[1; 2] * mpo[end][2 -2; -3 -4]
6060
end
6161
end
6262

6363
# right to left
6464
for i in (length(mpo) - 1):-1:1
65-
U, S, V, = tsvd!(O_right; trunc = alg.trscheme, alg = alg.alg_svd)
66-
@inbounds mpo[i + 1] = transpose(V, ((1, 4), (2, 3)))
65+
U, S, Vᴴ = svd_trunc!(O_right; trunc = alg.trscheme, alg = alg.alg_svd)
66+
@inbounds mpo[i + 1] = transpose(Vᴴ, ((1, 4), (2, 3)))
6767
if i > 1
6868
@plansor O_right[-1; -3 -4 -2] := mpo[i][-1 -2; -3 2] * U[2; 1] * S[1; -4]
6969
else
70-
@plansor _O[-1 -2; -3 -4] := mpo[1][-1 -2; -3 2] * U[2; 1] *
71-
S[1; -4]
70+
@plansor _O[-1 -2; -3 -4] := mpo[1][-1 -2; -3 2] * U[2; 1] * S[1; -4]
7271
@inbounds mpo[1] = _O
7372
end
7473
end
@@ -91,7 +90,7 @@ function changebonds(ψ::InfiniteMPS, alg::SvdCut)
9190
ncr = ψ.C[1]
9291

9392
for i in 1:length(ψ)
94-
U, ncr, = tsvd.C[i]; trunc = alg.trscheme, alg = alg.alg_svd)
93+
U, ncr, = svd_trunc.C[i]; trunc = alg.trscheme, alg = alg.alg_svd)
9594
copied[i] = copied[i] * U
9695
copied[i + 1] = _transpose_front(U' * _transpose_tail(copied[i + 1]))
9796
end

src/algorithms/changebonds/vumpssvd.jl

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ $(TYPEDFIELDS)
1717
"algorithm used for the singular value decomposition"
1818
alg_svd = Defaults.alg_svd()
1919

20-
"algorithm used for [truncation][@extref TensorKit.tsvd] of the two-site update"
21-
trscheme::TruncationScheme
20+
"algorithm used for [truncation][@extref MatrixAlgebraKit.TruncationStrategy] of the two-site update"
21+
trscheme::TruncationStrategy
2222
end
2323

2424
function changebonds_1(
@@ -50,7 +50,6 @@ function changebonds_1(
5050
end
5151

5252
function changebonds_n(state::InfiniteMPS, H, alg::VUMPSSvdCut, envs = environments(state, H))
53-
meps = 0.0
5453
for loc in 1:length(state)
5554
@plansor AC2[-1 -2; -3 -4] := state.AC[loc][-1 -2; 1] * state.AR[loc + 1][1 -4; -3]
5655

@@ -61,13 +60,12 @@ function changebonds_n(state::InfiniteMPS, H, alg::VUMPSSvdCut, envs = environme
6160
_, nC2 = fixedpoint(Hc, state.C[loc + 1], :SR, alg.alg_eigsolve)
6261

6362
#svd ac2, get new AL1 and S,V ---> AC
64-
AL1, S, V, eps = tsvd!(nAC2; trunc = alg.trscheme, alg = alg.alg_svd)
63+
AL1, S, V = svd_trunc!(nAC2; trunc = alg.trscheme, alg = alg.alg_svd)
6564
@plansor AC[-1 -2; -3] := S[-1; 1] * V[1; -3 -2]
66-
meps = max(eps, meps)
6765

6866
#find AL2 from AC and C as in vumps paper
69-
QAC, _ = leftorth(AC; alg = QRpos())
70-
QC, _ = leftorth(nC2; alg = QRpos())
67+
QAC, _ = qr_compact(AC)
68+
QC, _ = qr_compact(nC2; positive = true)
7169
dom_map = isometry(domain(QC), domain(QAC))
7270

7371
@plansor AL2[-1 -2; -3] := QAC[-1 -2; 1] * conj(dom_map[2; 1]) * conj(QC[-3; 2])

src/algorithms/excitation/chepigaansatz.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ function excitations(
121121
# map back to finitemps
122122
ψs = map(AC2s) do ac
123123
ψ′ = copy(ψ)
124-
AL, C, AR, = tsvd!(ac; trunc = alg.trscheme)
124+
AL, C, AR = svd_trunc!(ac; trunc = alg.trscheme)
125125
normalize!(C)
126126
ψ′.AC[pos] = (AL, complex(C))
127127
ψ′.AC[pos + 1] = (complex(C), _transpose_front(AR))

src/algorithms/grassmann.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ Here we use the Tikhonov regularization, i.e. `inv(ρ) = inv(C * C' + δ²1)`,
216216
where the regularization parameter is `δ = rtol * norm(C)`.
217217
"""
218218
function rho_inv_regularized(C; rtol = eps(real(scalartype(C)))^(3 / 4))
219-
U, S, _ = tsvd(C)
219+
U, S, _ = svd_compact(C)
220220
return U * pinv_tikhonov!!(S; rtol) * U'
221221
end
222222

src/algorithms/groundstate/dmrg.jl

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ struct DMRG2{A, S, F} <: Algorithm
9292
"algorithm used for the singular value decomposition"
9393
alg_svd::S
9494

95-
"algorithm used for [truncation](@extref TensorKit.tsvd) of the two-site update"
96-
trscheme::TruncationScheme
95+
"algorithm used for [truncation](@extref MatrixAlgebraKit.TruncationStrategy) of the two-site update"
96+
trscheme::TruncationStrategy
9797

9898
"callback function applied after each iteration, of signature `finalize(iter, ψ, H, envs) -> ψ, envs`"
9999
finalize::F
@@ -125,10 +125,9 @@ function find_groundstate!(ψ::AbstractFiniteMPS, H, alg::DMRG2, envs = environm
125125
Hac2 = AC2_hamiltonian(pos, ψ, H, ψ, envs)
126126
_, newA2center = fixedpoint(Hac2, ac2, :SR, alg_eigsolve)
127127

128-
al, c, ar, = tsvd!(newA2center; trunc = alg.trscheme, alg = alg.alg_svd)
128+
al, c, ar = svd_trunc!(newA2center; trunc = alg.trscheme, alg = alg.alg_svd)
129129
normalize!(c)
130-
v = @plansor ac2[1 2; 3 4] * conj(al[1 2; 5]) * conj(c[5; 6]) *
131-
conj(ar[6; 3 4])
130+
v = @plansor ac2[1 2; 3 4] * conj(al[1 2; 5]) * conj(c[5; 6]) * conj(ar[6; 3 4])
132131
ϵs[pos] = max(ϵs[pos], abs(1 - abs(v)))
133132

134133
ψ.AC[pos] = (al, complex(c))
@@ -141,10 +140,9 @@ function find_groundstate!(ψ::AbstractFiniteMPS, H, alg::DMRG2, envs = environm
141140
Hac2 = AC2_hamiltonian(pos, ψ, H, ψ, envs)
142141
_, newA2center = fixedpoint(Hac2, ac2, :SR, alg_eigsolve)
143142

144-
al, c, ar, = tsvd!(newA2center; trunc = alg.trscheme, alg = alg.alg_svd)
143+
al, c, ar = svd_trunc!(newA2center; trunc = alg.trscheme, alg = alg.alg_svd)
145144
normalize!(c)
146-
v = @plansor ac2[1 2; 3 4] * conj(al[1 2; 5]) * conj(c[5; 6]) *
147-
conj(ar[6; 3 4])
145+
v = @plansor ac2[1 2; 3 4] * conj(al[1 2; 5]) * conj(c[5; 6]) * conj(ar[6; 3 4])
148146
ϵs[pos] = max(ϵs[pos], abs(1 - abs(v)))
149147

150148
ψ.AC[pos + 1] = (complex(c), _transpose_front(ar))

0 commit comments

Comments
 (0)