Skip to content

Commit ff01886

Browse files
committed
generalise A4Object to BimoduleSector where possible
1 parent b4c79c0 commit ff01886

File tree

1 file changed

+27
-23
lines changed

1 file changed

+27
-23
lines changed

src/bimodulesector.jl

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ struct BimoduleSector{Name} <: Sector
1515
end
1616

1717
BimoduleSector{Name}(data::NTuple{3,Int}) where {Name} = BimoduleSector{Name}(data...)
18+
BimoduleSectorName(::Type{BimoduleSector{Name}}) where {Name} = Name
1819
const A4Object = BimoduleSector{:A4}
1920

2021
Base.convert(::Type{<:BimoduleSector{Name}}, labels::NTuple{3,Int}) where {Name} = BimoduleSector{Name}(labels...)
@@ -55,21 +56,21 @@ function Base.iterate(iter::SectorValues{<:BimoduleSector}, (I, label)=(1, 1))
5556
end
5657
end
5758

58-
function Base.length(::SectorValues{A4Object})
59-
s = size(A4Object)
60-
return sum(_numlabels(A4Object, i, j) for i in 1:s, j in 1:s)
59+
function Base.length(::SectorValues{I}) where {I<:BimoduleSector}
60+
s = size(I)
61+
return sum(_numlabels(I, i, j) for i in 1:s, j in 1:s)
6162
end
6263

6364
TensorKitSectors.FusionStyle(::Type{A4Object}) = GenericFusion()
64-
TensorKitSectors.BraidingStyle(::Type{A4Object}) = NoBraiding()
65+
TensorKitSectors.BraidingStyle(::Type{<:BimoduleSector}) = NoBraiding()
6566
TensorKitSectors.sectorscalartype(::Type{A4Object}) = ComplexF64
6667

67-
function TensorKitSectors.:(a::A4Object, b::A4Object)
68+
function TensorKitSectors.:(a::I, b::I) where {I<:BimoduleSector}
6869
@assert a.j == b.i
69-
Ncache = _get_Ncache(A4Object)[a.i, a.j, b.j]
70-
return A4Object[A4Object(a.i, b.j, c_l)
71-
for (a_l, b_l, c_l) in keys(Ncache)
72-
if (a_l == a.label && b_l == b.label)]
70+
Ncache = _get_Ncache(I)[a.i, a.j, b.j]
71+
return I[I(a.i, b.j, c_l)
72+
for (a_l, b_l, c_l) in keys(Ncache)
73+
if (a_l == a.label && b_l == b.label)]
7374
end
7475

7576
function _numlabels(::Type{T}, i, j) where {T<:BimoduleSector}
@@ -84,14 +85,15 @@ end
8485
# ---------------
8586
const artifact_path = joinpath(artifact"fusiondata", "MultiTensorKit.jl-data-v0.1.5")
8687

87-
function extract_Nsymbol(::Type{A4Object})
88-
filename = joinpath(artifact_path, "A4", "Nsymbol.txt")
89-
isfile(filename) || throw(LoadError(filename, 0, "Nsymbol file not found for A4"))
88+
function extract_Nsymbol(::Type{I}) where {I <: BimoduleSector}
89+
name = string(BimoduleSectorName(I))
90+
filename = joinpath(artifact_path, name, "Nsymbol.txt")
91+
isfile(filename) || throw(LoadError(filename, 0, "Nsymbol file not found for $name"))
9092
Narray = readdlm(filename) # matrix with 7 columns
9193

9294
data_dict = Dict{NTuple{3,Int},Dict{NTuple{3,Int},Int}}()
9395
for row in eachrow(Narray)
94-
i, j, k, a, b, c, N = Int.(@view(row[1:size(A4Object)]))
96+
i, j, k, a, b, c, N = Int.(@view(row[1:size(I)]))
9597
colordict = get!(data_dict, (i, j, k), Dict{NTuple{3,Int},Int}())
9698
push!(colordict, (a, b, c) => N)
9799
end
@@ -109,7 +111,7 @@ function _get_Ncache(::Type{T}) where {T<:BimoduleSector}
109111
end
110112
end
111113

112-
function TensorKitSectors.Nsymbol(a::I, b::I, c::I) where {I<:A4Object}
114+
function TensorKitSectors.Nsymbol(a::I, b::I, c::I) where {I<:BimoduleSector}
113115
# TODO: should this error or return 0?
114116
(a.j == b.i && a.i == c.i && b.j == c.j) ||
115117
throw(ArgumentError("invalid fusion channel"))
@@ -126,9 +128,9 @@ function _get_dual_cache(::Type{T}) where {T<:BimoduleSector}
126128
end
127129
end
128130

129-
function extract_dual(::Type{A4Object})
130-
N = _get_Ncache(A4Object)
131-
ncats = size(A4Object)
131+
function extract_dual(::Type{I}) where {I <: BimoduleSector}
132+
N = _get_Ncache(I)
133+
ncats = size(I)
132134
Is = zeros(Int, ncats)
133135

134136
map(1:ncats) do i
@@ -205,24 +207,25 @@ function Base.conj(a::BimoduleSector)
205207
return typeof(a)(a.j, a.i, _get_dual_cache(typeof(a))[2][a.i, a.j][a.label])
206208
end
207209

208-
function extract_Fsymbol(::Type{A4Object})
210+
function extract_Fsymbol(::Type{I}) where {I <: BimoduleSector}
209211
result = Dict{NTuple{4,Int},Dict{NTuple{6,Int},Array{ComplexF64,4}}}()
210-
filename = joinpath(artifact_path, "A4", "Fsymbol.txt")
212+
name = string(BimoduleSectorName(I))
213+
filename = joinpath(artifact_path, name, "Fsymbol.txt")
211214
@assert isfile(filename) "cannot find $filename"
212215
Farray = readdlm(filename)
213216
for ((i, j, k, l), colordict) in convert_Fs(Farray)
214217
result[(i, j, k, l)] = Dict{NTuple{6,Int},Array{ComplexF64,4}}()
215218
for ((a, b, c, d, e, f), Fvals) in colordict
216-
a_ob, b_ob, c_ob, d_ob, e_ob, f_ob = A4Object.(((i, j, a), (j, k, b),
219+
a_ob, b_ob, c_ob, d_ob, e_ob, f_ob = I.(((i, j, a), (j, k, b),
217220
(k, l, c), (i, l, d),
218221
(i, k, e), (j, l, f)))
219222
result[(i, j, k, l)][(a, b, c, d, e, f)] = zeros(ComplexF64,
220223
Nsymbol(a_ob, b_ob, e_ob),
221224
Nsymbol(e_ob, c_ob, d_ob),
222225
Nsymbol(b_ob, c_ob, f_ob),
223226
Nsymbol(a_ob, f_ob, d_ob))
224-
for (I, v) in Fvals
225-
result[(i, j, k, l)][(a, b, c, d, e, f)][I] = v
227+
for (K, v) in Fvals
228+
result[(i, j, k, l)][(a, b, c, d, e, f)][K] = v
226229
end
227230
end
228231
end
@@ -258,7 +261,7 @@ function _get_Fcache(::Type{T}) where {T<:BimoduleSector}
258261
end
259262

260263
function TensorKitSectors.Fsymbol(a::I, b::I, c::I, d::I, e::I,
261-
f::I) where {I<:A4Object}
264+
f::I) where {I<:BimoduleSector}
262265
# required to keep track of multiplicities where F-move is partially unallowed
263266
# also deals with invalid fusion channels
264267
Nabe = Nsymbol(a, b, e)
@@ -278,6 +281,7 @@ end
278281
# interface with TensorKit where necessary
279282
#-----------------------------------------
280283

284+
#TODO: generalise
281285
function TensorKit.blocksectors(W::TensorMapSpace{S,N₁,N₂}) where
282286
{S<:Union{Vect[A4Object],
283287
SumSpace{Vect[A4Object]}},N₁,N₂}

0 commit comments

Comments
 (0)