Skip to content

Commit

Permalink
Formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
lkdvos committed Oct 5, 2023
1 parent e2e2984 commit 8284bf6
Show file tree
Hide file tree
Showing 8 changed files with 252 additions and 244 deletions.
3 changes: 2 additions & 1 deletion src/sectors/sectors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,8 @@ function pentagon_equation(a::I, b::I, c::I, d::I; kwargs...) where {I<:Sector}
end

function hexagon_equation(a::I, b::I, c::I; kwargs...) where {I<:Sector}
BraidingStyle(I) isa NoBraiding && throw(ArgumentError("Hexagon equation only defined for sectors with braiding"))
BraidingStyle(I) isa NoBraiding &&
throw(ArgumentError("Hexagon equation only defined for sectors with braiding"))
for e in (c, a), f in (c, b)
for d in intersect((e, b), (a, f))
if FusionStyle(I) isa MultiplicityFreeFusion
Expand Down
8 changes: 4 additions & 4 deletions test/ad.jl
Original file line number Diff line number Diff line change
Expand Up @@ -201,21 +201,21 @@ Vlist = ((ℂ^2, (ℂ^3)', ℂ^3, ℂ^2, (ℂ^2)'),
β = randn(T)

C = _randomize!(tensoralloc_contract(T, pC, A, pA, :N,
B, pB, :N, false))
B, pB, :N, false))
test_rrule(tensorcontract!, C, pC, A, pA, :N, B, pB, :N, α, β; atol, rtol)

A2 = TensorMap(randn, T, V[1]' V[2]' V[3]' V[4]' V[5]')
C = _randomize!(tensoralloc_contract(T, pC, A2, pA, :C,
B, pB, :N, false))
B, pB, :N, false))
test_rrule(tensorcontract!, C, pC, A2, pA, :C, B, pB, :N, α, β; atol, rtol)

B2 = TensorMap(randn, T, V[3]' V[1] V[2]')
C = _randomize!(tensoralloc_contract(T, pC, A, pA, :N,
B2, pB, :C, false))
B2, pB, :C, false))
test_rrule(tensorcontract!, C, pC, A, pA, :N, B2, pB, :C, α, β; atol, rtol)

C = _randomize!(tensoralloc_contract(T, pC, A2, pA, :C,
B2, pB, :C, false))
B2, pB, :C, false))
test_rrule(tensorcontract!, C, pC, A2, pA, :C, B2, pB, :C, α, β; atol, rtol)
end

Expand Down
16 changes: 9 additions & 7 deletions test/choosetests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,23 @@ const TESTNAMES = ["sectors", "spaces", "fusiontrees", "tensors", "planar", "ad"
const TESTGROUPS = String[]

const SECTORNAMES = ["Trivial", "Z2Irrep", "Z3Irrep", "Z4Irrep", "U1Irrep", "CU1Irrep",
"SU2Irrep", "NewSU2Irrep", "FibonacciAnyon", "IsingAnyon",
"FermionParity", "FermionNumber", "FermionSpin", "Z3Irrep ⊠ Z4Irrep",
"FermionNumber ⊠ SU2Irrep", "FermionSpin ⊠ SU2Irrep",
"NewSU2Irrep ⊠ NewSU2Irrep", "FibonacciAnyon", "Object{E6}",
"Z2Irrep ⊠ FibonacciAnyon ⊠ FibonacciAnyon"]
"SU2Irrep", "NewSU2Irrep", "FibonacciAnyon", "IsingAnyon",
"FermionParity", "FermionNumber", "FermionSpin", "Z3Irrep ⊠ Z4Irrep",
"FermionNumber ⊠ SU2Irrep", "FermionSpin ⊠ SU2Irrep",
"NewSU2Irrep ⊠ NewSU2Irrep", "FibonacciAnyon", "Object{E6}",
"Z2Irrep ⊠ FibonacciAnyon ⊠ FibonacciAnyon"]
const DEFAULT_SECTORNAMES = try
if ENV["CI"] == "true"
println("Detected CI environment")
if Sys.iswindows()
["Trivial", "Z2Irrep", "FermionParity", "Z3Irrep", "U1Irrep",
"FermionNumber", "CU1Irrep", "SU2Irrep"]
elseif Sys.isapple()
["Trivial", "Z2Irrep", "FermionParity", "Z3Irrep", "FermionNumber", "FermionSpin"]
["Trivial", "Z2Irrep", "FermionParity", "Z3Irrep", "FermionNumber",
"FermionSpin"]
else
["Trivial", "Z2Irrep", "FermionParity", "U1Irrep", "CU1Irrep", "SU2Irrep", "FermionSpin"]
["Trivial", "Z2Irrep", "FermionParity", "U1Irrep", "CU1Irrep", "SU2Irrep",
"FermionSpin"]
end
else
SECTORNAMES
Expand Down
254 changes: 129 additions & 125 deletions test/fusiontrees.jl

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions test/planar.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ println("------------------------------------")
println("Planar")
println("------------------------------------")

using TensorKit: planaradd!, planartrace!, planarcontract!, BraidingTensor, SymmetricBraiding
using TensorKit: planaradd!, planartrace!, planarcontract!, BraidingTensor,
SymmetricBraiding
using TensorOperations

@testset "$(TensorKit.type_repr(I))" verbose = true for I in sectorlist
Expand Down Expand Up @@ -52,7 +53,7 @@ using TensorOperations
planarcontract!(C′, A′, pA, B′, pB, pAB, true, true)
end
end

@testset "BraidingTensor conversion" begin
for (V1, V2) in [(V1, V1), (V1', V1), (V1, V1'), (V1', V1')]
τ = BraidingTensor(V1, V2)
Expand All @@ -72,7 +73,7 @@ using TensorOperations
end
end
end

t = TensorMap(randn, V1 * V1' * V1' * V1, V1 * V1')

ττ = copy(BraidingTensor(V1, V1'))
Expand Down Expand Up @@ -312,4 +313,4 @@ end
end
@test C C′
end
end
end
92 changes: 46 additions & 46 deletions test/spaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,56 +87,56 @@ end
@test @constinferred(supremum(V', ℝ^3)) ==^3
end

@timedtestset "ElementarySpace: ComplexSpace" begin
d = 2
V =^d
@test eval(Meta.parse(sprint(show, V))) == V
@test eval(Meta.parse(sprint(show, V'))) == V'
@test eval(Meta.parse(sprint(show, typeof(V)))) == typeof(V)
@test isa(V, VectorSpace)
@test isa(V, ElementarySpace)
@test isa(InnerProductStyle(V), HasInnerProduct)
@test isa(InnerProductStyle(V), EuclideanProduct)
@test isa(V, ComplexSpace)
@test !isdual(V)
@test isdual(V')
@test V == ComplexSpace(Trivial() => d) == ComplexSpace(Dict(Trivial() => d))
@test @constinferred(hash(V)) == hash(deepcopy(V)) != hash(V')
@test @constinferred(dual(V)) == @constinferred(conj(V)) ==
@constinferred(adjoint(V)) != V
@test @constinferred(field(V)) ==
@test @constinferred(sectortype(V)) == Trivial
@test @constinferred(sectortype(V)) == Trivial
@test ((@constinferred sectors(V))...,) == (Trivial(),)
@test length(sectors(V)) == 1
@test @constinferred(TensorKit.hassector(V, Trivial()))
@test @constinferred(dim(V)) == d == @constinferred(dim(V, Trivial()))
@test dim(@constinferred(typeof(V)())) == 0
@test (sectors(typeof(V)())...,) == ()
@test @constinferred(TensorKit.axes(V)) == Base.OneTo(d)
@test^d == Vect[Trivial](d) == Vect[](Trivial() => d) == ℂ[](d) == typeof(V)(d)
W = @constinferred^1
@test @constinferred(oneunit(V)) == W == oneunit(typeof(V))
@test @constinferred((V, V)) ==^(2d)
@test_throws SpaceMismatch ((V, V'))
@timedtestset "ElementarySpace: ComplexSpace" begin
d = 2
V =^d
@test eval(Meta.parse(sprint(show, V))) == V
@test eval(Meta.parse(sprint(show, V'))) == V'
@test eval(Meta.parse(sprint(show, typeof(V)))) == typeof(V)
@test isa(V, VectorSpace)
@test isa(V, ElementarySpace)
@test isa(InnerProductStyle(V), HasInnerProduct)
@test isa(InnerProductStyle(V), EuclideanProduct)
@test isa(V, ComplexSpace)
@test !isdual(V)
@test isdual(V')
@test V == ComplexSpace(Trivial() => d) == ComplexSpace(Dict(Trivial() => d))
@test @constinferred(hash(V)) == hash(deepcopy(V)) != hash(V')
@test @constinferred(dual(V)) == @constinferred(conj(V)) ==
@constinferred(adjoint(V)) != V
@test @constinferred(field(V)) ==
@test @constinferred(sectortype(V)) == Trivial
@test @constinferred(sectortype(V)) == Trivial
@test ((@constinferred sectors(V))...,) == (Trivial(),)
@test length(sectors(V)) == 1
@test @constinferred(TensorKit.hassector(V, Trivial()))
@test @constinferred(dim(V)) == d == @constinferred(dim(V, Trivial()))
@test dim(@constinferred(typeof(V)())) == 0
@test (sectors(typeof(V)())...,) == ()
@test @constinferred(TensorKit.axes(V)) == Base.OneTo(d)
@test^d == Vect[Trivial](d) == Vect[](Trivial() => d) == ℂ[](d) == typeof(V)(d)
W = @constinferred^1
@test @constinferred(oneunit(V)) == W == oneunit(typeof(V))
@test @constinferred((V, V)) ==^(2d)
@test_throws SpaceMismatch ((V, V'))
promote_except = ErrorException("promotion of types $(typeof(ℝ^d)) and " *
"$(typeof(ℂ^d)) failed to change any arguments")
@test_throws promote_except ((ℝ^d, ℂ^d))
@test_throws promote_except ((ℝ^d, ℂ^d))
@test @constinferred((V, V)) ==^(2d)
@test @constinferred((V, oneunit(V))) ==^(d + 1)
@test @constinferred((V, V, V, V)) ==^(4d)
@test @constinferred(fuse(V, V)) ==^(d^2)
@test @constinferred(fuse(V, V', V, V')) ==^(d^4)
@test @constinferred(flip(V)) == V'
@test flip(V) V
@test flip(V) V
@test flip(V) V
@test V (V, V)
@test !(V (V, V))
@test @constinferred(infimum(V, ℂ^3)) == V
@test @constinferred(supremum(V', (ℂ^3)')) == dual(ℂ^3) == conj(ℂ^3)
end
@test @constinferred((V, V)) ==^(2d)
@test @constinferred((V, oneunit(V))) ==^(d + 1)
@test @constinferred((V, V, V, V)) ==^(4d)
@test @constinferred(fuse(V, V)) ==^(d^2)
@test @constinferred(fuse(V, V', V, V')) ==^(d^4)
@test @constinferred(flip(V)) == V'
@test flip(V) V
@test flip(V) V
@test flip(V) V
@test V (V, V)
@test !(V (V, V))
@test @constinferred(infimum(V, ℂ^3)) == V
@test @constinferred(supremum(V', (ℂ^3)')) == dual(ℂ^3) == conj(ℂ^3)
end

@testset "GeneralSpace" begin
d = 2
Expand Down
112 changes: 56 additions & 56 deletions test/tensors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -379,67 +379,67 @@ end
end
end

t = Tensor(rand, T, V1 V1' V2 V2')
@testset "eig and isposdef" begin
D, V = eigen(t, ((1, 3), (2, 4)))
t2 = permute(t, ((1, 3), (2, 4)))
@test t2 * V V * D
@test !isposdef(t2) # unlikely for non-hermitian map
t2 = (t2 + t2')
D, V = eigen(t2)
VdV = V' * V
@test VdV one(VdV)
D̃, Ṽ = @constinferred eigh(t2)
@test D
@test V
λ = minimum(minimum(real(LinearAlgebra.diag(b)))
for (c, b) in blocks(D))
@test isposdef(t2) == isposdef(λ)
@test isposdef(t2 - λ * one(t2) + 0.1 * one(t2))
@test !isposdef(t2 - λ * one(t2) - 0.1 * one(t2))
end
t = Tensor(rand, T, V1 V1' V2 V2')
@testset "eig and isposdef" begin
D, V = eigen(t, ((1, 3), (2, 4)))
t2 = permute(t, ((1, 3), (2, 4)))
@test t2 * V V * D
@test !isposdef(t2) # unlikely for non-hermitian map
t2 = (t2 + t2')
D, V = eigen(t2)
VdV = V' * V
@test VdV one(VdV)
D̃, Ṽ = @constinferred eigh(t2)
@test D
@test V
λ = minimum(minimum(real(LinearAlgebra.diag(b)))
for (c, b) in blocks(D))
@test isposdef(t2) == isposdef(λ)
@test isposdef(t2 - λ * one(t2) + 0.1 * one(t2))
@test !isposdef(t2 - λ * one(t2) - 0.1 * one(t2))
end
end
@timedtestset "Tensor truncation" begin
for T in (Float32, ComplexF64)
for p in (1, 2, 3, Inf)
# Test both a normal tensor and an adjoint one.
ts = (TensorMap(randn, T, V1 V2 V3, V4 V5),
TensorMap(randn, T, V4 V5, V1 V2 V3)')
for t in ts
U₀, S₀, V₀, = tsvd(t)
t = rmul!(t, 1 / norm(S₀, p))
U, S, V, ϵ = @constinferred tsvd(t; trunc=truncerr(5e-1), p=p)
# @show p, ϵ
# @show domain(S)
# @test min(space(S,1), space(S₀,1)) != space(S₀,1)
U′, S′, V′, ϵ′ = tsvd(t; trunc=truncerr(nextfloat(ϵ)), p=p)
@test (U, S, V, ϵ) == (U′, S′, V′, ϵ′)
U′, S, V, ϵ= tsvd(t; trunc=truncdim(ceil(Int, dim(domain(S)))),
p=p)
@test (U, S, V, ϵ) == (U′, S′, V′, ϵ′)
U′, S, V, ϵ= tsvd(t; trunc=truncspace(space(S, 1)), p=p)
@test (U, S, V, ϵ) == (U′, S′, V′, ϵ′)
# results with truncationcutoff cannot be compared because they don't take degeneracy into account, and thus truncate differently
U, S, V, ϵ = tsvd(t; trunc=truncbelow(1 / dim(domain(S₀))), p=p)
# @show p, ϵ
# @show domain(S)
# @test min(space(S,1), space(S₀,1)) != space(S₀,1)
U′, S′, V′, ϵ′ = tsvd(t; trunc=truncspace(space(S, 1)), p=p)
@test (U, S, V, ϵ) == (U′, S′, V′, ϵ′)
end
end
@timedtestset "Tensor truncation" begin
for T in (Float32, ComplexF64)
for p in (1, 2, 3, Inf)
# Test both a normal tensor and an adjoint one.
ts = (TensorMap(randn, T, V1 V2 V3, V4 V5),
TensorMap(randn, T, V4 V5, V1 V2 V3)')
for t in ts
U₀, S₀, V₀, = tsvd(t)
t = rmul!(t, 1 / norm(S₀, p))
U, S, V, ϵ = @constinferred tsvd(t; trunc=truncerr(5e-1), p=p)
# @show p, ϵ
# @show domain(S)
# @test min(space(S,1), space(S₀,1)) != space(S₀,1)
U′, S, V, ϵ= tsvd(t; trunc=truncerr(nextfloat(ϵ)), p=p)
@test (U, S, V, ϵ) == (U′, S′, V′, ϵ′)
U′, S′, V′, ϵ′ = tsvd(t; trunc=truncdim(ceil(Int, dim(domain(S)))),
p=p)
@test (U, S, V, ϵ) == (U′, S′, V′, ϵ′)
U′, S, V, ϵ= tsvd(t; trunc=truncspace(space(S, 1)), p=p)
@test (U, S, V, ϵ) == (U′, S′, V′, ϵ′)
# results with truncationcutoff cannot be compared because they don't take degeneracy into account, and thus truncate differently
U, S, V, ϵ = tsvd(t; trunc=truncbelow(1 / dim(domain(S₀))), p=p)
# @show p, ϵ
# @show domain(S)
# @test min(space(S,1), space(S₀,1)) != space(S₀,1)
U′, S, V, ϵ= tsvd(t; trunc=truncspace(space(S, 1)), p=p)
@test (U, S, V, ϵ) == (U′, S′, V′, ϵ′)
end
end
end
if hasfusiontensor(I)
@timedtestset "Tensor functions" begin
W = V1 V2
for T in (Float64, ComplexF64)
t = TensorMap(randn, T, W, W)
s = dim(W)
expt = @constinferred exp(t)
@test reshape(convert(Array, expt), (s, s))
exp(reshape(convert(Array, t), (s, s)))
end
if hasfusiontensor(I)
@timedtestset "Tensor functions" begin
W = V1 V2
for T in (Float64, ComplexF64)
t = TensorMap(randn, T, W, W)
s = dim(W)
expt = @constinferred exp(t)
@test reshape(convert(Array, expt), (s, s))
exp(reshape(convert(Array, t), (s, s)))

@test (@constinferred sqrt(t))^2 t
@test reshape(convert(Array, sqrt(t^2)), (s, s))
Expand Down
2 changes: 1 addition & 1 deletion test/utility.jl
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,4 @@ function force_planar(tsrc::TensorMap{<:GradedSpace})
copyto!(blocks(tdst)[c PlanarTrivial()], b)
end
return tdst
end
end

0 comments on commit 8284bf6

Please sign in to comment.