Skip to content

Commit a2add70

Browse files
lkdvosclaude
andauthored
Update JET to 0.12 and run the package analysis in CI (#570)
* Update JET to 0.12 and run the package analysis as a test group Mooncake 0.5.45 lifted its `JET = "0.9 - 0.11"` cap, so JET 0.12 is now resolvable. Add `test/other/jet.jl`, which runs `JET.test_package` over TensorKit, and gate it in `runtests.jl`. JET 0.12 only works on Julia 1.12+; on older versions it loads empty stubs and signals this through `JET_AVAILABLE`. Whole-package analysis is therefore pinned to the 0.12 generation, so its reports need not be curated for several JET/Julia combinations. Mooncake's tangent tests reach JET through Mooncake's extension and work with any functional JET, so they are gated separately. The `Mooncake = "0.5.45"` floor is load-bearing: with an older Mooncake the resolver settles on JET 0.11 and the analysis would be silently skipped. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * Fix genuine errors uncovered by JET Four latent bugs on paths that no test exercises: - `@planar ... order=(...)` called a bare `normalizeindex`, which is not in scope: an outright `UndefVarError`. Nothing tests `order=`. - `_extract_contraction_pairs` interpolated `$ex` into its error message, but the argument is named `rhs`, so constructing the error threw instead. - `src/tensors/linalg.jl` threw `DimensionError`, which does not exist; the intended type is `IndexError`. - `numout`/`numin`'s fallbacks built `MethodError(f, T)` from a bare type. `MethodError`'s second field must be the argument *tuple*, so `showerror` itself threw `ErrorException("expected tuple type")` and the intended error was never printable. Every other site in the file already uses `(T,)`. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * Make the JET analysis clean No behavioural changes; each hunk silences a report that JET cannot see through. Inference cannot narrow a `local` binding that is only assigned inside a branch, so replace the sentinel-by-undefinedness idiom with real sentinel values: `@cached`'s `hasparams`/`typed` flags become `nothing` checks on `params`/`typeex`, `planar_trace`'s `local i, j` becomes `i = j = 0`, and `_construct_braidingtensors!` tracks `V1`/`V2` as `nothing` rather than via `foundV1`/`foundV2`. `OneOrNoneIterator`'s default `state = true` is a `Bool`, but a recursive call passes an `Int`, so `if state` is reported as a non-boolean context; `isone` accepts both and keeps the `Bool` default. `fusiontensor` used `TupleTools.prod(d)` on a value inferred as `Union{Tuple, NamedTuple}`; `reshape(F, :, sz[end])` computes the same leading dimension without the union split. The remaining reports came from functions that serve both tensors and spaces under one name. Julia narrows a slot after a call that would otherwise throw a `MethodError`, so an untyped argument passed to such a function is refined to `Union{AbstractTensorMap, TensorMapSpace}` rather than to a tensor, and the next call splits on a branch that has no method. `_braid!`/`_transpose!` are fixed structurally rather than by annotation: they now take `space(tdst)`/`space(tsrc)` once and pass the spaces to both `spacecheck_transform` and `treebraider`/`treetransposer`, whose tensor-accepting forwarding methods are therefore removed. `permute!`/`braid!`/`transpose!` likewise pass spaces to `spacecheck_transform`, so its tensor-accepting method is removed too. `space` has no space-accepting method, so this narrows the arguments on its own, and the non-dense path now computes two spaces instead of four. Where no such restructuring applies, the contract is written down instead: `_trace_permute!` (matching `add_transform!` next door), the `UniqueTreeTransformer`/`GenericTreeTransformer` constructors (`::HomSpace`, their only caller always passes one), `parenttype(::Type{Union{}})`, and the primal `A` of `trace_permute_pullback_ΔA!`. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * Fix JET reports in code merged from main - `_recouple!`: pass `true`/`false` as gemm scalars so they cannot be union-split independently of `U`'s eltype - `nothing_or_block`: only accept a `Diagonal` wrapping a `SectorVector`, the only one `block` supports - `_fsbraid`: assert the `FusionTreeBlock` before the final `repartition` - drop `numind(::AbstractTensorMap)`, which the generic `numind(x) = numin(x) + numout(x)` already covers Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Drop the schur DefaultAlgorithm forwarding and its JET ignores TensorKit has no schur implementation for tensors, so `schur_full`/`schur_vals` already fail in `select_algorithm`. The forwarding methods only gave JET an unimplemented `DiagonalAlgorithm` path to report; MatrixAlgebraKit#276 itself has been fixed upstream. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix _dense_strides for ndims = 1 --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 60076fd commit a2add70

22 files changed

Lines changed: 95 additions & 63 deletions

‎ext/TensorKitGPUArraysExt.jl‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ struct DeviceGenericTreeTransformer{VO <: AbstractVector{Int}, DA <: DeviceUniqu
195195
end
196196

197197
# strides of a dense array of shape `sz`
198-
_dense_strides(size::Dims) = (1, Base.front(cumprod(size))...)
198+
_dense_strides(size::Dims) = Base.front((1, cumprod(size)...))
199199

200200
# `permute(Vsrc, p) == Vdst` is enforced when the transformer is built, so the permuted
201201
# source shape always matches `sz_dst` and the two views share Cartesian inds.

‎src/auxiliary/caches.jl‎

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,16 @@ function _cached(mod::Module, ex)
8787
end
8888
fcall = ex.args[1]
8989
if Meta.isexpr(fcall, :where)
90-
hasparams = true
9190
params = fcall.args[2:end]
9291
fcall = fcall.args[1]
9392
else
94-
hasparams = false
93+
params = nothing
9594
end
9695
if Meta.isexpr(fcall, :(::))
97-
typed = true
9896
typeex = fcall.args[2]
9997
fcall = fcall.args[1]
10098
else
101-
typed = false
99+
typeex = nothing
102100
end
103101
Meta.isexpr(fcall, :call) || _cached_error("expected a function signature", fcall)
104102
fname = fcall.args[1]
@@ -117,14 +115,14 @@ function _cached(mod::Module, ex)
117115
# actual implenetation, with underscore name
118116
_fname = Symbol(:_, basename)
119117
_fcall = Expr(:call, _fname, fargs...)
120-
if hasparams
118+
if !isnothing(params)
121119
_fcall = Expr(:where, _fcall, params...)
122120
end
123121
_fex = Expr(:function, _fcall, _fbody)
124122

125123
# implementation that chooses the cache style
126124
newfcall = fcall
127-
if hasparams
125+
if !isnothing(params)
128126
newfcall = Expr(:where, newfcall, params...)
129127
end
130128
cachestylevar = gensym(:cachestyle)
@@ -138,11 +136,11 @@ function _cached(mod::Module, ex)
138136

139137
# nocache implementation
140138
fnocachecall = Expr(:call, fname, fargs..., :(::$NoCache))
141-
if hasparams
139+
if !isnothing(params)
142140
fnocachecall = Expr(:where, fnocachecall, params...)
143141
end
144142
fnocachebody = _timeit_expr(misslabel, Expr(:call, _fname, fargnames...))
145-
if typed
143+
if !isnothing(typeex)
146144
T = gensym(:T)
147145
fnocachebody = Expr(:block, Expr(:(=), T, typeex), Expr(:(::), fnocachebody, T))
148146
end
@@ -151,7 +149,7 @@ function _cached(mod::Module, ex)
151149
# tasklocal cache implementation
152150
Dvar = gensym(:D)
153151
flocalcachecall = Expr(:call, fname, fargs..., :(::$TaskLocalCache{$Dvar}))
154-
if hasparams
152+
if !isnothing(params)
155153
flocalcachecall = Expr(:where, flocalcachecall, params..., Dvar)
156154
else
157155
flocalcachecall = Expr(:where, flocalcachecall, Dvar)
@@ -172,7 +170,7 @@ function _cached(mod::Module, ex)
172170
end
173171
missex = _timeit_expr(misslabel, Expr(:call, _fname, fargnames...))
174172
getvalex = _timeit_expr(lookuplabel, :(get!(() -> $missex, $cachevar, $key)))
175-
if typed
173+
if !isnothing(typeex)
176174
T = gensym(:T)
177175
flocalcachebody = Expr(
178176
:block,
@@ -193,11 +191,11 @@ function _cached(mod::Module, ex)
193191

194192
# # global cache implementation
195193
fglobalcachecall = Expr(:call, fname, fargs..., :(::$GlobalLRUCache))
196-
if hasparams
194+
if !isnothing(params)
197195
fglobalcachecall = Expr(:where, fglobalcachecall, params...)
198196
end
199197
getglobalcachex = Expr(:(=), cachevar, globalcachename)
200-
if typed
198+
if !isnothing(typeex)
201199
T = gensym(:T)
202200
fglobalcachebody = Expr(
203201
:block,

‎src/auxiliary/iterators.jl‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ struct OneOrNoneIterator{T}
44
end
55

66
function Base.iterate(it::OneOrNoneIterator, state = true)
7-
if state && it.cond
7+
if isone(state) && it.cond
88
return (it.first, false)
99
else
1010
return nothing

‎src/factorizations/matrixalgebrakit.jl‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ MAK.zero!(t::AbstractTensorMap) = zerovector!(t)
103103
for f in [
104104
:lq_full, :lq_compact, :lq_null,
105105
:qr_full, :qr_compact, :qr_null,
106-
:schur_full, :schur_vals,
107106
:eig_full, :eig_vals, :eig_trunc, :eig_trunc_no_error,
108107
:eigh_full, :eigh_vals, :eigh_trunc, :eigh_trunc_no_error,
109108
:svd_full, :svd_compact, :svd_trunc, :svd_trunc_no_error, :svd_vals,

‎src/factorizations/pullbacks.jl‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
nothing_or_block(x, c) = isnothing(x) ? x : block(x, c)
2-
nothing_or_block(x::Diagonal, c) = block(MAK.diagonal(parent(x)), c)
2+
nothing_or_block(x::Diagonal{T, <:SectorVector{T}}, c) where {T} = block(MAK.diagonal(parent(x)), c)
33

44
for pullback! in (
55
:qr_pullback!, :lq_pullback!, :left_polar_pullback!, :right_polar_pullback!,

‎src/fusiontrees/braiding_manipulations.jl‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ end
332332
if N₂ == 0
333333
return dst => U
334334
else
335-
dst, U_tmp = repartition(dst, N₁)
335+
dst, U_tmp = repartition(dst::FusionTreeBlock{I}, N₁)
336336
U = U_tmp * U
337337
return dst => U
338338
end

‎src/fusiontrees/duality_manipulations.jl‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ function planar_trace(f::FusionTree, (q₁, q₂)::Index2Tuple)
657657
# We thus handle the total trace recursively, by first looking for and
658658
# tracing away neighbouring pairs.
659659
k = 1
660-
local i, j
660+
i = j = 0
661661
while k <= length(q₁)
662662
if mod1(q₁[k] + 1, length(f)) == q₂[k]
663663
i = q₁[k]

‎src/fusiontrees/fusiontrees.jl‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,7 @@ function fusiontensor((f₁, f₂)::FusionTreePair)
338338
d1 = TupleTools.front(sz1)
339339
d2 = TupleTools.front(sz2)
340340
return reshape(
341-
reshape(F₁, TupleTools.prod(d1), sz1[end]) *
342-
reshape(F₂, TupleTools.prod(d2), sz2[end])', (d1..., d2...)
341+
reshape(F₁, :, sz1[end]) * reshape(F₂, :, sz2[end])', (d1..., d2...)
343342
)
344343
end
345344
fusiontensor(src::FusionTreeBlock) = sum(fusiontensor, fusiontrees(src))

‎src/planar/macros.jl‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function planarparser(planarexpr, kwargs...)
5656
if name == :order
5757
isexpr(val, :tuple) ||
5858
throw(ArgumentError("Invalid use of `order`, should be `order=(...,)`"))
59-
indexorder = map(normalizeindex, val.args)
59+
indexorder = map(TO.normalizeindex, val.args)
6060
parser.contractiontreebuilder = network -> TO.indexordertree(
6161
network, indexorder
6262
)

‎src/planar/preprocessors.jl‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,22 +180,18 @@ function _construct_braidingtensors!(ex, preargs, indexmap, non_braiding) # ex i
180180
i1a, i2a, = rightind
181181
end
182182

183-
foundV1, foundV2 = false, false
183+
V1 = V2 = nothing
184184
if haskey(indexmap, i1a)
185185
V1 = indexmap[i1a]
186-
foundV1 = true
187186
elseif haskey(indexmap, i1b)
188187
V1 = Expr(:call, :dual, indexmap[i1b])
189-
foundV1 = true
190188
end
191189
if haskey(indexmap, i2a)
192190
V2 = indexmap[i2a]
193-
foundV2 = true
194191
elseif haskey(indexmap, i2b)
195192
V2 = Expr(:call, :dual, indexmap[i2b])
196-
foundV2 = true
197193
end
198-
if foundV1 && foundV2
194+
if !isnothing(V1) && !isnothing(V2)
199195
s = gensym(:τ)
200196
scalarex = Expr(
201197
:call, :promote_type,
@@ -609,7 +605,7 @@ function _extract_contraction_pairs(rhs, lhs, pre, temporaries)
609605
newarg = _extract_contraction_pairs(rhs.args[3], lhs, pre, temporaries)
610606
return Expr(:call, :\, rhs.args[2], newarg)
611607
else
612-
throw(ArgumentError("unknown tensor expression $ex"))
608+
throw(ArgumentError("unknown tensor expression $rhs"))
613609
end
614610
end
615611

0 commit comments

Comments
 (0)