Skip to content

Commit e793ae7

Browse files
committed
Merge branch 'main' of https://github.com/QuantumKitHub/TensorKitSectors.jl into bd/repa4
2 parents 4a694bb + 6f8ab3e commit e793ae7

File tree

5 files changed

+219
-149
lines changed

5 files changed

+219
-149
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

@@ -47,8 +38,13 @@ const sectorlist = (
4738
TimeReversed{FermionParity SU2Irrep NewSU2Irrep},
4839
)
4940

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

5450
@testset "Deligne product" begin
@@ -57,17 +53,17 @@ end
5753
a = first(smallset(I1))
5854
b = first(smallset(I2))
5955

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

66-
@test @constinferred(length(allunits(I1 I2))) == 1
67-
@test @constinferred(unit(I1 I2)) == leftunit(a b) == rightunit(a b)
62+
@test @testinferred(length(allunits(I1 I2))) == 1
63+
@test @testinferred(unit(I1 I2)) == leftunit(a b) == rightunit(a b)
6864
end
69-
@test @constinferred(Tuple(SU2Irrep(1) U1Irrep(0))) == (SU2Irrep(1), U1Irrep(0))
70-
@test @constinferred(length(FermionParity(1) SU2Irrep(1 // 2) U1Irrep(1))) == 3
65+
@test @testinferred(Tuple(SU2Irrep(1) U1Irrep(0))) == (SU2Irrep(1), U1Irrep(0))
66+
@test @testinferred(length(FermionParity(1) SU2Irrep(1 // 2) U1Irrep(1))) == 3
7167
end
7268

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

test/sectors.jl

Lines changed: 94 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,108 +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))
8785

88-
for c in cs, c′ in cs
89-
cgc1 = fusiontensor(a, b, c)
90-
cgc2 = fusiontensor(a, b, c′)
91-
for μ in 1:Nsymbol(a, b, c), ν in 1:Nsymbol(a, b, c′)
92-
overlap = reshape(cgc1[:, :, :, μ], :, dim(c))' *
93-
reshape(cgc2[:, :, :, ν], :, dim(c′))
94-
if μ == ν && c == c′
95-
@test isapprox(overlap, LinearAlgebra.I; atol = 1.0e-12)
96-
else
97-
@test isapprox(LinearAlgebra.norm(overlap), 0; atol = 1.0e-12)
98-
end
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)
99113
end
100114
end
101115
end
102116
end
103117
end
104118

105-
@testset "Sector $Istr: Unitarity of F-move" begin
119+
@testsuite "Unitarity of F-move" I -> begin
106120
for a in smallset(I), b in smallset(I), c in smallset(I)
107121
for d in (a, b, c)
108122
es = collect(intersect((a, b), map(dual, (c, dual(d)))))
@@ -114,31 +128,30 @@ end
114128
Fblocks = Vector{Any}()
115129
for e in es, f in fs
116130
Fs = Fsymbol(a, b, c, d, e, f)
117-
push!(
118-
Fblocks,
119-
reshape(Fs, (size(Fs, 1) * size(Fs, 2), size(Fs, 3) * size(Fs, 4)))
120-
)
131+
push!(Fblocks, reshape(Fs, (size(Fs, 1) * size(Fs, 2), size(Fs, 3) * size(Fs, 4))))
121132
end
122133
F = hvcat(length(fs), Fblocks...)
123134
end
124135
@test isapprox(F' * F, one(F); atol = 1.0e-12, rtol = 1.0e-12)
125136
end
126137
end
127138
end
128-
@testset "Sector $Istr: Triangle equation" begin
139+
140+
@testsuite "Triangle equation" I -> begin
129141
for a in smallset(I), b in smallset(I)
130142
@test triangle_equation(a, b; atol = 1.0e-12, rtol = 1.0e-12)
131143
end
132144
end
133-
@testset "Sector $Istr: Pentagon equation" begin
145+
146+
@testsuite "Pentagon equation" I -> begin
134147
for a in smallset(I), b in smallset(I), c in smallset(I), d in smallset(I)
135148
@test pentagon_equation(a, b, c, d; atol = 1.0e-12, rtol = 1.0e-12)
136149
end
137150
end
138-
if BraidingStyle(I) isa HasBraiding
139-
@testset "Sector $Istr: Hexagon equation" begin
140-
for a in smallset(I), b in smallset(I), c in smallset(I)
141-
@test hexagon_equation(a, b, c; atol = 1.0e-12, rtol = 1.0e-12)
142-
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)
143156
end
144157
end

test/testsetup.jl

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

0 commit comments

Comments
 (0)