Skip to content

Commit 9e000a4

Browse files
authored
Update MatrixAlgebraKit algorithm specification (#418)
* Update MatrixAlgebraKit algorithm specification * Use default SVD algorithm * `DefaultAlgorithm` should solve everything? * Spelling * `qr`/`lq` -> `orth` * Try to handle `left_orth` with SVD algorithm
1 parent 99a2a8a commit 9e000a4

11 files changed

Lines changed: 26 additions & 47 deletions

File tree

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ HalfIntegers = "1.6.0"
4242
KrylovKit = "0.8.3, 0.9.2, 0.10"
4343
LinearAlgebra = "1.6"
4444
LoggingExtras = "~1.0"
45-
MatrixAlgebraKit = "0.6"
45+
MatrixAlgebraKit = "0.6.5"
4646
OhMyThreads = "0.7, 0.8"
4747
OptimKit = "0.3.1, 0.4"
4848
ParallelTestRunner = "2"

src/MPSKit.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ using TensorKit
6262
using TensorKit: BraidingTensor
6363
using TensorKit: TupleTools as TT
6464
using MatrixAlgebraKit
65-
using MatrixAlgebraKit: TruncationStrategy, PolarViaSVD, LAPACK_SVDAlgorithm
65+
using MatrixAlgebraKit: TruncationStrategy
6666
using BlockTensorKit
6767
using BlockTensorKit: TensorMapSumSpace
6868
using TensorOperations

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 = Defaults.alg_qr()
68+
alg_orth = Defaults.alg_orth()
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 = Defaults.alg_qr()
91+
alg_orth = Defaults.alg_orth()
9292

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

src/algorithms/changebonds/svdcut.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,11 @@ function changebonds!(H::FiniteMPOHamiltonian, alg::SvdCut)
122122
# swipe right
123123
alg_trunc = MatrixAlgebraKit.TruncatedAlgorithm(alg.alg_svd, alg.trscheme)
124124
for i in 1:(length(H) - 1)
125-
H = left_canonicalize!(H, i; alg = alg_trunc)
125+
H = left_canonicalize!(H, i; alg = MatrixAlgebraKit.LeftOrthViaSVD(alg_trunc))
126126
end
127127
# swipe left -- TODO: do we really need this double sweep?
128128
for i in length(H):-1:2
129-
H = right_canonicalize!(H, i; alg = alg_trunc)
129+
H = right_canonicalize!(H, i; alg = MatrixAlgebraKit.RightOrthViaSVD(alg_trunc))
130130
end
131131

132132
return H

src/algorithms/groundstate/vumps.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ function localupdate_step!(
106106
it::IterativeSolver{<:VUMPS}, state, scheduler = Defaults.scheduler[]
107107
)
108108
alg_eigsolve = updatetol(it.alg_eigsolve, state.iter, state.ϵ)
109-
alg_orth = Defaults.alg_qr()
109+
alg_orth = Defaults.alg_orth()
110110

111111
mps = state.mps
112112
src_Cs = mps isa Multiline ? eachcol(mps.C) : mps.C
@@ -127,7 +127,7 @@ end
127127

128128
function _localupdate_vumps_step!(
129129
site, mps, operator, envs, AC₀, C₀;
130-
parallel::Bool = false, alg_orth = Defaults.alg_qr(),
130+
parallel::Bool = false, alg_orth = Defaults.alg_orth(),
131131
alg_eigsolve = Defaults.eigsolver, which
132132
)
133133
if !parallel

src/algorithms/statmech/vomps.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ end
102102
function localupdate_step!(
103103
::IterativeSolver{<:VOMPS}, state, scheduler = Defaults.scheduler[]
104104
)
105-
alg_orth = Defaults.alg_qr()
105+
alg_orth = Defaults.alg_orth()
106106
mps = state.mps
107107
ACs = similar(mps.AC)
108108
dst_ACs = state.mps isa Multiline ? eachcol(ACs) : ACs
@@ -119,7 +119,7 @@ function localupdate_step!(
119119
end
120120

121121
function _localupdate_vomps_step!(
122-
site, mps, operator, envs; parallel::Bool = false, alg_orth = Defaults.alg_qr()
122+
site, mps, operator, envs; parallel::Bool = false, alg_orth = Defaults.alg_orth()
123123
)
124124
if !parallel
125125
AC = AC_projection(site, mps, operator, mps, envs)

src/operators/ortho.jl

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

@@ -88,7 +88,7 @@ end
8888

8989
function right_canonicalize!(
9090
H::FiniteMPOHamiltonian, i::Int;
91-
alg::MatrixAlgebraKit.AbstractAlgorithm = Defaults.alg_lq()
91+
alg::MatrixAlgebraKit.AbstractAlgorithm = Defaults.alg_orth()
9292
)
9393
1 < i length(H) || throw(ArgumentError("Bounds error in canonicalize"))
9494

src/states/abstractmps.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,20 +110,20 @@ function isfullrank(V::TensorKit.TensorMapSpace; side = :both)
110110
end
111111

112112
"""
113-
makefullrank!(A::PeriodicVector{<:GenericMPSTensor}; alg=Defaults.alg_qr())
113+
makefullrank!(A::PeriodicVector{<:GenericMPSTensor}; alg=Defaults.alg_orth())
114114
115115
Make the set of MPS tensors full rank by performing a series of orthogonalizations.
116116
"""
117-
function makefullrank!(A::PeriodicVector{<:GenericMPSTensor}; alg_leftorth = Defaults.alg_qr(), alg_rightorth = Defaults.alg_lq())
117+
function makefullrank!(A::PeriodicVector{<:GenericMPSTensor}; alg_orth = Defaults.alg_orth())
118118
while true
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 = alg_rightorth)
122+
L, Q = right_orth!(_transpose_tail(A[i]); alg = alg_orth)
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 = alg_leftorth)
126+
A[i], R = left_orth!(A[i]; alg = alg_orth)
127127
A[i + 1] = _transpose_front(R * _transpose_tail(A[i + 1]))
128128
end
129129
end

src/states/ortho.jl

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ $(TYPEDFIELDS)
2121
verbosity::Int = VERBOSE_WARN
2222

2323
"algorithm used for orthogonalization of the tensors"
24-
alg_orth = Defaults.alg_qr()
24+
alg_orth = Defaults.alg_orth()
2525
"algorithm used for the eigensolver"
2626
alg_eigsolve = _GAUGE_ALG_EIGSOLVE
2727
"minimal amount of iterations before using the eigensolver steps"
@@ -46,7 +46,7 @@ $(TYPEDFIELDS)
4646
verbosity::Int = VERBOSE_WARN
4747

4848
"algorithm used for orthogonalization of the tensors"
49-
alg_orth = Defaults.alg_lq()
49+
alg_orth = Defaults.alg_orth()
5050
"algorithm used for the eigensolver"
5151
alg_eigsolve = _GAUGE_ALG_EIGSOLVE
5252
"minimal amount of iterations before using the eigensolver steps"
@@ -73,31 +73,15 @@ end
7373

7474
function MixedCanonical(;
7575
tol::Real = Defaults.tolgauge, maxiter::Int = Defaults.maxiter,
76-
verbosity::Int = VERBOSE_WARN, alg_orth = Defaults.alg_qr(),
76+
verbosity::Int = VERBOSE_WARN, alg_orth = Defaults.alg_orth(),
7777
alg_eigsolve = _GAUGE_ALG_EIGSOLVE,
7878
eig_miniter::Int = 10, order::Symbol = :LR
7979
)
80-
if alg_orth isa LAPACK_HouseholderQR
81-
alg_leftorth = alg_orth
82-
alg_rightorth = LAPACK_HouseholderLQ(; alg_orth.kwargs...)
83-
elseif alg_orth isa CUSOLVER_HouseholderQR
84-
alg_leftorth = alg_orth
85-
alg_rightorth = LQViaTransposedQR(CUSOLVER_HouseholderQR(; alg_orth.kwargs...))
86-
elseif alg_orth isa LAPACK_HouseholderLQ
87-
alg_leftorth = LAPACK_HouseholderQR(; alg_orth.kwargs...)
88-
alg_rightorth = alg_orth
89-
elseif alg_orth isa LQViaTransposedQR
90-
alg_leftorth = alg_orth
91-
alg_rightorth = alg_orth.qr_alg
92-
else
93-
alg_leftorth = alg_rightorth = alg_orth
94-
end
95-
9680
left = LeftCanonical(;
97-
tol, maxiter, verbosity, alg_orth = alg_leftorth, alg_eigsolve, eig_miniter
81+
tol, maxiter, verbosity, alg_orth, alg_eigsolve, eig_miniter
9882
)
9983
right = RightCanonical(;
100-
tol, maxiter = maxiter, verbosity, alg_orth = alg_rightorth, alg_eigsolve, eig_miniter
84+
tol, maxiter = maxiter, verbosity, alg_orth, alg_eigsolve, eig_miniter
10185
)
10286

10387
return MixedCanonical(left, right, order)
@@ -168,7 +152,7 @@ performance for accuracy.
168152
regauge!
169153

170154
function regauge!(
171-
AC::GenericMPSTensor, C::MPSBondTensor; alg = Defaults.alg_qr()
155+
AC::GenericMPSTensor, C::MPSBondTensor; alg = Defaults.alg_orth()
172156
)
173157
Q_AC, _ = left_orth!(AC; alg)
174158
Q_C, _ = left_orth!(C; alg)
@@ -181,7 +165,7 @@ function regauge!(AC::AbstractVector{<:GenericMPSTensor}, C::AbstractVector{<:MP
181165
return AC
182166
end
183167
function regauge!(
184-
CL::MPSBondTensor, AC::GenericMPSTensor; alg = Defaults.alg_lq()
168+
CL::MPSBondTensor, AC::GenericMPSTensor; alg = Defaults.alg_orth()
185169
)
186170
AC_tail = _transpose_tail(AC)
187171
_, Q_AC = right_orth!(AC_tail; alg)

src/utility/defaults.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import KrylovKit: GMRES, Arnoldi, Lanczos
99
using OhMyThreads
1010
using ..MPSKit: DynamicTol
1111
using TensorKit: TensorKit
12-
using MatrixAlgebraKit: LAPACK_HouseholderQR, LAPACK_HouseholderLQ, LAPACK_DivideAndConquer
12+
using MatrixAlgebraKit: DefaultAlgorithm, Householder
1313

1414
const VERBOSE_NONE = 0
1515
const VERBOSE_WARN = 1
@@ -57,9 +57,8 @@ function alg_eigsolve(;
5757
return dynamic_tols ? DynamicTol(alg, tol_min, tol_max, tol_factor) : alg
5858
end
5959

60-
alg_svd() = LAPACK_DivideAndConquer()
61-
alg_qr() = LAPACK_HouseholderQR(; positive = true)
62-
alg_lq() = LAPACK_HouseholderLQ(; positive = true)
60+
alg_svd() = DefaultAlgorithm()
61+
alg_orth() = Householder(; positive = true)
6362

6463
# TODO: make verbosity and maxiter actually do something
6564
function alg_environments(;

0 commit comments

Comments
 (0)