Skip to content

Commit ee29572

Browse files
leburgelclaude
andcommitted
Transform the fusion tree pairs of a UniqueTreeTransformer on several tasks
The pairs are split into one equal range per task, on up to get_num_manipulation_threads() tasks with taskforeach, as the fusion tree blocks of a GenericTreeTransformer already are. Every task gets at least 1024 pairs, so small transformers stay serial. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent d03b3ba commit ee29572

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

‎docs/src/Changelog.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ When releasing a new version, move the "Unreleased" changes to a new version sec
4949
- `taskforeach` with a single worker is a plain loop without an atomic counter, which lowers the cost per subblock of single-threaded index manipulations and planar traces
5050
- Tree transformers for sectors with multiple fusion channels share equal recoupling matrices, which only depend on the sectors, instead of storing one copy per transformer
5151
- The cached braids and transposes of fusion tree blocks keep their recoupling matrices in the scalar type of the tree transformers that use them, instead of a copy in that type for every transformer
52+
- The fusion tree pairs of a `UniqueTreeTransformer` are transformed on up to `get_num_manipulation_threads()` tasks, as the fusion tree blocks of a `GenericTreeTransformer` already were, which speeds up the construction of the index manipulations of abelian tensors with many fusion tree pairs
5253

5354
## [0.17.3](https://github.com/QuantumKitHub/TensorKit.jl/compare/v0.17.2...v0.17.3) - 2026-10-30
5455

‎src/tensors/treetransformers.jl‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ end
3737
# (coefficient, destination position, source position)
3838
const UniqueTransformerData{T} = Tuple{T, Int, Int}
3939

40+
# the minimal number of fusion tree pairs per task of `UniqueTreeTransformer`
41+
const UNIQUE_TRANSFORM_MINPAIRS = 1024
42+
4043
"""
4144
UniqueTreeTransformer{T, N} <: TreeTransformer
4245
@@ -97,10 +100,18 @@ function UniqueTreeTransformer(::Type{A}, transform, p, Vdst::HomSpace, Vsrc::Ho
97100
T = recoupling_scalartype(A, sectorscalartype(sectortype(Vdst)))
98101
data = Vector{UniqueTransformerData{T}}(undef, length(src_trees))
99102

100-
@timeit_debug GLOBAL_TIMER "symmetry: tree transform" for (isrc, (f₁, f₂)) in enumerate(src_trees)
101-
f_dst, coeff = transform(conjsrc ? (f₂, f₁) : (f₁, f₂))
102-
_, (_, idst) = gettoken(dst_trees, f_dst)
103-
data[isrc] = (convert(T, coeff), idst, isrc)
103+
# the pairs are split into one equal range per task, with enough pairs in every range
104+
ntasks = clamp(length(data) ÷ UNIQUE_TRANSFORM_MINPAIRS, 1, get_num_manipulation_threads())
105+
chunks = Iterators.partition(eachindex(data), max(cld(length(data), ntasks), 1))
106+
@timeit_debug GLOBAL_TIMER "symmetry: tree transform" begin
107+
taskforeach(chunks, ntasks) do isrcs
108+
for isrc in isrcs
109+
f₁, f₂ = gettokenvalue(src_trees, isrc)
110+
f_dst, coeff = transform(conjsrc ? (f₂, f₁) : (f₁, f₂))
111+
_, (_, idst) = gettoken(dst_trees, f_dst)
112+
data[isrc] = (convert(T, coeff), idst, isrc)
113+
end
114+
end
104115
end
105116

106117
structure_dst = degeneracystructure(Vdst).subblockstructure

0 commit comments

Comments
 (0)