Skip to content

Commit 0c88157

Browse files
committed
FusionTreePair
1 parent 5fa3a86 commit 0c88157

File tree

9 files changed

+106
-127
lines changed

9 files changed

+106
-127
lines changed

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: 71 additions & 94 deletions
Large diffs are not rendered by default.

src/planar/planaroperations.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ function planartrace!(C::AbstractTensorMap,
9595
end
9696
β′ = One()
9797
for (f₁, f₂) in fusiontrees(A)
98-
for ((f₁′, f₂′), coeff) in planar_trace(f₁, f₂, p₁, p₂, q₁, q₂)
98+
for ((f₁′, f₂′), coeff) in planar_trace((f₁, f₂), (p₁, p₂), (q₁, q₂))
9999
TO.tensortrace!(C[f₁′, f₂′], A[f₁, f₂], (p₁, p₂), (q₁, q₂), false, α * coeff,
100100
β′,
101101
backend, allocator)

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: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function AbelianTreeTransformer(transform, p, Vdst, Vsrc)
2626

2727
for i in 1:L
2828
f₁, f₂ = structure_src.fusiontreelist[i]
29-
(f₃, f₄), coeff = only(transform(f₁, f₂))
29+
(f₃, f₄), coeff = only(transform((f₁, f₂)))
3030
j = structure_dst.fusiontreeindices[(f₃, f₄)]
3131
stridestructure_dst = structure_dst.fusiontreestructure[j]
3232
stridestructure_src = structure_src.fusiontreestructure[i]
@@ -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: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ ti = time()
142142
@test bf bf′ atol = 1e-12
143143
end
144144

145-
d2 = @constinferred TK.planar_trace(f, (1, 3), (2, 4))
145+
d2 = @constinferred TK.planar_trace(f, ((1, 3), (2, 4)))
146146
oind2 = (5, 6, 7)
147147
bf2 = tensortrace(af, (:a, :a, :b, :b, :c, :d, :e))
148148
bf2′ = zero(bf2)
@@ -151,7 +151,7 @@ ti = time()
151151
end
152152
@test bf2 bf2′ atol = 1e-12
153153

154-
d2 = @constinferred TK.planar_trace(f, (5, 6), (2, 1))
154+
d2 = @constinferred TK.planar_trace(f, ((5, 6), (2, 1)))
155155
oind2 = (3, 4, 7)
156156
bf2 = tensortrace(af, (:a, :b, :c, :d, :b, :a, :e))
157157
bf2′ = zero(bf2)
@@ -160,7 +160,7 @@ ti = time()
160160
end
161161
@test bf2 bf2′ atol = 1e-12
162162

163-
d2 = @constinferred TK.planar_trace(f, (1, 4), (6, 3))
163+
d2 = @constinferred TK.planar_trace(f, ((1, 4), (6, 3)))
164164
bf2 = tensortrace(af, (:a, :b, :c, :c, :d, :a, :e))
165165
bf2′ = zero(bf2)
166166
for (f2′, coeff) in d2
@@ -170,7 +170,7 @@ ti = time()
170170

171171
q1 = (1, 3, 5)
172172
q2 = (2, 4, 6)
173-
d3 = @constinferred TK.planar_trace(f, q1, q2)
173+
d3 = @constinferred TK.planar_trace(f, (q1, q2))
174174
bf3 = tensortrace(af, (:a, :a, :b, :b, :c, :c, :d))
175175
bf3′ = zero(bf3)
176176
for (f3′, coeff) in d3
@@ -180,7 +180,7 @@ ti = time()
180180

181181
q1 = (1, 3, 5)
182182
q2 = (6, 2, 4)
183-
d3 = @constinferred TK.planar_trace(f, q1, q2)
183+
d3 = @constinferred TK.planar_trace(f, (q1, q2))
184184
bf3 = tensortrace(af, (:a, :b, :b, :c, :c, :a, :d))
185185
bf3′ = zero(bf3)
186186
for (f3′, coeff) in d3
@@ -190,7 +190,7 @@ ti = time()
190190

191191
q1 = (1, 2, 3)
192192
q2 = (6, 5, 4)
193-
d3 = @constinferred TK.planar_trace(f, q1, q2)
193+
d3 = @constinferred TK.planar_trace(f, (q1, q2))
194194
bf3 = tensortrace(af, (:a, :b, :c, :c, :b, :a, :d))
195195
bf3′ = zero(bf3)
196196
for (f3′, coeff) in d3
@@ -200,7 +200,7 @@ ti = time()
200200

201201
q1 = (1, 2, 4)
202202
q2 = (6, 3, 5)
203-
d3 = @constinferred TK.planar_trace(f, q1, q2)
203+
d3 = @constinferred TK.planar_trace(f, (q1, q2))
204204
bf3 = tensortrace(af, (:a, :b, :b, :c, :c, :a, :d))
205205
bf3′ = zero(bf3)
206206
for (f3′, coeff) in d3
@@ -381,12 +381,12 @@ ti = time()
381381

382382
@testset "Double fusion tree $Istr: repartioning" begin
383383
for n in 0:(2 * N)
384-
d = @constinferred TK.repartition(f1, f2, $n)
384+
d = @constinferred TK.repartition((f1, f2), $n)
385385
@test dim(incoming)
386386
sum(abs2(coef) * dim(f1.coupled) for ((f1, f2), coef) in d)
387387
d2 = Dict{typeof((f1, f2)),valtype(d)}()
388388
for ((f1′, f2′), coeff) in d
389-
for ((f1′′, f2′′), coeff2) in TK.repartition(f1′, f2′, N)
389+
for ((f1′′, f2′′), coeff2) in TK.repartition((f1′, f2′), N)
390390
d2[(f1′′, f2′′)] = get(d2, (f1′′, f2′′), zero(coeff)) + coeff2 * coeff
391391
end
392392
end
@@ -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)