Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Random = "1"
Reexport = "1"
TensorOperations = "5"
Test = "1"
TestExtras = "0.3"
TestExtras = "0.3.2"
WignerSymbols = "1,2"

[extras]
Expand Down
34 changes: 15 additions & 19 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
using Test
using TestExtras
using Random
# using TensorKit: TensorKitSectors
using TensorKitSectors
using TensorOperations
using Base.Iterators: take, product
using LinearAlgebra: LinearAlgebra

const TKS = TensorKitSectors

include("testsetup.jl")
using .TestSetup
include("newsectors.jl")
using .NewSectors

Expand Down Expand Up @@ -46,8 +37,13 @@ const sectorlist = (
TimeReversed{FermionParity ⊠ SU2Irrep ⊠ NewSU2Irrep},
)

@testset "$(TensorKitSectors.type_repr(I))" for I in sectorlist
@include("sectors.jl")
include("testsuite.jl")
using .SectorTestSuite

@testset "Sector test suite" verbose = true begin
for sectortype in sectorlist
@time SectorTestSuite.test_sector(sectortype)
end
end

@testset "Deligne product" begin
Expand All @@ -56,17 +52,17 @@ end
a = first(smallset(I1))
b = first(smallset(I2))

@constinferred a ⊠ b
@constinferred a ⊠ b ⊠ a
@constinferred a ⊠ b ⊠ a ⊠ b
@constinferred I1 ⊠ I2
@testinferred a ⊠ b
@testinferred a ⊠ b ⊠ a
@testinferred a ⊠ b ⊠ a ⊠ b
@testinferred I1 ⊠ I2
@test typeof(a ⊠ b) == I1 ⊠ I2

@test @constinferred(length(allunits(I1 ⊠ I2))) == 1
@test @constinferred(unit(I1 ⊠ I2)) == leftunit(a ⊠ b) == rightunit(a ⊠ b)
@test @testinferred(length(allunits(I1 ⊠ I2))) == 1
@test @testinferred(unit(I1 ⊠ I2)) == leftunit(a ⊠ b) == rightunit(a ⊠ b)
end
@test @constinferred(Tuple(SU2Irrep(1) ⊠ U1Irrep(0))) == (SU2Irrep(1), U1Irrep(0))
@test @constinferred(length(FermionParity(1) ⊠ SU2Irrep(1 // 2) ⊠ U1Irrep(1))) == 3
@test @testinferred(Tuple(SU2Irrep(1) ⊠ U1Irrep(0))) == (SU2Irrep(1), U1Irrep(0))
@test @testinferred(length(FermionParity(1) ⊠ SU2Irrep(1 // 2) ⊠ U1Irrep(1))) == 3
end

@testset "Issue that came up in #11" begin
Expand Down
170 changes: 96 additions & 74 deletions test/sectors.jl
Original file line number Diff line number Diff line change
@@ -1,99 +1,122 @@
Istr = TKS.type_repr(I)
@testset "Sector $Istr: Basic properties" begin
using TensorOperations
using LinearAlgebra

@testsuite "Basic properties" I -> begin
s = (randsector(I), randsector(I), randsector(I))
@test eval(Meta.parse(sprint(show, I))) == I
@test eval(Meta.parse(TKS.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(unit(s[1])) == @constinferred(unit(I))
@constinferred dual(s[1])
@constinferred dim(s[1])
@constinferred frobenius_schur_phase(s[1])
@constinferred frobenius_schur_indicator(s[1])
@constinferred Nsymbol(s...)
@constinferred Asymbol(s...)
B = @constinferred Bsymbol(s...)
F = @constinferred Fsymbol(s..., s...)
@test Base.eval(Main, Meta.parse(sprint(show, I))) == I
@test Base.eval(Main, Meta.parse(TensorKitSectors.type_repr(I))) == I
@test Base.eval(Main, Meta.parse(sprint(show, s[1]))) == s[1]
@test @testinferred(hash(s[1])) == hash(deepcopy(s[1]))
@test @testinferred(unit(s[1])) == @testinferred(unit(I))
@testinferred dual(s[1])
@testinferred dim(s[1])
@testinferred frobenius_schur_phase(s[1])
@testinferred frobenius_schur_indicator(s[1])
@testinferred Nsymbol(s...)
@testinferred Asymbol(s...)
B = @testinferred Bsymbol(s...)
F = @testinferred Fsymbol(s..., s...)
if BraidingStyle(I) isa HasBraiding
R = @constinferred Rsymbol(s...)
R = @testinferred Rsymbol(s...)
if FusionStyle(I) === SimpleFusion()
@test typeof(R * F) <: @constinferred sectorscalartype(I)
@test typeof(R * F) <: @testinferred sectorscalartype(I)
else
@test Base.promote_op(*, eltype(R), eltype(F)) <: @constinferred sectorscalartype(I)
@test Base.promote_op(*, eltype(R), eltype(F)) <: @testinferred sectorscalartype(I)
end
else
if FusionStyle(I) === SimpleFusion()
@test typeof(F) <: @constinferred sectorscalartype(I)
@test typeof(F) <: @testinferred sectorscalartype(I)
else
@test eltype(F) <: @constinferred sectorscalartype(I)
@test eltype(F) <: @testinferred sectorscalartype(I)
end
end
it = @constinferred s[1] ⊗ s[2]
@constinferred ⊗(s..., s...)
@testinferred(s[1] ⊗ s[2])
@testinferred(⊗(s..., s...))
end
@testset "Sector $Istr: Value iterator" begin

@testsuite "Value iterator" I -> begin
@test eltype(values(I)) == I
sprev = unit(I)
for (i, s) in enumerate(values(I))
@test !isless(s, sprev) # confirm compatibility with sort order
@test s == @constinferred (values(I)[i])
@test !isless(s, sprev)
@test s == @testinferred(values(I)[i])
@test findindex(values(I), s) == i
sprev = s
i >= 10 && break
end
@test unit(I) == first(values(I))
@test length(allunits(I)) == 1
@test (@constinferred findindex(values(I), unit(I))) == 1
@test (@testinferred findindex(values(I), unit(I))) == 1
for s in smallset(I)
@test (@constinferred values(I)[findindex(values(I), s)]) == s
@test (@testinferred values(I)[findindex(values(I), s)]) == s
end
end
if BraidingStyle(I) isa Bosonic && hasfusiontensor(I)
@testset "Sector $Istr: 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
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 = 1.0e-12, rtol = 1.0e-12)

@testsuite "Fusion and dimensions" I -> begin
for a in smallset(I), b in smallset(I)
da = dim(a)
db = dim(b)
dc = sum(c -> dim(c) * Nsymbol(a, b, c), a ⊗ b)
@test da * db ≈ dc # needs to be ≈ because of anyons
end
end

@testsuite "Fusion tensor and F-move" I -> begin
hasfusiontensor(I) || return nothing
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 = 1.0e-12, rtol = 1.0e-12)
end
end
end
end
if hasfusiontensor(I)
@testset "Orthogonality of fusiontensors" begin
for a in smallset(I), b in smallset(I)
cs = vec(collect(a ⊗ b))
CGCs = map(c -> reshape(fusiontensor(a, b, c), :, dim(c)), cs)
M = map(Iterators.product(CGCs, CGCs)) do (cgc1, cgc2)
return LinearAlgebra.norm(cgc1' * cgc2)

@testsuite "Fusion tensor and R-move" I -> begin
(BraidingStyle(I) isa Bosonic && hasfusiontensor(I)) || return nothing
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

@testsuite "Orthogonality of fusiontensors" I -> begin
hasfusiontensor(I) || return nothing
for a in smallset(I), b in smallset(I)
cs = vec(collect(a ⊗ b))
cgcs = map(c -> fusiontensor(a, b, c), cs)
for (c, cgc) in zip(cs, cgcs), (c′, cgc′) in zip(cs, cgcs)
for μ in 1:Nsymbol(a, b, c), ν in 1:Nsymbol(a, b, c′)
@tensor overlap[mc mc'] := conj(view(cgc, :, :, :, μ)[ma mb mc]) *
view(cgc′, :, :, :, ν)[ma mb mc']
if μ == ν && c == c′
@test isapprox(overlap, LinearAlgebra.I; atol = 1.0e-12)
else
@test isapprox(LinearAlgebra.norm(overlap), 0; atol = 1.0e-12)
end
end
@test isapprox(M' * M, LinearAlgebra.Diagonal(dim.(cs)); atol = 1.0e-12)
end
end
end

@testset "Sector $Istr: Unitarity of F-move" begin
@testsuite "Unitarity of F-move" I -> 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)))))
Expand All @@ -105,31 +128,30 @@ end
Fblocks = Vector{Any}()
for e in es, 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)))
)
push!(Fblocks, reshape(Fs, (size(Fs, 1) * size(Fs, 2), size(Fs, 3) * size(Fs, 4))))
end
F = hvcat(length(fs), Fblocks...)
end
@test isapprox(F' * F, one(F); atol = 1.0e-12, rtol = 1.0e-12)
end
end
end
@testset "Sector $Istr: Triangle equation" begin

@testsuite "Triangle equation" I -> begin
for a in smallset(I), b in smallset(I)
@test triangle_equation(a, b; atol = 1.0e-12, rtol = 1.0e-12)
end
end
@testset "Sector $Istr: Pentagon equation" begin

@testsuite "Pentagon equation" I -> 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 = 1.0e-12, rtol = 1.0e-12)
end
end
if BraidingStyle(I) isa HasBraiding
@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 = 1.0e-12, rtol = 1.0e-12)
end

@testsuite "Hexagon equation" I -> begin
BraidingStyle(I) isa HasBraiding || return nothing
for a in smallset(I), b in smallset(I), c in smallset(I)
@test hexagon_equation(a, b, c; atol = 1.0e-12, rtol = 1.0e-12)
end
end
48 changes: 0 additions & 48 deletions test/testsetup.jl

This file was deleted.

Loading