Skip to content

Commit 8f7af24

Browse files
leburgelclaudelkdvos
authored
Construct fusion tree blocks from the shorter side, and group the cached trees in fusionblocks (#581)
* Construct `FusionTreeBlock`s from the fusion product of the shorter side For sectors with a simple unit, a superset of the coupled sectors suffices, as the fusion tree iterators yield nothing for the others: the unit if one side is empty, and otherwise the fusion product of the shorter side only, instead of the intersection of the fusion products of both sides. The trees and their order are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Group the cached fusion trees in `fusionblocks` Instead of constructing a block for every combination of codomain and domain sectors, `fusionblocks` groups the cached `fusiontrees(W)` by their uncoupled sectors, in the same order as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Test the blocks of a HomSpace; changelog Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Compute the rank of each block once when sorting in `fusionblocks` `sort!(...; by = rank)` evaluated `rank`, and with it the `Dict` lookups of (product) sectors, at every comparison. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Use the fusion product of the shorter side for every UnitStyle; check only the longer side for trees Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Use the unit of the other side as the coupled sector of a block with no legs on one side Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Only try coupled sectors whose units match the ends of the other side For several units, a coupled sector of a block must be compatible with the units at both ends of either side; otherwise the fusion tree iterator throws instead of being empty. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Order the blocks by comparing their sectors Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Compute the sort key of each block once Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Keep the blocks in the order in which their uncoupled sectors first occur Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Fill the vectors of the fusion tree blocks directly Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Reuse the fusion tree iterator of the longer side Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: lkdvos <ldevos98@gmail.com>
1 parent 0e7ad34 commit 8f7af24

4 files changed

Lines changed: 53 additions & 15 deletions

File tree

‎docs/src/Changelog.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ When releasing a new version, move the "Unreleased" changes to a new version sec
4242
### Performance
4343

4444
- Recoupling matrices are stored such that they can leverage BLAS, also for mixed complex tensor with real recoupling coefficients.
45+
- Constructing a `FusionTreeBlock` only takes the fusion product of the shorter side, and `fusionblocks` groups the cached fusion trees of the space instead of constructing a block for every combination of sectors (internal)
4546

4647
## [0.17.2](https://github.com/QuantumKitHub/TensorKit.jl/compare/v0.17.1...v0.17.2) - 2026-09-20
4748

‎src/fusiontrees/fusiontrees.jl‎

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,18 +140,35 @@ function FusionTreeBlock{I}(
140140
end
141141

142142
# note: cs is unique due to ⊗ returning unique fusion results
143-
cs = if N₁ == 0
144-
sort!(collect(filter(isunit, ⊗(uncoupled[2]...))))
145-
elseif N₂ == 0
146-
sort!(collect(filter(isunit, ⊗(uncoupled[1]...))))
143+
# a superset of the coupled sectors suffices, as there are no fusion trees for the others:
144+
# the unit of the other side, or the fusion product of the shorter side, which avoids that of
145+
# the longer side (`vec`: products of `ProductSector`s have a shape)
146+
cs = if N₁ == 0 || N₂ == 0
147+
# the only unit that can couple: on the left of the first and on the right of the last sector
148+
us = N₁ == 0 ? uncoupled[2] : uncoupled[1]
149+
leftunit(first(us)) == rightunit(last(us)) ? [leftunit(first(us))] : I[]
147150
else
148-
sort!(collect(intersect(⊗(uncoupled[1]...), ⊗(uncoupled[2]...))))
151+
sort!(vec(collect(⊗(uncoupled[N₁ <= N₂ ? 1 : 2]...))))
149152
end
150153

151-
for c in cs,
152-
f₂ in fusiontrees(uncoupled[2], c, isdual[2]),
153-
f₁ in fusiontrees(uncoupled[1], c, isdual[1])
154-
push!(trees, (f₁, f₂))
154+
for c in cs
155+
# the shorter side has fusion trees for every candidate, the longer side not necessarily
156+
# (with several units, `c` must also have the units at the ends of the longer side)
157+
us = N₁ <= N₂ ? uncoupled[2] : uncoupled[1]
158+
UnitStyle(I) isa SimpleUnit || N₁ == 0 || N₂ == 0 ||
159+
(leftunit(c) == leftunit(first(us)) && rightunit(c) == rightunit(last(us))) || continue
160+
if N₁ <= N₂
161+
ftrees₂ = fusiontrees(uncoupled[2], c, isdual[2])
162+
isempty(ftrees₂) && continue
163+
ftrees₁ = fusiontrees(uncoupled[1], c, isdual[1])
164+
else
165+
ftrees₁ = fusiontrees(uncoupled[1], c, isdual[1])
166+
isempty(ftrees₁) && continue
167+
ftrees₂ = fusiontrees(uncoupled[2], c, isdual[2])
168+
end
169+
for f₂ in ftrees₂, f₁ in ftrees₁
170+
push!(trees, (f₁, f₂))
171+
end
155172
end
156173
return FusionTreeBlock(trees)
157174
end

‎src/spaces/homspace.jl‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,20 @@ grouped by their uncoupled charges.
210210
function fusionblocks(W::HomSpace)
211211
I = sectortype(W)
212212
N₁, N₂ = numout(W), numin(W)
213-
isdual_src = (map(isdual, codomain(W)), map(isdual, domain(W)))
214-
fblocks = Vector{FusionTreeBlock{I, N₁, N₂, fusiontreetype(I, N₁, N₂)}}()
215-
for dom_uncoupled_src in sectors(domain(W)), cod_uncoupled_src in sectors(codomain(W))
216-
fs_src = FusionTreeBlock{I}((cod_uncoupled_src, dom_uncoupled_src), isdual_src)
217-
isempty(fs_src) || push!(fblocks, fs_src)
213+
F = fusiontreetype(I, N₁, N₂)
214+
# group the (cached) fusion trees of `W` by their uncoupled sectors,
215+
# in the order in which these first occur
216+
blocks = FusionTreeBlock{I, N₁, N₂, F}[]
217+
trees_of = Dict{Tuple{NTuple{N₁, I}, NTuple{N₂, I}}, Vector{F}}()
218+
for (f₁, f₂) in fusiontrees(W)
219+
trees = get!(trees_of, (f₁.uncoupled, f₂.uncoupled)) do
220+
newtrees = F[]
221+
push!(blocks, FusionTreeBlock(newtrees))
222+
return newtrees
223+
end
224+
push!(trees, (f₁, f₂))
218225
end
219-
return fblocks
226+
return blocks
220227
end
221228

222229
function diagonalblockstructure(W::HomSpace)

‎test/symmetries/doubletree.jl‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,19 @@ using TensorKitSectors
235235
end
236236
end
237237

238+
UnitStyle(I) isa SimpleUnit && @testset "Double fusion tree: blocks of a HomSpace" begin
239+
V = Vect[I](Dict(s => 1 for s in (out..., incoming)))
240+
W = V ⊗ V' ← V ⊗ V' # never empty: the unit couples both sides
241+
trees = collect(fusiontrees(W))
242+
blocks = TK.fusionblocks(W)
243+
# every block holds the trees of `W` with its uncoupled sectors, in the same order
244+
for block in blocks
245+
@test fusiontrees(block) == filter(f -> (f[1].uncoupled, f[2].uncoupled) == block.uncoupled, trees)
246+
end
247+
@test sum(length, blocks) == length(trees)
248+
@test allunique(map(block -> block.uncoupled, blocks))
249+
end
250+
238251
@testset "Double fusion tree: planar trace" begin
239252
if FusionStyle(I) isa UniqueFusion
240253
f1, f1 = src

0 commit comments

Comments
 (0)