Skip to content

Commit 8284bf6

Browse files
committed
Formatter
1 parent e2e2984 commit 8284bf6

File tree

8 files changed

+252
-244
lines changed

8 files changed

+252
-244
lines changed

src/sectors/sectors.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,8 @@ function pentagon_equation(a::I, b::I, c::I, d::I; kwargs...) where {I<:Sector}
397397
end
398398

399399
function hexagon_equation(a::I, b::I, c::I; kwargs...) where {I<:Sector}
400-
BraidingStyle(I) isa NoBraiding && throw(ArgumentError("Hexagon equation only defined for sectors with braiding"))
400+
BraidingStyle(I) isa NoBraiding &&
401+
throw(ArgumentError("Hexagon equation only defined for sectors with braiding"))
401402
for e in (c, a), f in (c, b)
402403
for d in intersect((e, b), (a, f))
403404
if FusionStyle(I) isa MultiplicityFreeFusion

test/ad.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -201,21 +201,21 @@ Vlist = ((ℂ^2, (ℂ^3)', ℂ^3, ℂ^2, (ℂ^2)'),
201201
β = randn(T)
202202

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

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

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

217217
C = _randomize!(tensoralloc_contract(T, pC, A2, pA, :C,
218-
B2, pB, :C, false))
218+
B2, pB, :C, false))
219219
test_rrule(tensorcontract!, C, pC, A2, pA, :C, B2, pB, :C, α, β; atol, rtol)
220220
end
221221

test/choosetests.jl

+9-7
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,23 @@ const TESTNAMES = ["sectors", "spaces", "fusiontrees", "tensors", "planar", "ad"
44
const TESTGROUPS = String[]
55

66
const SECTORNAMES = ["Trivial", "Z2Irrep", "Z3Irrep", "Z4Irrep", "U1Irrep", "CU1Irrep",
7-
"SU2Irrep", "NewSU2Irrep", "FibonacciAnyon", "IsingAnyon",
8-
"FermionParity", "FermionNumber", "FermionSpin", "Z3Irrep ⊠ Z4Irrep",
9-
"FermionNumber ⊠ SU2Irrep", "FermionSpin ⊠ SU2Irrep",
10-
"NewSU2Irrep ⊠ NewSU2Irrep", "FibonacciAnyon", "Object{E6}",
11-
"Z2Irrep ⊠ FibonacciAnyon ⊠ FibonacciAnyon"]
7+
"SU2Irrep", "NewSU2Irrep", "FibonacciAnyon", "IsingAnyon",
8+
"FermionParity", "FermionNumber", "FermionSpin", "Z3Irrep ⊠ Z4Irrep",
9+
"FermionNumber ⊠ SU2Irrep", "FermionSpin ⊠ SU2Irrep",
10+
"NewSU2Irrep ⊠ NewSU2Irrep", "FibonacciAnyon", "Object{E6}",
11+
"Z2Irrep ⊠ FibonacciAnyon ⊠ FibonacciAnyon"]
1212
const DEFAULT_SECTORNAMES = try
1313
if ENV["CI"] == "true"
1414
println("Detected CI environment")
1515
if Sys.iswindows()
1616
["Trivial", "Z2Irrep", "FermionParity", "Z3Irrep", "U1Irrep",
1717
"FermionNumber", "CU1Irrep", "SU2Irrep"]
1818
elseif Sys.isapple()
19-
["Trivial", "Z2Irrep", "FermionParity", "Z3Irrep", "FermionNumber", "FermionSpin"]
19+
["Trivial", "Z2Irrep", "FermionParity", "Z3Irrep", "FermionNumber",
20+
"FermionSpin"]
2021
else
21-
["Trivial", "Z2Irrep", "FermionParity", "U1Irrep", "CU1Irrep", "SU2Irrep", "FermionSpin"]
22+
["Trivial", "Z2Irrep", "FermionParity", "U1Irrep", "CU1Irrep", "SU2Irrep",
23+
"FermionSpin"]
2224
end
2325
else
2426
SECTORNAMES

test/fusiontrees.jl

+129-125
Large diffs are not rendered by default.

test/planar.jl

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ println("------------------------------------")
22
println("Planar")
33
println("------------------------------------")
44

5-
using TensorKit: planaradd!, planartrace!, planarcontract!, BraidingTensor, SymmetricBraiding
5+
using TensorKit: planaradd!, planartrace!, planarcontract!, BraidingTensor,
6+
SymmetricBraiding
67
using TensorOperations
78

89
@testset "$(TensorKit.type_repr(I))" verbose = true for I in sectorlist
@@ -52,7 +53,7 @@ using TensorOperations
5253
planarcontract!(C′, A′, pA, B′, pB, pAB, true, true)
5354
end
5455
end
55-
56+
5657
@testset "BraidingTensor conversion" begin
5758
for (V1, V2) in [(V1, V1), (V1', V1), (V1, V1'), (V1', V1')]
5859
τ = BraidingTensor(V1, V2)
@@ -72,7 +73,7 @@ using TensorOperations
7273
end
7374
end
7475
end
75-
76+
7677
t = TensorMap(randn, V1 * V1' * V1' * V1, V1 * V1')
7778

7879
ττ = copy(BraidingTensor(V1, V1'))
@@ -312,4 +313,4 @@ end
312313
end
313314
@test C C′
314315
end
315-
end
316+
end

test/spaces.jl

+46-46
Original file line numberDiff line numberDiff line change
@@ -87,56 +87,56 @@ end
8787
@test @constinferred(supremum(V', ℝ^3)) ==^3
8888
end
8989

90-
@timedtestset "ElementarySpace: ComplexSpace" begin
91-
d = 2
92-
V =^d
93-
@test eval(Meta.parse(sprint(show, V))) == V
94-
@test eval(Meta.parse(sprint(show, V'))) == V'
95-
@test eval(Meta.parse(sprint(show, typeof(V)))) == typeof(V)
96-
@test isa(V, VectorSpace)
97-
@test isa(V, ElementarySpace)
98-
@test isa(InnerProductStyle(V), HasInnerProduct)
99-
@test isa(InnerProductStyle(V), EuclideanProduct)
100-
@test isa(V, ComplexSpace)
101-
@test !isdual(V)
102-
@test isdual(V')
103-
@test V == ComplexSpace(Trivial() => d) == ComplexSpace(Dict(Trivial() => d))
104-
@test @constinferred(hash(V)) == hash(deepcopy(V)) != hash(V')
105-
@test @constinferred(dual(V)) == @constinferred(conj(V)) ==
106-
@constinferred(adjoint(V)) != V
107-
@test @constinferred(field(V)) ==
108-
@test @constinferred(sectortype(V)) == Trivial
109-
@test @constinferred(sectortype(V)) == Trivial
110-
@test ((@constinferred sectors(V))...,) == (Trivial(),)
111-
@test length(sectors(V)) == 1
112-
@test @constinferred(TensorKit.hassector(V, Trivial()))
113-
@test @constinferred(dim(V)) == d == @constinferred(dim(V, Trivial()))
114-
@test dim(@constinferred(typeof(V)())) == 0
115-
@test (sectors(typeof(V)())...,) == ()
116-
@test @constinferred(TensorKit.axes(V)) == Base.OneTo(d)
117-
@test^d == Vect[Trivial](d) == Vect[](Trivial() => d) == ℂ[](d) == typeof(V)(d)
118-
W = @constinferred^1
119-
@test @constinferred(oneunit(V)) == W == oneunit(typeof(V))
120-
@test @constinferred((V, V)) ==^(2d)
121-
@test_throws SpaceMismatch ((V, V'))
90+
@timedtestset "ElementarySpace: ComplexSpace" begin
91+
d = 2
92+
V =^d
93+
@test eval(Meta.parse(sprint(show, V))) == V
94+
@test eval(Meta.parse(sprint(show, V'))) == V'
95+
@test eval(Meta.parse(sprint(show, typeof(V)))) == typeof(V)
96+
@test isa(V, VectorSpace)
97+
@test isa(V, ElementarySpace)
98+
@test isa(InnerProductStyle(V), HasInnerProduct)
99+
@test isa(InnerProductStyle(V), EuclideanProduct)
100+
@test isa(V, ComplexSpace)
101+
@test !isdual(V)
102+
@test isdual(V')
103+
@test V == ComplexSpace(Trivial() => d) == ComplexSpace(Dict(Trivial() => d))
104+
@test @constinferred(hash(V)) == hash(deepcopy(V)) != hash(V')
105+
@test @constinferred(dual(V)) == @constinferred(conj(V)) ==
106+
@constinferred(adjoint(V)) != V
107+
@test @constinferred(field(V)) ==
108+
@test @constinferred(sectortype(V)) == Trivial
109+
@test @constinferred(sectortype(V)) == Trivial
110+
@test ((@constinferred sectors(V))...,) == (Trivial(),)
111+
@test length(sectors(V)) == 1
112+
@test @constinferred(TensorKit.hassector(V, Trivial()))
113+
@test @constinferred(dim(V)) == d == @constinferred(dim(V, Trivial()))
114+
@test dim(@constinferred(typeof(V)())) == 0
115+
@test (sectors(typeof(V)())...,) == ()
116+
@test @constinferred(TensorKit.axes(V)) == Base.OneTo(d)
117+
@test^d == Vect[Trivial](d) == Vect[](Trivial() => d) == ℂ[](d) == typeof(V)(d)
118+
W = @constinferred^1
119+
@test @constinferred(oneunit(V)) == W == oneunit(typeof(V))
120+
@test @constinferred((V, V)) ==^(2d)
121+
@test_throws SpaceMismatch ((V, V'))
122122
promote_except = ErrorException("promotion of types $(typeof(ℝ^d)) and " *
123123
"$(typeof(ℂ^d)) failed to change any arguments")
124124
@test_throws promote_except ((ℝ^d, ℂ^d))
125125
@test_throws promote_except ((ℝ^d, ℂ^d))
126-
@test @constinferred((V, V)) ==^(2d)
127-
@test @constinferred((V, oneunit(V))) ==^(d + 1)
128-
@test @constinferred((V, V, V, V)) ==^(4d)
129-
@test @constinferred(fuse(V, V)) ==^(d^2)
130-
@test @constinferred(fuse(V, V', V, V')) ==^(d^4)
131-
@test @constinferred(flip(V)) == V'
132-
@test flip(V) V
133-
@test flip(V) V
134-
@test flip(V) V
135-
@test V (V, V)
136-
@test !(V (V, V))
137-
@test @constinferred(infimum(V, ℂ^3)) == V
138-
@test @constinferred(supremum(V', (ℂ^3)')) == dual(ℂ^3) == conj(ℂ^3)
139-
end
126+
@test @constinferred((V, V)) ==^(2d)
127+
@test @constinferred((V, oneunit(V))) ==^(d + 1)
128+
@test @constinferred((V, V, V, V)) ==^(4d)
129+
@test @constinferred(fuse(V, V)) ==^(d^2)
130+
@test @constinferred(fuse(V, V', V, V')) ==^(d^4)
131+
@test @constinferred(flip(V)) == V'
132+
@test flip(V) V
133+
@test flip(V) V
134+
@test flip(V) V
135+
@test V (V, V)
136+
@test !(V (V, V))
137+
@test @constinferred(infimum(V, ℂ^3)) == V
138+
@test @constinferred(supremum(V', (ℂ^3)')) == dual(ℂ^3) == conj(ℂ^3)
139+
end
140140

141141
@testset "GeneralSpace" begin
142142
d = 2

test/tensors.jl

+56-56
Original file line numberDiff line numberDiff line change
@@ -379,67 +379,67 @@ end
379379
end
380380
end
381381

382-
t = Tensor(rand, T, V1 V1' V2 V2')
383-
@testset "eig and isposdef" begin
384-
D, V = eigen(t, ((1, 3), (2, 4)))
385-
t2 = permute(t, ((1, 3), (2, 4)))
386-
@test t2 * V V * D
387-
@test !isposdef(t2) # unlikely for non-hermitian map
388-
t2 = (t2 + t2')
389-
D, V = eigen(t2)
390-
VdV = V' * V
391-
@test VdV one(VdV)
392-
D̃, Ṽ = @constinferred eigh(t2)
393-
@test D
394-
@test V
395-
λ = minimum(minimum(real(LinearAlgebra.diag(b)))
396-
for (c, b) in blocks(D))
397-
@test isposdef(t2) == isposdef(λ)
398-
@test isposdef(t2 - λ * one(t2) + 0.1 * one(t2))
399-
@test !isposdef(t2 - λ * one(t2) - 0.1 * one(t2))
400-
end
382+
t = Tensor(rand, T, V1 V1' V2 V2')
383+
@testset "eig and isposdef" begin
384+
D, V = eigen(t, ((1, 3), (2, 4)))
385+
t2 = permute(t, ((1, 3), (2, 4)))
386+
@test t2 * V V * D
387+
@test !isposdef(t2) # unlikely for non-hermitian map
388+
t2 = (t2 + t2')
389+
D, V = eigen(t2)
390+
VdV = V' * V
391+
@test VdV one(VdV)
392+
D̃, Ṽ = @constinferred eigh(t2)
393+
@test D
394+
@test V
395+
λ = minimum(minimum(real(LinearAlgebra.diag(b)))
396+
for (c, b) in blocks(D))
397+
@test isposdef(t2) == isposdef(λ)
398+
@test isposdef(t2 - λ * one(t2) + 0.1 * one(t2))
399+
@test !isposdef(t2 - λ * one(t2) - 0.1 * one(t2))
401400
end
402401
end
403-
@timedtestset "Tensor truncation" begin
404-
for T in (Float32, ComplexF64)
405-
for p in (1, 2, 3, Inf)
406-
# Test both a normal tensor and an adjoint one.
407-
ts = (TensorMap(randn, T, V1 V2 V3, V4 V5),
408-
TensorMap(randn, T, V4 V5, V1 V2 V3)')
409-
for t in ts
410-
U₀, S₀, V₀, = tsvd(t)
411-
t = rmul!(t, 1 / norm(S₀, p))
412-
U, S, V, ϵ = @constinferred tsvd(t; trunc=truncerr(5e-1), p=p)
413-
# @show p, ϵ
414-
# @show domain(S)
415-
# @test min(space(S,1), space(S₀,1)) != space(S₀,1)
416-
U′, S′, V′, ϵ′ = tsvd(t; trunc=truncerr(nextfloat(ϵ)), p=p)
417-
@test (U, S, V, ϵ) == (U′, S′, V′, ϵ′)
418-
U′, S, V, ϵ= tsvd(t; trunc=truncdim(ceil(Int, dim(domain(S)))),
419-
p=p)
420-
@test (U, S, V, ϵ) == (U′, S′, V′, ϵ′)
421-
U′, S, V, ϵ= tsvd(t; trunc=truncspace(space(S, 1)), p=p)
422-
@test (U, S, V, ϵ) == (U′, S′, V′, ϵ′)
423-
# results with truncationcutoff cannot be compared because they don't take degeneracy into account, and thus truncate differently
424-
U, S, V, ϵ = tsvd(t; trunc=truncbelow(1 / dim(domain(S₀))), p=p)
425-
# @show p, ϵ
426-
# @show domain(S)
427-
# @test min(space(S,1), space(S₀,1)) != space(S₀,1)
428-
U′, S′, V′, ϵ′ = tsvd(t; trunc=truncspace(space(S, 1)), p=p)
429-
@test (U, S, V, ϵ) == (U′, S′, V′, ϵ′)
430-
end
402+
end
403+
@timedtestset "Tensor truncation" begin
404+
for T in (Float32, ComplexF64)
405+
for p in (1, 2, 3, Inf)
406+
# Test both a normal tensor and an adjoint one.
407+
ts = (TensorMap(randn, T, V1 V2 V3, V4 V5),
408+
TensorMap(randn, T, V4 V5, V1 V2 V3)')
409+
for t in ts
410+
U₀, S₀, V₀, = tsvd(t)
411+
t = rmul!(t, 1 / norm(S₀, p))
412+
U, S, V, ϵ = @constinferred tsvd(t; trunc=truncerr(5e-1), p=p)
413+
# @show p, ϵ
414+
# @show domain(S)
415+
# @test min(space(S,1), space(S₀,1)) != space(S₀,1)
416+
U′, S, V, ϵ= tsvd(t; trunc=truncerr(nextfloat(ϵ)), p=p)
417+
@test (U, S, V, ϵ) == (U′, S′, V′, ϵ′)
418+
U′, S′, V′, ϵ′ = tsvd(t; trunc=truncdim(ceil(Int, dim(domain(S)))),
419+
p=p)
420+
@test (U, S, V, ϵ) == (U′, S′, V′, ϵ′)
421+
U′, S, V, ϵ= tsvd(t; trunc=truncspace(space(S, 1)), p=p)
422+
@test (U, S, V, ϵ) == (U′, S′, V′, ϵ′)
423+
# results with truncationcutoff cannot be compared because they don't take degeneracy into account, and thus truncate differently
424+
U, S, V, ϵ = tsvd(t; trunc=truncbelow(1 / dim(domain(S₀))), p=p)
425+
# @show p, ϵ
426+
# @show domain(S)
427+
# @test min(space(S,1), space(S₀,1)) != space(S₀,1)
428+
U′, S, V, ϵ= tsvd(t; trunc=truncspace(space(S, 1)), p=p)
429+
@test (U, S, V, ϵ) == (U′, S′, V′, ϵ′)
431430
end
432431
end
433432
end
434-
if hasfusiontensor(I)
435-
@timedtestset "Tensor functions" begin
436-
W = V1 V2
437-
for T in (Float64, ComplexF64)
438-
t = TensorMap(randn, T, W, W)
439-
s = dim(W)
440-
expt = @constinferred exp(t)
441-
@test reshape(convert(Array, expt), (s, s))
442-
exp(reshape(convert(Array, t), (s, s)))
433+
end
434+
if hasfusiontensor(I)
435+
@timedtestset "Tensor functions" begin
436+
W = V1 V2
437+
for T in (Float64, ComplexF64)
438+
t = TensorMap(randn, T, W, W)
439+
s = dim(W)
440+
expt = @constinferred exp(t)
441+
@test reshape(convert(Array, expt), (s, s))
442+
exp(reshape(convert(Array, t), (s, s)))
443443

444444
@test (@constinferred sqrt(t))^2 t
445445
@test reshape(convert(Array, sqrt(t^2)), (s, s))

test/utility.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,4 @@ function force_planar(tsrc::TensorMap{<:GradedSpace})
145145
copyto!(blocks(tdst)[c PlanarTrivial()], b)
146146
end
147147
return tdst
148-
end
148+
end

0 commit comments

Comments
 (0)