Skip to content

Commit 519974e

Browse files
committed
FusionTreePair
1 parent 5fa3a86 commit 519974e

8 files changed

Lines changed: 94 additions & 115 deletions

File tree

src/fusiontrees/fusiontrees.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ function FusionTree(uncoupled::NTuple{N,I}, coupled::I,
9292
end
9393
FusionTree(uncoupled::Tuple{I,Vararg{I}}) where {I<:Sector} = FusionTree(uncoupled, one(I))
9494

95+
const FusionTreePair{I,N₁,N₂} = Tuple{FusionTree{I,N₁},FusionTree{I,N₂}}
96+
9597
# Properties
9698
sectortype(::Type{<:FusionTree{I}}) where {I<:Sector} = I
9799
FusionStyle(::Type{<:FusionTree{I}}) where {I<:Sector} = FusionStyle(I)
@@ -199,8 +201,7 @@ function Base.convert(A::Type{<:AbstractArray}, f::FusionTree{I,N}) where {I,N}
199201
end
200202

201203
# TODO: is this piracy?
202-
function Base.convert(A::Type{<:AbstractArray},
203-
(f₁, f₂)::Tuple{FusionTree{I},FusionTree{I}}) where {I}
204+
function Base.convert(A::Type{<:AbstractArray}, (f₁, f₂)::FusionTreePair{I}) where {I}
204205
F₁ = convert(A, f₁)
205206
F₂ = convert(A, f₂)
206207
sz1 = size(F₁)

src/fusiontrees/manipulations.jl

Lines changed: 70 additions & 93 deletions
Large diffs are not rendered by default.

src/tensors/braidingtensor.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ function planarcontract!(C::AbstractTensorMap,
230230
inv_braid = τ_levels[cindA[1]] > τ_levels[cindA[2]]
231231
for (f₁, f₂) in fusiontrees(B)
232232
local newtrees
233-
for ((f₁′, f₂′), coeff′) in transpose(f₁, f₂, cindB, oindB)
233+
for ((f₁′, f₂′), coeff′) in transpose((f₁, f₂), (cindB, oindB))
234234
for (f₁′′, coeff′′) in artin_braid(f₁′, 1; inv=inv_braid)
235235
f12 = (f₁′′, f₂′)
236236
coeff = coeff′ * coeff′′
@@ -281,7 +281,7 @@ function planarcontract!(C::AbstractTensorMap,
281281

282282
for (f₁, f₂) in fusiontrees(A)
283283
local newtrees
284-
for ((f₁′, f₂′), coeff′) in transpose(f₁, f₂, oindA, cindA)
284+
for ((f₁′, f₂′), coeff′) in transpose((f₁, f₂), oindA, cindA)
285285
for (f₂′′, coeff′′) in artin_braid(f₂′, 1; inv=inv_braid)
286286
f12 = (f₁′, f₂′′)
287287
coeff = coeff′ * conj(coeff′′)

src/tensors/diagonal.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ function permute(d::DiagonalTensorMap, (p₁, p₂)::Index2Tuple{1,1};
203203
d′ = typeof(d)(undef, dual(d.domain))
204204
for (c, b) in blocks(d)
205205
f = only(fusiontrees(codomain(d), c))
206-
((f′, _), coeff) = only(permute(f, f, p₁, p₂))
206+
((f′, _), coeff) = only(permute((f, f), (p₁, p₂)))
207207
c′ = f′.coupled
208208
scale!(block(d′, c′), b, coeff)
209209
end

src/tensors/indexmanipulations.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function flip(t::AbstractTensorMap, I; inv::Bool=false)
1717
P = flip(space(t), I)
1818
t′ = similar(t, P)
1919
for (f₁, f₂) in fusiontrees(t)
20-
(f₁′, f₂′), factor = only(flip(f₁, f₂, I; inv))
20+
(f₁′, f₂′), factor = only(flip((f₁, f₂), I; inv))
2121
scale!(t′[f₁′, f₂′], t[f₁, f₂], factor)
2222
end
2323
return t′
@@ -558,7 +558,7 @@ function _add_abelian_kernel_threaded!(tdst, tsrc, p, transformer, α, β, backe
558558
end
559559

560560
function _add_abelian_block!(tdst, tsrc, p, transformer, f₁, f₂, α, β, backend...)
561-
(f₁′, f₂′), coeff = first(transformer(f₁, f₂))
561+
(f₁′, f₂′), coeff = first(transformer((f₁, f₂)))
562562
@inbounds TO.tensoradd!(tdst[f₁′, f₂′], tsrc[f₁, f₂], p, false, α * coeff, β,
563563
backend...)
564564
return nothing
@@ -618,7 +618,7 @@ function _add_general_kernel_nonthreaded!(tdst, tsrc, p, transformer, α, β, ba
618618
tdst = scale!(tdst, β)
619619
end
620620
for (f₁, f₂) in fusiontrees(tsrc)
621-
for ((f₁′, f₂′), coeff) in transformer(f₁, f₂)
621+
for ((f₁′, f₂′), coeff) in transformer((f₁, f₂))
622622
@inbounds TO.tensoradd!(tdst[f₁′, f₂′], tsrc[f₁, f₂], p, false, α * coeff,
623623
One(), backend...)
624624
end
@@ -683,7 +683,7 @@ end
683683
function _add_nonabelian_sector!(tdst, tsrc, p, fusiontreetransform, s₁, s₂, α, backend...)
684684
for (f₁, f₂) in fusiontrees(tsrc)
685685
(f₁.uncoupled == s₁ && f₂.uncoupled == s₂) || continue
686-
for ((f₁′, f₂′), coeff) in fusiontreetransform(f₁, f₂)
686+
for ((f₁′, f₂′), coeff) in fusiontreetransform((f₁, f₂))
687687
@inbounds TO.tensoradd!(tdst[f₁′, f₂′], tsrc[f₁, f₂], p, false, α * coeff,
688688
One(), backend...)
689689
end

src/tensors/tensoroperations.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ function trace_permute!(tdst::AbstractTensorMap,
199199
r₁ = (p₁..., q₁...)
200200
r₂ = (p₂..., q₂...)
201201
for (f₁, f₂) in fusiontrees(tsrc)
202-
for ((f₁′, f₂′), coeff) in permute(f₁, f₂, r₁, r₂)
202+
for ((f₁′, f₂′), coeff) in permute((f₁, f₂), (r₁, r₂))
203203
f₁′′, g₁ = split(f₁′, N₁)
204204
f₂′′, g₂ = split(f₂′, N₂)
205205
g₁ == g₂ || continue

src/tensors/treetransformers.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,29 +166,29 @@ end
166166

167167
# braid is special because it has levels
168168
function treebraider(::AbstractTensorMap, ::AbstractTensorMap, p::Index2Tuple, levels)
169-
return fusiontreetransform(f1, f2) = braid(f1, f2, levels..., p...)
169+
return fusiontreetransform((f1, f2)) = braid((f1, f2), levels, p)
170170
end
171171
function treebraider(tdst::TensorMap, tsrc::TensorMap, p::Index2Tuple, levels)
172172
return treebraider(space(tdst), space(tsrc), p, levels)
173173
end
174174
@cached function treebraider(Vdst::TensorMapSpace, Vsrc::TensorMapSpace, p::Index2Tuple,
175175
levels)::treetransformertype(Vdst, Vsrc)
176-
fusiontreebraider(f1, f2) = braid(f1, f2, levels..., p...)
176+
fusiontreebraider((f1, f2)) = braid((f1, f2), levels, p)
177177
return TreeTransformer(fusiontreebraider, p, Vdst, Vsrc)
178178
end
179179

180180
for (transform, treetransformer) in
181181
((:permute, :treepermuter), (:transpose, :treetransposer))
182182
@eval begin
183183
function $treetransformer(::AbstractTensorMap, ::AbstractTensorMap, p::Index2Tuple)
184-
return fusiontreetransform(f1, f2) = $transform(f1, f2, p...)
184+
return fusiontreetransform(f1, f2) = $transform((f1, f2), p)
185185
end
186186
function $treetransformer(tdst::TensorMap, tsrc::TensorMap, p::Index2Tuple)
187187
return $treetransformer(space(tdst), space(tsrc), p)
188188
end
189189
@cached function $treetransformer(Vdst::TensorMapSpace, Vsrc::TensorMapSpace,
190190
p::Index2Tuple)::treetransformertype(Vdst, Vsrc)
191-
fusiontreetransform(f1, f2) = $transform(f1, f2, p...)
191+
fusiontreetransform((f1, f2)) = $transform((f1, f2), p)
192192
return TreeTransformer(fusiontreetransform, p, Vdst, Vsrc)
193193
end
194194
end

test/fusiontrees.jl

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -432,12 +432,12 @@ ti = time()
432432
ip = invperm(p)
433433
ip1, ip2 = ip[1:N], ip[(N + 1):(2N)]
434434

435-
d = @constinferred TensorKit.permute(f1, f2, p1, p2)
435+
d = @constinferred TensorKit.permute((f1, f2), (p1, p2))
436436
@test dim(incoming)
437437
sum(abs2(coef) * dim(f1.coupled) for ((f1, f2), coef) in d)
438438
d2 = Dict{typeof((f1, f2)),valtype(d)}()
439439
for ((f1′, f2′), coeff) in d
440-
d′ = TensorKit.permute(f1′, f2′, ip1, ip2)
440+
d′ = TensorKit.permute((f1′, f2′), (ip1, ip2))
441441
for ((f1′′, f2′′), coeff2) in d′
442442
d2[(f1′′, f2′′)] = get(d2, (f1′′, f2′′), zero(coeff)) +
443443
coeff2 * coeff
@@ -490,12 +490,12 @@ ti = time()
490490
ip′ = tuple(getindex.(Ref(vcat(1:n, (2N):-1:(n + 1))), ip)...)
491491
ip1, ip2 = ip′[1:N], ip′[(2N):-1:(N + 1)]
492492

493-
d = @constinferred transpose(f1, f2, p1, p2)
493+
d = @constinferred transpose((f1, f2), (p1, p2))
494494
@test dim(incoming)
495495
sum(abs2(coef) * dim(f1.coupled) for ((f1, f2), coef) in d)
496496
d2 = Dict{typeof((f1, f2)),valtype(d)}()
497497
for ((f1′, f2′), coeff) in d
498-
d′ = transpose(f1′, f2′, ip1, ip2)
498+
d′ = transpose((f1′, f2′), (ip1, ip2))
499499
for ((f1′′, f2′′), coeff2) in d′
500500
d2[(f1′′, f2′′)] = get(d2, (f1′′, f2′′), zero(coeff)) + coeff2 * coeff
501501
end
@@ -509,7 +509,7 @@ ti = time()
509509
end
510510

511511
if BraidingStyle(I) isa Bosonic
512-
d3 = permute(f1, f2, p1, p2)
512+
d3 = permute((f1, f2), (p1, p2))
513513
for (f1′, f2′) in union(keys(d), keys(d3))
514514
coeff1 = get(d, (f1′, f2′), zero(valtype(d)))
515515
coeff3 = get(d3, (f1′, f2′), zero(valtype(d3)))
@@ -546,14 +546,15 @@ ti = time()
546546
end
547547
end
548548
@testset "Double fusion tree $Istr: planar trace" begin
549-
d1 = transpose(f1, f1, (N + 1, 1:N..., ((2N):-1:(N + 3))...), (N + 2,))
549+
d1 = transpose((f1, f1), ((N + 1, 1:N..., ((2N):-1:(N + 3))...), (N + 2,)))
550550
f1front, = TK.split(f1, N - 1)
551551
T = typeof(Fsymbol(one(I), one(I), one(I), one(I), one(I), one(I))[1, 1, 1, 1])
552552
d2 = Dict{typeof((f1front, f1front)),T}()
553553
for ((f1′, f2′), coeff′) in d1
554554
for ((f1′′, f2′′), coeff′′) in
555-
TK.planar_trace(f1′, f2′, (2:N...,), (1, ((2N):-1:(N + 3))...), (N + 1,),
556-
(N + 2,))
555+
TK.planar_trace((f1′, f2′), ((2:N...,), (1, ((2N):-1:(N + 3))...)),
556+
((N + 1,),
557+
(N + 2,)))
557558
coeff = coeff′ * coeff′′
558559
d2[(f1′′, f2′′)] = get(d2, (f1′′, f2′′), zero(coeff)) + coeff
559560
end

0 commit comments

Comments
 (0)