Skip to content

Commit

Permalink
Implement review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
lkdvos committed Aug 28, 2024
1 parent df42e17 commit 8e5251e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 32 deletions.
2 changes: 1 addition & 1 deletion TensorKitSectors/src/TensorKitSectors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export Sector, Group, AbstractIrrep
export Irrep

export Nsymbol, Fsymbol, Rsymbol, Asymbol, Bsymbol
export Feltype, Reltype
export Fscalartype, Rscalartype
export dim, sqrtdim, invsqrtdim, frobeniusschur, twist, fusiontensor, dual
export otimes, deligneproduct, times
export FusionStyle, UniqueFusion, MultipleFusion, SimpleFusion, GenericFusion,
Expand Down
22 changes: 11 additions & 11 deletions TensorKitSectors/src/irreps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -201,23 +201,23 @@ Base.isreal(::Type{SU2Irrep}) = true

Nsymbol(sa::SU2Irrep, sb::SU2Irrep, sc::SU2Irrep) = WignerSymbols.δ(sa.j, sb.j, sc.j)

Feltype(::Type{SU2Irrep}) = Float64
Fscalartype(::Type{SU2Irrep}) = Float64
function Fsymbol(s1::SU2Irrep, s2::SU2Irrep, s3::SU2Irrep,
s4::SU2Irrep, s5::SU2Irrep, s6::SU2Irrep)
if all(==(_su2one), (s1, s2, s3, s4, s5, s6))
return 1.0
else
return sqrtdim(s5) * sqrtdim(s6) *
WignerSymbols.racahW(Feltype(SU2Irrep), s1.j, s2.j,
WignerSymbols.racahW(Fscalartype(SU2Irrep), s1.j, s2.j,
s4.j, s3.j, s5.j, s6.j)
end
end

Reltype(::Type{SU2Irrep}) = Feltype(SU2Irrep)
Rscalartype(::Type{SU2Irrep}) = Fscalartype(SU2Irrep)
function Rsymbol(sa::SU2Irrep, sb::SU2Irrep, sc::SU2Irrep)
Nsymbol(sa, sb, sc) || return zero(Reltype(SU2Irrep))
return iseven(convert(Int, sa.j + sb.j - sc.j)) ? one(Reltype(SU2Irrep)) :
-one(Reltype(SU2Irrep))
Nsymbol(sa, sb, sc) || return zero(Rscalartype(SU2Irrep))
return iseven(convert(Int, sa.j + sb.j - sc.j)) ? one(Rscalartype(SU2Irrep)) :
-one(Rscalartype(SU2Irrep))
end

function fusiontensor(a::SU2Irrep, b::SU2Irrep, c::SU2Irrep)
Expand Down Expand Up @@ -354,15 +354,15 @@ function Nsymbol(a::CU1Irrep, b::CU1Irrep, c::CU1Irrep)
(c.j == a.j + b.j) | (c.j == abs(a.j - b.j))))
end

Feltype(::Type{CU1Irrep}) = Float64
Fscalartype(::Type{CU1Irrep}) = Float64
function Fsymbol(a::CU1Irrep, b::CU1Irrep, c::CU1Irrep,
d::CU1Irrep, e::CU1Irrep, f::CU1Irrep)
Nabe = convert(Int, Nsymbol(a, b, e))
Necd = convert(Int, Nsymbol(e, c, d))
Nbcf = convert(Int, Nsymbol(b, c, f))
Nafd = convert(Int, Nsymbol(a, f, d))

T = Feltype(CU1Irrep)
T = Fscalartype(CU1Irrep)
Nabe * Necd * Nbcf * Nafd == 0 && return zero(T)

op = CU1Irrep(0, 0)
Expand Down Expand Up @@ -393,7 +393,7 @@ function Fsymbol(a::CU1Irrep, b::CU1Irrep, c::CU1Irrep,
if d == a
if e.j == 0
if f.j == 0
return f.s == 1 ? T(-0.5) : T(0.5)
return f.s == 1 ? T(-1 // 2) : T(1 // 2)
else
return e.s == 1 ? -s : s
end
Expand Down Expand Up @@ -443,9 +443,9 @@ function Fsymbol(a::CU1Irrep, b::CU1Irrep, c::CU1Irrep,
return one(T)
end

Reltype(::Type{CU1Irrep}) = Feltype(CU1Irrep)
Rscalartype(::Type{CU1Irrep}) = Fscalartype(CU1Irrep)
function Rsymbol(a::CU1Irrep, b::CU1Irrep, c::CU1Irrep)
R = convert(Reltype(CU1Irrep), Nsymbol(a, b, c))
R = convert(Rscalartype(CU1Irrep), Nsymbol(a, b, c))
return c.s == 1 && a.j > 0 ? -R : R
end

Expand Down
8 changes: 4 additions & 4 deletions TensorKitSectors/src/sectors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ which case it is complex).
"""
function Base.isreal(I::Type{<:Sector})
if BraidingStyle(I) isa HasBraiding
return Feltype(I) <: Real && Reltype(I) <: Real
return Fscalartype(I) <: Real && Rscalartype(I) <: Real
else
return Feltype(I) <: Real
return Fscalartype(I) <: Real
end
end

Expand Down Expand Up @@ -183,7 +183,7 @@ it is a rank 4 array of size
function Fsymbol end

# scalar type of the F symbols
Feltype(I::Type{<:Sector}) = eltype(Core.Compiler.return_type(Fsymbol, NTuple{6,I}))
Fscalartype(I::Type{<:Sector}) = eltype(Core.Compiler.return_type(Fsymbol, NTuple{6,I}))

# If a I::Sector with `fusion(I) == GenericFusion` fusion wants to have custom vertex
# labels, a specialized method for `vertindex2label` should be added
Expand Down Expand Up @@ -330,7 +330,7 @@ number. Otherwise it is a square matrix with row and column size
"""
function Rsymbol end

Reltype(I::Type{<:Sector}) = eltype(Core.Compiler.return_type(Rsymbol, NTuple{3,I}))
Rscalartype(I::Type{<:Sector}) = eltype(Core.Compiler.return_type(Rsymbol, NTuple{3,I}))

# properties that can be determined in terms of the R symbol

Expand Down
31 changes: 15 additions & 16 deletions src/fusiontrees/manipulations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function insertat(f₁::FusionTree{I}, i::Int, f₂::FusionTree{I,0}) where {I}
# this actually removes uncoupled line i, which should be trivial
(f₁.uncoupled[i] == f₂.coupled && !f₁.isdual[i]) ||
throw(SectorMismatch("cannot connect $(f₂.uncoupled) to $(f₁.uncoupled[i])"))
coeff = one(Feltype(I))
coeff = one(Fscalartype(I))

uncoupled = TupleTools.deleteat(f₁.uncoupled, i)
coupled = f₁.coupled
Expand All @@ -39,7 +39,7 @@ function insertat(f₁::FusionTree{I}, i, f₂::FusionTree{I,1}) where {I}
# identity operation
(f₁.uncoupled[i] == f₂.coupled && !f₁.isdual[i]) ||
throw(SectorMismatch("cannot connect $(f₂.uncoupled) to $(f₁.uncoupled[i])"))
coeff = one(Feltype(I))
coeff = one(Fscalartype(I))
isdual′ = TupleTools.setindex(f₁.isdual, f₂.isdual[1], i)
f = FusionTree{I}(f₁.uncoupled, f₁.coupled, isdual′, f₁.innerlines, f₁.vertices)
return fusiontreedict(I)(f => coeff)
Expand All @@ -59,7 +59,7 @@ function insertat(f₁::FusionTree{I}, i, f₂::FusionTree{I,2}) where {I}
isdual′ = (isdualb, isdualc, tail(isdual)...)
inner′ = (uncoupled[1], inner...)
vertices′ = (f₂.vertices..., f₁.vertices...)
coeff = one(Feltype(I))
coeff = one(Fscalartype(I))
f′ = FusionTree(uncoupled′, coupled, isdual′, inner′, vertices′)
return fusiontreedict(I)(f′ => coeff)
end
Expand Down Expand Up @@ -110,7 +110,7 @@ function insertat(f₁::FusionTree{I,N₁}, i, f₂::FusionTree{I,N₂}) where {
F = fusiontreetype(I, N₁ + N₂ - 1)
(f₁.uncoupled[i] == f₂.coupled && !f₁.isdual[i]) ||
throw(SectorMismatch("cannot connect $(f₂.uncoupled) to $(f₁.uncoupled[i])"))
coeff = one(Feltype(I))
coeff = one(Fscalartype(I))
T = typeof(coeff)
if length(f₁) == 1
return fusiontreedict(I){F,T}(f₂ => coeff)
Expand Down Expand Up @@ -457,7 +457,7 @@ function _recursive_repartition(f₁::FusionTree{I,N₁},
# precompute the parameters of the return type
F₁ = fusiontreetype(I, N)
F₂ = fusiontreetype(I, N₁ + N₂ - N)
coeff = one(Feltype(I))
coeff = one(Fscalartype(I))
T = typeof(coeff)
if N == N₁
return fusiontreedict(I){Tuple{F₁,F₂},T}((f₁, f₂) => coeff)
Expand Down Expand Up @@ -500,7 +500,7 @@ function Base.transpose(f₁::FusionTree{I}, f₂::FusionTree{I},
p = linearizepermutation(p1, p2, length(f₁), length(f₂))
@assert iscyclicpermutation(p)
if usetransposecache[]
T = Feltype(I)
T = Fscalartype(I)
F₁ = fusiontreetype(I, N₁)
F₂ = fusiontreetype(I, N₂)
D = fusiontreedict(I){Tuple{F₁,F₂},T}
Expand Down Expand Up @@ -586,7 +586,7 @@ function planar_trace(f₁::FusionTree{I}, f₂::FusionTree{I},
map(l -> l - count(l .> q′), TupleTools.getindices(linearindex, p2)))
end

T = Feltype(I)
T = Fscalartype(I)
F₁ = fusiontreetype(I, N₁)
F₂ = fusiontreetype(I, N₂)
newtrees = FusionTreeDict{Tuple{F₁,F₂},T}()
Expand All @@ -613,7 +613,7 @@ of output trees and corresponding coefficients.
"""
function planar_trace(f::FusionTree{I,N},
q1::IndexTuple{N₃}, q2::IndexTuple{N₃}) where {I<:Sector,N,N₃}
T = Feltype(I)
T = Fscalartype(I)
F = fusiontreetype(I, N - 2 * N₃)
newtrees = FusionTreeDict{F,T}()
N₃ === 0 && return push!(newtrees, f => one(T))
Expand Down Expand Up @@ -670,7 +670,7 @@ function elementary_trace(f::FusionTree{I,N}, i) where {I<:Sector,N}
i < N || f.coupled == one(I) ||
throw(ArgumentError("Cannot trace outputs i=$N and 1 of fusion tree that couples to non-trivial sector"))

T = Feltype(I)
T = Fscalartype(I)
F = fusiontreetype(I, N - 2)
newtrees = FusionTreeDict{F,T}()

Expand Down Expand Up @@ -784,9 +784,9 @@ function artin_braid(f::FusionTree{I,N}, i; inv::Bool=false) where {I<:Sector,N}
u = one(I)

if BraidingStyle(I) isa NoBraiding
oneT = one(Feltype(I))
oneT = one(Fscalartype(I))
else
oneT = one(Feltype(I)) * one(Reltype(I))
oneT = one(Fscalartype(I)) * one(Rscalartype(I))
end

if u in (uncoupled[i], uncoupled[i + 1])
Expand Down Expand Up @@ -921,7 +921,7 @@ function braid(f::FusionTree{I,N},
p::NTuple{N,Int}) where {I<:Sector,N}
TupleTools.isperm(p) || throw(ArgumentError("not a valid permutation: $p"))
if FusionStyle(I) isa UniqueFusion && BraidingStyle(I) isa SymmetricBraiding
coeff = Rsymbol(one(I), one(I), one(I)) # one(Reltype(I)) ?
coeff = one(Rscalartype(I))
for i in 1:N
for j in 1:(i - 1)
if p[j] > p[i]
Expand All @@ -936,8 +936,8 @@ function braid(f::FusionTree{I,N},
f′ = FusionTree{I}(uncoupled′, coupled′, isdual′)
return fusiontreedict(I)(f′ => coeff)
else
T = BraidingStyle(I) isa NoBraiding ? Feltype(I) :
typeof(one(Feltype(I)) * one(Reltype(I)))
T = BraidingStyle(I) isa NoBraiding ? Fscalartype(I) :
typeof(one(Fscalartype(I)) * one(Rscalartype(I)))
coeff = one(T)
trees = FusionTreeDict(f => coeff)
newtrees = empty(trees)
Expand Down Expand Up @@ -1014,8 +1014,7 @@ function braid(f₁::FusionTree{I}, f₂::FusionTree{I},
else
if usebraidcache_nonabelian[]
T = BraidingStyle(I) isa NoBraiding ?
Feltype(I) :
typeof(one(Feltype(I)) * one(Reltype(I)) * sqrtdim(one(I))) # do we need sqrtdim here ?
Fscalartype(I) : typeof(one(Fscalartype(I)) * one(Rscalartype(I)))
F₁ = fusiontreetype(I, N₁)
F₂ = fusiontreetype(I, N₂)
D = FusionTreeDict{Tuple{F₁,F₂},T}
Expand Down

0 comments on commit 8e5251e

Please sign in to comment.