Skip to content

Commit c1437f3

Browse files
lkdvosclaude
andcommitted
Drop the extra cache registry now that extension caches are owned by TensorKit
The GPU transformers are cached through `@cached` methods of `treebraider` and `treetransposer`, which share TensorKit's caches. These are inspected, emptied and timed through MemoizationKit, so the separate `GLOBAL_CACHES` registry is no longer needed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent a3b793a commit c1437f3

3 files changed

Lines changed: 6 additions & 26 deletions

File tree

‎docs/src/Changelog.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ When releasing a new version, move the "Unreleased" changes to a new version sec
2828

2929
- Extend VectorInterface compat to include v0.7
3030
- Require TensorKitSectors v0.3.10
31-
- `@cached` can be used from other modules, such as package extensions, which then own the cache of the methods they add; these caches are shown with their module in `global_cache_info` after registration in `__init__` (internal)
31+
- Caching is provided by [MemoizationKit.jl](https://github.com/QuantumKitHub/MemoizationKit.jl), which can inspect, resize and configure TensorKit's caches, also by memory size; this replaces the internal `@cached` machinery and the LRUCache.jl dependency
32+
- Storage-specific transformers of package extensions are cached by adding `@cached` methods to `treebraider` and `treetransposer`, sharing their cache (internal)
3233
- The `TreeTransformer`s used in index manipulations are now constructed and cached per storagetype of the destination tensor, which is also a dispatch point for storage-specific transformers with their own cache (internal)
3334

3435
### Deprecated

‎src/auxiliary/caches.jl‎

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,6 @@
44
import MemoizationKit: CacheStyle
55
using MemoizationKit: MemoizationKit, @cached, NoCache, GlobalCache, Hashed, LRU
66

7-
"""
8-
const GLOBAL_CACHES
9-
10-
Registry of additional global caches, which are not managed by `@cached` (e.g. by
11-
extensions), as `name => cache` pairs. They are emptied by [`empty_globalcaches!`](@ref)
12-
and listed by [`global_cache_info`](@ref), together with the caches of TensorKit's cached
13-
functions.
14-
"""
15-
const GLOBAL_CACHES = Pair{Symbol, Any}[]
16-
17-
const DEFAULT_GLOBALCACHE_SIZE = Ref(10^4)
18-
197
# Buffer payloads can be measured without visiting their elements when stored inline.
208
# Reference-containing sector/scalar types need the recursive fallback to include their data.
219
_cache_payload_size(a::Array{T}) where {T} = isbitstype(T) ? sizeof(a) : Base.summarysize(a)
@@ -39,7 +27,6 @@ See also [`global_cache_info`](@ref) to display the status.
3927
"""
4028
function empty_globalcaches!()
4129
MemoizationKit.empty_caches!(TensorKit)
42-
foreach(empty! ∘ last, GLOBAL_CACHES)
4330
return nothing
4431
end
4532

@@ -54,8 +41,5 @@ function global_cache_info(io::IO = stdout)
5441
for (f, cache) in MemoizationKit.cache_info(TensorKit)
5542
println(io, nameof(f), ":\t", cache)
5643
end
57-
for (name, cache) in GLOBAL_CACHES
58-
println(io, name, ":\t", cache)
59-
end
6044
return
6145
end

‎test/other/caches.jl‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ end
2525
V = GradedSpace{I}(labels[1] => 2, labels[2] => 2)
2626
W = V ⊗ V ← V ⊗ V
2727
p, levels = ((2, 1), (4, 3)), (1, 2, 3, 4)
28-
transformer = TensorKit.treebraider(W, W, p, false, levels)
28+
transformer = TensorKit.treebraider(Vector{Float64}, W, W, p, false, levels)
2929
for value in (sectorstructure(W), degeneracystructure(W), transformer)
3030
bytes = @constinferred MemoizationKit.cachesize(value)
3131
@test 0 < bytes <= Base.summarysize(value)
@@ -39,8 +39,8 @@ end
3939
# retain its own size budget even if the degeneracy cache has been cleared.
4040
MemoizationKit.set_cache_size!(TensorKit.treebraider, MemoizationKit.cachesize(transformer); by = MemoizationKit.cachesize)
4141
try
42-
TensorKit.treebraider(W, W, p, false, levels)
43-
TensorKit.treebraider(W, W, ((1, 2), (3, 4)), false, levels)
42+
TensorKit.treebraider(Vector{Float64}, W, W, p, false, levels)
43+
TensorKit.treebraider(Vector{Float64}, W, W, ((1, 2), (3, 4)), false, levels)
4444
MemoizationKit.empty_caches!(degeneracystructure)
4545
cache = only(MemoizationKit.cache_info(TensorKit.treebraider)).second
4646
stats = MemoizationKit.cache_stats(cache)
@@ -51,7 +51,7 @@ end
5151

5252
MemoizationKit.set_cache_size!(TensorKit.treebraider, 0; by = MemoizationKit.cachesize)
5353
@test isempty(cache)
54-
@test TensorKit.treebraider(W, W, p, false, levels).data == transformer.data
54+
@test TensorKit.treebraider(Vector{Float64}, W, W, p, false, levels).data == transformer.data
5555
@test isempty(cache)
5656
finally
5757
MemoizationKit.set_cache_size!(TensorKit.treebraider, 10_000)
@@ -72,8 +72,6 @@ MemoizationKit.@cached unrelated_cache(x) = [x]
7272

7373
@testset "TensorKit cache management" begin
7474
retained = unrelated_cache(1)
75-
extra = Dict(:key => :value)
76-
push!(TensorKit.GLOBAL_CACHES, :extension_cache => extra)
7775
try
7876
V = SU2Space(0 => 2, 1 // 2 => 2)
7977
t = rand(V ⊗ V ← V ⊗ V)
@@ -82,13 +80,10 @@ MemoizationKit.@cached unrelated_cache(x) = [x]
8280
@test (@constinferred permute(permute(t, p), p)) ≈ t
8381
info = sprint(TensorKit.global_cache_info)
8482
@test occursin("treebraider", info)
85-
@test occursin("extension_cache", info)
8683
@test empty_globalcaches!() === nothing
8784
@test all(isempty(cache) for (_, cache) in MemoizationKit.cache_info(TensorKit))
88-
@test isempty(extra)
8985
@test unrelated_cache(1) === retained
9086
finally
91-
pop!(TensorKit.GLOBAL_CACHES)
9287
MemoizationKit.empty_caches!(unrelated_cache)
9388
end
9489
end

0 commit comments

Comments
 (0)