Skip to content

Commit f9d7665

Browse files
committed
separate tests into groups
1 parent 2d90cc1 commit f9d7665

13 files changed

Lines changed: 742 additions & 347 deletions

File tree

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

0 commit comments

Comments
 (0)