Skip to content

Commit 3b931dc

Browse files
committed
update operators
1 parent fed4cf1 commit 3b931dc

File tree

4 files changed

+32
-56
lines changed

4 files changed

+32
-56
lines changed

src/operators/mpo.jl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,14 @@ function Base.:+(mpo1::FiniteMPO{<:MPOTensor}, mpo2::FiniteMPO{<:MPOTensor})
126126
A, (right_virtualspace(mpo1, 1) right_virtualspace(mpo2, 1)),
127127
right_virtualspace(mpo1, 1)
128128
)
129-
F₂ = leftnull(F₁)
129+
F₂ = left_null(F₁)
130130
@assert _lastspace(F₂) == right_virtualspace(mpo2, 1)'
131131

132132
@plansor O[-3 -1 -2; -4] := mpo1[1][-1 -2; -3 1] * conj(F₁[-4; 1]) +
133133
mpo2[1][-1 -2; -3 1] * conj(F₂[-4; 1])
134134

135135
# making sure that the new operator is "full rank"
136-
O, R = leftorth!(O)
136+
O, R = qr_compact!(O)
137137
O′ = transpose(O, ((2, 3), (1, 4)))
138138
mpo = similar(mpo1, typeof(O′))
139139
mpo[1] = O′
@@ -148,13 +148,13 @@ function Base.:+(mpo1::FiniteMPO{<:MPOTensor}, mpo2::FiniteMPO{<:MPOTensor})
148148
A, (right_virtualspace(mpo1, i) right_virtualspace(mpo2, i)),
149149
right_virtualspace(mpo1, i)
150150
)
151-
F₂ = leftnull(F₁)
151+
F₂ = left_null(F₁)
152152
@assert _lastspace(F₂) == right_virtualspace(mpo2, i)'
153153
@plansor O[-3 -1 -2; -4] := O₁[-1 -2; -3 1] * conj(F₁[-4; 1]) +
154154
O₂[-1 -2; -3 1] * conj(F₂[-4; 1])
155155

156156
# making sure that the new operator is "full rank"
157-
O, R = leftorth!(O)
157+
O, R = qr_compact!(O)
158158
mpo[i] = transpose(O, ((2, 3), (1, 4)))
159159
end
160160

@@ -165,14 +165,14 @@ function Base.:+(mpo1::FiniteMPO{<:MPOTensor}, mpo2::FiniteMPO{<:MPOTensor})
165165
A, left_virtualspace(mpo1, N) left_virtualspace(mpo2, N),
166166
left_virtualspace(mpo1, N)
167167
)
168-
F₂ = leftnull(F₁)
168+
F₂ = left_null(F₁)
169169
@assert _lastspace(F₂) == left_virtualspace(mpo2, N)'
170170

171171
@plansor O[-1; -3 -4 -2] := F₁[-1; 1] * mpo1[N][1 -2; -3 -4] +
172172
F₂[-1; 1] * mpo2[N][1 -2; -3 -4]
173173

174174
# making sure that the new operator is "full rank"
175-
L, O = rightorth!(O)
175+
L, O = lq_compact!(O)
176176
mpo[end] = transpose(O, ((1, 4), (2, 3)))
177177

178178
for i in (N - 1):-1:(halfN + 1)
@@ -185,13 +185,13 @@ function Base.:+(mpo1::FiniteMPO{<:MPOTensor}, mpo2::FiniteMPO{<:MPOTensor})
185185
A, left_virtualspace(mpo1, i) left_virtualspace(mpo2, i),
186186
left_virtualspace(mpo1, i)
187187
)
188-
F₂ = leftnull(F₁)
188+
F₂ = left_null(F₁)
189189
@assert _lastspace(F₂) == left_virtualspace(mpo2, i)'
190190
@plansor O[-1; -3 -4 -2] := F₁[-1; 1] * O₁[1 -2; -3 -4] +
191191
F₂[-1; 1] * O₂[1 -2; -3 -4]
192192

193193
# making sure that the new operator is "full rank"
194-
L, O = rightorth!(O)
194+
L, O = lq_compact!(O)
195195
mpo[i] = transpose(O, ((1, 4), (2, 3)))
196196
end
197197

@@ -247,7 +247,7 @@ function Base.:*(mpo::FiniteMPO, mps::FiniteMPS)
247247
Fᵣ = fuser(A, right_virtualspace(mps, i), right_virtualspace(mpo, i))
248248
return _fuse_mpo_mps(mpo[i], A1, Fₗ, Fᵣ)
249249
end
250-
trscheme = truncbelow(eps(real(T)))
250+
trscheme = trunctol(; atol = eps(real(T)))
251251
return changebonds!(FiniteMPS(A2), SvdCut(; trscheme); normalize = false)
252252
end
253253
function Base.:*(mpo::InfiniteMPO, mps::InfiniteMPS)
@@ -392,8 +392,8 @@ function Base.isapprox(
392392
end
393393

394394
@doc """
395-
swap(mpo::FiniteMPO, i::Integer; inv::Bool=false, alg=SDD(), trscheme)
396-
swap!(mpo::FiniteMPO, i::Integer; inv::Bool=false, alg=SDD(), trscheme)
395+
swap(mpo::FiniteMPO, i::Integer; inv::Bool=false, alg=Defaults.alg_svd(), trscheme)
396+
swap!(mpo::FiniteMPO, i::Integer; inv::Bool=false, alg=Defaults.alg_svd(), trscheme)
397397
398398
Compose the mpo with a swap gate applied to indices `i` and `i + 1`, effectively creating an
399399
operator that acts on the Hilbert spaces with those factors swapped.
@@ -405,7 +405,7 @@ swap(mpo::FiniteMPO, i::Integer; kwargs...) = swap!(copy(mpo), i; kwargs...)
405405
function swap!(
406406
mpo::FiniteMPO{<:MPOTensor}, i::Integer;
407407
inv::Bool = false,
408-
alg = SDD(), trscheme = truncbelow(eps(real(scalartype(mpo)))^(4 / 5))
408+
alg = Defaults.alg_svd(), trscheme = trunctol(; atol = eps(real(scalartype(mpo)))^(4 / 5))
409409
)
410410
O₁, O₂ = mpo[i], mpo[i + 1]
411411

@@ -417,7 +417,7 @@ function swap!(
417417
τ[-3 -6; 4 5] * O₁[-2 4; 2 1] * O₂[1 5; 3 -5] * τ'[2 3; -1 -4]
418418
end
419419

420-
U, S, Vᴴ, = tsvd!(O₂₁; alg, trunc = trscheme)
420+
U, S, Vᴴ = svd_trunc!(O₂₁; alg, trunc = trscheme)
421421
sqrtS = sqrt(S)
422422
@plansor mpo[i][-1 -2; -3 -4] := U[-3 -1 -2; 1] * sqrtS[1; -4]
423423
@plansor mpo[i + 1][-1 -2; -3 -4] := sqrtS[-1; 1] * Vᴴ[1; -3 -4 -2]

src/operators/mpohamiltonian.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -791,31 +791,31 @@ function Base.:*(H::FiniteMPOHamiltonian, mps::FiniteMPS)
791791
# left to middle
792792
U = ones(scalartype(H), left_virtualspace(H, 1))
793793
@plansor a[-1 -2; -3 -4] := A[1][-1 2; -3] * H[1][1 -2; 2 -4] * conj(U[1])
794-
Q, R = leftorth!(a; alg = QR())
795-
A′[1] = convert(TensorMap, Q)
794+
Q, R = qr_compact!(a)
795+
A′[1] = TensorMap(Q)
796796

797797
for i in 2:(N ÷ 2)
798798
@plansor a[-1 -2; -3 -4] := R[-1; 1 2] * A[i][1 3; -3] * H[i][2 -2; 3 -4]
799-
Q, R = leftorth!(a; alg = QR())
800-
A′[i] = convert(TensorMap, Q)
799+
Q, R = qr_compact!(a)
800+
A′[i] = TensorMap(Q)
801801
end
802802

803803
# right to middle
804804
U = ones(scalartype(H), right_virtualspace(H, N))
805805
@plansor a[-1 -2; -3 -4] := A[end][-1 2; -3] * H[end][-2 -4; 2 1] * U[1]
806-
L, Q = rightorth!(a; alg = LQ())
807-
A′[end] = transpose(convert(TensorMap, Q), ((1, 3), (2,)))
806+
L, Q = lq_compact!(a)
807+
A′[end] = transpose(TensorMap(Q), ((1, 3), (2,)))
808808

809809
for i in (N - 1):-1:(N ÷ 2 + 2)
810810
@plansor a[-1 -2; -3 -4] := A[i][-1 3; 1] * H[i][-2 -4; 3 2] * L[1 2; -3]
811-
L, Q = rightorth!(a; alg = LQ())
812-
A′[i] = transpose(convert(TensorMap, Q), ((1, 3), (2,)))
811+
L, Q = lq_compact!(a)
812+
A′[i] = transpose(TensorMap(Q), ((1, 3), (2,)))
813813
end
814814

815815
# connect pieces
816816
@plansor a[-1 -2; -3] := R[-1; 1 2] * A[N ÷ 2 + 1][1 3; 4] * H[N ÷ 2 + 1][2 -2; 3 5] *
817817
L[4 5; -3]
818-
A′[N ÷ 2 + 1] = convert(TensorMap, a)
818+
A′[N ÷ 2 + 1] = TensorMap(a)
819819

820820
return FiniteMPS(A′)
821821
end
@@ -826,7 +826,7 @@ function Base.:*(H::FiniteMPOHamiltonian{<:MPOTensor}, x::AbstractTensorMap)
826826
L = removeunit(H[1], 1)
827827
M = Tuple(H[2:(end - 1)])
828828
R = removeunit(H[end], 4)
829-
return convert(TensorMap, _apply_finitempo(x, L, M, R))
829+
return TensorMap(_apply_finitempo(x, L, M, R))
830830
end
831831

832832
function TensorKit.dot(H₁::FiniteMPOHamiltonian, H₂::FiniteMPOHamiltonian)

src/operators/ortho.jl

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

@@ -19,14 +19,7 @@ function left_canonicalize!(
1919
# QR of second column
2020
if size(W, 1) == 1
2121
tmp = transpose(C′, ((2, 1), (3,)))
22-
23-
if trscheme == notrunc()
24-
Q, R = leftorth!(tmp; alg)
25-
else
26-
@assert alg == SVD() || alg == SDD()
27-
Q, Σ, Vᴴ = tsvd!(tmp; alg, trunc = trscheme)
28-
R = Σ * Vᴴ
29-
end
22+
Q, R = _left_orth!(tmp; alg, trunc = trscheme)
3023

3124
if dim(R) == 0 # fully truncated
3225
V = BlockTensorKit.oplus(oneunit(S), oneunit(S))
@@ -42,13 +35,8 @@ function left_canonicalize!(
4235
H[i] = JordanMPOTensor(codomain(W) physicalspace(W) V, Q1, W.B, Q2, W.D)
4336
else
4437
tmp = transpose(cat(insertleftunit(C′, 1), W.A; dims = 1), ((3, 1, 2), (4,)))
45-
if trscheme == notrunc()
46-
Q, R = leftorth!(tmp; alg)
47-
else
48-
@assert alg == SVD() || alg == SDD()
49-
Q, Σ, Vᴴ = tsvd!(tmp; alg, trunc = trscheme)
50-
R = Σ * Vᴴ
51-
end
38+
Q, R = _left_orth!(tmp; alg, trunc = trscheme)
39+
5240
if dim(R) == 0 # fully truncated
5341
V = BlockTensorKit.oplus(oneunit(S), oneunit(S))
5442
Q1 = typeof(W.A)(undef, SumSpace{S}() physicalspace(W) physicalspace(W) SumSpace{S}())
@@ -98,7 +86,7 @@ end
9886

9987
function right_canonicalize!(
10088
H::FiniteMPOHamiltonian, i::Int;
101-
alg = LQpos(), trscheme::TruncationScheme = notrunc()
89+
alg = Defaults.alg_lq(), trscheme::TruncationStrategy = notrunc()
10290
)
10391
1 < i length(H) || throw(ArgumentError("Bounds error in canonicalize"))
10492

@@ -117,13 +105,7 @@ function right_canonicalize!(
117105
# LQ of second row
118106
if size(W, 4) == 1
119107
tmp = transpose(B′, ((1,), (3, 2)))
120-
if trscheme == notrunc()
121-
R, Q = rightorth!(tmp; alg)
122-
else
123-
@assert alg == SVD() || alg == SDD()
124-
U, Σ, Q = tsvd!(tmp; alg, trunc = trscheme)
125-
R = U * Σ
126-
end
108+
R, Q = _right_orth!(tmp; alg, trunc = trscheme)
127109

128110
if dim(R) == 0
129111
V = BlockTensorKit.oplus(oneunit(S), oneunit(S))
@@ -139,13 +121,7 @@ function right_canonicalize!(
139121
H[i] = JordanMPOTensor(V physicalspace(W) domain(W), Q1, Q2, W.C, W.D)
140122
else
141123
tmp = transpose(cat(insertleftunit(B′, 4), W.A; dims = 4), ((1,), (3, 4, 2)))
142-
if trscheme == notrunc()
143-
R, Q = rightorth!(tmp; alg)
144-
else
145-
@assert alg == SVD() || alg == SDD()
146-
U, Σ, Q = tsvd!(tmp; alg, trunc = trscheme)
147-
R = U * Σ
148-
end
124+
R, Q = _right_orth!(tmp; alg, trunc = trscheme)
149125
if dim(R) == 0
150126
V = BlockTensorKit.oplus(oneunit(S), oneunit(S))
151127
Q1 = typeof(W.A)(undef, SumSpace{S}() physicalspace(W) physicalspace(W) SumSpace{S}())

test/operators.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ module TestOperators
180180
FiniteMPOHamiltonian(lattice, 3 => O₁)
181181
@test 0.8 * H1 + 0.2 * H1 H1 atol = 1.0e-6
182182
@test convert(TensorMap, H1 + H2) convert(TensorMap, H1) + convert(TensorMap, H2) atol = 1.0e-6
183-
H1_trunc = changebonds(H1, SvdCut(; trscheme = truncdim(0)))
183+
H1_trunc = changebonds(H1, SvdCut(; trscheme = truncrank(0)))
184184
@test H1_trunc H1
185185
@test all(left_virtualspace(H1_trunc) .== left_virtualspace(H1))
186186

@@ -212,7 +212,7 @@ module TestOperators
212212
FiniteMPOHamiltonian(grid, vertical_operators) +
213213
FiniteMPOHamiltonian(grid, horizontal_operators) atol = 1.0e-4
214214

215-
H5 = changebonds(H4 / 3 + 2H4 / 3, SvdCut(; trscheme = truncbelow(1.0e-12)))
215+
H5 = changebonds(H4 / 3 + 2H4 / 3, SvdCut(; trscheme = trunctol(; atol = 1.0e-12)))
216216
psi = FiniteMPS(physicalspace(H5), V oneunit(V))
217217
@test expectation_value(psi, H4) expectation_value(psi, H5)
218218
end

0 commit comments

Comments
 (0)