Skip to content

Commit 58ee5e0

Browse files
committed
various fixes and improvements
1 parent b87de7c commit 58ee5e0

File tree

1 file changed

+94
-22
lines changed

1 file changed

+94
-22
lines changed

src/bimodulesector.jl

Lines changed: 94 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ struct BimoduleSector{Name} <: Sector
33
j::Int
44
label::Int
55
end
6-
6+
BimoduleSector{Name}(data::NTuple{3,Int}) where {Name} = BimoduleSector{Name}(data...)
77
const A4Object = BimoduleSector{:A4}
88

99
# Utility implementations
@@ -12,7 +12,9 @@ function Base.isless(a::I, b::I) where {I<:BimoduleSector}
1212
return isless((a.i, a.j, a.label), (b.i, b.j, b.label))
1313
end
1414
Base.hash(a::BimoduleSector, h::UInt) = hash(a.i, hash(a.j, hash(a.label, h)))
15-
Base.convert(::Type{BimoduleSector{Name}}, d::NTuple{3,Int}) = BimoduleSector{Name}(d...)
15+
function Base.convert(::Type{BimoduleSector{Name}}, d::NTuple{3,Int}) where {Name}
16+
return BimoduleSector{Name}(d...)
17+
end
1618

1719
Base.IteratorSize(::Type{SectorValues{<:BimoduleSector}}) = Base.SizeUnknown()
1820

@@ -39,14 +41,6 @@ function TensorKitSectors.:⊗(a::A4Object, b::A4Object)
3941
numlabels(A4Object, a.i, b.j)))
4042
end
4143

42-
# TODO: can I assume A4Irrep(i, i, 1) is identity?
43-
function Base.conj(a::A4Object)
44-
i, j = a.i, a.j
45-
label = findfirst(x -> Nsymbol(a, A4Irrep(j, i, x), A4Irrep(i, i, 1)) == 1,
46-
1:numlabels(A4Object, j, i))
47-
return A4Object(j, i, label)
48-
end
49-
5044
# Data from files
5145
# ---------------
5246
const artifact_path = joinpath(artifact"fusiondata", "MultiTensorKit.jl-data-v0.1.0")
@@ -62,35 +56,113 @@ function extract_Nsymbol(::Type{A4Object})
6256
a, b, c = parse.(Int, split(string(k)[2:(end - 1)], ", "))
6357
y[(a, b, c)] = v
6458
end
59+
return y
60+
end
61+
end
62+
63+
const Ncache = IdDict{Type{<:BimoduleSector},Array{Dict{NTuple{3,Int},Int},3}}()
64+
65+
function _get_Ncache(::Type{T}) where {T<:BimoduleSector}
66+
global Ncache
67+
return get!(Ncache, T) do
68+
return extract_Nsymbol(T)
6569
end
6670
end
6771

68-
const A4_Ncache = extract_Nsymbol(A4Object)
6972
function TensorKitSectors.Nsymbol(a::I, b::I, c::I) where {I<:A4Object}
7073
# TODO: should this error or return 0?
7174
(a.j == b.i && a.i == c.i && b.j == c.j) ||
7275
throw(ArgumentError("invalid fusion channel"))
7376
i, j, k = a.i, a.j, b.j
74-
return get(A4_Ncache[i, j, k], (a.label, b.label, c.label), 0)
77+
return get(_get_Ncache(I)[i, j, k], (a.label, b.label, c.label), 0)
78+
end
79+
80+
# TODO: can we define dual for modules?
81+
const Dualcache = IdDict{Type{<:BimoduleSector},Vector{Tuple{Int,Vector{Int}}}}()
82+
83+
function _get_dual_cache(::Type{T}) where {T<:BimoduleSector}
84+
global Dualcache
85+
return get!(Dualcache, T) do
86+
return extract_dual(T)
87+
end
88+
end
89+
90+
function extract_dual(::Type{A4Object})
91+
N = _get_Ncache(A4Object)
92+
ncats = size(N, 1)
93+
return map(1:ncats) do i
94+
Niii = N[i, i, i]
95+
nobj = maximum(first, keys(Niii))
96+
97+
# find identity object:
98+
# I x I -> I, a x I -> a, I x a -> a
99+
I = findfirst(1:nobj) do u
100+
get(Niii, (u, u, u), 0) == 1 || return false
101+
for j in 1:nobj
102+
get(Niii, (j, u, j), 0) == 1 || return false
103+
get(Niii, (u, j, j), 0) == 1 || return false
104+
end
105+
return true
106+
end
107+
108+
# find duals
109+
# a x abar -> I
110+
duals = map(1:nobj) do j
111+
return findfirst(1:nobj) do k
112+
return get(Niii, (j, k, I), 0) == 1
113+
end
114+
end
115+
116+
return I, duals
117+
end
118+
end
119+
120+
function Base.one(a::A4Object)
121+
a.i == a.j || error("don't know how to define one for modules")
122+
global Dualcache
123+
return A4Object(i, i, get(Dualcache, T)[1])
124+
end
125+
126+
function Base.conj(a::A4Object)
127+
a.i == a.j || error("don't know how to define dual for modules")
128+
global Dualcache
129+
return A4Object(i, i, get(Dualcache, T)[2][i])
75130
end
76131

77132
function extract_Fsymbol(::Type{A4Object})
78-
return mapreduce(vcat, 1:12) do i
79-
filename = joinpath(artifact_path, "A4", "Fsymbol$i.json")
80-
@assert isfile(filename)
133+
return mapreduce((x, y) -> cat(x, y; dims=1), 1:12) do i
134+
filename = joinpath(artifact_path, "A4", "Fsymbol_$i.json")
135+
@assert isfile(filename) "cannot find $filename"
81136
json_string = read(filename, String)
82137
Farray_part = copy(JSON3.read(json_string))
83-
return map(reshape(Farray_part, 12, 12, 12, 12)) do x
84-
y = Dict{NTuple{6,Int},ComplexF64}()
85-
for (k, v) in x
86-
a, b, c, d, e, f = parse.(Int, split(string(k)[2:(end - 1)], ", "))
87-
y[(a, b, c, d, e, f)] = v
138+
return map(enumerate(Farray_part[Symbol(i)])) do (I, x)
139+
j, k, l = Tuple(CartesianIndices((12, 12, 12))[I])
140+
y = Dict{NTuple{6,Int},Array{ComplexF64,4}}()
141+
for (key, v) in x
142+
a, b, c, d, e, f = parse.(Int, split(string(key)[2:(end - 1)], ", "))
143+
a_ob, b_ob, c_ob, d_ob, e_ob, f_ob = A4Object.(((i, j, a), (j, k, b),
144+
(k, l, c), (i, l, d),
145+
(i, j, e), (j, l, f)))
146+
y[(a, b, c, d, e, f)] = reshape(v,
147+
(Nsymbol(a_ob, b_ob, e_ob),
148+
Nsymbol(e_ob, c_ob, d_ob),
149+
Nsymbol(b_ob, c_ob, f_ob),
150+
Nsymbol(a_ob, f_ob, d_ob)))
88151
end
89152
end
90153
end
91154
end
92155

93-
const A4_Fcache = extract_Fsymbol(A4Object)
156+
const Fcache = IdDict{Type{<:BimoduleSector},
157+
Array{Dict{NTuple{6,Int},Array{ComplexF64,4}},4}}()
158+
159+
function _get_Fcache(::Type{T}) where {T<:BimoduleSector}
160+
global Fcache
161+
return get!(Fcache, T) do
162+
return extract_Fsymbol(T)
163+
end
164+
end
165+
94166
function TensorKitSectors.Fsymbol(a::I, b::I, c::I, d::I, e::I,
95167
f::I) where {I<:A4Object}
96168
# TODO: should this error or return 0?
@@ -99,7 +171,7 @@ function TensorKitSectors.Fsymbol(a::I, b::I, c::I, d::I, e::I,
99171
throw(ArgumentError("invalid fusion channel"))
100172

101173
i, j, k, l = a.i, a.j, b.j, c.j
102-
return get(A4_Fcache[i, j, k, l],
174+
return get(_get_Fcache(I)[i, j, k, l],
103175
(a.label, b.label, c.label, d.label, e.label, f.label)) do
104176
return zeros(sectorscalartype(A4Object),
105177
(Nsymbol(a, b, e), Nsymbol(e, c, d), Nsymbol(b, c, f),

0 commit comments

Comments
 (0)