Skip to content

Store the fusion trees of both sides instead of every fusion tree pair - #600

Draft
leburgel wants to merge 8 commits into
mainfrom
lb/fusion_tree_pairs
Draft

leburgel wants to merge 8 commits into
mainfrom
lb/fusion_tree_pairs

Conversation

@leburgel

@leburgel leburgel commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Closes #596.

  • fusiontrees(W) is a FusionTreePairs, an AbstractIndices that stores the splitting and fusion trees of every coupled sector instead of every pair. The position of a pair follows from those of its trees, and is its (integer) token.
  • subblockstructure(W) is a FusionTreePairDict sharing those tokens.
  • fusionblocks groups the trees of each side by their uncoupled sectors, combines the groups in the order in which they first occur (the order of Construct fusion tree blocks from the shorter side, and group the cached trees in fusionblocks #581), and fills every block once at its final size.
  • degeneracystructure loops over the trees of both sides.
  • The tree and trace transformers keep the tokens of all their blocks in one vector of Int32 pairs, of which every block holds a range (SubblockIndices), instead of two vectors per block. After all 480 permutations of a fermionic SU(2) tensor, this takes TensorKit's caches from 75.0 to 56.8 MiB (reproducer below); cachesize, which does not count the headers of the small vectors, hardly changes (58.1 to 57.2 MiB).

The transformers are identical to those of #581, block order included, on all transformers of one CTMRG iteration (554 for fℤ₂ × U(1) × SU(3), 550 for fℤ₂ × U(1) × SU(2) × U(1)).

Building those transformers, on top of main + #580 + #581 + #592, before the packed tokens (D = 7, shared machine at load 16–29, ranges over 3 interleaved rounds):

before after
fℤ₂ × U(1) × SU(2) × U(1), serial preparation 15.6–17.3 s 9.9–11.1 s
fℤ₂ × U(1) × SU(2) × U(1), 1 thread 27.0–29.5 s 20.5–22.9 s
fℤ₂ × U(1) × SU(2) × U(1), 8 threads 18.9–20.0 s 14.1–17.9 s
fℤ₂ × U(1) × SU(3), serial preparation 4.4–4.7 s 3.4–3.7 s
fℤ₂ × U(1) × SU(3), 1 thread 10.6–10.7 s 9.5–10.3 s
fℤ₂ × U(1) × SU(3), 8 threads 4.9–5.5 s 4.2–4.6 s

Keying the groups by the integer positions of the uncoupled sectors instead makes fusionblocks about 1 s faster for SU(2), but the totals are within the noise, so this keeps the simpler version.

Reproducer
using TensorKit, Printf
using TensorKit: MemoizationKit

s(p, n, j) = FermionParity(p) ⊠ U1Irrep(n) ⊠ SU2Irrep(j)
I = typeof(s(0, 0, 0))
P = Vect[I](s(0, 0, 0) => 1, s(1, 1, 1 // 2) => 1, s(0, 2, 0) => 1)
V = Vect[I](s(0, 0, 0) => 2, s(1, 1, 1 // 2) => 1, s(1, -1, 1 // 2) => 1, s(0, 2, 0) => 1, s(0, -2, 0) => 1, s(0, 0, 1) => 1)
t = randn(P ⊗ V ⊗ V ← V ⊗ V)
perms = [(p[1:k], p[(k + 1):end]) for p in Iterators.product(ntuple(_ -> 1:5, 5)...) if allunique(p) for k in 1:4]
permuteall(t) = foreach(p -> permute(t, p), perms)

cachedvalues() = [v for (_, c) in MemoizationKit.cache_info(TensorKit) for (_, v) in c]
permuteall(t) # compile
empty_globalcaches!(); GC.gc()
cold = @elapsed permuteall(t)
warm = @elapsed permuteall(t)
vs = cachedvalues()
@printf("%d permutations, %d cached values\n", length(perms), length(vs))
@printf("TensorKit caches: %.1f MiB (summarysize, shared arrays once), %.1f MiB (sum of cachesize)\n",
    Base.summarysize(vs) / 2^20, sum(v -> MemoizationKit.cachesize(v), vs) / 2^20)
@printf("permutations from empty caches %.2f s, with full caches %.3f s\n", cold, warm)

before the packed tokens (776ac93d):

480 permutations, 10719 cached values
TensorKit caches: 75.0 MiB (summarysize, shared arrays once), 58.1 MiB (sum of cachesize)
permutations from empty caches 1.25 s, with full caches 0.154 s

with them (6baaf9ee):

480 permutations, 10719 cached values
TensorKit caches: 56.8 MiB (summarysize, shared arrays once), 57.2 MiB (sum of cachesize)
permutations from empty caches 1.35 s, with full caches 0.155 s

🤖 Generated with Claude Code

@lkdvos
lkdvos force-pushed the lb/fusiontreeblock_construction branch from 8e373fa to 3f74b72 Compare October 28, 2026 19:19
Base automatically changed from lb/fusiontreeblock_construction to main October 28, 2026 22:53
@leburgel
leburgel force-pushed the lb/fusion_tree_pairs branch from 5da53cf to dc18d84 Compare October 29, 2026 06:47
@codecov

codecov Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.12871% with 26 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/spaces/structure.jl 81.73% 21 Missing ⚠️
src/pullbacks/tensoroperations.jl 0.00% 4 Missing ⚠️
src/tensors/treetransformers.jl 97.95% 1 Missing ⚠️
Files with missing lines Coverage Δ
ext/TensorKitGPUArraysExt.jl 96.96% <ø> (ø)
src/TensorKit.jl 13.79% <ø> (ø)
src/spaces/homspace.jl 94.21% <100.00%> (+0.58%) ⬆️
src/tensors/blockiterators.jl 47.50% <100.00%> (-0.40%) ⬇️
src/tensors/indexmanipulations.jl 91.82% <100.00%> (+0.06%) ⬆️
src/tensors/tensor.jl 81.46% <100.00%> (-0.22%) ⬇️
src/tensors/treetransformers.jl 97.15% <97.95%> (+0.30%) ⬆️
src/pullbacks/tensoroperations.jl 41.81% <0.00%> (-0.78%) ⬇️
src/spaces/structure.jl 83.08% <81.73%> (-12.88%) ⬇️

... and 6 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@leburgel
leburgel force-pushed the lb/fusion_tree_pairs branch 2 times, most recently from e291962 to b0ff22f Compare November 2, 2026 06:49
@lkdvos
lkdvos force-pushed the lb/fusion_tree_pairs branch from b0ff22f to 9a2ebbf Compare November 10, 2026 17:15
leburgel and others added 5 commits November 16, 2026 20:29
`fusiontrees(W)` is a `FusionTreePairs`, an `AbstractIndices` holding the
splitting and fusion trees of every coupled sector; the position of a pair
follows from those of its trees, and is its token. `subblockstructure(W)`
shares these tokens. `fusionblocks` groups the trees of each side by their
uncoupled sectors, combines the groups in the order in which they first occur,
and fills every block once at its final size; `degeneracystructure` loops over
the trees of both sides.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ePairs

The units of a product sector, the block sectors of a space without indices, come with a shape,
and showing a FusionTreePairs iterates it in reverse.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Replace the per-tree block indices by the coupled sectors, and use the
pair of tree positions as the token, with `pairposition` converting it
into the position of the pair.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…cystructure

Collecting them with `map` made the subblock loop 10-15% slower than on
main, independently of how the strided structures are stored.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`degeneracystructure` now stores the sizes, strides and offset of every
splitting and fusion tree, zero-padded such that the structure of a
subblock is their sum, instead of the structure of every subblock. The
strides follow in closed form from the column-major layout of the blocks.
The tree transformers address subblocks by the tokens of their fusion
tree pairs, which index these per-tree structures directly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@leburgel
leburgel force-pushed the lb/fusion_tree_pairs branch from f687a06 to 776ac93 Compare November 16, 2026 19:32
leburgel and others added 3 commits November 20, 2026 11:21
… of Int32 pairs

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	docs/src/Changelog.md
#	src/tensors/treetransformers.jl

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Serial sectorstructure and fusionblocks dominate building transformers of product sectors

2 participants