Skip to content

Commit 0fe74f9

Browse files
committed
remove _left_orth and _right_orth workarounds
1 parent 705d0eb commit 0fe74f9

File tree

4 files changed

+14
-42
lines changed

4 files changed

+14
-42
lines changed

src/operators/ortho.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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, trunc = trscheme)
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, trunc = trscheme)
3939

4040
if dim(R) == 0 # fully truncated
4141
V = oneunit(S) oneunit(S)
@@ -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, trunc = trscheme)
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, trunc = trscheme)
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/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)