From 8aeb0972e577a6e14e5aa32ce6f1f717ee14a1c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Gauth=C3=A9?= Date: Thu, 26 Sep 2024 10:05:17 -0400 Subject: [PATCH] explicit imports --- NDTensors/src/lib/Sectors/src/Sectors.jl | 13 ++++ .../src/lib/Sectors/src/abstractcategory.jl | 60 ++++++++----------- .../Sectors/src/category_definitions/su2k.jl | 2 +- .../src/lib/Sectors/src/category_product.jl | 23 ++++--- .../src/lib/Sectors/src/symmetry_style.jl | 7 +-- 5 files changed, 50 insertions(+), 55 deletions(-) diff --git a/NDTensors/src/lib/Sectors/src/Sectors.jl b/NDTensors/src/lib/Sectors/src/Sectors.jl index f6c8bca92b..9b99eeaba2 100644 --- a/NDTensors/src/lib/Sectors/src/Sectors.jl +++ b/NDTensors/src/lib/Sectors/src/Sectors.jl @@ -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") diff --git a/NDTensors/src/lib/Sectors/src/abstractcategory.jl b/NDTensors/src/lib/Sectors/src/abstractcategory.jl index da1c064b0f..60443de5a7 100644 --- a/NDTensors/src/lib/Sectors/src/abstractcategory.jl +++ b/NDTensors/src/lib/Sectors/src/abstractcategory.jl @@ -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).") @@ -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) @@ -55,7 +52,7 @@ 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 @@ -63,10 +60,8 @@ 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) @@ -76,50 +71,45 @@ 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) @@ -127,5 +117,5 @@ function GradedAxes.tensor_product(c1::AbstractCategory, c2::AbstractCategory) end function GradedAxes.fusion_product(c::AbstractCategory) - return GradedAxes.fusion_product(to_graded_axis(c)) + return to_graded_axis(c) end diff --git a/NDTensors/src/lib/Sectors/src/category_definitions/su2k.jl b/NDTensors/src/lib/Sectors/src/category_definitions/su2k.jl index 736e9987b8..2f1c22538b 100644 --- a/NDTensors/src/lib/Sectors/src/category_definitions/su2k.jl +++ b/NDTensors/src/lib/Sectors/src/category_definitions/su2k.jl @@ -8,7 +8,7 @@ end SymmetryStyle(::su2) = NonGroupCategory() -dual(s::su2) = s +GradedAxes.dual(s::su2) = s category_label(s::su2) = s.j diff --git a/NDTensors/src/lib/Sectors/src/category_product.jl b/NDTensors/src/lib/Sectors/src/category_product.jl index 04a2d33df9..f56d01a93f 100644 --- a/NDTensors/src/lib/Sectors/src/category_product.jl +++ b/NDTensors/src/lib/Sectors/src/category_product.jl @@ -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))) @@ -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) @@ -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 ====================================== diff --git a/NDTensors/src/lib/Sectors/src/symmetry_style.jl b/NDTensors/src/lib/Sectors/src/symmetry_style.jl index f65a65fc91..417c506c6d 100644 --- a/NDTensors/src/lib/Sectors/src/symmetry_style.jl +++ b/NDTensors/src/lib/Sectors/src/symmetry_style.jl @@ -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 @@ -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))