Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

define DualSector #9

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SymmetrySectors"
uuid = "f8a8ad64-adbc-4fce-92f7-ffe2bb36a86e"
authors = ["ITensor developers <[email protected]> and contributors"]
version = "0.1.5"
version = "0.2.0"

[deps]
BlockArrays = "8e7c35d0-a365-5155-bbbb-fb81a777f24e"
Expand All @@ -11,7 +11,7 @@ LabelledNumbers = "f856a3a6-4152-4ec4-b2a7-02c1a55d7993"

[compat]
BlockArrays = "1.2.0"
GradedUnitRanges = "0.1.1"
GradedUnitRanges = "0.2.0"
HalfIntegers = "1.6.0"
LabelledNumbers = "0.1.0"
julia = "1.10"
2 changes: 2 additions & 0 deletions src/SymmetrySectors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ export U1, Z, dual

include("symmetry_style.jl")
include("abstractsector.jl")
include("dualsector.jl")

include("sector_definitions/fib.jl")
include("sector_definitions/ising.jl")
include("sector_definitions/o2.jl")
Expand Down
68 changes: 68 additions & 0 deletions src/dualsector.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# This file defines type DualSector

using GradedUnitRanges: dual, isdual, nondual, nondual_type

struct DualSector{NonDualSector<:AbstractSector} <: AbstractSector
nondual::NonDualSector

function DualSector(s::AbstractSector)
return new{typeof(s)}(s)
end
end

GradedUnitRanges.nondual(s::DualSector) = s.nondual
GradedUnitRanges.nondual(s::AbstractSector) = s

# =================================== Base interface =====================================
function Base.:(==)(s1::DualSector, s2::DualSector)
return ==(nondual(s1), nondual(s2))
end

function Base.isless(s1::S, s2::S) where {S<:DualSector}
return isless(nondual(s1), nondual(s2))
end

function Base.show(io::IO, s::DualSector)
show(io, nondual(s))
return print(io, "'")
end

# ================================ GradedUnitRanges interface ============================
GradedUnitRanges.dual(s::AbstractSector) = DualSector(s)
GradedUnitRanges.dual(s::DualSector) = nondual(s)

GradedUnitRanges.dual_type(S::Type{<:AbstractSector}) = DualSector{S}
function GradedUnitRanges.dual_type(
::Type{<:DualSector{NonDualSector}}
) where {NonDualSector}
return NonDualSector
end

GradedUnitRanges.flip(s::AbstractSector) = dual(label_dual(s))
GradedUnitRanges.flip(s::DualSector) = label_dual(nondual(s))

GradedUnitRanges.isdual(::Type{<:DualSector}) = true

GradedUnitRanges.sector_type(DS::Type{<:DualSector}) = nondual_type(DS)

# ============================= SymmetrySectors interface ================================
label_dual(s::DualSector) = dual(label_dual(dual(s)))

SymmetryStyle(DS::Type{<:DualSector}) = SymmetryStyle(nondual_type(DS))

function quantum_dimension(::NotAbelianStyle, s::DualSector)
return quantum_dimension(NotAbelianStyle(), nondual(s))
end

trivial(DS::Type{<:DualSector}) = trivial(nondual_type(DS))

×(s1::DualSector, s2::DualSector) = dual(nondual(s1) × nondual(s2))
×(s1::DualSector, s2::AbstractSector) = throw("Not implemented")
×(s1::AbstractSector, s2::DualSector) = throw("Not implemented")

# =============================== Fusion rule interface ==================================
fusion_rule(c1::DualSector, c2::AbstractSector) = fusion_rule(label_dual(nondual(c1)), c2)
fusion_rule(c1::AbstractSector, c2::DualSector) = fusion_rule(c1, label_dual(nondual(c2)))
function fusion_rule(c1::DualSector, c2::DualSector)
return fusion_rule(label_dual(nondual(c1)), label_dual(nondual(c2)))
end
2 changes: 1 addition & 1 deletion src/sector_definitions/fib.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ end

SymmetryStyle(::Type{Fib}) = NotAbelianStyle()

GradedUnitRanges.dual(f::Fib) = f
label_dual(f::Fib) = f

sector_label(f::Fib) = f.l

Expand Down
2 changes: 1 addition & 1 deletion src/sector_definitions/ising.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ end

SymmetryStyle(::Type{Ising}) = NotAbelianStyle()

GradedUnitRanges.dual(i::Ising) = i
label_dual(i::Ising) = i

sector_label(i::Ising) = i.l

Expand Down
2 changes: 1 addition & 1 deletion src/sector_definitions/o2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ iszero_odd(l::HalfInteger) = l == sector_label(zero_odd(O2))

quantum_dimension(::NotAbelianStyle, s::O2) = 2 - is_zero_even_or_odd(s)

GradedUnitRanges.dual(s::O2) = s
label_dual(s::O2) = s

function Base.show(io::IO, s::O2)
if iszero_odd(s)
Expand Down
4 changes: 2 additions & 2 deletions src/sector_definitions/su.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function quantum_dimension(::NotAbelianStyle, s::SU)
return Int(d)
end

function GradedUnitRanges.dual(s::SU)
function label_dual(s::SU)
l = sector_label(s)
nl = reverse(cumsum((l[begin:(end - 1)] .- l[(begin + 1):end]..., l[end])))
return typeof(s)(nl)
Expand Down Expand Up @@ -87,7 +87,7 @@ end
# optimize implementation
quantum_dimension(s::SU{2}) = sector_label(s)[1] + 1

GradedUnitRanges.dual(s::SU{2}) = s
label_dual(s::SU{2}) = s

function label_fusion_rule(::Type{<:SU{2}}, s1, s2)
irreps = [SU{2}((i,)) for i in (abs(s1[1] - s2[1])):2:(s1[1] + s2[1])]
Expand Down
2 changes: 1 addition & 1 deletion src/sector_definitions/su2k.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ end

SymmetryStyle(::Type{<:su2}) = NotAbelianStyle()

GradedUnitRanges.dual(s::su2) = s
label_dual(s::su2) = s

sector_label(s::su2) = s.j

Expand Down
5 changes: 4 additions & 1 deletion src/sector_definitions/trivial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ SymmetryStyle(::Type{TrivialSector}) = AbelianStyle()

trivial(::Type{TrivialSector}) = TrivialSector()

GradedUnitRanges.dual(::TrivialSector) = TrivialSector()
label_dual(::TrivialSector) = TrivialSector()

# TrivialSector acts as trivial on any AbstractSector
function fusion_rule(::NotAbelianStyle, ::TrivialSector, c::AbstractSector)
Expand All @@ -36,6 +36,9 @@ Base.:(==)(c::AbstractSector, ::TrivialSector) = istrivial(c)
Base.:(==)(::TrivialSector, c::AbstractSector) = istrivial(c)
Base.:(==)(::TrivialSector, ::TrivialSector) = true

Base.:(==)(c::DualSector, ::TrivialSector) = false
Base.:(==)(::TrivialSector, c::DualSector) = false

# sorts as trivial for any Sector
Base.isless(c::AbstractSector, ::TrivialSector) = c < trivial(c)
Base.isless(::TrivialSector, c::AbstractSector) = trivial(c) < c
Expand Down
2 changes: 1 addition & 1 deletion src/sector_definitions/u1.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ SymmetryStyle(::Type{<:U1}) = AbelianStyle()
sector_label(u::U1) = u.n

set_sector_label(s::U1, sector_label) = typeof(s)(sector_label)
GradedUnitRanges.dual(s::U1) = set_sector_label(s, -sector_label(s))
label_dual(s::U1) = set_sector_label(s, -sector_label(s))

trivial(::Type{U1}) = trivial(U1{Int})
trivial(::Type{U1{T}}) where {T} = U1(zero(T))
Expand Down
2 changes: 1 addition & 1 deletion src/sector_definitions/zn.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ SymmetryStyle(::Type{<:Z}) = AbelianStyle()
sector_label(c::Z) = c.m

set_sector_label(s::Z, sector_label) = typeof(s)(sector_label)
GradedUnitRanges.dual(s::Z) = set_sector_label(s, -sector_label(s))
label_dual(s::Z) = set_sector_label(s, -sector_label(s))

trivial(sector_type::Type{<:Z}) = sector_type(0)

Expand Down
3 changes: 2 additions & 1 deletion src/sector_product.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ end
SectorProduct(c::SectorProduct) = _SectorProduct(arguments(c))

arguments(s::SectorProduct) = s.arguments
arguments(s::DualSector{<:SectorProduct}) = map(dual, arguments(nondual(s))) # need map in NamedTuple

# ================================= Sectors interface ====================================
function SymmetryStyle(T::Type{<:SectorProduct})
Expand All @@ -25,7 +26,7 @@ function quantum_dimension(::NotAbelianStyle, s::SectorProduct)
end

# use map instead of broadcast to support both Tuple and NamedTuple
GradedUnitRanges.dual(s::SectorProduct) = SectorProduct(map(dual, arguments(s)))
label_dual(s::SectorProduct) = SectorProduct(map(label_dual, arguments(s)))

function trivial(type::Type{<:SectorProduct})
return SectorProduct(arguments_trivial(arguments_type(type)))
Expand Down
Loading
Loading