Skip to content

Commit a3b793a

Browse files
lkdvosclaude
andcommitted
Address review: descriptive cache names and transpose inference
- Rename `fsbraid`/`fstranspose` to `fusiontreebraid`/`fusiontreetranspose`, as these are now user-facing through the MemoizationKit APIs and dashboard. - Restore the return type annotation on `fusiontreetranspose`, without which the `FusionTreePair` path infers `Any` and the cache stores untyped values. - Update the Enzyme inactivity rule for the new three-argument `fusiontreebraid`. - Refer to the MemoizationKit documentation for further features. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent cfb5c7f commit a3b793a

6 files changed

Lines changed: 25 additions & 15 deletions

File tree

‎docs/src/man/fusiontrees.md‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,7 @@ These estimate bytes from the fixed-size fields and live array buffers; matrix c
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 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.
285+
Further features, such as the live cache dashboard, disk caching and the full configuration options, are described in the [MemoizationKit.jl documentation](https://quantumkithub.github.io/MemoizationKit.jl/stable/).
287286

288287
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.
289288

‎ext/TensorKitEnzymeExt/utility.jl‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,7 @@ end
142142
@inline EnzymeRules.inactive(::typeof(TensorKit.fusiontrees), ::Any) = nothing
143143
@inline EnzymeRules.inactive(::typeof(TensorKit.fusiontrees), ::Any, ::Any) = nothing
144144
@inline EnzymeRules.inactive(::typeof(TensorKit.fusiontrees), ::Any, ::Any, ::Any) = nothing
145-
@inline EnzymeRules.inactive(::typeof(TensorKit.fsbraid), ::Any) = nothing
146-
@inline EnzymeRules.inactive(::typeof(TensorKit.fsbraid), ::Any, ::Any) = nothing
145+
@inline EnzymeRules.inactive(::typeof(TensorKit.fusiontreebraid), ::Any, ::Any, ::Any) = nothing
147146
@inline EnzymeRules.inactive(::typeof(TensorKit.artin_braid), ::Any, ::Any) = nothing
148147
@inline EnzymeRules.inactive(::typeof(TensorKit.fstranspose), ::Any) = nothing
149148
@inline EnzymeRules.inactive(::typeof(TensorKit.fstranspose), ::Any, ::Any) = nothing

‎src/fusiontrees/braiding_manipulations.jl‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ function braid(src::Union{FusionTreePair, FusionTreeBlock}, p::Index2Tuple, leve
284284
@assert numind(src) == length(p[1]) + length(p[2])
285285
@assert numout(src) == length(levels[1]) && numin(src) == length(levels[2])
286286
@assert TupleTools.isperm((p[1]..., p[2]...))
287-
return fsbraid(src, p, levels)
287+
return fusiontreebraid(src, p, levels)
288288
end
289289
function braid(src::ProductSectorBlock, p::Index2Tuple, levels::Index2Tuple)
290290
isempty(src) && return fsbraid((src, p, levels))
@@ -296,7 +296,7 @@ end
296296

297297
# Braiding can promote real fusion coefficients to complex values. Keep the result
298298
# type explicit so all braid paths remain inferred, including anyonic sectors.
299-
Base.@assume_effects :foldable function fsbraidtype(
299+
Base.@assume_effects :foldable function fusiontreebraidtype(
300300
src::Union{FusionTreePair{I}, FusionTreeBlock{I}}, ::Index2Tuple{N₁, N₂}
301301
) where {I, N₁, N₂}
302302
T = sectorscalartype(I)
@@ -308,10 +308,10 @@ Base.@assume_effects :foldable function fsbraidtype(
308308
end
309309
end
310310

311-
@cached function fsbraid(
311+
@cached function fusiontreebraid(
312312
src::Union{FusionTreePair{I}, FusionTreeBlock{I}},
313313
p::Index2Tuple{N₁, N₂}, levels::Index2Tuple
314-
)::fsbraidtype(src, p) where {I, N₁, N₂}
314+
)::fusiontreebraidtype(src, p) where {I, N₁, N₂}
315315
p1, p2 = p
316316
l1, l2 = levels
317317
if src isa FusionTreePair
@@ -349,7 +349,7 @@ end
349349
end
350350
end
351351

352-
CacheStyle(::typeof(fsbraid), src::Union{FusionTreePair{I}, FusionTreeBlock{I}}, args...) where {I} =
352+
CacheStyle(::typeof(fusiontreebraid), src::Union{FusionTreePair{I}, FusionTreeBlock{I}}, args...) where {I} =
353353
FusionStyle(I) isa UniqueFusion ? NoCache() : GlobalCache()
354354

355355
"""

‎src/fusiontrees/duality_manipulations.jl‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ function Base.transpose(src::Union{FusionTreePair, FusionTreeBlock}, p::Index2Tu
524524
N == length(p[1]) + length(p[2]) || throw(ArgumentError("invalid permutation p = $p of length N = $N"))
525525
p′ = linearizepermutation(p..., numout(src), numin(src))
526526
iscyclicpermutation(p′) || throw(ArgumentError("invalid cyclic or planar permutation p = $p"))
527-
return fstranspose(src, p)
527+
return fusiontreetranspose(src, p)
528528
end
529529
function Base.transpose(src::ProductSectorBlock, p::Index2Tuple)
530530
isempty(src) && return fstranspose((src, p))
@@ -534,9 +534,21 @@ function Base.transpose(src::ProductSectorBlock, p::Index2Tuple)
534534
end::_fsdicttype(typeof((src, p)))
535535
end
536536

537-
@cached function fstranspose(
538-
src::Union{FusionTreePair{I}, FusionTreeBlock{I}}, p::Index2Tuple{N₁, N₂}
537+
Base.@assume_effects :foldable function fusiontreetransposetype(
538+
src::Union{FusionTreePair{I}, FusionTreeBlock{I}}, ::Index2Tuple{N₁, N₂}
539539
) where {I, N₁, N₂}
540+
T = fusionscalartype(I)
541+
if src isa FusionTreePair
542+
return Pair{fusiontreetype(I, N₁, N₂), T}
543+
else
544+
F = Tuple{fusiontreetype(I, N₁), fusiontreetype(I, N₂)}
545+
return Pair{FusionTreeBlock{I, N₁, N₂, F}, Matrix{T}}
546+
end
547+
end
548+
549+
@cached function fusiontreetranspose(
550+
src::Union{FusionTreePair{I}, FusionTreeBlock{I}}, p::Index2Tuple{N₁, N₂}
551+
)::fusiontreetransposetype(src, p) where {I, N₁, N₂}
540552
p1, p2 = p
541553

542554
N = N₁ + N₂
@@ -562,7 +574,7 @@ end
562574
return dst => U
563575
end
564576

565-
CacheStyle(::typeof(fstranspose), src::Union{FusionTreePair{I}, FusionTreeBlock{I}}, args...) where {I} =
577+
CacheStyle(::typeof(fusiontreetranspose), src::Union{FusionTreePair{I}, FusionTreeBlock{I}}, args...) where {I} =
566578
FusionStyle(I) isa UniqueFusion ? NoCache() : GlobalCache()
567579

568580
# COMPOSITE DUALITY MANIPULATIONS PART 2: Planar traces

‎src/tensors/treetransformers.jl‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ end
220220

221221
# Keep TensorKit's profiling categories for the phases instrumented by MemoizationKit.
222222
const TensorKitCachedFunction = Union{
223-
typeof(fsbraid), typeof(fstranspose), typeof(treebraider), typeof(treetransposer),
223+
typeof(fusiontreebraid), typeof(fusiontreetranspose), typeof(treebraider), typeof(treetransposer),
224224
typeof(sectorstructure), typeof(degeneracystructure),
225225
}
226226
MemoizationKit.instrument_label(f::TensorKitCachedFunction, ::Val{:lookup}) = "bookkeeping: cache $(nameof(f))"

‎test/other/caches.jl‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ end
3131
@test 0 < bytes <= Base.summarysize(value)
3232
end
3333
for src in TensorKit.fusionblocks(W)
34-
result = TensorKit.fsbraid(src, p, ((1, 2), (3, 4)))
34+
result = TensorKit.fusiontreebraid(src, p, ((1, 2), (3, 4)))
3535
@test 0 < (@constinferred MemoizationKit.cachesize(result)) <= Base.summarysize(result)
3636
end
3737

0 commit comments

Comments
 (0)