Skip to content

Commit 8d5d02f

Browse files
lkdvosclaude
andcommitted
Precompute planar trace kernels in a TraceTransformer
`planartrace!` now precomputes the subblock positions and recoupling coefficients in a cached `TraceTransformer`, and executes them with a sector-independent kernel, analogous to the index manipulations. This replaces the per-tree loop that built ad-hoc single-pair `FusionTreeBlock`s. - `planar_trace` is defined for `Union{FusionTreePair, FusionTreeBlock}`, with unique-fusion pairs returning `dst => coeff` and blocks `dst => U`, and throws when the traced sectors are not dual to each other - the transformer skips such (sub)blocks upfront and groups the data by destination, such that every destination subblock is written once and `β` is handled inside the kernel - blocks with several destination trees are traced (and permuted) into a buffer, recoupled with a single matmul and added into the destination - `FusionTreeBlock`s hash their uncoupled sectors and duality flags Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 770983c commit 8d5d02f

7 files changed

Lines changed: 258 additions & 75 deletions

File tree

‎docs/src/Changelog.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ When releasing a new version, move the "Unreleased" changes to a new version sec
3030
- Require TensorKitSectors v0.3.10
3131
- `@cached` can be used from other modules, such as package extensions, which then own the cache of the methods they add; these caches are shown with their module in `global_cache_info` after registration in `__init__` (internal)
3232
- The `TreeTransformer`s used in index manipulations are now constructed and cached per storagetype of the destination tensor, which is also a dispatch point for storage-specific transformers with their own cache (internal)
33+
- `planartrace!` precomputes and caches a `TraceTransformer` with the subblock positions and recoupling coefficients, and executes it with a kernel shared by all sectortypes, analogous to the index manipulations; `planar_trace` is now also defined for `FusionTreeBlock`s (internal)
3334

3435
### Deprecated
3536

‎docs/src/lib/fusiontrees.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,5 @@ repartition(src::Union{FusionTreePair, FusionTreeBlock}, N::Int)
4848
Base.transpose(src::Union{FusionTreePair, FusionTreeBlock}, p::Index2Tuple)
4949
braid(src::Union{FusionTreePair, FusionTreeBlock}, p::Index2Tuple, levels::Index2Tuple)
5050
permute(src::Union{FusionTreePair, FusionTreeBlock}, p::Index2Tuple)
51+
planar_trace(src::Union{FusionTreePair, FusionTreeBlock}, p::Index2Tuple, q::Index2Tuple)
5152
```

‎src/fusiontrees/duality_manipulations.jl‎

Lines changed: 71 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -584,58 +584,85 @@ CacheStyle(::typeof(fstranspose), k::FSBTransposeKey{I}) where {I} =
584584
# -> composite manipulations that depend on the duality (rigidity) and pivotal structure
585585
# -> planar manipulations that do not require braiding, everything is in Fsymbol (A/Bsymbol)
586586

587-
function planar_trace((f₁, f₂)::FusionTreePair, (p₁, p₂)::Index2Tuple, (q₁, q₂)::Index2Tuple)
587+
# leg positions of a planar trace of a tree pair with `N₁` outgoing and `N₂` incoming legs, after
588+
# repartitioning all legs to the outgoing side: the traced pairs `q′`, the remaining legs `r` in
589+
# increasing order and the permutation `p′` that is applied after removing the traced legs
590+
function _planar_trace_indices(::Val{N₁}, ::Val{N₂}, (p₁, p₂)::Index2Tuple, (q₁, q₂)::Index2Tuple) where {N₁, N₂}
588591
length(q₁) == length(q₂) ||
589592
throw(ArgumentError(lazy"trace index tuples q₁ and q₂ must have equal length, got $(length(q₁)) and $(length(q₂))"))
590-
I = sectortype(f₁)
591593
N = length(p₁) + length(p₂) + 2 * length(q₁)
592-
length(f₁) + length(f₂) == N ||
593-
throw(ArgumentError(lazy"fusion tree pair has $(length(f₁) + length(f₂)) indices, but permutation expects $N = $(length(p₁)) + $(length(p₂)) + 2×$(length(q₁))"))
594-
if isempty(q₁)
595-
return transpose((f₁, f₂), (p₁, p₂))
596-
end
597-
598-
linearindex = (
599-
ntuple(identity, Val(length(f₁)))...,
600-
reverse(length(f₁) .+ ntuple(identity, Val(length(f₂))))...,
601-
)
602-
594+
N₁ + N₂ == N ||
595+
throw(ArgumentError(lazy"fusion tree pair has $(N₁ + N₂) indices, but permutation expects $N = $(length(p₁)) + $(length(p₂)) + 2×$(length(q₁))"))
596+
linearindex = (ntuple(identity, Val(N₁))..., reverse(N₁ .+ ntuple(identity, Val(N₂)))...)
603597
q₁′ = TupleTools.getindices(linearindex, q₁)
604598
q₂′ = TupleTools.getindices(linearindex, q₂)
605-
p₁′, p₂′ = let q′ = (q₁′..., q₂′...)
606-
(
607-
map(l -> l - count(l .> q′), TupleTools.getindices(linearindex, p₁)),
608-
map(l -> l - count(l .> q′), TupleTools.getindices(linearindex, p₂)),
609-
)
610-
end
599+
q′ = (q₁′..., q₂′...)
600+
p₁′ = map(l -> l - count(l .> q′), TupleTools.getindices(linearindex, p₁))
601+
p₂′ = map(l -> l - count(l .> q′), TupleTools.getindices(linearindex, p₂))
602+
r = TupleTools.sort(TupleTools.getindices(linearindex, (p₁..., p₂...)))
603+
return (p₁′, p₂′), (q₁′, q₂′), r
604+
end
611605

612-
T = fusionscalartype(I)
613-
F₁ = fusiontreetype(I, length(p₁))
614-
F₂ = fusiontreetype(I, length(p₂))
615-
newtrees = FusionTreeDict{Tuple{F₁, F₂}, T}()
616-
if FusionStyle(I) isa UniqueFusion
617-
(f₁′, f₂′), coeff′ = repartition((f₁, f₂), N)
618-
for (f₁′′, coeff′′) in planar_trace(f₁′, (q₁′, q₂′))
619-
(f12′′′, coeff′′′) = transpose((f₁′′, f₂′), (p₁′, p₂′))
620-
coeff = coeff′ * coeff′′ * coeff′′′
621-
iszero(coeff) || (newtrees[f12′′′] = get(newtrees, f12′′′, zero(coeff)) + coeff)
622-
end
606+
# the sectors of the traced legs have to be dual to each other for a nonzero trace, where the
607+
# sector of an incoming leg is the dual of the corresponding uncoupled sector of the fusion tree
608+
function trace_sectors_match(src::Union{FusionTreePair, FusionTreeBlock}, (q₁, q₂)::Index2Tuple)
609+
f₁, f₂ = src isa FusionTreePair ? src : first(fusiontrees(src))
610+
N₁ = length(f₁)
611+
legsector(i) = i <= N₁ ? f₁.uncoupled[i] : dual(f₂.uncoupled[i - N₁])
612+
return all(map((i, j) -> legsector(i) == dual(legsector(j)), q₁, q₂))
613+
end
614+
615+
"""
616+
planar_trace((f₁, f₂)::FusionTreePair, (p₁, p₂)::Index2Tuple, (q₁, q₂)::Index2Tuple) -> (f₁′, f₂′) => coeff
617+
planar_trace(src::FusionTreeBlock, (p₁, p₂)::Index2Tuple, (q₁, q₂)::Index2Tuple) -> dst => U
618+
619+
Perform a planar trace of the legs `q₁[i]` with `q₂[i]` of a fusion tree pair, followed by a
620+
planar permutation `(p₁, p₂)` of the remaining legs. The sectors of the traced legs have to be
621+
dual to each other.
622+
623+
For `FusionStyle(I) isa UniqueFusion`, the input is a single fusion tree pair, which is mapped
624+
to a single output tree pair with a coefficient. For generic `FusionStyle`s, the input and
625+
output consist of `FusionTreeBlock`s, where `src` and `dst` contain all tree pairs of the
626+
traced and remaining legs respectively, and `U[j, i]` is the coefficient of the `j`th tree pair
627+
of `dst` in the trace of the `i`th tree pair of `src`.
628+
"""
629+
function planar_trace(src::Union{FusionTreePair, FusionTreeBlock}, (p₁, p₂)::Index2Tuple, (q₁, q₂)::Index2Tuple)
630+
src isa FusionTreePair && @assert FusionStyle(src) === UniqueFusion()
631+
p′, q′, r = _planar_trace_indices(Val(numout(src)), Val(numin(src)), (p₁, p₂), (q₁, q₂))
632+
trace_sectors_match(src, (q₁, q₂)) ||
633+
throw(ArgumentError(lazy"sectors of the traced legs $q₁ and $q₂ are not dual to each other"))
634+
isempty(q₁) && return transpose(src, (p₁, p₂))
635+
636+
# bend all legs to the outgoing side, where the trace only acts on the splitting trees
637+
src′, U₁ = repartition(src, numind(src))
638+
traced, U₂ = _planar_trace_splitting(src′, q′, r)
639+
# for multiple fusion channels, the remaining legs need not couple to the unit
640+
if traced isa FusionTreeBlock && isempty(traced)
641+
I = sectortype(src)
642+
F = fusiontreetype(I, length(p₁), length(p₂))
643+
return FusionTreeBlock(F[]) => zeros(fusionscalartype(I), 0, length(src))
623644
else
624-
# TODO: this is a bit of a hack to fix the traces for now
625-
src = FusionTreeBlock([(f₁, f₂)])
626-
dst, U = repartition(src, N)
627-
for ((f₁′, f₂′), coeff′) in zip(fusiontrees(dst), U)
628-
for (f₁′′, coeff′′) in planar_trace(f₁′, (q₁′, q₂′))
629-
src′ = FusionTreeBlock([(f₁′′, f₂′)])
630-
dst′, U′ = transpose(src′, (p₁′, p₂′))
631-
for (f12′′′, coeff′′′) in zip(fusiontrees(dst′), U′)
632-
coeff = coeff′ * coeff′′ * coeff′′′
633-
iszero(coeff) || (newtrees[f12′′′] = get(newtrees, f12′′′, zero(coeff)) + coeff)
634-
end
635-
end
636-
end
645+
dst, U₃ = transpose(traced, p′)
646+
return dst => U₃ * U₂ * U₁
637647
end
638-
return newtrees
648+
end
649+
650+
function _planar_trace_splitting((f, f₀)::FusionTreePair, q′, r)
651+
f′, coeff = only(planar_trace(f, q′))
652+
return (f′, f₀) => coeff
653+
end
654+
function _planar_trace_splitting(src::FusionTreeBlock, q′, r)
655+
I = sectortype(src)
656+
f₀, = first(fusiontrees(src))
657+
uncoupled = TupleTools.getindices(f₀.uncoupled, r)
658+
isdual = TupleTools.getindices(f₀.isdual, r)
659+
dst = FusionTreeBlock{I}((uncoupled, ()), (isdual, ()))
660+
U = zeros(fusionscalartype(I), length(dst), length(src))
661+
positions = Dict(f => i for (i, (f, _)) in enumerate(fusiontrees(dst)))
662+
for (j, (f, _)) in enumerate(fusiontrees(src)), (f′, coeff) in planar_trace(f, q′)
663+
U[positions[f′], j] += coeff
664+
end
665+
return dst => U
639666
end
640667

641668
"""

‎src/fusiontrees/fusiontrees.jl‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,12 @@ function Base.hash(f::FusionTree{I}, h::UInt) where {I}
238238
end
239239
return h
240240
end
241-
# Hashing the first tree pair covers the block's defining data `(uncoupled, isdual)`, while
242-
# also disambiguating the ad-hoc single-pair blocks constructed in `planar_trace`
243-
Base.hash(b::FusionTreeBlock, h::UInt) = isempty(b) ? h : hash(first(fusiontrees(b)), h)
241+
# a block is defined by the uncoupled sectors and duality flags shared by all its tree pairs
242+
function Base.hash(b::FusionTreeBlock, h::UInt)
243+
isempty(b) && return h
244+
f₁, f₂ = first(fusiontrees(b))
245+
return hash(f₁.uncoupled, hash(f₁.isdual, hash(f₂.uncoupled, hash(f₂.isdual, h))))
246+
end
244247

245248
function Base.:(==)(f₁::FusionTree{I, N}, f₂::FusionTree{I, N}) where {I <: Sector, N}
246249
f₁.coupled == f₂.coupled || return false

‎src/planar/planaroperations.jl‎

Lines changed: 69 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -92,24 +92,79 @@ function planartrace!(
9292
end
9393

9494
@timeit_debug GLOBAL_TIMER "planartrace!" begin
95-
if iszero(β)
96-
fill!(C, β)
97-
elseif !isone(β)
98-
rmul!(C, β)
95+
transformer = treetracer(storagetype(C), space(C), space(A), (p₁, p₂), (q₁, q₂))
96+
dst, src = _transform_subblocks(C, A, transformer)
97+
ntasks = get_num_transformer_threads(A)
98+
trace_transform_kernel!(dst, src, (p₁, p₂), (q₁, q₂), transformer, α, β, backend, allocator, ntasks)
99+
end
100+
return C
101+
end
102+
103+
# kernel for computing `tdst = β * tdst + α * tr(tsrc)`, with the planar trace encoded in `transformer`
104+
function trace_transform_kernel!(
105+
dst::TransformSubblocks, src::TransformSubblocks, p::Index2Tuple, q::Index2Tuple,
106+
transformer::TraceTransformer, α, β, backend, allocator, ntasks::Int
107+
)
108+
bufsize = buffersize(transformer)
109+
if bufsize == 0 # every block has a single destination subblock
110+
taskforeach(transformer.data, ntasks) do (U, inds_dst, inds_src)
111+
_trace_transform_block!(dst, src, p, q, U, inds_dst, inds_src, nothing, α, β, backend, allocator)
112+
end
113+
else
114+
# see `add_transform_kernel!` for the workspace strategy
115+
cp = TO.allocator_checkpoint!(allocator)
116+
@timeit_debug GLOBAL_TIMER "alloc: buffers" buffers = [
117+
TO.tensoralloc(storagetype(dst), bufsize, Val(true), allocator)
118+
for _ in 1:min(length(transformer.data), ntasks)
119+
]
120+
taskforeach(transformer.data, buffers) do (U, inds_dst, inds_src), buffer
121+
_trace_transform_block!(dst, src, p, q, U, inds_dst, inds_src, buffer, α, β, backend, allocator)
122+
end
123+
foreach(Base.Fix2(TO.tensorfree!, allocator), buffers)
124+
TO.allocator_reset!(allocator, cp)
125+
end
126+
return nothing
127+
end
128+
129+
function _trace_transform_block!(
130+
dst::TransformSubblocks, src::TransformSubblocks, p::Index2Tuple, q::Index2Tuple,
131+
U, inds_dst, inds_src, buffer, α, β, backend, allocator
132+
)
133+
if size(U, 1) == 1 # single destination: trace every source directly into it
134+
idst = only(inds_dst)
135+
if isempty(inds_src)
136+
@inbounds iszero(β) ? zerovector!(dst[idst]) : scale!(dst[idst], β)
137+
return nothing
99138
end
100-
β′ = One()
101-
for (f₁, f₂) in fusiontrees(A)
102-
for ((f₁′, f₂′), coeff) in planar_trace((f₁, f₂), (p₁, p₂), (q₁, q₂))
103-
@timeit_debug GLOBAL_TIMER "dense: trace" TO.tensortrace!(
104-
C[f₁′, f₂′],
105-
A[f₁, f₂], (p₁, p₂), (q₁, q₂), false,
106-
α * coeff, β′,
107-
backend, allocator
108-
)
139+
@timeit_debug GLOBAL_TIMER "dense: trace" @inbounds begin
140+
TO.tensortrace!(dst[idst], src[first(inds_src)], p, q, false, α * U[1, 1], β, backend, allocator)
141+
for i in 2:length(inds_src)
142+
TO.tensortrace!(dst[idst], src[inds_src[i]], p, q, false, α * U[1, i], One(), backend, allocator)
109143
end
110144
end
145+
else # trace → recoupling matmul → unpack
146+
rows, cols = size(U)
147+
sz = size(@inbounds(dst[first(inds_dst)]))
148+
ptriv = (ntuple(identity, length(sz)), ())
149+
blocksize = prod(sz)
150+
buffer_dst = StridedView(buffer, (blocksize, rows), (1, blocksize), 0)
151+
buffer_src = StridedView(buffer, (blocksize, cols), (1, blocksize), blocksize * rows)
152+
153+
# the permutation is applied while tracing, such that unpacking is a plain addition
154+
@timeit_debug GLOBAL_TIMER "dense: trace" @inbounds for (i, isrc) in enumerate(inds_src)
155+
TO.tensortrace!(
156+
sreshape(view(buffer_src, :, i), sz), src[isrc], p, q, false,
157+
One(), Zero(), backend, allocator
158+
)
159+
end
160+
@timeit_debug GLOBAL_TIMER "dense: recouple mul!" _recouple!(buffer, buffer_dst, buffer_src, U)
161+
@timeit_debug GLOBAL_TIMER "dense: unpack" @inbounds for (j, idst) in enumerate(inds_dst)
162+
TO.tensoradd!(
163+
dst[idst], sreshape(view(buffer_dst, :, j), sz), ptriv, false, α, β, backend, allocator
164+
)
165+
end
111166
end
112-
return C
167+
return nothing
113168
end
114169

115170
# insert default backend

‎src/tensors/treetransformers.jl‎

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,4 +202,104 @@ end
202202
return TreeTransformer(A, fusiontreetransform, p, Vdst, Vsrc, conjsrc)
203203
end
204204

205+
206+
"""
207+
TraceTransformer{T, N₁, N₂}
208+
209+
Planar trace of a tensor with `N₂` indices into a tensor with `N₁` indices, stored as
210+
`(U, inds_dst, inds_src)` where `U[j, i]` is the coefficient with which the trace of source
211+
subblock `inds_src[i]` contributes to destination subblock `inds_dst[j]`. The data is grouped by
212+
destination, such that every destination subblock appears in exactly one entry, where those
213+
without contributions have no source subblocks. The subblock structures of the destination and source
214+
spaces are kept alongside, such that the [`StridedSubblocks`](@ref) of both tensors can be
215+
created without further lookups.
216+
"""
217+
struct TraceTransformer{T, N₁, N₂}
218+
data::Vector{GenericTransformerData{T}}
219+
structure_dst::Vector{StridedStructure{N₁}}
220+
structure_src::Vector{StridedStructure{N₂}}
221+
end
222+
223+
function TraceTransformer(::Type{A}, Vdst::HomSpace, Vsrc::HomSpace, p::Index2Tuple, q::Index2Tuple) where {A}
224+
t₀ = Base.time()
225+
src_trees, dst_trees = fusiontrees(Vsrc), fusiontrees(Vdst)
226+
T = recoupling_scalartype(A, sectorscalartype(sectortype(Vdst)))
227+
228+
# destination positions => (columns of the recoupling matrix, source positions)
229+
groups = Dict{Vector{Int}, Tuple{Vector{Vector{T}}, Vector{Int}}}()
230+
function addcolumn!(inds_dst, u, isrc)
231+
any(!iszero, u) || return nothing
232+
us, inds_src = get!(() -> (Vector{T}[], Int[]), groups, inds_dst)
233+
push!(us, u)
234+
push!(inds_src, isrc)
235+
return nothing
236+
end
237+
@timeit_debug GLOBAL_TIMER "symmetry: trace coefficients" if FusionStyle(sectortype(Vdst)) isa UniqueFusion
238+
for (isrc, f) in enumerate(src_trees)
239+
trace_sectors_match(f, q) || continue
240+
f′, coeff = planar_trace(f, p, q)
241+
_, (_, idst) = gettoken(dst_trees, f′)
242+
addcolumn!([idst], [convert(T, coeff)], isrc)
243+
end
244+
else
245+
for fs_src in fusionblocks(Vsrc)
246+
trace_sectors_match(fs_src, q) || continue
247+
fs_dst, U = planar_trace(fs_src, p, q)
248+
inds_dst = map(fusiontrees(fs_dst)) do f
249+
_, (_, idst) = gettoken(dst_trees, f)
250+
return idst
251+
end
252+
for (i, f) in enumerate(fusiontrees(fs_src))
253+
_, (_, isrc) = gettoken(src_trees, f)
254+
addcolumn!(inds_dst, convert(Vector{T}, U[:, i]), isrc)
255+
end
256+
end
257+
end
258+
data = GenericTransformerData{T}[(reduce(hcat, us), inds_dst, inds_src) for (inds_dst, (us, inds_src)) in groups]
259+
# destination subblocks without contributions are only scaled
260+
covered = falses(length(dst_trees))
261+
foreach(inds_dst -> covered[inds_dst] .= true, keys(groups))
262+
for idst in findall(!, covered)
263+
push!(data, (zeros(T, 1, 0), [idst], Int[]))
264+
end
265+
266+
structure_dst = degeneracystructure(Vdst).subblockstructure
267+
structure_src = degeneracystructure(Vsrc).subblockstructure
268+
# sort by (approximate) weight to facilitate multi-threading strategies
269+
weights = map(data) do (U, inds_dst, _)
270+
return length(U) * prod(structure_dst[first(inds_dst)][1])
271+
end
272+
Base.permute!(data, sortperm(weights; rev = true))
273+
transformer = TraceTransformer(data, structure_dst, structure_src)
274+
275+
Δt = Base.time() - t₀
276+
@debug("TraceTransformer for $Vsrc to $Vdst via $p and $q", nblocks = length(data), Δt)
277+
278+
return transformer
279+
end
280+
281+
"""
282+
buffersize(transformer::TraceTransformer) -> Int
283+
284+
Compute the workspace size required to trace, recouple and unpack the largest block with
285+
multiple destination subblocks, i.e. `prod(sz_dst) * (rows + cols)` where `(rows, cols) = size(U)`.
286+
"""
287+
function buffersize(transformer::TraceTransformer)
288+
structure_dst = transformer.structure_dst
289+
return maximum(transformer.data; init = 0) do (U, inds_dst, _)
290+
return size(U, 1) == 1 ? 0 : prod(structure_dst[first(inds_dst)][1]) * sum(size(U))
291+
end
292+
end
293+
294+
function tracetransformertype(::Type{A}, Vdst, Vsrc) where {A}
295+
T = recoupling_scalartype(A, sectorscalartype(sectortype(Vdst)))
296+
return TraceTransformer{T, numind(Vdst), numind(Vsrc)}
297+
end
298+
299+
@cached function treetracer(
300+
A::Type{TA}, Vdst::TensorMapSpace, Vsrc::TensorMapSpace, p::Index2Tuple, q::Index2Tuple
301+
)::tracetransformertype(A, Vdst, Vsrc) where {TA}
302+
return TraceTransformer(A, Vdst, Vsrc, p, q)
303+
end
304+
205305
# default cachestyle is GlobalLRUCache

‎test/symmetries/doubletree.jl‎

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -249,28 +249,24 @@ using TensorKitSectors
249249
end
250250

251251
@testset "Double fusion tree: planar trace" begin
252+
p1 = ((N + 1, 1:N..., ((2N):-1:(N + 3))...), (N + 2,))
253+
p2, q2 = ((2:N...,), (1, ((2N):-1:(N + 3))...)), ((N + 1,), (N + 2,))
252254
if FusionStyle(I) isa UniqueFusion
253255
f1, f1 = src
254-
dst, U = transpose((f1, f1), ((N + 1, 1:N..., ((2N):-1:(N + 3))...), (N + 2,)))
255-
d1 = zip((dst,), (U,))
256+
dst, U = transpose((f1, f1), p1)
257+
@test TK.trace_sectors_match(dst, q2)
258+
dst2, U2 = @constinferred TK.planar_trace(dst, p2, q2)
259+
d2 = Dict(dst2 => U2 * U)
256260
else
257261
f1, f1 = first(fusiontrees(src))
258262
src′ = FusionTreeBlock{I}((f1.uncoupled, f1.uncoupled), (f1.isdual, f1.isdual))
259-
dst, U = transpose(src′, ((N + 1, 1:N..., ((2N):-1:(N + 3))...), (N + 2,)))
260-
d1 = zip(fusiontrees(dst), U[:, 1])
263+
dst, U = transpose(src′, p1)
264+
@test TK.trace_sectors_match(dst, q2)
265+
dst2, U2 = TK.planar_trace(dst, p2, q2)
266+
d2 = Dict(zip(fusiontrees(dst2), U2 * U[:, 1]))
261267
end
262268

263269
f1front, = TK.split(f1, N - 1)
264-
T = sectorscalartype(I)
265-
d2 = Dict{typeof((f1front, f1front)), T}()
266-
for ((f1′, f2′), coeff′) in d1
267-
for ((f1′′, f2′′), coeff′′) in TK.planar_trace(
268-
(f1′, f2′), ((2:N...,), (1, ((2N):-1:(N + 3))...)), ((N + 1,), (N + 2,))
269-
)
270-
coeff = coeff′ * coeff′′
271-
d2[(f1′′, f2′′)] = get(d2, (f1′′, f2′′), zero(coeff)) + coeff
272-
end
273-
end
274270
for ((f1_, f2_), coeff) in d2
275271
if (f1_, f2_) == (f1front, f1front)
276272
@test coeff ≈ dim(f1.coupled) / dim(f1front.coupled)

0 commit comments

Comments
 (0)