Skip to content

Commit 49e7b01

Browse files
lkdvosclaude
andcommitted
Switch to registered MemoizationKit.jl
Cached.jl was registered as MemoizationKit.jl under QuantumKitHub; depend on the registered release and drop the `[sources]` entry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent fd767e4 commit 49e7b01

10 files changed

Lines changed: 59 additions & 62 deletions

File tree

‎Project.toml‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ projects = ["test", "docs"]
88

99
[deps]
1010
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
11-
Cached = "1b238080-9255-4fe9-b224-89eb24efe93b"
1211
Dictionaries = "85a47980-9c8c-11e8-2b9f-f7ca1fa99fb4"
1312
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1413
MatrixAlgebraKit = "6c742aac-3347-4629-af66-fc926824e5e4"
14+
MemoizationKit = "1b238080-9255-4fe9-b224-89eb24efe93b"
1515
OhMyThreads = "67456a42-1dca-4109-a031-0a68de7e3ad5"
1616
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
1717
Preferences = "21216c6a-2e73-6563-6e65-726566657250"
@@ -45,13 +45,9 @@ TensorKitFiniteDifferencesExt = "FiniteDifferences"
4545
TensorKitGPUArraysExt = "GPUArrays"
4646
TensorKitMooncakeExt = "Mooncake"
4747

48-
[sources]
49-
Cached = {url = "https://github.com/lkdvos/Cached.jl.git", rev = "main"}
50-
5148
[compat]
5249
AMDGPU = "2"
5350
Adapt = "4"
54-
Cached = "0.1"
5551
CUDA = "6"
5652
ChainRulesCore = "1"
5753
Dictionaries = "0.4"
@@ -61,6 +57,7 @@ FiniteDifferences = "0.12"
6157
GPUArrays = "11.4.1"
6258
LinearAlgebra = "1"
6359
MatrixAlgebraKit = "0.6.9"
60+
MemoizationKit = "0.1"
6461
Mooncake = "0.5.27"
6562
OhMyThreads = "0.8.0"
6663
PrecompileTools = "1"

‎docs/src/man/fusiontrees.md‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -260,30 +260,30 @@ This is simply given by
260260

261261
The `braid` and `permute` routines for double fusion trees will be the main access point for corresponding manipulations on tensors.
262262
As a consequence, results from these routines are memoized via a `@cached` mechanism.
263-
The caching strategy is controlled by `Cached.CacheStyle`: for `FusionStyle(I) isa UniqueFusion` no caching is used (`NoCache()`), since the result is a single cheap scalar coefficient; for `MultipleFusion` or `GenericFusion` sectors, `GlobalCache()` uses Cached.jl's configured container (ClockCache by default), as computing the transformation matrix can be expensive and results are reused frequently.
263+
The caching strategy is controlled by `MemoizationKit.CacheStyle`: for `FusionStyle(I) isa UniqueFusion` no caching is used (`NoCache()`), since the result is a single cheap scalar coefficient; for `MultipleFusion` or `GenericFusion` sectors, `GlobalCache()` uses MemoizationKit.jl's configured container (ClockCache by default), as computing the transformation matrix can be expensive and results are reused frequently.
264264

265-
TensorKit also uses Cached.jl for sector structures, degeneracy structures and fusion tree transformers.
266-
Sector structures share cache entries across spaces with the same sectors, even if their degeneracy dimensions differ, through `Cached.cachekey`.
267-
The Cached APIs can inspect, resize and configure these caches:
265+
TensorKit also uses MemoizationKit.jl for sector structures, degeneracy structures and fusion tree transformers.
266+
Sector structures share cache entries across spaces with the same sectors, even if their degeneracy dimensions differ, through `MemoizationKit.cachekey`.
267+
The MemoizationKit APIs can inspect, resize and configure these caches:
268268

269269
```julia
270-
using TensorKit, Cached
271-
Cached.cache_info(TensorKit)
272-
Cached.set_cache_size!(TensorKit.treebraider, 50_000)
273-
Cached.set_cache_size!(TensorKit.treebraider, 2^30; by = Cached.cachesize) # 1 GiB of cached values
274-
Cached.set_cache_preferences!(TensorKit; maxsize = 50_000, measure = "bytes")
275-
Cached.set_cache_preferences!(; container = "LRU")
270+
using TensorKit, MemoizationKit
271+
MemoizationKit.cache_info(TensorKit)
272+
MemoizationKit.set_cache_size!(TensorKit.treebraider, 50_000)
273+
MemoizationKit.set_cache_size!(TensorKit.treebraider, 2^30; by = MemoizationKit.cachesize) # 1 GiB of cached values
274+
MemoizationKit.set_cache_preferences!(TensorKit; maxsize = 50_000, measure = "bytes")
275+
MemoizationKit.set_cache_preferences!(; container = "LRU")
276276
```
277277

278278
Preferences are saved in `LocalPreferences.toml` and apply after restarting Julia; a runtime size change applies immediately.
279-
`Cached.uncached(f, args...)` computes a result without consulting or filling the cache.
280-
TensorKit supplies efficient `Cached.cachesize` methods for its structure, fusion-tree and transformer results.
279+
`MemoizationKit.uncached(f, args...)` computes a result without consulting or filling the cache.
280+
TensorKit supplies efficient `MemoizationKit.cachesize` methods for its structure, fusion-tree and transformer results.
281281
These estimate bytes from the fixed-size fields and live array buffers; matrix coefficients and inline sector values are not traversed individually.
282282
Reference-containing scalar or sector arrays fall back to `Base.summarysize`.
283283
Buffers shared between cache entries count toward each entry, while identical source and destination structure buffers within a transformer count once.
284284
The budget excludes cache keys, container and allocation overhead, and spare array capacity; it is a cached-value estimate rather than a limit on total process memory.
285-
Optional Cached features, such as the Tachikoma dashboard and SQLite disk caching, remain available through Cached's extensions.
286-
Disk caching requires loading SQLite and defining `Cached.DiskCacheStyle` for the desired function; it is disabled by default, and `empty_globalcaches!()` clears only in-memory caches.
285+
Optional MemoizationKit features, such as the Tachikoma dashboard and SQLite disk caching, remain available through MemoizationKit's extensions.
286+
Disk caching requires loading SQLite and defining `MemoizationKit.DiskCacheStyle` for the desired function; it is disabled by default, and `empty_globalcaches!()` clears only in-memory caches.
287287

288288
This caching implies that potential inefficiencies in the fusion tree manipulations (which we nonetheless try to avoid) will not seriously affect performance of tensor manipulations.
289289

‎docs/src/man/profiling.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# [Profiling and timers](@id s_profiling)
22

33
TensorKit's index manipulations, tensor contractions and factorizations are instrumented with [TimerOutputs.jl](https://github.com/KristofferC/TimerOutputs.jl) sections that are compiled away by default, so they incur no runtime cost.
4-
Enabling TensorKit's timers also enables Cached.jl's cache lookup and computation timers, recorded in the same timer tree and categories.
4+
Enabling TensorKit's timers also enables MemoizationKit.jl's cache lookup and computation timers, recorded in the same timer tree and categories.
55
They can be enabled to obtain a detailed breakdown of where time is spent inside these operations, in particular the split between the different kinds of work involved in manipulating symmetric tensors:
66

77
| category | contents |

‎ext/TensorKitEnzymeExt/utility.jl‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pullback_dC!(ΔC, β::Number) = scale!(ΔC, conj(β))
2626
@inline EnzymeRules.inactive_type(::Type{<:TensorKit.GenericTreeTransformer}) = true
2727
@inline EnzymeRules.inactive_type(::Type{<:TensorKit.UniqueTreeTransformer}) = true
2828
@inline EnzymeRules.inactive_type(::Type{<:TensorKit.VectorSpace}) = true
29-
@inline EnzymeRules.inactive_type(::Type{<:TensorKit.Cached.AbstractCache}) = true
29+
@inline EnzymeRules.inactive_type(::Type{<:TensorKit.MemoizationKit.AbstractCache}) = true
3030

3131
function EnzymeRules.augmented_primal(
3232
config::EnzymeRules.RevConfigWidth{1},

‎src/auxiliary/caches.jl‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# Caching of the fusion tree manipulations and tensor structures is provided by Cached.jl.
1+
# Caching of the fusion tree manipulations and tensor structures is provided by MemoizationKit.jl.
22
# `CacheStyle` is imported (not just used) so that the `CacheStyle(::typeof(f), ...)`
3-
# specializations in TensorKit, and those of users, extend `Cached.CacheStyle`.
4-
import Cached: CacheStyle
5-
using Cached: Cached, @cached, NoCache, GlobalCache, Hashed, LRU
3+
# specializations in TensorKit, and those of users, extend `MemoizationKit.CacheStyle`.
4+
import MemoizationKit: CacheStyle
5+
using MemoizationKit: MemoizationKit, @cached, NoCache, GlobalCache, Hashed, LRU
66

77
"""
88
const GLOBAL_CACHES
@@ -38,7 +38,7 @@ Since everything is recomputed on demand, this is purely a memory measure.
3838
See also [`global_cache_info`](@ref) to display the status.
3939
"""
4040
function empty_globalcaches!()
41-
Cached.empty_caches!(TensorKit)
41+
MemoizationKit.empty_caches!(TensorKit)
4242
foreach(empty! ∘ last, GLOBAL_CACHES)
4343
return nothing
4444
end
@@ -51,7 +51,7 @@ Print the hit/miss statistics and current size of every global cache of TensorKi
5151
See also [`empty_globalcaches!`](@ref).
5252
"""
5353
function global_cache_info(io::IO = stdout)
54-
for (f, cache) in Cached.cache_info(TensorKit)
54+
for (f, cache) in MemoizationKit.cache_info(TensorKit)
5555
println(io, nameof(f), ":\t", cache)
5656
end
5757
for (name, cache) in GLOBAL_CACHES

‎src/auxiliary/timers.jl‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ host-side dispatch of asynchronous kernels unless the workload is explicitly syn
6161
"""
6262
function enable_timers!()
6363
TimerOutputs.enable_debug_timings(TensorKit)
64-
Cached.enable_cache_timers!(TensorKit, GLOBAL_TIMER)
64+
MemoizationKit.enable_cache_timers!(TensorKit, GLOBAL_TIMER)
6565
return nothing
6666
end
6767

@@ -73,7 +73,7 @@ Also triggers recompilation of the instrumented methods on first use.
7373
"""
7474
function disable_timers!()
7575
TimerOutputs.disable_debug_timings(TensorKit)
76-
Cached.disable_cache_timers!(TensorKit)
76+
MemoizationKit.disable_cache_timers!(TensorKit)
7777
return nothing
7878
end
7979

‎src/fusiontrees/fusiontrees.jl‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,14 @@ struct FusionTreeBlock{I, N₁, N₂, F <: FusionTreePair{I, N₁, N₂}}
122122
trees::Vector{F}
123123
end
124124

125-
Cached.cachesize(b::FusionTreeBlock) = sizeof(b) + _cache_payload_size(b.trees)
125+
MemoizationKit.cachesize(b::FusionTreeBlock) = sizeof(b) + _cache_payload_size(b.trees)
126126

127127
# The scalar result is inline for ordinary sectors. Matrix results include the output
128128
# trees and the recoupling matrix, without walking every coefficient.
129-
Cached.cachesize(p::Pair{<:FusionTreePair, <:Number}) =
129+
MemoizationKit.cachesize(p::Pair{<:FusionTreePair, <:Number}) =
130130
isbitstype(typeof(p)) ? sizeof(p) : Base.summarysize(p)
131-
Cached.cachesize(p::Pair{<:FusionTreeBlock, <:Matrix}) =
132-
sizeof(p) + Cached.cachesize(first(p)) + _cache_payload_size(last(p))
131+
MemoizationKit.cachesize(p::Pair{<:FusionTreeBlock, <:Matrix}) =
132+
sizeof(p) + MemoizationKit.cachesize(first(p)) + _cache_payload_size(last(p))
133133

134134
function FusionTreeBlock{I}(
135135
uncoupled::Tuple{NTuple{N₁, I}, NTuple{N₂, I}},

‎src/spaces/structure.jl‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct SectorStructure{I <: Sector, F <: FusionTreePair{I}}
2121
fusiontrees::Indices{F}
2222
end
2323

24-
Cached.cachesize(s::SectorStructure) =
24+
MemoizationKit.cachesize(s::SectorStructure) =
2525
sizeof(s) + _cache_payload_size(s.blocksectors) + _cache_payload_size(s.fusiontrees)
2626

2727
Base.@assume_effects :foldable function sectorstructuretype(::S) where {S <: HomSpace}
@@ -71,7 +71,7 @@ See also [`degeneracystructure`](@ref), [`fusiontrees`](@ref), [`blocksectors`](
7171
return SectorStructure{I, F}(Indices(bs), Indices(trees))
7272
end
7373

74-
Cached.cachekey(::typeof(sectorstructure), W::HomSpace) = (Hashed(W, sectorhash, sectorequal),)
74+
MemoizationKit.cachekey(::typeof(sectorstructure), W::HomSpace) = (Hashed(W, sectorhash, sectorequal),)
7575

7676
# DegeneracyStructure: degeneracy-dependent characterization of HomSpaces
7777
# -----------------------------------------------------------------------
@@ -97,7 +97,7 @@ struct DegeneracyStructure{N}
9797
subblockstructure::Vector{StridedStructure{N}}
9898
end
9999

100-
Cached.cachesize(s::DegeneracyStructure) = sizeof(s) + sizeof(s.blockstructure) + sizeof(s.subblockstructure)
100+
MemoizationKit.cachesize(s::DegeneracyStructure) = sizeof(s) + sizeof(s.blockstructure) + sizeof(s.subblockstructure)
101101

102102
function degeneracystructuretype(W::HomSpace)
103103
N = length(codomain(W)) + length(domain(W))

‎src/tensors/treetransformers.jl‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ end
5252
_cache_structure_size(t::TreeTransformer) = sizeof(t.structure_src) +
5353
(t.structure_src === t.structure_dst ? 0 : sizeof(t.structure_dst))
5454

55-
Cached.cachesize(t::UniqueTreeTransformer) = sizeof(t) + _cache_payload_size(t.data) + _cache_structure_size(t)
55+
MemoizationKit.cachesize(t::UniqueTreeTransformer) = sizeof(t) + _cache_payload_size(t.data) + _cache_structure_size(t)
5656

57-
function Cached.cachesize(t::GenericTreeTransformer)
57+
function MemoizationKit.cachesize(t::GenericTreeTransformer)
5858
bytes = sizeof(t) + sizeof(t.data) + _cache_structure_size(t)
5959
for (U, inds_dst, inds_src) in t.data
6060
bytes += _cache_payload_size(U) + sizeof(inds_src) +
@@ -199,13 +199,13 @@ end
199199
return TreeTransformer(fusiontreetransform, p, Vdst, Vsrc, conjsrc)
200200
end
201201

202-
# Keep TensorKit's profiling categories for the phases instrumented by Cached.
202+
# Keep TensorKit's profiling categories for the phases instrumented by MemoizationKit.
203203
const TensorKitCachedFunction = Union{
204204
typeof(fsbraid), typeof(fstranspose), typeof(treebraider), typeof(treetransposer),
205205
typeof(sectorstructure), typeof(degeneracystructure),
206206
}
207-
Cached.instrument_label(f::TensorKitCachedFunction, ::Val{:lookup}) = "bookkeeping: cache $(nameof(f))"
208-
Cached.instrument_label(f::TensorKitCachedFunction, ::Val{:compute}) = "symmetry: compute $(nameof(f))"
207+
MemoizationKit.instrument_label(f::TensorKitCachedFunction, ::Val{:lookup}) = "bookkeeping: cache $(nameof(f))"
208+
MemoizationKit.instrument_label(f::TensorKitCachedFunction, ::Val{:compute}) = "symmetry: compute $(nameof(f))"
209209

210210
# For CPU arrays the recoupling matrix can be used as is, also when the scalar types
211211
# do not match, since Strided handles mixed-eltype mul! without the copy that

‎test/other/caches.jl‎

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
using Test, TestExtras
22
using TensorKit
3-
using TensorKit: Cached, sectorstructure, degeneracystructure
3+
using TensorKit: MemoizationKit, sectorstructure, degeneracystructure
44

5-
@testset "Cached structure keys" begin
5+
@testset "Cache structure keys" begin
66
V1 = SU2Space(0 => 2, 1 // 2 => 3)
77
V2 = SU2Space(0 => 4, 1 // 2 => 1)
88
W1, W2 = V1 ⊗ V1 ← V1, V2 ⊗ V2 ← V2
99
empty_globalcaches!()
1010
s1 = @constinferred sectorstructure(W1)
1111
@test s1 === @constinferred sectorstructure(W2)
12-
fresh = Cached.uncached(sectorstructure, W1)
12+
fresh = MemoizationKit.uncached(sectorstructure, W1)
1313
@test s1.blocksectors == fresh.blocksectors
1414
@test s1.fusiontrees == fresh.fusiontrees
15-
@test parent(only(Cached.cachekey(sectorstructure, W1))) === W1
16-
@test length(only(Cached.cache_info(sectorstructure)).second) == 1
15+
@test parent(only(MemoizationKit.cachekey(sectorstructure, W1))) === W1
16+
@test length(only(MemoizationKit.cache_info(sectorstructure)).second) == 1
1717
@test (@constinferred degeneracystructure(W1)).totaldim !=
1818
(@constinferred degeneracystructure(W2)).totaldim
19-
@test length(only(Cached.cache_info(degeneracystructure)).second) == 2
19+
@test length(only(MemoizationKit.cache_info(degeneracystructure)).second) == 2
2020
end
2121

2222
@testset "TensorKit cached-value sizes" begin
@@ -27,48 +27,48 @@ end
2727
p, levels = ((2, 1), (4, 3)), (1, 2, 3, 4)
2828
transformer = TensorKit.treebraider(W, W, p, false, levels)
2929
for value in (sectorstructure(W), degeneracystructure(W), transformer)
30-
bytes = @constinferred Cached.cachesize(value)
30+
bytes = @constinferred MemoizationKit.cachesize(value)
3131
@test 0 < bytes <= Base.summarysize(value)
3232
end
3333
for src in TensorKit.fusionblocks(W)
3434
result = TensorKit.fsbraid(src, p, ((1, 2), (3, 4)))
35-
@test 0 < (@constinferred Cached.cachesize(result)) <= Base.summarysize(result)
35+
@test 0 < (@constinferred MemoizationKit.cachesize(result)) <= Base.summarysize(result)
3636
end
3737

3838
# Two distinct transformer entries share structure buffers. Each entry must
3939
# retain its own size budget even if the degeneracy cache has been cleared.
40-
Cached.set_cache_size!(TensorKit.treebraider, Cached.cachesize(transformer); by = Cached.cachesize)
40+
MemoizationKit.set_cache_size!(TensorKit.treebraider, MemoizationKit.cachesize(transformer); by = MemoizationKit.cachesize)
4141
try
4242
TensorKit.treebraider(W, W, p, false, levels)
4343
TensorKit.treebraider(W, W, ((1, 2), (3, 4)), false, levels)
44-
Cached.empty_caches!(degeneracystructure)
45-
cache = only(Cached.cache_info(TensorKit.treebraider)).second
46-
stats = Cached.cache_stats(cache)
47-
@test stats.by === Cached.cachesize
44+
MemoizationKit.empty_caches!(degeneracystructure)
45+
cache = only(MemoizationKit.cache_info(TensorKit.treebraider)).second
46+
stats = MemoizationKit.cache_stats(cache)
47+
@test stats.by === MemoizationKit.cachesize
4848
@test stats.currentsize <= stats.maxsize
4949
@test stats.length <= 1
50-
@test stats.currentsize == sum(Cached.cachesize, values(cache); init = 0)
50+
@test stats.currentsize == sum(MemoizationKit.cachesize, values(cache); init = 0)
5151

52-
Cached.set_cache_size!(TensorKit.treebraider, 0; by = Cached.cachesize)
52+
MemoizationKit.set_cache_size!(TensorKit.treebraider, 0; by = MemoizationKit.cachesize)
5353
@test isempty(cache)
5454
@test TensorKit.treebraider(W, W, p, false, levels).data == transformer.data
5555
@test isempty(cache)
5656
finally
57-
Cached.set_cache_size!(TensorKit.treebraider, 10_000)
57+
MemoizationKit.set_cache_size!(TensorKit.treebraider, 10_000)
5858
end
5959
end
6060

6161
# An empty transformer still costs space, and arbitrary-precision coefficients
6262
# include their referenced storage instead of just the array's pointer slots.
6363
strides = TensorKit.StridedStructure{2}[]
6464
empty_transformer = TensorKit.UniqueTreeTransformer(Tuple{Float64, Int, Int}[], strides, strides)
65-
@test Cached.cachesize(empty_transformer) > 0
65+
@test MemoizationKit.cachesize(empty_transformer) > 0
6666
big_transformer = TensorKit.UniqueTreeTransformer([(BigFloat(1), 1, 1)], strides, strides)
67-
@test Cached.cachesize(big_transformer) >= Base.summarysize(big_transformer.data)
67+
@test MemoizationKit.cachesize(big_transformer) >= Base.summarysize(big_transformer.data)
6868
end
6969

7070
# A cache owned by another module must survive TensorKit's cache clearing.
71-
Cached.@cached unrelated_cache(x) = [x]
71+
MemoizationKit.@cached unrelated_cache(x) = [x]
7272

7373
@testset "TensorKit cache management" begin
7474
retained = unrelated_cache(1)
@@ -84,11 +84,11 @@ Cached.@cached unrelated_cache(x) = [x]
8484
@test occursin("treebraider", info)
8585
@test occursin("extension_cache", info)
8686
@test empty_globalcaches!() === nothing
87-
@test all(isempty(cache) for (_, cache) in Cached.cache_info(TensorKit))
87+
@test all(isempty(cache) for (_, cache) in MemoizationKit.cache_info(TensorKit))
8888
@test isempty(extra)
8989
@test unrelated_cache(1) === retained
9090
finally
9191
pop!(TensorKit.GLOBAL_CACHES)
92-
Cached.empty_caches!(unrelated_cache)
92+
MemoizationKit.empty_caches!(unrelated_cache)
9393
end
9494
end

0 commit comments

Comments
 (0)