Skip to content

Commit

Permalink
try new formatting with TestExtras v0.2 in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jutho committed Jul 27, 2023
1 parent d5230be commit 8b9bd72
Show file tree
Hide file tree
Showing 4 changed files with 488 additions and 500 deletions.
14 changes: 7 additions & 7 deletions test/fusiontrees.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ println("------------------------------------")
println("Fusion Trees")
println("------------------------------------")
ti = time()
@timedtestset "Fusion trees for $(TensorKit.type_repr(I))" for I in sectorlist
@timedtestset "Fusion trees for $(TensorKit.type_repr(I))" verbose=true for I in sectorlist
Istr = TensorKit.type_repr(I)
N = 5
out = ntuple(n -> randsector(I), N)
Expand All @@ -17,7 +17,7 @@ ti = time()
it = @constinferred fusiontrees(out, in, isdual)
@constinferred Nothing iterate(it)
f = @constinferred first(it)
@testset "Fusion tree $I: printing" begin
@testset "Fusion tree $Istr: printing" begin
@test eval(Meta.parse(sprint(show, f))) == f
end
@testset "Fusion tree $Istr: insertat" begin
Expand All @@ -42,13 +42,13 @@ ti = time()
@test first(TK.insertat(f1b, 1, f1a)) == (f1 => 1)

levels = ntuple(identity, N)
gen = Base.Generator(braid(f1, levels, (i, (1:(i - 1))..., ((i + 1):N)...))) do (t,
c)
(t′, c′) = first(TK.insertat(t, 1, f2))
function _reinsert_partial_tree(t, f)
(t′, c′) = first(TK.insertat(t, 1, f))
@test c′ == one(c′)
return t′ => c
return t′
end
trees2 = Dict(gen)
braid_i_to_1 = braid(f1, levels, (i, (1:(i - 1))..., ((i + 1):N)...))
trees2 = Dict(_reinsert_partial_tree(t,f2)=>c for (t,c) in braid_i_to_1)
trees3 = empty(trees2)
p = (((N + 1):(N + i - 1))..., (1:N)..., ((N + i):(2N - 1))...)
levels = ((i:(N + i - 1))..., (1:(i - 1))..., ((i + N):(2N - 1))...)
Expand Down
199 changes: 97 additions & 102 deletions test/sectors.jl
Original file line number Diff line number Diff line change
@@ -1,123 +1,118 @@
println("------------------------------------")
println("Sectors")
println("------------------------------------")
ti = time()

@timedtestset "Sector properties of $(TensorKit.type_repr(I))" for I in sectorlist
Istr = TensorKit.type_repr(I)
@testset "Sector $Istr: Basic properties" begin
s = (randsector(I), randsector(I), randsector(I))
@test eval(Meta.parse(sprint(show, I))) == I
@test eval(Meta.parse(TensorKit.type_repr(I))) == I
@test eval(Meta.parse(sprint(show, s[1]))) == s[1]
@test @constinferred(hash(s[1])) == hash(deepcopy(s[1]))
@test @constinferred(one(s[1])) == @constinferred(one(I))
@constinferred dual(s[1])
@constinferred dim(s[1])
@constinferred frobeniusschur(s[1])
@constinferred Nsymbol(s...)
@constinferred Rsymbol(s...)
@constinferred Bsymbol(s...)
@constinferred Fsymbol(s..., s...)
it = @constinferred s[1] s[2]
@constinferred (s..., s...)
end
@testset "Sector $Istr: Value iterator" begin
@test eltype(values(I)) == I
sprev = one(I)
for (i, s) in enumerate(values(I))
@test !isless(s, sprev) # confirm compatibility with sort order
@timedtestset "Sectors" verbose = true begin
@timedtestset "Sector properties of $(TensorKit.type_repr(I))" for I in sectorlist
Istr = TensorKit.type_repr(I)
@testset "Sector $Istr: Basic properties" begin
s = (randsector(I), randsector(I), randsector(I))
@test eval(Meta.parse(sprint(show, I))) == I
@test eval(Meta.parse(TensorKit.type_repr(I))) == I
@test eval(Meta.parse(sprint(show, s[1]))) == s[1]
@test @constinferred(hash(s[1])) == hash(deepcopy(s[1]))
@test @constinferred(one(s[1])) == @constinferred(one(I))
@constinferred dual(s[1])
@constinferred dim(s[1])
@constinferred frobeniusschur(s[1])
@constinferred Nsymbol(s...)
@constinferred Rsymbol(s...)
@constinferred Bsymbol(s...)
@constinferred Fsymbol(s..., s...)
it = @constinferred s[1] s[2]
@constinferred (s..., s...)
end
@testset "Sector $Istr: Value iterator" begin
@test eltype(values(I)) == I
sprev = one(I)
for (i, s) in enumerate(values(I))
@test !isless(s, sprev) # confirm compatibility with sort order
if Base.IteratorSize(values(I)) == Base.IsInfinite() && I <: ProductSector
@test_throws ArgumentError values(I)[i]
@test_throws ArgumentError TensorKit.findindex(values(I), s)
elseif hasmethod(Base.getindex, Tuple{typeof(values(I)),Int})
@test s == @constinferred (values(I)[i])
@test TensorKit.findindex(values(I), s) == i
end
sprev = s
i >= 10 && break
end
@test one(I) == first(values(I))
if Base.IteratorSize(values(I)) == Base.IsInfinite() && I <: ProductSector
@test_throws ArgumentError values(I)[i]
@test_throws ArgumentError TensorKit.findindex(values(I), s)
@test_throws ArgumentError TensorKit.findindex(values(I), one(I))
elseif hasmethod(Base.getindex, Tuple{typeof(values(I)),Int})
@test s == @constinferred (values(I)[i])
@test TensorKit.findindex(values(I), s) == i
end
sprev = s
i >= 10 && break
end
@test one(I) == first(values(I))
if Base.IteratorSize(values(I)) == Base.IsInfinite() && I <: ProductSector
@test_throws ArgumentError TensorKit.findindex(values(I), one(I))
elseif hasmethod(Base.getindex, Tuple{typeof(values(I)),Int})
@test (@constinferred TensorKit.findindex(values(I), one(I))) == 1
for s in smallset(I)
@test (@constinferred values(I)[TensorKit.findindex(values(I), s)]) == s
@test (@constinferred TensorKit.findindex(values(I), one(I))) == 1
for s in smallset(I)
@test (@constinferred values(I)[TensorKit.findindex(values(I), s)]) == s
end
end
end
end
if hasfusiontensor(I)
@testset "Sector $I: fusion tensor and F-move and R-move" begin
for a in smallset(I), b in smallset(I)
for c in (a, b)
X1 = permutedims(fusiontensor(a, b, c), (2, 1, 3, 4))
X2 = fusiontensor(b, a, c)
l = dim(a) * dim(b) * dim(c)
R = LinearAlgebra.transpose(Rsymbol(a, b, c))
sz = (l, convert(Int, Nsymbol(a, b, c)))
@test reshape(X1, sz) reshape(X2, sz) * R
if hasfusiontensor(I)
@testset "Sector $I: fusion tensor and F-move and R-move" begin
for a in smallset(I), b in smallset(I)
for c in (a, b)
X1 = permutedims(fusiontensor(a, b, c), (2, 1, 3, 4))
X2 = fusiontensor(b, a, c)
l = dim(a) * dim(b) * dim(c)
R = LinearAlgebra.transpose(Rsymbol(a, b, c))
sz = (l, convert(Int, Nsymbol(a, b, c)))
@test reshape(X1, sz) reshape(X2, sz) * R
end
end
end
for a in smallset(I), b in smallset(I), c in smallset(I)
for e in (a, b), f in (b, c)
for d in intersect((e, c), (a, f))
X1 = fusiontensor(a, b, e)
X2 = fusiontensor(e, c, d)
Y1 = fusiontensor(b, c, f)
Y2 = fusiontensor(a, f, d)
@tensor f1[-1, -2, -3, -4] := conj(Y2[a, f, d, -4]) *
conj(Y1[b, c, f, -3]) *
X1[a, b, e, -1] * X2[e, c, d, -2]
if FusionStyle(I) isa MultiplicityFreeFusion
f2 = fill(Fsymbol(a, b, c, d, e, f) * dim(d), (1, 1, 1, 1))
else
f2 = Fsymbol(a, b, c, d, e, f) * dim(d)
for a in smallset(I), b in smallset(I), c in smallset(I)
for e in (a, b), f in (b, c)
for d in intersect((e, c), (a, f))
X1 = fusiontensor(a, b, e)
X2 = fusiontensor(e, c, d)
Y1 = fusiontensor(b, c, f)
Y2 = fusiontensor(a, f, d)
@tensor f1[-1, -2, -3, -4] := conj(Y2[a, f, d, -4]) *
conj(Y1[b, c, f, -3]) *
X1[a, b, e, -1] * X2[e, c, d, -2]
if FusionStyle(I) isa MultiplicityFreeFusion
f2 = fill(Fsymbol(a, b, c, d, e, f) * dim(d), (1, 1, 1, 1))
else
f2 = Fsymbol(a, b, c, d, e, f) * dim(d)
end
@test isapprox(f1, f2; atol=1e-12, rtol=1e-12)
end
@test isapprox(f1, f2; atol=1e-12, rtol=1e-12)
end
end
end
end
end
@testset "Sector $Istr: Unitarity of F-move" begin
for a in smallset(I), b in smallset(I), c in smallset(I)
for d in (a, b, c)
es = collect(intersect((a, b), map(dual, (c, dual(d)))))
fs = collect(intersect((b, c), map(dual, (dual(d), a))))
if FusionStyle(I) isa MultiplicityFreeFusion
@test length(es) == length(fs)
F = [Fsymbol(a, b, c, d, e, f) for e in es, f in fs]
else
Fblocks = Vector{Any}()
for e in es
for f in fs
Fs = Fsymbol(a, b, c, d, e, f)
push!(Fblocks,
reshape(Fs,
(size(Fs, 1) * size(Fs, 2),
size(Fs, 3) * size(Fs, 4))))
@testset "Sector $Istr: Unitarity of F-move" begin
for a in smallset(I), b in smallset(I), c in smallset(I)
for d in (a, b, c)
es = collect(intersect((a, b), map(dual, (c, dual(d)))))
fs = collect(intersect((b, c), map(dual, (dual(d), a))))
if FusionStyle(I) isa MultiplicityFreeFusion
@test length(es) == length(fs)
F = [Fsymbol(a, b, c, d, e, f) for e in es, f in fs]
else
Fblocks = Vector{Any}()
for e in es
for f in fs
Fs = Fsymbol(a, b, c, d, e, f)
push!(Fblocks,
reshape(Fs,
(size(Fs, 1) * size(Fs, 2),
size(Fs, 3) * size(Fs, 4))))
end
end
F = hvcat(length(fs), Fblocks...)
end
F = hvcat(length(fs), Fblocks...)
@test isapprox(F' * F, one(F); atol=1e-12, rtol=1e-12)
end
@test isapprox(F' * F, one(F); atol=1e-12, rtol=1e-12)
end
end
end
@testset "Sector $Istr: Pentagon equation" begin
for a in smallset(I), b in smallset(I), c in smallset(I), d in smallset(I)
@test pentagon_equation(a, b, c, d; atol=1e-12, rtol=1e-12)
@testset "Sector $Istr: Pentagon equation" begin
for a in smallset(I), b in smallset(I), c in smallset(I), d in smallset(I)
@test pentagon_equation(a, b, c, d; atol=1e-12, rtol=1e-12)
end
end
end
@testset "Sector $Istr: Hexagon equation" begin
for a in smallset(I), b in smallset(I), c in smallset(I)
@test hexagon_equation(a, b, c; atol=1e-12, rtol=1e-12)
@testset "Sector $Istr: Hexagon equation" begin
for a in smallset(I), b in smallset(I), c in smallset(I)
@test hexagon_equation(a, b, c; atol=1e-12, rtol=1e-12)
end
end
end
end
tf = time()
printstyled("Finished sector tests in ",
string(round(tf - ti; sigdigits=3)),
" seconds."; bold=true, color=Base.info_color())
println()
end
Loading

0 comments on commit 8b9bd72

Please sign in to comment.