Skip to content

Commit

Permalink
explicit imports
Browse files Browse the repository at this point in the history
  • Loading branch information
ogauthe committed Sep 26, 2024
1 parent ad12d60 commit 8aeb097
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 55 deletions.
13 changes: 13 additions & 0 deletions NDTensors/src/lib/Sectors/src/Sectors.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
module Sectors

using BlockArrays: blocklengths

using NDTensors.LabelledNumbers:
LabelledInteger, label, label_type, labelled, unlabel, unlabel_type
using NDTensors.GradedAxes:
GradedAxes,
blocklabels,
dual,
fuse_blocklengths,
fusion_product,
gradedrange,
tensor_product

include("symmetry_style.jl")
include("abstractcategory.jl")
include("category_definitions/fib.jl")
Expand Down
60 changes: 25 additions & 35 deletions NDTensors/src/lib/Sectors/src/abstractcategory.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ end
# ================================= Sectors interface ====================================
trivial(x) = trivial(typeof(x))
function trivial(axis_type::Type{<:AbstractUnitRange})
return GradedAxes.gradedrange([trivial(eltype(axis_type))]) # always returns nondual
return gradedrange([trivial(eltype(axis_type))]) # always returns nondual
end
function trivial(la_type::Type{<:LabelledNumbers.LabelledInteger})
return LabelledNumbers.labelled(
one(LabelledNumbers.unlabel_type(la_type)), trivial(LabelledNumbers.label_type(la_type))
)
function trivial(la_type::Type{<:LabelledInteger})
return labelled(one(unlabel_type(la_type)), trivial(label_type(la_type)))
end
function trivial(type::Type)
return error("`trivial` not defined for type $(type).")
Expand All @@ -29,10 +27,9 @@ function category_label(c::AbstractCategory)
end

block_dimensions(g::AbstractUnitRange) = block_dimensions(SymmetryStyle(g), g)
block_dimensions(::AbelianGroup, g) = LabelledNumbers.unlabel.(BlockArrays.blocklengths(g))
block_dimensions(::AbelianGroup, g) = unlabel.(blocklengths(g))
function block_dimensions(::SymmetryStyle, g)
return Sectors.quantum_dimension.(GradedAxes.blocklabels(g)) .*
BlockArrays.blocklengths(g)
return quantum_dimension.(blocklabels(g)) .* blocklengths(g)
end

quantum_dimension(x) = quantum_dimension(SymmetryStyle(x), x)
Expand All @@ -55,18 +52,16 @@ end

function fusion_rule(::SymmetryStyle, c1::C, c2::C) where {C<:AbstractCategory}
degen, labels = label_fusion_rule(C, category_label(c1), category_label(c2))
return GradedAxes.gradedrange(LabelledNumbers.labelled.(degen, C.(labels)))
return gradedrange(labelled.(degen, C.(labels)))
end

# abelian case: return Category
function fusion_rule(::AbelianGroup, c1::C, c2::C) where {C<:AbstractCategory}
return C(label_fusion_rule(C, category_label(c1), category_label(c2)))
end

function fusion_rule(
::EmptyCategory, l1::LabelledNumbers.LabelledInteger, l2::LabelledNumbers.LabelledInteger
)
return LabelledNumbers.labelled(l1 * l2, sector())
function fusion_rule(::EmptyCategory, l1::LabelledInteger, l2::LabelledInteger)
return labelled(l1 * l2, sector())
end

function label_fusion_rule(category_type::Type{<:AbstractCategory}, ::Any, ::Any)
Expand All @@ -76,56 +71,51 @@ end
# ================================ GradedAxes interface ==================================
# tensor_product interface
function GradedAxes.fuse_blocklengths(
l1::LabelledNumbers.LabelledInteger{<:Integer,<:Sectors.AbstractCategory},
l2::LabelledNumbers.LabelledInteger{<:Integer,<:Sectors.AbstractCategory},
l1::LabelledInteger{<:Integer,<:AbstractCategory},
l2::LabelledInteger{<:Integer,<:AbstractCategory},
)
return GradedAxes.fuse_blocklengths(
combine_styles(SymmetryStyle(l1), SymmetryStyle(l2)), l1, l2
)
return fuse_blocklengths(combine_styles(SymmetryStyle(l1), SymmetryStyle(l2)), l1, l2)
end

function GradedAxes.fuse_blocklengths(
::SymmetryStyle, l1::LabelledNumbers.LabelledInteger, l2::LabelledNumbers.LabelledInteger
::SymmetryStyle, l1::LabelledInteger, l2::LabelledInteger
)
fused = LabelledNumbers.label(l1) LabelledNumbers.label(l2)
v =
LabelledNumbers.labelled.(
l1 * l2 .* BlockArrays.blocklengths(fused), GradedAxes.blocklabels(fused)
)
return GradedAxes.gradedrange(v)
fused = label(l1) label(l2)
v = labelled.(l1 * l2 .* blocklengths(fused), blocklabels(fused))
return gradedrange(v)
end

function GradedAxes.fuse_blocklengths(
::AbelianGroup, l1::LabelledNumbers.LabelledInteger, l2::LabelledNumbers.LabelledInteger
::AbelianGroup, l1::LabelledInteger, l2::LabelledInteger
)
fused = LabelledNumbers.label(l1) LabelledNumbers.label(l2)
return LabelledNumbers.labelled(l1 * l2, fused)
fused = label(l1) label(l2)
return labelled(l1 * l2, fused)
end

function GradedAxes.fuse_blocklengths(
::EmptyCategory, l1::LabelledNumbers.LabelledInteger, l2::LabelledNumbers.LabelledInteger
::EmptyCategory, l1::LabelledInteger, l2::LabelledInteger
)
return LabelledNumbers.labelled(l1 * l2, sector())
return labelled(l1 * l2, sector())
end

# cast to range
to_graded_axis(c::AbstractCategory) = to_graded_axis(LabelledNumbers.labelled(1, c))
to_graded_axis(l::LabelledNumbers.LabelledInteger) = GradedAxes.gradedrange([l])
to_graded_axis(c::AbstractCategory) = to_graded_axis(labelled(1, c))
to_graded_axis(l::LabelledInteger) = gradedrange([l])
to_graded_axis(g::AbstractUnitRange) = g

# allow to fuse a category with a GradedUnitRange
function GradedAxes.tensor_product(c::AbstractCategory, g::AbstractUnitRange)
return GradedAxes.tensor_product(to_graded_axis(c), g)
return tensor_product(to_graded_axis(c), g)
end

function GradedAxes.tensor_product(g::AbstractUnitRange, c::AbstractCategory)
return GradedAxes.tensor_product(c, g)
return tensor_product(g, to_graded_axis(c))
end

function GradedAxes.tensor_product(c1::AbstractCategory, c2::AbstractCategory)
return to_graded_axis(fusion_rule(c1, c2))
end

function GradedAxes.fusion_product(c::AbstractCategory)
return GradedAxes.fusion_product(to_graded_axis(c))
return to_graded_axis(c)
end
2 changes: 1 addition & 1 deletion NDTensors/src/lib/Sectors/src/category_definitions/su2k.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ end

SymmetryStyle(::su2) = NonGroupCategory()

dual(s::su2) = s
GradedAxes.dual(s::su2) = s

category_label(s::su2) = s.j

Expand Down
23 changes: 10 additions & 13 deletions NDTensors/src/lib/Sectors/src/category_product.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function quantum_dimension(::NonGroupCategory, s::CategoryProduct)
return prod(map(quantum_dimension, categories(s)))
end

GradedAxes.dual(s::CategoryProduct) = CategoryProduct(map(GradedAxes.dual, categories(s)))
GradedAxes.dual(s::CategoryProduct) = CategoryProduct(map(dual, categories(s)))

trivial(type::Type{<:CategoryProduct}) = sector(categories_trivial(categories_type(type)))

Expand Down Expand Up @@ -83,10 +83,9 @@ function recover_key(T::Type, fused::Tuple)
# here fused contains at leat one GradedUnitRange
g0 = reduce(×, fused)
# convention: keep unsorted blocklabels as produced by F order loops in ×
new_labels = recover_key.(T, GradedAxes.blocklabels(g0))
new_blocklengths =
LabelledNumbers.labelled.(GradedAxes.unlabel.(BlockArrays.blocklengths(g0)), new_labels)
return GradedAxes.gradedrange(new_blocklengths)
new_labels = recover_key.(T, blocklabels(g0))
new_blocklengths = labelled.(unlabel.(blocklengths(g0)), new_labels)
return gradedrange(new_blocklengths)
end

sector(T::Type{<:CategoryProduct}, cats::Tuple) = sector(categories_type(T), cats)
Expand All @@ -105,20 +104,18 @@ end
×(c1::NamedTuple, c2::AbstractCategory) = ×(CategoryProduct(c1), CategoryProduct(c2))
×(c1::AbstractCategory, c2::NamedTuple) = ×(CategoryProduct(c1), CategoryProduct(c2))

function ×(l1::LabelledNumbers.LabelledInteger, l2::LabelledNumbers.LabelledInteger)
c3 = LabelledNumbers.label(l1) × LabelledNumbers.label(l2)
m3 = LabelledNumbers.unlabel(l1) * LabelledNumbers.unlabel(l2)
return LabelledNumbers.labelled(m3, c3)
function ×(l1::LabelledInteger, l2::LabelledInteger)
c3 = label(l1) × label(l2)
m3 = unlabel(l1) * unlabel(l2)
return labelled(m3, c3)
end

function ×(g1::AbstractUnitRange, g2::AbstractUnitRange)
v = map(
((l1, l2),) -> l1 × l2,
Iterators.flatten((
Iterators.product(BlockArrays.blocklengths(g1), BlockArrays.blocklengths(g2)),
),),
Iterators.flatten((Iterators.product(blocklengths(g1), blocklengths(g2)),),),
)
return GradedAxes.gradedrange(v)
return gradedrange(v)
end

# ==================================== Fusion rules ======================================
Expand Down
7 changes: 1 addition & 6 deletions NDTensors/src/lib/Sectors/src/symmetry_style.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
# This file defines SymmetryStyle, a trait to distinguish abelian groups, non-abelian groups
# and non-group fusion categories.

using BlockArrays

using NDTensors.LabelledNumbers
using NDTensors.GradedAxes

abstract type SymmetryStyle end

struct AbelianGroup <: SymmetryStyle end
Expand All @@ -25,7 +20,7 @@ combine_styles(::EmptyCategory, s::SymmetryStyle) = s
combine_styles(s::SymmetryStyle, ::EmptyCategory) = s
combine_styles(::EmptyCategory, ::EmptyCategory) = EmptyCategory()

SymmetryStyle(l::LabelledNumbers.LabelledInteger) = SymmetryStyle(LabelledNumbers.label(l))
SymmetryStyle(l::LabelledInteger) = SymmetryStyle(label(l))

# crash for empty g. Currently impossible to construct.
SymmetryStyle(g::AbstractUnitRange) = SymmetryStyle(first(g))

0 comments on commit 8aeb097

Please sign in to comment.