Skip to content

Commit 8915f3f

Browse files
committed
separate tests into groups
1 parent 2aae89f commit 8915f3f

File tree

14 files changed

+739
-783
lines changed

14 files changed

+739
-783
lines changed

test/ad.jl renamed to test/autodiff/ad.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
using Test, TestExtras
2+
using TensorKit
3+
using TensorOperations
14
using ChainRulesCore
25
using ChainRulesTestUtils
36
using FiniteDifferences: FiniteDifferences, central_fdm, forward_fdm

test/braidingtensor.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# TODO: Make into proper tests and integrate in testset
2+
# note: this is not part of the testsuite!
23

34
import TensorKit: BraidingTensor
45

test/bugfixes.jl

Lines changed: 0 additions & 83 deletions
This file was deleted.

test/other/aqua.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
using Aqua
2+
Aqua.test_all(TensorKit)

test/other/bugfixes.jl

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
using Test, TestExtras
2+
using TensorKit
3+
using TensorOperations
4+
using LinearAlgebra: LinearAlgebra
5+
using Zygote
6+
7+
@testset "BugfixConvert" begin
8+
v = randn(
9+
ComplexF64,
10+
(
11+
Vect[(Irrep[U₁] Irrep[SU₂] FermionParity)](
12+
(-3, 1 / 2, 1) => 3, (-5, 1 / 2, 1) => 10, (-7, 1 / 2, 1) => 13,
13+
(-9, 1 / 2, 1) => 9, (-11, 1 / 2, 1) => 1, (-5, 3 / 2, 1) => 3,
14+
(-7, 3 / 2, 1) => 3, (-9, 3 / 2, 1) => 1
15+
) Vect[(Irrep[U₁] Irrep[SU₂] FermionParity)]((1, 1 / 2, 1) => 1)'
16+
) Vect[(Irrep[U₁] Irrep[SU₂] FermionParity)](
17+
(-3, 1 / 2, 1) => 3, (-5, 1 / 2, 1) => 10, (-7, 1 / 2, 1) => 13,
18+
(-9, 1 / 2, 1) => 9, (-11, 1 / 2, 1) => 1, (-5, 3 / 2, 1) => 3,
19+
(-7, 3 / 2, 1) => 3, (-9, 3 / 2, 1) => 1
20+
)
21+
)
22+
w = convert(typeof(real(v)), v)
23+
@test w == v
24+
@test scalartype(w) == Float64
25+
end
26+
27+
# https://github.com/quantumkithub/TensorKit.jl/issues/178
28+
@testset "Issue #178" begin
29+
t = rand(U1Space(1 => 1) U1Space(1 => 1)')
30+
a = convert(Array, t)
31+
@test a == zeros(size(a))
32+
end
33+
34+
# https://github.com/quantumkithub/TensorKit.jl/issues/194
35+
@testset "Issue #194" begin
36+
t1 = rand(ℂ^4 ^4)
37+
t2 = tensoralloc(typeof(t1), space(t1), Val(true), TensorOperations.ManualAllocator())
38+
t3 = similar(t2, ComplexF64, space(t1))
39+
@test storagetype(t3) == Vector{ComplexF64}
40+
t4 = similar(t2, domain(t1))
41+
@test storagetype(t4) == Vector{Float64}
42+
t5 = similar(t2)
43+
@test storagetype(t5) == Vector{Float64}
44+
tensorfree!(t2)
45+
end
46+
47+
# https://github.com/quantumkithub/TensorKit.jl/issues/201
48+
@testset "Issue #201" begin
49+
function f(A::AbstractTensorMap)
50+
U, S, V, = svd_compact(A)
51+
return tr(S)
52+
end
53+
function f(A::AbstractMatrix)
54+
S = LinearAlgebra.svdvals(A)
55+
return sum(S)
56+
end
57+
A₀ = randn(Z2Space(4, 4) Z2Space(4, 4))
58+
grad1, = Zygote.gradient(f, A₀)
59+
grad2, = Zygote.gradient(f, convert(Array, A₀))
60+
@test convert(Array, grad1) grad2
61+
62+
function g(A::AbstractTensorMap)
63+
U, S, V, = svd_compact(A)
64+
return tr(U * V)
65+
end
66+
function g(A::AbstractMatrix)
67+
U, S, V, = LinearAlgebra.svd(A)
68+
return tr(U * V')
69+
end
70+
B₀ = randn(ComplexSpace(4) ← ComplexSpace(4))
71+
grad3, = Zygote.gradient(g, B₀)
72+
grad4, = Zygote.gradient(g, convert(Array, B₀))
73+
@test convert(Array, grad3) ≈ grad4
74+
end
75+
76+
# https://github.com/quantumkithub/TensorKit.jl/issues/209
77+
@testset "Issue #209" begin
78+
function f(T, D)
79+
@tensor T[1, 4, 1, 3] * D[3, 4]
80+
end
81+
V = Z2Space(2, 2)
82+
D = DiagonalTensorMap(randn(4), V)
83+
T = randn(V ⊗ V ← V ⊗ V)
84+
g1, = Zygote.gradient(f, T, D)
85+
g2, = Zygote.gradient(f, T, TensorMap(D))
86+
@test g1 ≈ g2
87+
end

test/runtests.jl

Lines changed: 0 additions & 179 deletions
Original file line numberDiff line numberDiff line change
@@ -70,182 +70,3 @@ istestfile(fn) = endswith(fn, ".jl") && !contains(fn, "setup")
7070
end
7171
end
7272
end
73-
74-
75-
using Test
76-
using TestExtras
77-
using Random
78-
using TensorKit
79-
using Combinatorics
80-
using TensorKit: ProductSector, fusiontensor, pentagon_equation, hexagon_equation
81-
using TensorOperations
82-
using Base.Iterators: take, product
83-
# using SUNRepresentations: SUNIrrep
84-
# const SU3Irrep = SUNIrrep{3}
85-
using LinearAlgebra: LinearAlgebra
86-
using Zygote: Zygote
87-
88-
const TK = TensorKit
89-
90-
Random.seed!(1234)
91-
92-
# don't run all tests on GPU, only the GPU
93-
# specific ones
94-
is_buildkite = get(ENV, "BUILDKITE", "false") == "true"
95-
96-
smallset(::Type{I}) where {I <: Sector} = take(values(I), 5)
97-
function smallset(::Type{ProductSector{Tuple{I1, I2}}}) where {I1, I2}
98-
iter = product(smallset(I1), smallset(I2))
99-
s = collect(i j for (i, j) in iter if dim(i) * dim(j) <= 6)
100-
return length(s) > 6 ? rand(s, 6) : s
101-
end
102-
function smallset(::Type{ProductSector{Tuple{I1, I2, I3}}}) where {I1, I2, I3}
103-
iter = product(smallset(I1), smallset(I2), smallset(I3))
104-
s = collect(i j k for (i, j, k) in iter if dim(i) * dim(j) * dim(k) <= 6)
105-
return length(s) > 6 ? rand(s, 6) : s
106-
end
107-
function randsector(::Type{I}) where {I <: Sector}
108-
s = collect(smallset(I))
109-
a = rand(s)
110-
while a == one(a) # don't use trivial label
111-
a = rand(s)
112-
end
113-
return a
114-
end
115-
function hasfusiontensor(I::Type{<:Sector})
116-
try
117-
fusiontensor(one(I), one(I), one(I))
118-
return true
119-
catch e
120-
if e isa MethodError
121-
return false
122-
else
123-
rethrow(e)
124-
end
125-
end
126-
end
127-
128-
sectorlist = (
129-
Z2Irrep, Z3Irrep, Z4Irrep, Z3Irrep Z4Irrep,
130-
U1Irrep, CU1Irrep, SU2Irrep,
131-
FermionParity, FermionParity FermionParity,
132-
FermionParity U1Irrep SU2Irrep, FermionParity SU2Irrep SU2Irrep, # Hubbard-like
133-
FibonacciAnyon, IsingAnyon,
134-
Z2Irrep FibonacciAnyon FibonacciAnyon,
135-
)
136-
137-
# spaces
138-
Vtr = (ℂ^2, (ℂ^3)', ℂ^4, ℂ^3, (ℂ^2)')
139-
Vℤ₂ = (
140-
Vect[Z2Irrep](0 => 1, 1 => 1),
141-
Vect[Z2Irrep](0 => 1, 1 => 2)',
142-
Vect[Z2Irrep](0 => 3, 1 => 2)',
143-
Vect[Z2Irrep](0 => 2, 1 => 3),
144-
Vect[Z2Irrep](0 => 2, 1 => 5),
145-
)
146-
Vfℤ₂ = (
147-
Vect[FermionParity](0 => 1, 1 => 1),
148-
Vect[FermionParity](0 => 1, 1 => 2)',
149-
Vect[FermionParity](0 => 2, 1 => 1)',
150-
Vect[FermionParity](0 => 2, 1 => 3),
151-
Vect[FermionParity](0 => 2, 1 => 5),
152-
)
153-
Vℤ₃ = (
154-
Vect[Z3Irrep](0 => 1, 1 => 2, 2 => 1),
155-
Vect[Z3Irrep](0 => 2, 1 => 1, 2 => 1),
156-
Vect[Z3Irrep](0 => 1, 1 => 2, 2 => 1)',
157-
Vect[Z3Irrep](0 => 1, 1 => 2, 2 => 3),
158-
Vect[Z3Irrep](0 => 1, 1 => 3, 2 => 3)',
159-
)
160-
VU₁ = (
161-
Vect[U1Irrep](0 => 1, 1 => 2, -1 => 2),
162-
Vect[U1Irrep](0 => 3, 1 => 1, -1 => 1),
163-
Vect[U1Irrep](0 => 2, 1 => 2, -1 => 1)',
164-
Vect[U1Irrep](0 => 1, 1 => 2, -1 => 3),
165-
Vect[U1Irrep](0 => 1, 1 => 3, -1 => 3)',
166-
)
167-
VfU₁ = (
168-
Vect[FermionNumber](0 => 1, 1 => 2, -1 => 2),
169-
Vect[FermionNumber](0 => 3, 1 => 1, -1 => 1),
170-
Vect[FermionNumber](0 => 2, 1 => 2, -1 => 1)',
171-
Vect[FermionNumber](0 => 1, 1 => 2, -1 => 3),
172-
Vect[FermionNumber](0 => 1, 1 => 3, -1 => 3)',
173-
)
174-
VCU₁ = (
175-
Vect[CU1Irrep]((0, 0) => 1, (0, 1) => 2, 1 => 1),
176-
Vect[CU1Irrep]((0, 0) => 3, (0, 1) => 0, 1 => 1),
177-
Vect[CU1Irrep]((0, 0) => 1, (0, 1) => 0, 1 => 2)',
178-
Vect[CU1Irrep]((0, 0) => 2, (0, 1) => 2, 1 => 1),
179-
Vect[CU1Irrep]((0, 0) => 2, (0, 1) => 1, 1 => 2)',
180-
)
181-
VSU₂ = (
182-
Vect[SU2Irrep](0 => 3, 1 // 2 => 1),
183-
Vect[SU2Irrep](0 => 2, 1 => 1),
184-
Vect[SU2Irrep](1 // 2 => 1, 1 => 1)',
185-
Vect[SU2Irrep](0 => 2, 1 // 2 => 2),
186-
Vect[SU2Irrep](0 => 1, 1 // 2 => 1, 3 // 2 => 1)',
187-
)
188-
VfSU₂ = (
189-
Vect[FermionSpin](0 => 3, 1 // 2 => 1),
190-
Vect[FermionSpin](0 => 2, 1 => 1),
191-
Vect[FermionSpin](1 // 2 => 1, 1 => 1)',
192-
Vect[FermionSpin](0 => 2, 1 // 2 => 2),
193-
Vect[FermionSpin](0 => 1, 1 // 2 => 1, 3 // 2 => 1)',
194-
)
195-
VSU₂U₁ = (
196-
Vect[SU2Irrep U1Irrep]((0, 0) => 1, (1 // 2, -1) => 1),
197-
Vect[SU2Irrep U1Irrep](
198-
(0, 0) => 2, (0, 2) => 1, (1, 0) => 1, (1, -2) => 1,
199-
(1 // 2, -1) => 1
200-
),
201-
Vect[SU2Irrep U1Irrep]((1 // 2, 1) => 1, (1, -2) => 1)',
202-
Vect[SU2Irrep U1Irrep]((0, 0) => 2, (0, 2) => 1, (1 // 2, 1) => 1),
203-
Vect[SU2Irrep U1Irrep]((0, 0) => 1, (1 // 2, 1) => 1)',
204-
)
205-
Vfib = (
206-
Vect[FibonacciAnyon](:I => 1, :τ => 1),
207-
Vect[FibonacciAnyon](:I => 1, :τ => 2)',
208-
Vect[FibonacciAnyon](:I => 3, :τ => 2)',
209-
Vect[FibonacciAnyon](:I => 2, :τ => 3),
210-
Vect[FibonacciAnyon](:I => 2, :τ => 2),
211-
)
212-
213-
if !is_buildkite
214-
Ti = time()
215-
@time include("fusiontrees.jl")
216-
@time include("spaces.jl")
217-
@time include("tensors.jl")
218-
@time include("factorizations.jl")
219-
@time include("diagonal.jl")
220-
@time include("planar.jl")
221-
if !(Sys.isapple() && get(ENV, "CI", "false") == "true") && isempty(VERSION.prerelease)
222-
@time include("ad.jl")
223-
end
224-
@time include("bugfixes.jl")
225-
Tf = time()
226-
printstyled(
227-
"Finished all tests in ",
228-
string(round((Tf - Ti) / 60; sigdigits = 3)),
229-
" minutes."; bold = true, color = Base.info_color()
230-
)
231-
println()
232-
@testset "Aqua" verbose = true begin
233-
using Aqua
234-
Aqua.test_all(TensorKit)
235-
end
236-
else
237-
Ti = time()
238-
#=using CUDA
239-
if CUDA.functional()
240-
end
241-
using AMDGPU
242-
if AMDGPU.functional()
243-
end=#
244-
Tf = time()
245-
printstyled(
246-
"Finished all GPU tests in ",
247-
string(round((Tf - Ti) / 60; sigdigits = 3)),
248-
" minutes."; bold = true, color = Base.info_color()
249-
)
250-
println()
251-
end

0 commit comments

Comments
 (0)