Skip to content

Commit 1056afd

Browse files
committed
fix implementation and support fermions
1 parent 0ee6b1b commit 1056afd

File tree

3 files changed

+57
-21
lines changed

3 files changed

+57
-21
lines changed

src/fusiontrees/manipulations.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,26 @@ end
242242
# -> B-move (bendleft, bendright) is simple in standard basis
243243
# -> A-move (foldleft, foldright) is complicated, needs to be reexpressed in standard form
244244

245+
# flip a duality flag of a fusion tree
246+
function flip(f₁::FusionTree{I,N₁}, f₂::FusionTree{I,N₂}, i::Int) where {I<:Sector,N₁,N₂}
247+
@assert 0 < i N₁ + N₂
248+
if i N₁
249+
a = f₁.uncoupled[i]
250+
fs = frobeniusschur(a) * twist(a)
251+
factor = f₁.isdual[i] ? fs : one(fs)
252+
isdual′ = TupleTools.setindex(f₁.isdual, !f₁.isdual[i], i)
253+
f₁′ = FusionTree{I}(f₁.uncoupled, f₁.coupled, isdual′, f₁.innerlines, f₁.vertices)
254+
return SingletonDict((f₁′, f₂) => factor)
255+
else
256+
i -= N₁
257+
a = f₂.uncoupled[i]
258+
factor = f₂.isdual[i] ? frobeniusschur(a) : twist(a)
259+
isdual′ = TupleTools.setindex(f₂.isdual, !f₂.isdual[i], i)
260+
f₂′ = FusionTree{I}(f₂.uncoupled, f₂.coupled, isdual′, f₂.innerlines, f₂.vertices)
261+
return SingletonDict((f₁, f₂′) => factor)
262+
end
263+
end
264+
245265
# change to N₁ - 1, N₂ + 1
246266
function bendright(f₁::FusionTree{I,N₁}, f₂::FusionTree{I,N₂}) where {I<:Sector,N₁,N₂}
247267
# map final splitting vertex (a, b)<-c to fusion vertex a<-(c, dual(b))

src/tensors/indexmanipulations.jl

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,18 @@ Return a new tensor that is isomorphic to `t` but where the arrows on the indice
88
"""
99
function flip(t::AbstractTensorMap, I)
1010
P = flip(space(t), I)
11-
t2 = similar(t, P)
12-
for (c, b) in blocks(t)
13-
copy!(t2[c], b)
11+
t′ = similar(t, P)
12+
for (f₁, f₂) in fusiontrees(t)
13+
f₁′, f₂′ = f₁, f₂
14+
factor = one(scalartype(t))
15+
for i in I
16+
(f₁′, f₂′), s = only(flip(f₁′, f₂′, i))
17+
factor *= s
18+
end
19+
scale!(t′[f₁′, f₂′], t[f₁, f₂], factor)
1420
end
15-
return t
21+
return t
1622
end
17-
flip(t::TensorMap, I) = TensorMap(t.data, flip(space(t), I))
1823

1924
"""
2025
permute!(tdst::AbstractTensorMap, tsrc::AbstractTensorMap, (p₁, p₂)::Index2Tuple)

test/tensors.jl

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -326,22 +326,33 @@ for V in spacelist
326326
@test HrA12array convert(Array, HrA12)
327327
end
328328
end
329-
if BraidingStyle(I) isa Bosonic # TODO: add fermionic tests by including parity tensors
330-
@timedtestset "Index flipping: test via contraction" begin
331-
t1 = rand(ComplexF64, V1 V2 V3 V4)
332-
t2 = rand(ComplexF64, V2' V5 V4' V1)
333-
@tensor ta[a, b] := t1[x, y, a, z] * t2[y, b, z, x]
334-
@tensor tb[a, b] := flip(t1, 1)[x, y, a, z] * flip(t2, 4)[y, b, z, x]
335-
@test ta tb
336-
@tensor tb[a, b] := flip(t1, (2, 4))[x, y, a, z] *
337-
flip(t2, (1, 3))[y, b, z, x]
338-
@test ta tb
339-
@tensor tb[a, b] := flip(t1, (1, 2, 4))[x, y, a, z] *
340-
flip(t2, (1, 3, 4))[y, b, z, x]
341-
@tensor tb[a, b] := flip(t1, (1, 3))[x, y, a, z] *
342-
flip(t2, (2, 4))[y, b, z, x]
343-
@test flip(ta, (1, 2)) tb
344-
end
329+
@timedtestset "Index flipping: test via explicit flip" begin
330+
t = rand(ComplexF64, V1 V1' V1' V1)
331+
F1 = unitary(flip(V1), V1)
332+
333+
@tensor tf[a, b; c, d] := F1[a, a'] * t[a', b; c, d]
334+
@test flip(t, 1) tf
335+
@tensor tf[a, b; c, d] := conj(F1[b, b']) * t[a, b'; c, d]
336+
@test twist!(flip(t, 2), 2) tf
337+
@tensor tf[a, b; c, d] := F1[c, c'] * t[a, b; c', d]
338+
@test flip(t, 3) tf
339+
@tensor tf[a, b; c, d] := conj(F1[d, d']) * t[a, b; c, d']
340+
@test twist!(flip(t, 4), 4) tf
341+
end
342+
@timedtestset "Index flipping: test via contraction" begin
343+
t1 = rand(ComplexF64, V1 V2 V3 V4)
344+
t2 = rand(ComplexF64, V2' V5 V4' V1)
345+
@tensor ta[a, b] := t1[x, y, a, z] * t2[y, b, z, x]
346+
@tensor tb[a, b] := flip(t1, 1)[x, y, a, z] * flip(t2, 4)[y, b, z, x]
347+
@test ta tb
348+
@tensor tb[a, b] := flip(t1, (2, 4))[x, y, a, z] *
349+
flip(t2, (1, 3))[y, b, z, x]
350+
@test ta tb
351+
@tensor tb[a, b] := flip(t1, (1, 2, 4))[x, y, a, z] *
352+
flip(t2, (1, 3, 4))[y, b, z, x]
353+
@tensor tb[a, b] := flip(t1, (1, 3))[x, y, a, z] *
354+
flip(t2, (2, 4))[y, b, z, x]
355+
@test flip(ta, (1, 2)) tb
345356
end
346357
@timedtestset "Multiplication of isometries: test properties" begin
347358
W2 = V4 V5

0 commit comments

Comments
 (0)