Skip to content

Commit e450403

Browse files
github-actions[bot]CompatHelper JuliaYue-Zhengyuanleburgellkdvos
authored
CompatHelper: bump compat for TensorKit to 0.16, (keep existing compat) (#314)
* CompatHelper: bump compat for TensorKit to 0.16, (keep existing compat) * Bump MPSKit and MatrixAlgebraKit version * Get SU trunc error directly from svd_trunc * Add compat entry for ChainRulesTestUtils, SafeTestsets * Adapt trnorm * Add SectorVector to DiagonalTensorMap conversion * Fix P_left indexing in renormalize_east_edge * Cleanups * Explicitly use positive QR decomposition in `CTMRGEnv` gauge fixing * Remove manual truncation error computation in favor of `MatrixAlgebraKit.truncation_error` * Add missing brackets * Import `MatrixAlgebraKit.diagview` * reimplement _singular_value_distance * update test * update trnorm * Fix inference in `sequential_projectors` * bump minimal TensorKit version * clean up _singular_value_distance * No longer need `sv_to_dtm` * Remove `_truncate_eigh` hack * Bump TensorKit, MPSKit version * Force `positive = true` in left/right_orth --------- Co-authored-by: CompatHelper Julia <compathelper_noreply@julialang.org> Co-authored-by: Yue Zhengyuan <yuezy1997@icloud.com> Co-authored-by: leburgel <lander.burgelman@gmail.com> Co-authored-by: Lukas Devos <ldevos98@gmail.com>
1 parent 81be8c0 commit e450403

18 files changed

Lines changed: 66 additions & 101 deletions

File tree

Project.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,24 @@ Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
2828
[compat]
2929
Accessors = "0.1"
3030
ChainRulesCore = "1.0"
31+
ChainRulesTestUtils = "1.13"
32+
SafeTestsets = "0.1"
3133
Compat = "3.46, 4.2"
3234
DocStringExtensions = "0.9.3"
3335
FiniteDifferences = "0.12"
3436
KrylovKit = "0.9.5, 0.10"
3537
LinearAlgebra = "1"
3638
LoggingExtras = "1"
37-
MPSKit = "0.13.7"
39+
MPSKit = "0.13.9"
3840
MPSKitModels = "0.4"
39-
MatrixAlgebraKit = "0.5.0"
41+
MatrixAlgebraKit = "0.6"
4042
OhMyThreads = "0.7, 0.8"
4143
OptimKit = "0.4"
4244
Printf = "1"
4345
QuadGK = "2.11.1"
4446
Random = "1"
4547
Statistics = "1"
46-
TensorKit = "0.15"
48+
TensorKit = "0.16.2"
4749
TensorOperations = "5"
4850
TestExtras = "0.3"
4951
VectorInterface = "0.4, 0.5"

src/PEPSKit.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ using VectorInterface
88
import VectorInterface as VI
99

1010
using MatrixAlgebraKit
11-
using MatrixAlgebraKit: TruncationStrategy, LAPACK_DivideAndConquer, LAPACK_QRIteration
12-
using MatrixAlgebraKit: NoTruncation, LAPACK_EighAlgorithm, truncate
13-
using MatrixAlgebraKit: eigh_pullback!, eigh_trunc_pullback!, findtruncated, diagview
11+
using MatrixAlgebraKit: LAPACK_DivideAndConquer, LAPACK_QRIteration
12+
using MatrixAlgebraKit:
13+
TruncationStrategy, NoTruncation, truncate, findtruncated, truncation_error, diagview
14+
using MatrixAlgebraKit: LAPACK_EighAlgorithm, eigh_pullback!, eigh_trunc_pullback!
1415

1516
using TensorKit
1617
using TensorKit: AdjointTensorMap, SectorDict

src/algorithms/bp/beliefpropagation.jl

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,7 @@ function tr_distance(A::BPEnv, B::BPEnv)
126126
end / length(A.messages)
127127
end
128128

129-
function trnorm(M::AbstractTensorMap, p::Real = 1)
130-
return TensorKit._norm(svdvals(M), p, zero(real(scalartype(M))))
131-
end
132-
function trnorm!(M::AbstractTensorMap, p::Real = 1)
133-
return TensorKit._norm(svdvals!(M), p, zero(real(scalartype(M))))
134-
end
129+
trnorm(M::AbstractTensorMap, p::Real = 1) = norm(svdvals(M), p)
130+
trnorm!(M::AbstractTensorMap, p::Real = 1) = norm(svdvals!(M), p)
135131

136132
project_hermitian!!(t) = add(t, t', 1 / 2, 1 / 2)

src/algorithms/bp/gaugefix.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ function SUWeight(env::BPEnv)
117117
wts = map(Iterators.product(1:2, axes(env, 2), axes(env, 3))) do (dir′, row, col)
118118
I = CartesianIndex(mod1(dir′ + 1, 2), row, col)
119119
sqrtM12, _, sqrtM21, _ = _sqrt_bp_messages(I, env)
120-
Λ = svd_vals!(sqrtM12 * sqrtM21)
120+
Λ = DiagonalTensorMap(svd_vals!(sqrtM12 * sqrtM21))
121121
return isdual(space(sqrtM12, 1)) ? _fliptwist_s(Λ) : Λ
122122
end
123123
return SUWeight(wts)

src/algorithms/contractions/bondenv/gaugefix.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ function fixgauge_benv(
6161
6262
2
6363
=#
64-
QL, L = left_orth(permute(Z, ((2, 1), (3,))))
65-
QR, R = left_orth(permute(Z, ((3, 1), (2,))))
64+
QL, L = left_orth(permute(Z, ((2, 1), (3,))); positive = true)
65+
QR, R = left_orth(permute(Z, ((3, 1), (2,))); positive = true)
6666
@debug "cond(L) = $(LinearAlgebra.cond(L)); cond(R) = $(LinearAlgebra.cond(R))"
6767
# TODO: find a better way to fix gauge that avoids `inv`
6868
Linv, Rinv = inv(L), inv(R)

src/algorithms/contractions/ctmrg/renormalize_edge.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ function renormalize_east_edge(
9191
)
9292
return renormalize_east_edge(
9393
env.edges[EAST, row, _next(col, end)],
94-
P_left[EAST, row, col, end],
94+
P_left[EAST, row, col],
9595
P_right[EAST, _prev(row, end), col],
9696
network[row, col],
9797
)

src/algorithms/ctmrg/ctmrg.jl

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -164,27 +164,31 @@ end
164164
@non_differentiable ctmrg_logfinish!(args...)
165165
@non_differentiable ctmrg_logcancel!(args...)
166166

167-
# TODO: we might want to consider embedding the smaller tensor into the larger space and then compute the difference
168167
"""
169-
_singular_value_distance((S₁, S₂))
168+
_singular_value_distance(S₁, S₂)
170169
171170
Compute the singular value distance as an error measure, e.g. for CTMRG iterations.
172171
To that end, the singular values of the current iteration `S₁` are compared with the
173172
previous one `S₂`. When the virtual spaces change, this comparison is not directly possible
174173
such that both tensors are projected into the smaller space and then subtracted.
175174
"""
176-
function _singular_value_distance((S₁, S₂))
177-
V₁ = space(S₁, 1)
178-
V₂ = space(S₂, 1)
179-
if V₁ == V₂
180-
return norm(S₁ - S₂)
181-
else
182-
V = infimum(V₁, V₂)
183-
e1 = isometry(V₁, V)
184-
e2 = isometry(V₂, V)
185-
return norm(e1' * S₁ * e1 - e2' * S₂ * e2)
175+
function _singular_value_distance(S₁::SV, S₂::SV) where {SV <: TensorKit.SectorVector}
176+
# allocate vector for difference - possibly grow
177+
V₁ = Vect[sectortype(S₁)](c => length(v) for (c, v) in blocks(S₁))
178+
V₂ = Vect[sectortype(S₂)](c => length(v) for (c, v) in blocks(S₂))
179+
diff = zerovector!(SV(undef, supremum(V₁, V₂)))
180+
181+
for (c, b) in blocks(S₁)
182+
diff[c][1:length(b)] .= b
186183
end
184+
for (c, b) in blocks(S₂)
185+
diff[c][1:length(b)] .-= b
186+
end
187+
188+
return norm(diff)
187189
end
190+
_singular_value_distance(S₁::DiagonalTensorMap, S₂::DiagonalTensorMap) =
191+
_singular_value_distance(diagview(S₁), diagview(S₂))
188192

189193
"""
190194
calc_convergence(env, CS_old, TS_old)
@@ -196,10 +200,10 @@ This determined either from the previous corner and edge singular values
196200
"""
197201
function calc_convergence(env, CS_old, TS_old)
198202
CS_new = map(svd_vals, env.corners)
199-
ΔCS = maximum(_singular_value_distance, zip(CS_old, CS_new))
203+
ΔCS = maximum(splat(_singular_value_distance), zip(CS_old, CS_new))
200204

201205
TS_new = map(svd_vals, env.edges)
202-
ΔTS = maximum(_singular_value_distance, zip(TS_old, TS_new))
206+
ΔTS = maximum(splat(_singular_value_distance), zip(TS_old, TS_new))
203207

204208
@debug "maxᵢ|Cⁿ⁺¹ - Cⁿ|ᵢ = $ΔCS maxᵢ|Tⁿ⁺¹ - Tⁿ|ᵢ = $ΔTS"
205209

src/algorithms/ctmrg/gaugefix.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ function gauge_fix(envfinal::CTMRGEnv{C, T}, envprev::CTMRGEnv{C, T}, ::Scrambli
8080
ρfinal = transfermatrix_fixedpoint(Tsfinal, M, ρinit)
8181

8282
# Decompose and multiply
83-
Qprev, = left_orth!(ρprev)
84-
Qfinal, = left_orth!(ρfinal)
83+
Qprev, = left_orth!(ρprev; positive = true)
84+
Qfinal, = left_orth!(ρfinal; positive = true)
8585

8686
return Qprev * Qfinal'
8787
end
@@ -115,8 +115,8 @@ function gauge_fix(envfinal::CTMRGEnv{C, T}, envprev::CTMRGEnv{C, T}, ::Scrambli
115115
ρfinal = c4v_transfermatrix_fixedpoint(Tfinal, M, ρinit)
116116

117117
# Decompose and multiply
118-
Qprev, = left_orth!(ρprev)
119-
Qfinal, = left_orth!(ρfinal)
118+
Qprev, = left_orth!(ρprev; positive = true)
119+
Qfinal, = left_orth!(ρfinal; positive = true)
120120

121121
σ = Qprev * Qfinal'
122122

src/algorithms/ctmrg/sequential.jl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,7 @@ function sequential_projectors(col::Int, network, env::CTMRGEnv, alg::ProjectorA
8686
)
8787
proj_and_info = similar(coordinates, T_dst)
8888
proj_and_info′::typeof(proj_and_info) = dtmap!!(proj_and_info, coordinates) do (r, c)
89-
trunc = truncation_strategy(alg, env.edges[WEST, _prev(r, size(env, 2)), c])
90-
proj, info = sequential_projectors(
91-
(WEST, r, c), network, env, @set(alg.trunc = trunc)
92-
)
89+
proj, info = sequential_projectors((WEST, r, c), network, env, alg)
9390
return proj, info
9491
end
9592
return _split_proj_and_info(proj_and_info′)
@@ -99,9 +96,11 @@ function sequential_projectors(
9996
)
10097
_, r, c = coordinate
10198
r′ = _prev(r, size(env, 2))
99+
trunc = truncation_strategy(alg, env.edges[WEST, r′, c])
100+
alg′ = @set alg.trunc = trunc
102101
Q1 = TensorMap(EnlargedCorner(network, env, (SOUTHWEST, r, c)))
103102
Q2 = TensorMap(EnlargedCorner(network, env, (NORTHWEST, r′, c)))
104-
return compute_projector((Q1, Q2), coordinate, alg)
103+
return compute_projector((Q1, Q2), coordinate, alg)
105104
end
106105
function sequential_projectors(
107106
coordinate::NTuple{3, Int}, network, env::CTMRGEnv, alg::FullInfiniteProjector
@@ -110,13 +109,15 @@ function sequential_projectors(
110109
coordinate_nw = _next_coordinate(coordinate, rowsize, colsize)
111110
coordinate_ne = _next_coordinate(coordinate_nw, rowsize, colsize)
112111
coordinate_se = _next_coordinate(coordinate_ne, rowsize, colsize)
112+
trunc = truncation_strategy(alg, env.edges[WEST, coordinate_nw[2:3]...])
113+
alg′ = @set alg.trunc = trunc
113114
ec = (
114115
TensorMap(EnlargedCorner(network, env, coordinate_se)),
115116
TensorMap(EnlargedCorner(network, env, coordinate)),
116117
TensorMap(EnlargedCorner(network, env, coordinate_nw)),
117118
TensorMap(EnlargedCorner(network, env, coordinate_ne)),
118119
)
119-
return compute_projector(ec, coordinate, alg)
120+
return compute_projector(ec, coordinate, alg)
120121
end
121122

122123
"""

src/algorithms/ctmrg/simultaneous.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,12 @@ end
102102
function simultaneous_projectors(
103103
coordinate, enlarged_corners::Array{E, 3}, env, alg::FullInfiniteProjector
104104
) where {E}
105-
coordinate′ = _next_coordinate(coordinate, size(env)[2:3]...)
106-
trunc = truncation_strategy(alg, env.edges[coordinate[1], coordinate′[2:3]...])
107-
alg′ = @set alg.trunc = trunc
108-
rowsize, colsize = size(enlarged_corners)[2:3]
105+
rowsize, colsize = size(env)[2:3]
109106
coordinate2 = _next_coordinate(coordinate, rowsize, colsize)
110107
coordinate3 = _next_coordinate(coordinate2, rowsize, colsize)
111108
coordinate4 = _next_coordinate(coordinate3, rowsize, colsize)
109+
trunc = truncation_strategy(alg, env.edges[coordinate[1], coordinate2[2:3]...])
110+
alg′ = @set alg.trunc = trunc
112111
ec = (
113112
enlarged_corners[coordinate4...],
114113
enlarged_corners[coordinate...],

0 commit comments

Comments
 (0)