Skip to content

Commit f6b6a59

Browse files
committed
start on multifusion space tests
1 parent 662efd8 commit f6b6a59

File tree

1 file changed

+178
-3
lines changed

1 file changed

+178
-3
lines changed

test/test_A4.jl

Lines changed: 178 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,184 @@ end
169169
end
170170
end
171171

172-
println("-----------------------------")
173-
println("| F-symbol data tests |")
174-
println("-----------------------------")
172+
### start of TensorKit tests ###
173+
174+
println("---------------------------------")
175+
println("| Multifusion space tests |")
176+
println("---------------------------------")
177+
178+
i = 1
179+
j = 2
180+
181+
V = (Vect[I]((i, i, label) => 1 for label in MTK._numlabels(I, i, i)),
182+
Vect[I]((i, i, 1) => 1, (i, i, 2) => 2),
183+
Vect[I]((i, i, 1) => 1, (i, i, 2) => 1),
184+
Vect[I]((i, i, label) => 1 for label in MTK._numlabels(I, i, i)),
185+
Vect[I]((i, i, 1) => 2, (i, i, 3) => 3))
186+
187+
@timedtestset "Multifusion spaces " verbose = true begin
188+
@timedtestset "GradedSpace: $(TK.type_repr(Vect[I]))" begin
189+
gen = (values(I)[k] => (k + 1) for k in 1:length(values(I)))
190+
191+
V = GradedSpace(gen)
192+
@test eval(Meta.parse(TK.type_repr(typeof(V)))) == typeof(V)
193+
@test eval(Meta.parse(sprint(show, V))) == V
194+
@test eval(Meta.parse(sprint(show, V'))) == V'
195+
@test V' == GradedSpace(gen; dual=true)
196+
@test V == @constinferred GradedSpace(gen...)
197+
@test V' == @constinferred GradedSpace(gen...; dual=true)
198+
@test V == @constinferred GradedSpace(tuple(gen...))
199+
@test V' == @constinferred GradedSpace(tuple(gen...); dual=true)
200+
@test V == @constinferred GradedSpace(Dict(gen))
201+
@test V' == @constinferred GradedSpace(Dict(gen); dual=true)
202+
@test V == @inferred Vect[I](gen)
203+
@test V' == @constinferred Vect[I](gen; dual=true)
204+
@test V == @constinferred Vect[I](gen...)
205+
@test V' == @constinferred Vect[I](gen...; dual=true)
206+
@test V == @constinferred Vect[I](Dict(gen))
207+
@test V' == @constinferred Vect[I](Dict(gen); dual=true)
208+
@test V == @constinferred typeof(V)(c => dim(V, c) for c in sectors(V))
209+
@test @constinferred(hash(V)) == hash(deepcopy(V)) != hash(V')
210+
@test V == GradedSpace(reverse(collect(gen))...)
211+
@test eval(Meta.parse(sprint(show, V))) == V
212+
@test eval(Meta.parse(sprint(show, typeof(V)))) == typeof(V)
213+
214+
@test isa(V, VectorSpace)
215+
@test isa(V, ElementarySpace)
216+
@test isa(InnerProductStyle(V), HasInnerProduct)
217+
@test isa(InnerProductStyle(V), EuclideanInnerProduct)
218+
@test isa(V, GradedSpace)
219+
@test isa(V, GradedSpace{I})
220+
@test @constinferred(dual(V)) == @constinferred(conj(V)) ==
221+
@constinferred(adjoint(V)) != V
222+
@test @constinferred(field(V)) ==
223+
@test @constinferred(sectortype(V)) == I
224+
slist = @constinferred sectors(V)
225+
@test @constinferred(hassector(V, first(slist)))
226+
@test @constinferred(dim(V)) == sum(dim(s) * dim(V, s) for s in slist)
227+
@test @constinferred(reduceddim(V)) == sum(dim(V, s) for s in slist)
228+
@constinferred dim(V, first(slist))
229+
230+
@test @constinferred((V, zero(V))) == V
231+
@test @constinferred((V, V)) == Vect[I](c => 2dim(V, c) for c in sectors(V))
232+
@test @constinferred((V, V, V, V)) == Vect[I](c => 4dim(V, c) for c in sectors(V))
233+
234+
@testset "$Istr ($i, $j) spaces" for i in 1:r, j in 1:r
235+
# space with a single sector
236+
Wleft = @constinferred Vect[I]((i, i, label) => 1 for label in 1:MTK._numlabels(I, i, i))
237+
Wright = @constinferred Vect[I]((j, j, label) => 1 for label in 1:MTK._numlabels(I, j, j))
238+
WM = @constinferred Vect[I]((i, j, label) => 1 for label in 1:MTK._numlabels(I, i, j))
239+
WMop = @constinferred Vect[I]((j, i, label) => 1 for label in 1:MTK._numlabels(I, j, i))
240+
241+
@test @constinferred(oneunit(Wleft)) == leftoneunit(Wleft) == rightoneunit(Wleft)
242+
@test @constinferred(oneunit(Wright)) == leftoneunit(Wright) == rightoneunit(Wright)
243+
@test @constinferred(leftoneunit((Wleft, WM))) == oneunit(Wleft)
244+
@test @constinferred(leftoneunit((Wright, WMop))) == oneunit(Wright)
245+
@test @constinferred(rightoneunit((Wright, WM))) == oneunit(Wright)
246+
@test @constinferred(rightoneunit((Wleft, WMop))) == oneunit(Wleft)
247+
248+
@test_throws ArgumentError oneunit(I)
249+
250+
if i != j # some tests specialised for modules
251+
@test_throws ArgumentError oneunit(WM)
252+
@test_throws ArgumentError oneunit(WMop)
253+
254+
# sensible direct sums and fuses
255+
ul, ur = one(I(i, i, 1)), one(I(j, j, 1))
256+
@test @constinferred((Wleft, WM)) ==
257+
Vect[I](c => 1 for c in sectors(V) if leftone(c) == ul == rightone(c) || (c.i == i && c.j == j))
258+
@test @constinferred((Wright, WMop)) ==
259+
Vect[I](c => 1 for c in sectors(V) if leftone(c) == ur == rightone(c) || (c.i == j && c.j == i))
260+
@test @constinferred((Wright, WM)) ==
261+
Vect[I](c => 1 for c in sectors(V) if rightone(c) == ur == leftone(c) || (c.i == i && c.j == j))
262+
@test @constinferred((Wleft, WMop)) ==
263+
Vect[I](c => 1 for c in sectors(V) if rightone(c) == ul == leftone(c) || (c.i == j && c.j == i))
264+
@test @constinferred(fuse(Wleft, WM)) == Vect[I](c => dim(Wleft) for c in sectors(WM)) # this might be wrong
265+
@test @constinferred(fuse(Wright, WMop)) == Vect[I](c => dim(Wright) for c in sectors(WMop)) # same
266+
267+
# less sensible fuse
268+
@test @constinferred(fuse(Wleft, WMop)) == fuse(Wright, WM) ==
269+
Vect[I](c => 0 for c in sectors(V))
270+
271+
for W in [WM, WMop, Wright]
272+
@test infimum(Wleft, W) == Vect[I](c => 0 for c in sectors(V))
273+
end
274+
else
275+
@test @constinferred((Wleft, Wright)) ==
276+
Vect[I](c => 2 for c in sectors(V) if c.i == c.j == i)
277+
@test @constinferred(fuse(Wleft, WMop)) == fuse(Wright, WM)
278+
end
279+
280+
for W in [Wleft, Wright]
281+
@test @constinferred((W, oneunit(W))) ==
282+
Vect[I](c => isone(c) + dim(W, c) for c in sectors(W))
283+
@test @constinferred(fuse(W, oneunit(W))) == W
284+
end
285+
end
286+
287+
d = Dict{I,Int}()
288+
for a in sectors(V), b in sectors(V)
289+
a.j == b.i || continue # skip if not compatible
290+
for c in a b
291+
d[c] = get(d, c, 0) + dim(V, a) * dim(V, b) * Nsymbol(a, b, c)
292+
end
293+
end
294+
@test @constinferred(fuse(V, V)) == GradedSpace(d)
295+
@test @constinferred(flip(V)) ==
296+
Vect[I](conj(c) => dim(V, c) for c in sectors(V))'
297+
@test flip(V) V
298+
@test flip(V) V
299+
@test flip(V) V
300+
@test @constinferred((V, V)) == @constinferred supremum(V, (V, V))
301+
@test V == @constinferred infimum(V, (V, V))
302+
@test V (V, V)
303+
@test !(V (V, V))
304+
randlen = rand(1:length(values(I)))
305+
s = rand(collect(values(I))[randlen:end]) # such that dim(V, s) > randlen
306+
@test infimum(V, GradedSpace(s => randlen)) ==
307+
GradedSpace(s => randlen)
308+
@test_throws SpaceMismatch ((V, V'))
309+
end
310+
311+
# CONTINUE HERE
312+
313+
@timedtestset "HomSpace with $(TK.type_repr(Vect[I])) " begin
314+
for (V1, V2, V3, V4, V5) in (VIBC, VIBD, VIBM1, VIBM2, VIBMop1, VIBMop2)
315+
W = HomSpace(V1 V2, V3 V4 V5)
316+
@test W == (V3 V4 V5 V1 V2)
317+
@test W == (V1 V2 V3 V4 V5)
318+
@test W' == (V1 V2 V3 V4 V5)
319+
@test eval(Meta.parse(sprint(show, W))) == W
320+
@test eval(Meta.parse(sprint(show, typeof(W)))) == typeof(W)
321+
@test spacetype(W) == typeof(V1)
322+
@test sectortype(W) == sectortype(V1)
323+
@test W[1] == V1
324+
@test W[2] == V2
325+
@test W[3] == V3'
326+
@test W[4] == V4'
327+
@test W[5] == V5'
328+
329+
@test @constinferred(hash(W)) == hash(deepcopy(W)) != hash(W')
330+
@test W == deepcopy(W)
331+
@test W == @constinferred permute(W, ((1, 2), (3, 4, 5)))
332+
@test permute(W, ((2, 4, 5), (3, 1))) == (V2 V4' V5' V3 V1')
333+
@test (V1 V2 V1 V2) == @constinferred TK.compose(W, W')
334+
335+
@test_throws ErrorException insertleftunit(W)
336+
@test insertrightunit(W) == (V1 V2 V3 V4 V5 rightoneunit(V5))
337+
@test_throws ErrorException insertrightunit(W, 6)
338+
@test_throws ErrorException insertleftunit(W, 6)
339+
340+
@test (V1 V2 rightoneunit(V2) V3 V4 V5) ==
341+
@constinferred(insertrightunit(W, 2))
342+
@test (V1 V2 leftoneunit(V3) V3 V4 V5) ==
343+
@constinferred(insertleftunit(W, 3))
344+
@test @constinferred(removeunit(insertleftunit(W, 3), 3)) == W
345+
@test_throws ErrorException @constinferred(insertrightunit(one(V1) V1, 0)) # should I specify it's the other error?
346+
@test_throws ErrorException insertleftunit(one(V1) V1, 0)
347+
end
348+
end
349+
end
175350

176351
@testset "$Istr ($i, $j) left and right units" for i in 1:r, j in 1:r
177352
Cij_obs = I.(i, j, MTK._get_dual_cache(I)[2][i, j])

0 commit comments

Comments
 (0)