-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtestsetup.jl
More file actions
48 lines (42 loc) · 1.29 KB
/
testsetup.jl
File metadata and controls
48 lines (42 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
"""
module TestSetup
Basic utility for testing sectors.
"""
module TestSetup
export smallset, randsector, hasfusiontensor
using TensorKitSectors, Test, Random
using TestExtras
using Base.Iterators: take, product
smallset(::Type{I}) where {I <: Sector} = take(values(I), 5)
function smallset(::Type{ProductSector{Tuple{I1, I2}}}) where {I1, I2}
iter = product(smallset(I1), smallset(I2))
s = collect(i ⊠ j for (i, j) in iter if dim(i) * dim(j) <= 6)
return length(s) > 6 ? rand(s, 6) : s
end
function smallset(::Type{ProductSector{Tuple{I1, I2, I3}}}) where {I1, I2, I3}
iter = product(smallset(I1), smallset(I2), smallset(I3))
s = collect(i ⊠ j ⊠ k for (i, j, k) in iter if dim(i) * dim(j) * dim(k) <= 6)
return length(s) > 6 ? rand(s, 6) : s
end
function randsector(::Type{I}) where {I <: Sector}
s = collect(smallset(I))
a = rand(s)
while isunit(a) # don't use trivial label
a = rand(s)
end
return a
end
randsector(::Type{I}) where {I <: Union{Trivial, PlanarTrivial}} = unit(I)
function hasfusiontensor(I::Type{<:Sector})
try
fusiontensor(unit(I), unit(I), unit(I))
return true
catch e
if e isa MethodError
return false
else
rethrow(e)
end
end
end
end # module TestSetup