Skip to content

Commit 6f8ab3e

Browse files
authored
Add a reusable test suite (#40)
1 parent 19a3d88 commit 6f8ab3e

File tree

5 files changed

+221
-142
lines changed

5 files changed

+221
-142
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Random = "1"
1919
Reexport = "1"
2020
TensorOperations = "5"
2121
Test = "1"
22-
TestExtras = "0.3"
22+
TestExtras = "0.3.2"
2323
WignerSymbols = "1,2"
2424

2525
[extras]

test/runtests.jl

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
11
using Test
22
using TestExtras
3-
using Random
4-
# using TensorKit: TensorKitSectors
53
using TensorKitSectors
6-
using TensorOperations
7-
using Base.Iterators: take, product
8-
using LinearAlgebra: LinearAlgebra
94

10-
const TKS = TensorKitSectors
11-
12-
include("testsetup.jl")
13-
using .TestSetup
145
include("newsectors.jl")
156
using .NewSectors
167

@@ -46,8 +37,13 @@ const sectorlist = (
4637
TimeReversed{FermionParity SU2Irrep NewSU2Irrep},
4738
)
4839

49-
@testset "$(TensorKitSectors.type_repr(I))" for I in sectorlist
50-
@include("sectors.jl")
40+
include("testsuite.jl")
41+
using .SectorTestSuite
42+
43+
@testset "Sector test suite" verbose = true begin
44+
for sectortype in sectorlist
45+
@time SectorTestSuite.test_sector(sectortype)
46+
end
5147
end
5248

5349
@testset "Deligne product" begin
@@ -56,17 +52,17 @@ end
5652
a = first(smallset(I1))
5753
b = first(smallset(I2))
5854

59-
@constinferred a b
60-
@constinferred a b a
61-
@constinferred a b a b
62-
@constinferred I1 I2
55+
@testinferred a b
56+
@testinferred a b a
57+
@testinferred a b a b
58+
@testinferred I1 I2
6359
@test typeof(a b) == I1 I2
6460

65-
@test @constinferred(length(allunits(I1 I2))) == 1
66-
@test @constinferred(unit(I1 I2)) == leftunit(a b) == rightunit(a b)
61+
@test @testinferred(length(allunits(I1 I2))) == 1
62+
@test @testinferred(unit(I1 I2)) == leftunit(a b) == rightunit(a b)
6763
end
68-
@test @constinferred(Tuple(SU2Irrep(1) U1Irrep(0))) == (SU2Irrep(1), U1Irrep(0))
69-
@test @constinferred(length(FermionParity(1) SU2Irrep(1 // 2) U1Irrep(1))) == 3
64+
@test @testinferred(Tuple(SU2Irrep(1) U1Irrep(0))) == (SU2Irrep(1), U1Irrep(0))
65+
@test @testinferred(length(FermionParity(1) SU2Irrep(1 // 2) U1Irrep(1))) == 3
7066
end
7167

7268
@testset "Issue that came up in #11" begin

test/sectors.jl

Lines changed: 96 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,122 @@
1-
Istr = TKS.type_repr(I)
2-
@testset "Sector $Istr: Basic properties" begin
1+
using TensorOperations
2+
using LinearAlgebra
3+
4+
@testsuite "Basic properties" I -> begin
35
s = (randsector(I), randsector(I), randsector(I))
4-
@test eval(Meta.parse(sprint(show, I))) == I
5-
@test eval(Meta.parse(TKS.type_repr(I))) == I
6-
@test eval(Meta.parse(sprint(show, s[1]))) == s[1]
7-
@test @constinferred(hash(s[1])) == hash(deepcopy(s[1]))
8-
@test @constinferred(unit(s[1])) == @constinferred(unit(I))
9-
@constinferred dual(s[1])
10-
@constinferred dim(s[1])
11-
@constinferred frobenius_schur_phase(s[1])
12-
@constinferred frobenius_schur_indicator(s[1])
13-
@constinferred Nsymbol(s...)
14-
@constinferred Asymbol(s...)
15-
B = @constinferred Bsymbol(s...)
16-
F = @constinferred Fsymbol(s..., s...)
6+
@test Base.eval(Main, Meta.parse(sprint(show, I))) == I
7+
@test Base.eval(Main, Meta.parse(TensorKitSectors.type_repr(I))) == I
8+
@test Base.eval(Main, Meta.parse(sprint(show, s[1]))) == s[1]
9+
@test @testinferred(hash(s[1])) == hash(deepcopy(s[1]))
10+
@test @testinferred(unit(s[1])) == @testinferred(unit(I))
11+
@testinferred dual(s[1])
12+
@testinferred dim(s[1])
13+
@testinferred frobenius_schur_phase(s[1])
14+
@testinferred frobenius_schur_indicator(s[1])
15+
@testinferred Nsymbol(s...)
16+
@testinferred Asymbol(s...)
17+
B = @testinferred Bsymbol(s...)
18+
F = @testinferred Fsymbol(s..., s...)
1719
if BraidingStyle(I) isa HasBraiding
18-
R = @constinferred Rsymbol(s...)
20+
R = @testinferred Rsymbol(s...)
1921
if FusionStyle(I) === SimpleFusion()
20-
@test typeof(R * F) <: @constinferred sectorscalartype(I)
22+
@test typeof(R * F) <: @testinferred sectorscalartype(I)
2123
else
22-
@test Base.promote_op(*, eltype(R), eltype(F)) <: @constinferred sectorscalartype(I)
24+
@test Base.promote_op(*, eltype(R), eltype(F)) <: @testinferred sectorscalartype(I)
2325
end
2426
else
2527
if FusionStyle(I) === SimpleFusion()
26-
@test typeof(F) <: @constinferred sectorscalartype(I)
28+
@test typeof(F) <: @testinferred sectorscalartype(I)
2729
else
28-
@test eltype(F) <: @constinferred sectorscalartype(I)
30+
@test eltype(F) <: @testinferred sectorscalartype(I)
2931
end
3032
end
31-
it = @constinferred s[1] s[2]
32-
@constinferred (s..., s...)
33+
@testinferred(s[1] s[2])
34+
@testinferred((s..., s...))
3335
end
34-
@testset "Sector $Istr: Value iterator" begin
36+
37+
@testsuite "Value iterator" I -> begin
3538
@test eltype(values(I)) == I
3639
sprev = unit(I)
3740
for (i, s) in enumerate(values(I))
38-
@test !isless(s, sprev) # confirm compatibility with sort order
39-
@test s == @constinferred (values(I)[i])
41+
@test !isless(s, sprev)
42+
@test s == @testinferred(values(I)[i])
4043
@test findindex(values(I), s) == i
4144
sprev = s
4245
i >= 10 && break
4346
end
4447
@test unit(I) == first(values(I))
4548
@test length(allunits(I)) == 1
46-
@test (@constinferred findindex(values(I), unit(I))) == 1
49+
@test (@testinferred findindex(values(I), unit(I))) == 1
4750
for s in smallset(I)
48-
@test (@constinferred values(I)[findindex(values(I), s)]) == s
51+
@test (@testinferred values(I)[findindex(values(I), s)]) == s
4952
end
5053
end
51-
if BraidingStyle(I) isa Bosonic && hasfusiontensor(I)
52-
@testset "Sector $Istr: fusion tensor and F-move and R-move" begin
53-
for a in smallset(I), b in smallset(I)
54-
for c in (a, b)
55-
X1 = permutedims(fusiontensor(a, b, c), (2, 1, 3, 4))
56-
X2 = fusiontensor(b, a, c)
57-
l = dim(a) * dim(b) * dim(c)
58-
R = LinearAlgebra.transpose(Rsymbol(a, b, c))
59-
sz = (l, convert(Int, Nsymbol(a, b, c)))
60-
@test reshape(X1, sz) reshape(X2, sz) * R
61-
end
62-
end
63-
for a in smallset(I), b in smallset(I), c in smallset(I)
64-
for e in (a, b), f in (b, c)
65-
for d in intersect((e, c), (a, f))
66-
X1 = fusiontensor(a, b, e)
67-
X2 = fusiontensor(e, c, d)
68-
Y1 = fusiontensor(b, c, f)
69-
Y2 = fusiontensor(a, f, d)
70-
@tensor f1[-1, -2, -3, -4] := conj(Y2[a, f, d, -4]) *
71-
conj(Y1[b, c, f, -3]) * X1[a, b, e, -1] * X2[e, c, d, -2]
72-
if FusionStyle(I) isa MultiplicityFreeFusion
73-
f2 = fill(Fsymbol(a, b, c, d, e, f) * dim(d), (1, 1, 1, 1))
74-
else
75-
f2 = Fsymbol(a, b, c, d, e, f) * dim(d)
76-
end
77-
@test isapprox(f1, f2; atol = 1.0e-12, rtol = 1.0e-12)
54+
55+
@testsuite "Fusion and dimensions" I -> begin
56+
for a in smallset(I), b in smallset(I)
57+
da = dim(a)
58+
db = dim(b)
59+
dc = sum(c -> dim(c) * Nsymbol(a, b, c), a b)
60+
@test da * db dc # needs to be ≈ because of anyons
61+
end
62+
end
63+
64+
@testsuite "Fusion tensor and F-move" I -> begin
65+
hasfusiontensor(I) || return nothing
66+
for a in smallset(I), b in smallset(I), c in smallset(I)
67+
for e in (a, b), f in (b, c)
68+
for d in intersect((e, c), (a, f))
69+
X1 = fusiontensor(a, b, e)
70+
X2 = fusiontensor(e, c, d)
71+
Y1 = fusiontensor(b, c, f)
72+
Y2 = fusiontensor(a, f, d)
73+
@tensor f1[-1, -2, -3, -4] := conj(Y2[a, f, d, -4]) *
74+
conj(Y1[b, c, f, -3]) * X1[a, b, e, -1] * X2[e, c, d, -2]
75+
if FusionStyle(I) isa MultiplicityFreeFusion
76+
f2 = fill(Fsymbol(a, b, c, d, e, f) * dim(d), (1, 1, 1, 1))
77+
else
78+
f2 = Fsymbol(a, b, c, d, e, f) * dim(d)
7879
end
80+
@test isapprox(f1, f2; atol = 1.0e-12, rtol = 1.0e-12)
7981
end
8082
end
8183
end
8284
end
83-
if hasfusiontensor(I)
84-
@testset "Orthogonality of fusiontensors" begin
85-
for a in smallset(I), b in smallset(I)
86-
cs = vec(collect(a b))
87-
CGCs = map(c -> reshape(fusiontensor(a, b, c), :, dim(c)), cs)
88-
M = map(Iterators.product(CGCs, CGCs)) do (cgc1, cgc2)
89-
return LinearAlgebra.norm(cgc1' * cgc2)
85+
86+
@testsuite "Fusion tensor and R-move" I -> begin
87+
(BraidingStyle(I) isa Bosonic && hasfusiontensor(I)) || return nothing
88+
for a in smallset(I), b in smallset(I)
89+
for c in (a, b)
90+
X1 = permutedims(fusiontensor(a, b, c), (2, 1, 3, 4))
91+
X2 = fusiontensor(b, a, c)
92+
l = dim(a) * dim(b) * dim(c)
93+
R = LinearAlgebra.transpose(Rsymbol(a, b, c))
94+
sz = (l, convert(Int, Nsymbol(a, b, c)))
95+
@test reshape(X1, sz) reshape(X2, sz) * R
96+
end
97+
end
98+
end
99+
100+
@testsuite "Orthogonality of fusiontensors" I -> begin
101+
hasfusiontensor(I) || return nothing
102+
for a in smallset(I), b in smallset(I)
103+
cs = vec(collect(a b))
104+
cgcs = map(c -> fusiontensor(a, b, c), cs)
105+
for (c, cgc) in zip(cs, cgcs), (c′, cgc′) in zip(cs, cgcs)
106+
for μ in 1:Nsymbol(a, b, c), ν in 1:Nsymbol(a, b, c′)
107+
@tensor overlap[mc mc'] := conj(view(cgc, :, :, :, μ)[ma mb mc]) *
108+
view(cgc′, :, :, :, ν)[ma mb mc']
109+
if μ == ν && c == c′
110+
@test isapprox(overlap, LinearAlgebra.I; atol = 1.0e-12)
111+
else
112+
@test isapprox(LinearAlgebra.norm(overlap), 0; atol = 1.0e-12)
113+
end
90114
end
91-
@test isapprox(M' * M, LinearAlgebra.Diagonal(dim.(cs)); atol = 1.0e-12)
92115
end
93116
end
94117
end
95118

96-
@testset "Sector $Istr: Unitarity of F-move" begin
119+
@testsuite "Unitarity of F-move" I -> begin
97120
for a in smallset(I), b in smallset(I), c in smallset(I)
98121
for d in (a, b, c)
99122
es = collect(intersect((a, b), map(dual, (c, dual(d)))))
@@ -105,31 +128,30 @@ end
105128
Fblocks = Vector{Any}()
106129
for e in es, f in fs
107130
Fs = Fsymbol(a, b, c, d, e, f)
108-
push!(
109-
Fblocks,
110-
reshape(Fs, (size(Fs, 1) * size(Fs, 2), size(Fs, 3) * size(Fs, 4)))
111-
)
131+
push!(Fblocks, reshape(Fs, (size(Fs, 1) * size(Fs, 2), size(Fs, 3) * size(Fs, 4))))
112132
end
113133
F = hvcat(length(fs), Fblocks...)
114134
end
115135
@test isapprox(F' * F, one(F); atol = 1.0e-12, rtol = 1.0e-12)
116136
end
117137
end
118138
end
119-
@testset "Sector $Istr: Triangle equation" begin
139+
140+
@testsuite "Triangle equation" I -> begin
120141
for a in smallset(I), b in smallset(I)
121142
@test triangle_equation(a, b; atol = 1.0e-12, rtol = 1.0e-12)
122143
end
123144
end
124-
@testset "Sector $Istr: Pentagon equation" begin
145+
146+
@testsuite "Pentagon equation" I -> begin
125147
for a in smallset(I), b in smallset(I), c in smallset(I), d in smallset(I)
126148
@test pentagon_equation(a, b, c, d; atol = 1.0e-12, rtol = 1.0e-12)
127149
end
128150
end
129-
if BraidingStyle(I) isa HasBraiding
130-
@testset "Sector $Istr: Hexagon equation" begin
131-
for a in smallset(I), b in smallset(I), c in smallset(I)
132-
@test hexagon_equation(a, b, c; atol = 1.0e-12, rtol = 1.0e-12)
133-
end
151+
152+
@testsuite "Hexagon equation" I -> begin
153+
BraidingStyle(I) isa HasBraiding || return nothing
154+
for a in smallset(I), b in smallset(I), c in smallset(I)
155+
@test hexagon_equation(a, b, c; atol = 1.0e-12, rtol = 1.0e-12)
134156
end
135157
end

test/testsetup.jl

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)