Skip to content

Commit 5cce3b5

Browse files
committed
try getting TKS testsuite working
1 parent ebb8f65 commit 5cce3b5

3 files changed

Lines changed: 130 additions & 141 deletions

File tree

Project.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Random = "1"
1717
SafeTestsets = "0.1"
1818
TensorKit = "0.16"
1919
TensorKitSectors = "0.3"
20+
TensorOperations = "5"
2021
Test = "1.10"
2122
TestExtras = "0.3"
2223
julia = "1.10"
@@ -26,8 +27,12 @@ Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
2627
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
2728
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
2829
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
30+
TensorOperations = "6aa20fa7-93e2-5fca-9bc0-fbd0db3c71a2"
2931
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
3032
TestExtras = "5ed8adda-3752-4e41-b88a-e8b09835ee3a"
3133

3234
[targets]
33-
test = ["Aqua", "LinearAlgebra", "Random", "SafeTestsets", "Test", "TestExtras"]
35+
test = ["Aqua", "LinearAlgebra", "Random", "SafeTestsets", "TensorOperations", "Test", "TestExtras"]
36+
37+
[sources]
38+
TensorKitSectors = {url = "https://github.com/QuantumKitHub/TensorKitSectors.jl", rev = "bd/multitestcompat"}

test/setup.jl

Lines changed: 80 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,84 @@
11
module TestSetup
22

3-
export unitarity_test, rand_object, random_fusion, eval_show
4-
5-
using MultiTensorKit
6-
using TensorKitSectors
7-
using Random
8-
9-
const MTK = MultiTensorKit
10-
11-
Random.seed!(1234)
12-
13-
function unitarity_test(as::V, bs::V, cs::V) where {V <: AbstractVector{<:BimoduleSector}}
14-
@assert all(a.j == b.i for a in as, b in bs)
15-
@assert all(b.j == c.i for b in bs, c in cs)
16-
17-
for a in as, b in bs, c in cs
18-
for d in (a, b, c)
19-
es = collect(intersect((a, b), map(dual, (c, dual(d)))))
20-
fs = collect(intersect((b, c), map(dual, (dual(d), a))))
21-
Fblocks = Vector{Any}()
22-
for e in es, f in fs
23-
Fs = Fsymbol(a, b, c, d, e, f)
24-
push!(Fblocks, reshape(Fs, (size(Fs, 1) * size(Fs, 2), size(Fs, 3) * size(Fs, 4))))
25-
end
26-
F = hvcat(length(fs), Fblocks...)
27-
isapprox(F' * F, one(F); atol = 1.0e-12, rtol = 1.0e-12) || return false
28-
end
29-
end
30-
return true
31-
end
32-
33-
all_objects(::Type{<:BimoduleSector}, i::Int, j::Int) = [I(i, j, k) for k in 1:MTK._numlabels(I, i, j)]
34-
35-
function rand_object(I::Type{<:BimoduleSector}, i::Int, j::Int)
36-
obs = all_objects(I, i, j)
37-
ob = rand(obs)
38-
while isunit(ob) # unit of any fusion cat avoided
39-
ob = rand(obs)
40-
end
41-
42-
return ob
43-
end
44-
45-
function random_fusion(I::Type{<:BimoduleSector}, i::Int, j::Int, ::Val{N}) where {N} # for fusion tree tests
46-
N == 1 && return (rand_object(I, i, j),)
47-
tail = random_fusion(I, i, j, Val(N - 1))
48-
counter = 0
49-
50-
Cs = all_objects(I, i, i)
51-
Ds = all_objects(I, j, j)
52-
Ms = all_objects(I, i, j)
53-
Mops = all_objects(I, j, i)
54-
allobs = vcat(Cs, Ds, Ms, Mops)
55-
s = rand(allobs)
56-
57-
while isempty((s, first(tail))) && counter < 40
58-
counter += 1
59-
s = (counter < 40) ? rand(allobs) : leftunit(first(tail))
60-
end
61-
return (s, tail...)
62-
end
63-
64-
"""
65-
eval_show(x)
66-
67-
Use `show` to generate a string representation of `x`, then parse and evaluate the resulting expression.
68-
"""
69-
function eval_show(x)
70-
str = sprint(show, x; context = (:module => @__MODULE__))
71-
ex = Meta.parse(str)
72-
return eval(ex)
73-
end
3+
# export unitarity_test, rand_object, random_fusion, eval_show
4+
5+
# using MultiTensorKit
6+
# using TensorKitSectors
7+
# using Random
8+
9+
# const MTK = MultiTensorKit
10+
11+
# Random.seed!(1234)
12+
13+
# testsuite_path = joinpath(
14+
# dirname(dirname(pathof(TensorKitSectors))), # TensorKitSectors root
15+
# "test", "testsuite.jl"
16+
# )
17+
# include(testsuite_path)
18+
# using .SectorTestSuite
19+
20+
#TODO: remove if testsuite works
21+
# function unitarity_test(as::V, bs::V, cs::V) where {V <: AbstractVector{<:BimoduleSector}}
22+
# @assert all(a.j == b.i for a in as, b in bs)
23+
# @assert all(b.j == c.i for b in bs, c in cs)
24+
25+
# for a in as, b in bs, c in cs
26+
# for d in ⊗(a, b, c)
27+
# es = collect(intersect(⊗(a, b), map(dual, ⊗(c, dual(d)))))
28+
# fs = collect(intersect(⊗(b, c), map(dual, ⊗(dual(d), a))))
29+
# Fblocks = Vector{Any}()
30+
# for e in es, f in fs
31+
# Fs = Fsymbol(a, b, c, d, e, f)
32+
# push!(Fblocks, reshape(Fs, (size(Fs, 1) * size(Fs, 2), size(Fs, 3) * size(Fs, 4))))
33+
# end
34+
# F = hvcat(length(fs), Fblocks...)
35+
# isapprox(F' * F, one(F); atol = 1.0e-12, rtol = 1.0e-12) || return false
36+
# end
37+
# end
38+
# return true
39+
# end
40+
41+
# TODO: remove if TensorKit tests aren't done
42+
# all_objects(::Type{<:BimoduleSector}, i::Int, j::Int) = [I(i, j, k) for k in 1:MTK._numlabels(I, i, j)]
43+
44+
# function rand_object(I::Type{<:BimoduleSector}, i::Int, j::Int)
45+
# obs = all_objects(I, i, j)
46+
# ob = rand(obs)
47+
# while isunit(ob) # unit of any fusion cat avoided
48+
# ob = rand(obs)
49+
# end
50+
51+
# return ob
52+
# end
53+
54+
# function random_fusion(I::Type{<:BimoduleSector}, i::Int, j::Int, ::Val{N}) where {N} # for fusion tree tests
55+
# N == 1 && return (rand_object(I, i, j),)
56+
# tail = random_fusion(I, i, j, Val(N - 1))
57+
# counter = 0
58+
59+
# Cs = all_objects(I, i, i)
60+
# Ds = all_objects(I, j, j)
61+
# Ms = all_objects(I, i, j)
62+
# Mops = all_objects(I, j, i)
63+
# allobs = vcat(Cs, Ds, Ms, Mops)
64+
# s = rand(allobs)
65+
66+
# while isempty(⊗(s, first(tail))) && counter < 40
67+
# counter += 1
68+
# s = (counter < 40) ? rand(allobs) : leftunit(first(tail))
69+
# end
70+
# return (s, tail...)
71+
# end
72+
73+
# """
74+
# eval_show(x)
75+
76+
# Use `show` to generate a string representation of `x`, then parse and evaluate the resulting expression.
77+
# """
78+
# function eval_show(x)
79+
# str = sprint(show, x; context = (:module => @__MODULE__))
80+
# ex = Meta.parse(str)
81+
# return eval(ex)
82+
# end
7483

7584
end # end of module TestSetup

test/test_A4.jl

Lines changed: 44 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1+
using TensorKitSectors
2+
# @isdefined(TestSetup) || include("setup.jl")
3+
# using .TestSetup
4+
testsuite_path = joinpath(
5+
dirname(dirname(pathof(TensorKitSectors))), # TensorKitSectors root
6+
"test", "testsuite.jl"
7+
)
8+
include(testsuite_path)
9+
using .SectorTestSuite
10+
111
using MultiTensorKit
2-
using TensorKitSectors, TensorKit
312
using Test, TestExtras
4-
using Random
5-
using LinearAlgebra: LinearAlgebra
13+
# using TensorKit
14+
# using LinearAlgebra: LinearAlgebra
615

716
const MTK = MultiTensorKit
8-
const TK = TensorKit
9-
10-
@isdefined(TestSetup) || include("setup.jl")
11-
using .TestSetup
17+
# const TK = TensorKit
1218

1319
I = A4Object
1420
Istr = TensorKitSectors.type_repr(I)
@@ -17,29 +23,8 @@ r = size(I)
1723
println("----------------------")
1824
println("| Sector tests |")
1925
println("----------------------")
20-
21-
@testset "$Istr Basic type properties" verbose = true begin
22-
@test eval(Meta.parse(sprint(show, I))) == I
23-
@test eval(Meta.parse(TensorKitSectors.type_repr(I))) == I
24-
end
25-
26-
@testset "$Istr: Value iterator" begin
27-
@test eltype(values(I)) == I
28-
@test_throws ArgumentError unit(I)
29-
sprev = I(1, 1, 1) # first in SectorValues
30-
for (i, s) in enumerate(values(I))
31-
@test !isless(s, sprev) # confirm compatibility with sort order
32-
@test s == @constinferred (values(I)[i])
33-
@test findindex(values(I), s) == i
34-
sprev = s
35-
i >= 10 && break
36-
end
37-
@test I(1, 1, 1) == first(values(I))
38-
@test (@constinferred findindex(values(I), I(1, 1, 1))) == 1
39-
for s in collect(values(I))
40-
@test (@constinferred values(I)[findindex(values(I), s)]) == s
41-
end
42-
end
26+
@info "blablablabla"
27+
SectorTestSuite.test_sector(I)
4328

4429
@testset "$Istr ($i, $j) basic properties" for i in 1:r, j in 1:r
4530
Cii_obs = I.(i, i, MTK._get_dual_cache(I)[2][i, i])
@@ -50,54 +35,30 @@ end
5035

5136
if i == j
5237
@testset "Basic fusion properties" begin
53-
s = rand(Cii_obs, 3)
54-
@test eval(Meta.parse(sprint(show, s[1]))) == s[1]
55-
@test @constinferred(hash(s[1])) == hash(deepcopy(s[1]))
56-
@test isunit(@constinferred(unit(s[1])))
38+
@test isunit(@testinferred(unit(c)))
5739
u = I.(i, i, MTK._get_dual_cache(I)[1][i])
58-
@test u == @constinferred(leftunit(u)) == @constinferred(rightunit(u)) ==
59-
@constinferred(unit(u))
60-
@test isunit(@constinferred(unit(s[1])))
61-
@constinferred dual(s[1])
62-
@test dual(s[1]) == I.(i, i, MTK._get_dual_cache(I)[2][i, i][s[1].label])
63-
@constinferred dim(s[1])
64-
@constinferred frobenius_schur_phase(s[1])
65-
@constinferred frobenius_schur_indicator(s[1])
66-
@constinferred Nsymbol(s...)
67-
@constinferred Asymbol(s...)
68-
@constinferred Bsymbol(s...)
69-
F = @constinferred Fsymbol(s..., s...)
70-
@test eltype(F) <: @testinferred sectorscalartype(I)
40+
@test u == @testinferred(leftunit(u)) == @testinferred(rightunit(u)) ==
41+
@testinferred(unit(u))
42+
@test isunit(@testinferred(unit(c)))
43+
@test dual(c) == I.(i, i, MTK._get_dual_cache(I)[2][i, i][c.label])
7144
end
7245
else
7346
@testset "Basic module properties" begin
74-
@test eval(Meta.parse(sprint(show, m))) == m
75-
@test @constinferred(hash(m)) == hash(deepcopy(m))
76-
7747
@test isunit(m) == false
7848
@test isunit(mop) == false
79-
@test (isunit(@constinferred(leftunit(m))) && isunit(@constinferred(rightunit(m))))
49+
@test (isunit(@testinferred(leftunit(m))) && isunit(@testinferred(rightunit(m))))
8050
@test unit(c) == leftunit(m) == rightunit(mop)
8151
@test unit(d) == rightunit(m) == leftunit(mop)
8252
@test_throws DomainError unit(m)
8353
@test_throws DomainError unit(mop)
84-
85-
@constinferred dual(m)
8654
@test dual(m) == I.(j, i, MTK._get_dual_cache(I)[2][i, j][m.label])
87-
@test dual(dual(m)) == m
88-
89-
@constinferred dim(m)
90-
@constinferred frobenius_schur_phase(m)
91-
@constinferred frobenius_schur_indicator(m)
92-
@constinferred Bsymbol(m, mop, c)
93-
@constinferred Fsymbol(mop, m, mop, mop, d, c)
9455
end
9556

9657
@testset "$Istr Fusion rules" begin
9758
argerr = ArgumentError("invalid fusion channel")
9859
# forbidden fusions
9960
for obs in [(c, d), (d, c), (m, m), (mop, mop), (d, m), (m, c), (mop, d), (c, mop)]
100-
@test_throws AssertionError("a.j == b.i") isempty((obs...))
61+
@test isempty((obs...))
10162
@test_throws argerr Nsymbol(obs..., rand([c, m, mop, d]))
10263
end
10364

@@ -119,12 +80,16 @@ println("-----------------------------")
11980
println("| F-symbol data tests |")
12081
println("-----------------------------")
12182

83+
# explicitly test everything related to F-symbols
84+
# other option is to edit smallset to sample more
12285
for i in 1:r, j in 1:r
12386
@testset "Unitarity of $Istr F-move ($i, $j)" begin
12487
if i == j
12588
@testset "Unitarity of fusion F-move ($i, $j)" begin
12689
fusion_objects = I.(i, i, MTK._get_dual_cache(I)[2][i, i])
127-
@test unitarity_test(fusion_objects, fusion_objects, fusion_objects)
90+
for a in fusion_objects, b in fusion_objects, c in fusion_objects
91+
@test SectorTestSuite.F_unitarity_test(a, b, c)
92+
end
12893
end
12994
end
13095

@@ -135,31 +100,41 @@ for i in 1:r, j in 1:r
135100

136101
# C x C x M -> M or D x D x Mop -> Mop
137102
@testset "Unitarity of left module F-move ($i, $j)" begin
138-
@test unitarity_test(left_fusion_objects, left_fusion_objects, mod_objects)
103+
for a in left_fusion_objects, b in left_fusion_objects, A in mod_objects
104+
@test SectorTestSuite.F_unitarity_test(a, b, A)
105+
end
139106
end
140107

141108
# M x D x D -> M or Mop x C x C -> Mop
142109
@testset "Unitarity of right module F-move ($i, $j)" begin
143-
@test unitarity_test(mod_objects, right_fusion_objects, right_fusion_objects)
110+
for A in mod_objects, b in right_fusion_objects, c in right_fusion_objects
111+
@test SectorTestSuite.F_unitarity_test(A, b, c)
112+
end
144113
end
145114

146115
# C x M x D -> M or D x Mop x C -> Mop
147116
@testset "Unitarity of bimodule F-move ($i, $j)" begin
148-
@test unitarity_test(left_fusion_objects, mod_objects, right_fusion_objects)
117+
for a in left_fusion_objects, A in mod_objects, α in right_fusion_objects
118+
@test SectorTestSuite.F_unitarity_test(a, A, α)
119+
end
149120
end
150121

151122
@testset "Unitarity of mixed module F-move ($i, $j) and opposite ($j, $i)" begin
152123
modop_objects = I.(j, i, MTK._get_dual_cache(I)[2][j, i])
153124

154125
# C x M x Mop -> C or D x Mop x M -> D
155-
@test unitarity_test(left_fusion_objects, mod_objects, modop_objects)
156126
# M x Mop x C -> C or Mop x M x D -> D
157-
@test unitarity_test(mod_objects, modop_objects, left_fusion_objects)
158127
# Mop x C x M -> D or M x D x Mop -> C
159-
@test unitarity_test(modop_objects, left_fusion_objects, mod_objects)
128+
for a in left_fusion_objects, A in mod_objects, Aop in modop_objects
129+
@test SectorTestSuite.F_unitarity_test(a, A, Aop)
130+
@test SectorTestSuite.F_unitarity_test(A, Aop, a)
131+
@test SectorTestSuite.F_unitarity_test(Aop, a, A)
132+
end
160133

161134
# M x Mop x M -> M or Mop x M x Mop -> Mop
162-
@test unitarity_test(mod_objects, modop_objects, mod_objects)
135+
for A in mod_objects, Aop in modop_objects
136+
@test SectorTestSuite.F_unitarity_test(A, Aop, A)
137+
end
163138
end
164139
end
165140
end

0 commit comments

Comments
 (0)