Skip to content

Commit a549943

Browse files
committed
update code to account for new N- and F-symbols
1 parent a70b569 commit a549943

File tree

2 files changed

+45
-39
lines changed

2 files changed

+45
-39
lines changed

src/bimodulesector.jl

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ struct BimoduleSector{Name} <: Sector
33
j::Int
44
label::Int
55
function BimoduleSector{:A4}(i::Int, j::Int, label::Int)
6-
i <= 12 && j <= 12 || throw(DomainError("object outside the matrix A4"))
6+
i <= size(BimoduleSector{:A4}) && j <= size(BimoduleSector{:A4}) ||
7+
throw(DomainError("object outside the matrix A4"))
78
return label <= _numlabels(BimoduleSector{:A4}, i, j) ? new{:A4}(i, j, label) :
89
throw(DomainError("label outside category A4($i, $j)"))
910
end
@@ -21,12 +22,15 @@ function Base.convert(::Type{BimoduleSector{Name}}, d::NTuple{3,Int}) where {Nam
2122
return BimoduleSector{Name}(d...)
2223
end
2324

25+
Base.size(::Type{A4Object}) = 7
26+
2427
Base.IteratorSize(::Type{<:SectorValues{<:BimoduleSector}}) = Base.SizeUnknown()
2528

2629
# TODO: generalize?
2730
function Base.iterate(iter::SectorValues{A4Object}, (I, label)=(1, 1))
28-
I > 12 * 12 && return nothing
29-
i, j = CartesianIndices((12, 12))[I].I
31+
s = size(A4Object)
32+
I > s * s && return nothing
33+
i, j = CartesianIndices((s, s))[I].I
3034
maxlabel = _numlabels(A4Object, i, j)
3135
return if label > maxlabel
3236
iterate(iter, (I + 1, 1))
@@ -36,7 +40,8 @@ function Base.iterate(iter::SectorValues{A4Object}, (I, label)=(1, 1))
3640
end
3741

3842
function Base.length(::SectorValues{A4Object})
39-
return sum(_numlabels(A4Object, i, j) for i in 1:12, j in 1:12)
43+
s = size(A4Object)
44+
return sum(_numlabels(A4Object, i, j) for i in 1:s, j in 1:s)
4045
end
4146

4247
TensorKitSectors.FusionStyle(::Type{A4Object}) = GenericFusion()
@@ -60,21 +65,22 @@ end
6065
const artifact_path = joinpath(artifact"fusiondata", "MultiTensorKit.jl-data-v0.1.3")
6166

6267
function extract_Nsymbol(::Type{A4Object})
63-
filename = joinpath(artifact_path, "A4", "Nsymbol.json")
64-
isfile(filename) || throw(LoadError(filename, 0, "Nsymbol file not found for $Name"))
65-
json_string = read(filename, String)
66-
Narray = copy(JSON3.read(json_string))
67-
return map(reshape(Narray, 12, 12, 12)) do x
68-
y = Dict{NTuple{3,Int},Int}()
69-
for (k, v) in x
70-
a, b, c = parse.(Int, split(string(k)[2:(end - 1)], ", "))
71-
y[(a, b, c)] = v
72-
end
73-
return y
68+
filename = joinpath(artifact_path, "A4", "Nsymbol.txt")
69+
isfile(filename) || throw(LoadError(filename, 0, "Nsymbol file not found for A4"))
70+
Narray = readdlm(filename) # matrix with 7 columns
71+
72+
data_dict = Dict{NTuple{3,Int},Dict{NTuple{3,Int},Int}}()
73+
for row in eachrow(Narray)
74+
i, j, k, a, b, c, N = Int.(@view(row[1:size(A4Object)]))
75+
colordict = get!(data_dict, (i, j, k), Dict{NTuple{3,Int},Int}())
76+
push!(colordict, (a, b, c) => N)
7477
end
78+
79+
return data_dict
7580
end
7681

77-
const Ncache = IdDict{Type{<:BimoduleSector},Array{Dict{NTuple{3,Int},Int},3}}()
82+
const Ncache = IdDict{Type{<:BimoduleSector},
83+
Dict{NTuple{3,Int},Dict{NTuple{3,Int},Int}}}()
7884

7985
function _get_Ncache(::Type{T}) where {T<:BimoduleSector}
8086
global Ncache
@@ -102,7 +108,7 @@ end
102108

103109
function extract_dual(::Type{A4Object})
104110
N = _get_Ncache(A4Object)
105-
ncats = size(N, 1)
111+
ncats = size(A4Object)
106112
Is = zeros(Int, ncats)
107113

108114
map(1:ncats) do i
@@ -175,24 +181,22 @@ end
175181

176182
function extract_Fsymbol(::Type{A4Object})
177183
result = Dict{NTuple{4,Int},Dict{NTuple{6,Int},Array{ComplexF64,4}}}()
178-
for i in 1:12
179-
filename = joinpath(artifact_path, "A4", "Fsymbol_$i.txt")
180-
@assert isfile(filename) "cannot find $filename"
181-
Farray_part = readdlm(filename)
182-
for ((i, j, k, l), colordict) in convert_Fs(Farray_part)
183-
result[(i, j, k, l)] = Dict{NTuple{6,Int},Array{ComplexF64,4}}()
184-
for ((a, b, c, d, e, f), Fvals) in colordict
185-
a_ob, b_ob, c_ob, d_ob, e_ob, f_ob = A4Object.(((i, j, a), (j, k, b),
186-
(k, l, c), (i, l, d),
187-
(i, k, e), (j, l, f)))
188-
result[(i, j, k, l)][(a, b, c, d, e, f)] = zeros(ComplexF64,
189-
Nsymbol(a_ob, b_ob, e_ob),
190-
Nsymbol(e_ob, c_ob, d_ob),
191-
Nsymbol(b_ob, c_ob, f_ob),
192-
Nsymbol(a_ob, f_ob, d_ob))
193-
for (I, v) in Fvals
194-
result[(i, j, k, l)][(a, b, c, d, e, f)][I] = v
195-
end
184+
filename = joinpath(artifact_path, "A4", "Fsymbol.txt")
185+
@assert isfile(filename) "cannot find $filename"
186+
Farray = readdlm(filename)
187+
for ((i, j, k, l), colordict) in convert_Fs(Farray)
188+
result[(i, j, k, l)] = Dict{NTuple{6,Int},Array{ComplexF64,4}}()
189+
for ((a, b, c, d, e, f), Fvals) in colordict
190+
a_ob, b_ob, c_ob, d_ob, e_ob, f_ob = A4Object.(((i, j, a), (j, k, b),
191+
(k, l, c), (i, l, d),
192+
(i, k, e), (j, l, f)))
193+
result[(i, j, k, l)][(a, b, c, d, e, f)] = zeros(ComplexF64,
194+
Nsymbol(a_ob, b_ob, e_ob),
195+
Nsymbol(e_ob, c_ob, d_ob),
196+
Nsymbol(b_ob, c_ob, f_ob),
197+
Nsymbol(a_ob, f_ob, d_ob))
198+
for (I, v) in Fvals
199+
result[(i, j, k, l)][(a, b, c, d, e, f)][I] = v
196200
end
197201
end
198202
end
@@ -254,7 +258,8 @@ function TensorKit.blocksectors(W::TensorMapSpace{S,N₁,N₂}) where
254258
dom = domain(W)
255259
if N₁ == 0 && N₂ == 0 # 0x0-dimensional TensorMap is just a scalar, return all units
256260
# this is a problem in full contractions where the coloring outside is 𝒞
257-
return NTuple{12,A4Object}(one(A4Object(i, i, 1)) for i in 1:12) # have to return all units b/c no info on W in this case
261+
return NTuple{size(A4Object),A4Object}(one(A4Object(i, i, 1))
262+
for i in 1:size(A4Object)) # have to return all units b/c no info on W in this case
258263
elseif N₁ == 0
259264
@assert N₂ != 0 "one of Type A4Object doesn't exist"
260265
return filter!(isone, collect(blocksectors(dom)))

test/test_A4.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ using TensorKitSectors, TensorKit
33
using Test, TestExtras
44

55
I = A4Object
6+
s = size(A4Object)
67

78
@testset "Basic type properties" verbose = true begin
89
Istr = TensorKitSectors.type_repr(I)
910
@test eval(Meta.parse(sprint(show, I))) == I
1011
@test eval(Meta.parse(TensorKitSectors.type_repr(I))) == I
1112
end
1213

13-
@testset "Fusion Category $i" for i in 1:12
14+
@testset "Fusion Category $i" for i in 1:s
1415
objects = A4Object.(i, i, MultiTensorKit._get_dual_cache(I)[2][i, i])
1516

1617
@testset "Basic properties" begin
@@ -63,7 +64,7 @@ end
6364
end
6465
end
6566

66-
@testset "A4 Category ($i, $j) units and duals" for i in 1:12, j in 1:12
67+
@testset "A4 Category ($i, $j) units and duals" for i in 1:s, j in 1:s
6768
Cij_obs = A4Object.(i, j, MultiTensorKit._get_dual_cache(I)[2][i, j])
6869

6970
s = rand(Cij_obs, 1)[1]
@@ -76,7 +77,7 @@ end
7677
@test dual(dual(s)) == s
7778
end
7879

79-
@testset "A4 Category ($i, $j) left and right units" for i in 1:12, j in 1:12
80+
@testset "A4 Category ($i, $j) left and right units" for i in 1:s, j in 1:s
8081
Cij_obs = A4Object.(i, j, MultiTensorKit._get_dual_cache(I)[2][i, j])
8182

8283
s = rand(Cij_obs, 1)[1]

0 commit comments

Comments
 (0)