@@ -3,7 +3,7 @@ struct BimoduleSector{Name} <: Sector
33 j:: Int
44 label:: Int
55end
6-
6+ BimoduleSector {Name} (data :: NTuple{3,Int} ) where {Name} = BimoduleSector {Name} (data ... )
77const 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))
1313end
1414Base. 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
1719Base. IteratorSize (:: Type{SectorValues{<:BimoduleSector}} ) = Base. SizeUnknown ()
1820
@@ -62,35 +64,113 @@ function extract_Nsymbol(::Type{A4Object})
6264 a, b, c = parse .(Int, split (string (k)[2 : (end - 1 )], " , " ))
6365 y[(a, b, c)] = v
6466 end
67+ return y
68+ end
69+ end
70+
71+ const Ncache = IdDict{Type{<: BimoduleSector },Array{Dict{NTuple{3 ,Int},Int},3 }}()
72+
73+ function _get_Ncache (:: Type{T} ) where {T<: BimoduleSector }
74+ global Ncache
75+ return get! (Ncache, T) do
76+ return extract_Nsymbol (T)
6577 end
6678end
6779
68- const A4_Ncache = extract_Nsymbol (A4Object)
6980function TensorKitSectors. Nsymbol (a:: I , b:: I , c:: I ) where {I<: A4Object }
7081 # TODO : should this error or return 0?
7182 (a. j == b. i && a. i == c. i && b. j == c. j) ||
7283 throw (ArgumentError (" invalid fusion channel" ))
7384 i, j, k = a. i, a. j, b. j
74- return get (A4_Ncache[i, j, k], (a. label, b. label, c. label), 0 )
85+ return get (_get_Ncache (I)[i, j, k], (a. label, b. label, c. label), 0 )
86+ end
87+
88+ # TODO : can we define dual for modules?
89+ const Dualcache = IdDict{Type{<: BimoduleSector },Vector{Tuple{Int,Vector{Int}}}}()
90+
91+ function _get_dual_cache (:: Type{T} ) where {T<: BimoduleSector }
92+ global Dualcache
93+ return get! (Dualcache, T) do
94+ return extract_dual (T)
95+ end
96+ end
97+
98+ function extract_dual (:: Type{A4Object} )
99+ N = _get_Ncache (A4Object)
100+ ncats = size (N, 1 )
101+ return map (1 : ncats) do i
102+ Niii = N[i, i, i]
103+ nobj = maximum (first, keys (Niii))
104+
105+ # find identity object:
106+ # I x I -> I, a x I -> a, I x a -> a
107+ I = findfirst (1 : nobj) do u
108+ get (Niii, (u, u, u), 0 ) == 1 || return false
109+ for j in 1 : nobj
110+ get (Niii, (j, u, j), 0 ) == 1 || return false
111+ get (Niii, (u, j, j), 0 ) == 1 || return false
112+ end
113+ return true
114+ end
115+
116+ # find duals
117+ # a x abar -> I
118+ duals = map (1 : nobj) do j
119+ return findfirst (1 : nobj) do k
120+ return get (Niii, (j, k, I), 0 ) == 1
121+ end
122+ end
123+
124+ return I, duals
125+ end
126+ end
127+
128+ function Base. one (a:: A4Object )
129+ a. i == a. j || error (" don't know how to define one for modules" )
130+ global Dualcache
131+ return A4Object (i, i, get (Dualcache, T)[1 ])
132+ end
133+
134+ function Base. conj (a:: A4Object )
135+ a. i == a. j || error (" don't know how to define dual for modules" )
136+ global Dualcache
137+ return A4Object (i, i, get (Dualcache, T)[2 ][i])
75138end
76139
77140function 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)
141+ return mapreduce ((x, y) -> cat (x, y; dims = 1 ) , 1 : 12 ) do i
142+ filename = joinpath (artifact_path, " A4" , " Fsymbol_ $i .json" )
143+ @assert isfile (filename) " cannot find $filename "
81144 json_string = read (filename, String)
82145 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
146+ return map (enumerate (Farray_part[Symbol (i)])) do (I, x)
147+ j, k, l = Tuple (CartesianIndices ((12 , 12 , 12 ))[I])
148+ y = Dict {NTuple{6,Int},Array{ComplexF64,4}} ()
149+ for (key, v) in x
150+ a, b, c, d, e, f = parse .(Int, split (string (key)[2 : (end - 1 )], " , " ))
151+ a_ob, b_ob, c_ob, d_ob, e_ob, f_ob = A4Object .(((i, j, a), (j, k, b),
152+ (k, l, c), (i, l, d),
153+ (i, j, e), (j, l, f)))
154+ y[(a, b, c, d, e, f)] = reshape (v,
155+ (Nsymbol (a_ob, b_ob, e_ob),
156+ Nsymbol (e_ob, c_ob, d_ob),
157+ Nsymbol (b_ob, c_ob, f_ob),
158+ Nsymbol (a_ob, f_ob, d_ob)))
88159 end
89160 end
90161 end
91162end
92163
93- const A4_Fcache = extract_Fsymbol (A4Object)
164+ const Fcache = IdDict{Type{<: BimoduleSector },
165+ Array{Dict{NTuple{6 ,Int},Array{ComplexF64,4 }},4 }}()
166+
167+ function _get_Fcache (:: Type{T} ) where {T<: BimoduleSector }
168+ global Fcache
169+ return get! (Fcache, T) do
170+ return extract_Fsymbol (T)
171+ end
172+ end
173+
94174function TensorKitSectors. Fsymbol (a:: I , b:: I , c:: I , d:: I , e:: I ,
95175 f:: I ) where {I<: A4Object }
96176 # TODO : should this error or return 0?
@@ -99,7 +179,7 @@ function TensorKitSectors.Fsymbol(a::I, b::I, c::I, d::I, e::I,
99179 throw (ArgumentError (" invalid fusion channel" ))
100180
101181 i, j, k, l = a. i, a. j, b. j, c. j
102- return get (A4_Fcache [i, j, k, l],
182+ return get (_get_Fcache (I) [i, j, k, l],
103183 (a. label, b. label, c. label, d. label, e. label, f. label)) do
104184 return zeros (sectorscalartype (A4Object),
105185 (Nsymbol (a, b, e), Nsymbol (e, c, d), Nsymbol (b, c, f),
0 commit comments