Skip to content

Commit 6806fef

Browse files
authored
test: only run Core tests upon pkg> test (#659)
1 parent c20083f commit 6806fef

7 files changed

Lines changed: 148 additions & 135 deletions

File tree

DifferentiationInterface/Project.toml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,21 @@ Tracker = "9f7883ad-71c0-57eb-9f7f-b5c9e6d3789c"
103103
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
104104

105105
[targets]
106-
test = ["ADTypes", "Aqua", "ComponentArrays", "DataFrames", "ExplicitImports", "ForwardDiff", "JET", "JLArrays", "JuliaFormatter", "Pkg", "Random", "SparseArrays", "SparseConnectivityTracer", "SparseMatrixColorings", "StableRNGs", "StaticArrays", "Test", "Zygote"]
106+
test = [
107+
"ADTypes",
108+
"Aqua",
109+
"ComponentArrays",
110+
"DataFrames",
111+
"ExplicitImports",
112+
"JET",
113+
"JLArrays",
114+
"JuliaFormatter",
115+
"Pkg",
116+
"Random",
117+
"SparseArrays",
118+
"SparseConnectivityTracer",
119+
"SparseMatrixColorings",
120+
"StableRNGs",
121+
"StaticArrays",
122+
"Test",
123+
]

DifferentiationInterface/test/Core/Internals/backends.jl

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ using ADTypes
22
using ADTypes: mode
33
using DifferentiationInterface
44
using DifferentiationInterface:
5+
AutoSimpleFiniteDiff,
6+
AutoReverseFromPrimitive,
57
inner,
68
outer,
79
forward_backend,
@@ -11,39 +13,38 @@ using DifferentiationInterface:
1113
pullback_performance,
1214
hvp_mode
1315
import DifferentiationInterface as DI
14-
using ForwardDiff: ForwardDiff
15-
using Zygote: Zygote
1616
using Test
1717

18+
fb = AutoSimpleFiniteDiff()
19+
rb = AutoReverseFromPrimitive(AutoSimpleFiniteDiff())
20+
1821
@testset "SecondOrder" begin
19-
backend = SecondOrder(AutoForwardDiff(), AutoZygote())
20-
@test ADTypes.mode(backend) isa ADTypes.ForwardMode
21-
@test outer(backend) isa AutoForwardDiff
22-
@test inner(backend) isa AutoZygote
22+
backend = SecondOrder(fb, rb)
23+
@test check_available(backend)
24+
@test outer(backend) isa AutoSimpleFiniteDiff
25+
@test inner(backend) isa AutoReverseFromPrimitive
2326
@test mode(backend) isa ADTypes.ForwardMode
24-
@test !Bool(inplace_support(backend))
27+
@test Bool(inplace_support(backend))
2528
@test_throws ArgumentError pushforward_performance(backend)
2629
@test_throws ArgumentError pullback_performance(backend)
27-
@test check_available(backend)
2830
end
2931

3032
@testset "MixedMode" begin
31-
backend = MixedMode(AutoForwardDiff(), AutoZygote())
32-
@test ADTypes.mode(backend) isa DifferentiationInterface.ForwardAndReverseMode
33-
@test forward_backend(backend) isa AutoForwardDiff
34-
@test reverse_backend(backend) isa AutoZygote
35-
@test !Bool(inplace_support(backend))
33+
backend = MixedMode(fb, rb)
34+
@test check_available(backend)
35+
@test mode(backend) isa DifferentiationInterface.ForwardAndReverseMode
36+
@test forward_backend(backend) isa AutoSimpleFiniteDiff
37+
@test reverse_backend(backend) isa AutoReverseFromPrimitive
38+
@test Bool(inplace_support(backend))
3639
@test_throws MethodError pushforward_performance(backend)
3740
@test_throws MethodError pullback_performance(backend)
38-
@test check_available(backend)
3941
end
4042

4143
@testset "Sparse" begin
42-
for dense_backend in [AutoForwardDiff(), AutoZygote()]
44+
for dense_backend in [fb, rb]
4345
backend = AutoSparse(dense_backend)
44-
@test ADTypes.mode(backend) == ADTypes.mode(dense_backend)
45-
@test check_available(backend) == check_available(dense_backend)
46-
@test inplace_support(backend) == inplace_support(dense_backend)
46+
@test mode(backend) == ADTypes.mode(dense_backend)
47+
@test Bool(inplace_support(backend))
4748
@test_throws ArgumentError pushforward_performance(backend)
4849
@test_throws ArgumentError pullback_performance(backend)
4950
@test_throws ArgumentError hvp_mode(backend)

DifferentiationInterface/test/Core/Internals/display.jl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@ using DifferentiationInterface
33
using Test
44

55
backend = SecondOrder(AutoForwardDiff(), AutoZygote())
6-
@test startswith(string(backend), "SecondOrder(")
7-
@test endswith(string(backend), ")")
6+
@test string(backend) == "SecondOrder(AutoForwardDiff(), AutoZygote())"
87

98
detector = DenseSparsityDetector(AutoForwardDiff(); atol=1e-23)
10-
@test startswith(string(detector), "DenseSparsityDetector(")
11-
@test endswith(string(detector), ")")
9+
@test string(detector) ==
10+
"DenseSparsityDetector(AutoForwardDiff(); atol=1.0e-23, method=:iterative)"
1211

1312
diffwith = DifferentiateWith(exp, AutoForwardDiff())
14-
@test startswith(string(diffwith), "DifferentiateWith(")
15-
@test endswith(string(diffwith), ")")
13+
@test string(diffwith) == "DifferentiateWith(exp, AutoForwardDiff())"
1614

1715
@test DifferentiationInterface.package_name(AutoForwardDiff()) == "ForwardDiff"
1816
@test DifferentiationInterface.package_name(AutoZygote()) == "Zygote"

DifferentiationInterface/test/Core/SimpleFiniteDiff/test.jl

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -35,44 +35,44 @@ end
3535

3636
## Dense scenarios
3737

38-
test_differentiation(
39-
vcat(backends, second_order_backends),
40-
default_scenarios(; include_constantified=true);
41-
logging=LOGGING,
42-
);
43-
44-
## Sparse scenarios
45-
46-
test_differentiation(
47-
MyAutoSparse.(adaptive_backends),
48-
default_scenarios(; include_constantified=true);
49-
logging=LOGGING,
50-
);
51-
52-
test_differentiation(
53-
MyAutoSparse.(
54-
vcat(adaptive_backends, MixedMode(adaptive_backends[1], adaptive_backends[2]))
55-
),
56-
sparse_scenarios(; include_constantified=true);
57-
sparsity=true,
58-
logging=LOGGING,
59-
);
38+
@testset "Dense" begin
39+
test_differentiation(
40+
vcat(backends, second_order_backends),
41+
default_scenarios(; include_constantified=true);
42+
logging=LOGGING,
43+
)
44+
end
6045

61-
## Misc
46+
@testset "Sparse" begin
47+
test_differentiation(
48+
MyAutoSparse.(adaptive_backends),
49+
default_scenarios(; include_constantified=true);
50+
logging=LOGGING,
51+
)
6252

63-
@testset "SparseMatrixColorings access" begin
64-
jac_for_prep = prepare_jacobian(copy, MyAutoSparse(adaptive_backends[1]), rand(10))
65-
jac_rev_prep = prepare_jacobian(copy, MyAutoSparse(adaptive_backends[2]), rand(10))
66-
hess_prep = prepare_hessian(
67-
x -> sum(abs2, x), MyAutoSparse(adaptive_backends[1]), rand(10)
53+
test_differentiation(
54+
MyAutoSparse.(
55+
vcat(adaptive_backends, MixedMode(adaptive_backends[1], adaptive_backends[2]))
56+
),
57+
sparse_scenarios(; include_constantified=true);
58+
sparsity=true,
59+
logging=LOGGING,
6860
)
6961

70-
@test all(==(1), column_colors(jac_for_prep))
71-
@test all(==(1), row_colors(jac_rev_prep))
72-
@test all(==(1), column_colors(hess_prep))
73-
@test ncolors(jac_for_prep) == 1
74-
@test ncolors(hess_prep) == 1
75-
@test only(column_groups(jac_for_prep)) == 1:10
76-
@test only(row_groups(jac_rev_prep)) == 1:10
77-
@test only(column_groups(hess_prep)) == 1:10
62+
@testset "SparseMatrixColorings access" begin
63+
jac_for_prep = prepare_jacobian(copy, MyAutoSparse(adaptive_backends[1]), rand(10))
64+
jac_rev_prep = prepare_jacobian(copy, MyAutoSparse(adaptive_backends[2]), rand(10))
65+
hess_prep = prepare_hessian(
66+
x -> sum(abs2, x), MyAutoSparse(adaptive_backends[1]), rand(10)
67+
)
68+
69+
@test all(==(1), column_colors(jac_for_prep))
70+
@test all(==(1), row_colors(jac_rev_prep))
71+
@test all(==(1), column_colors(hess_prep))
72+
@test ncolors(jac_for_prep) == 1
73+
@test ncolors(hess_prep) == 1
74+
@test only(column_groups(jac_for_prep)) == 1:10
75+
@test only(row_groups(jac_rev_prep)) == 1:10
76+
@test only(column_groups(hess_prep)) == 1:10
77+
end
7878
end

DifferentiationInterface/test/Core/ZeroBackends/test.jl

Lines changed: 44 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -16,56 +16,51 @@ for backend in zero_backends
1616
@test check_inplace(backend)
1717
end
1818

19-
## Type stability
19+
@testset "Type stability" begin
20+
test_differentiation(
21+
AutoZeroForward(),
22+
default_scenarios(; include_batchified=false, include_constantified=true);
23+
correctness=false,
24+
type_stability=:full,
25+
logging=LOGGING,
26+
)
2027

21-
test_differentiation(
22-
AutoZeroForward(),
23-
default_scenarios(; include_batchified=false, include_constantified=true);
24-
correctness=false,
25-
type_stability=:full,
26-
logging=LOGGING,
27-
)
28+
test_differentiation(
29+
AutoZeroReverse(),
30+
default_scenarios(; include_batchified=false, include_constantified=true);
31+
correctness=false,
32+
type_stability=:full,
33+
logging=LOGGING,
34+
)
2835

29-
test_differentiation(
30-
AutoZeroReverse(),
31-
default_scenarios(; include_batchified=false, include_constantified=true);
32-
correctness=false,
33-
type_stability=:full,
34-
logging=LOGGING,
35-
)
36+
test_differentiation(
37+
[
38+
SecondOrder(AutoZeroForward(), AutoZeroReverse()),
39+
SecondOrder(AutoZeroReverse(), AutoZeroForward()),
40+
],
41+
default_scenarios(; include_batchified=false, include_constantified=true);
42+
correctness=false,
43+
type_stability=:full,
44+
logging=LOGGING,
45+
)
3646

37-
test_differentiation(
38-
[
39-
SecondOrder(AutoZeroForward(), AutoZeroReverse()),
40-
SecondOrder(AutoZeroReverse(), AutoZeroForward()),
41-
],
42-
default_scenarios(; include_batchified=false, include_constantified=true);
43-
correctness=false,
44-
type_stability=:full,
45-
logging=LOGGING,
46-
)
47-
48-
test_differentiation(
49-
AutoSparse.(zero_backends, coloring_algorithm=GreedyColoringAlgorithm()),
50-
default_scenarios(; include_constantified=true);
51-
correctness=false,
52-
type_stability=:full,
53-
excluded=[:pushforward, :pullback, :gradient, :derivative, :hvp, :second_derivative],
54-
logging=LOGGING,
55-
)
56-
57-
## Weird arrays
58-
59-
test_differentiation(
60-
[AutoZeroForward(), AutoZeroReverse()],
61-
zero.(vcat(component_scenarios(), static_scenarios()));
62-
correctness=true,
63-
logging=LOGGING,
64-
)
47+
test_differentiation(
48+
AutoSparse.(zero_backends, coloring_algorithm=GreedyColoringAlgorithm()),
49+
default_scenarios(; include_constantified=true);
50+
correctness=false,
51+
type_stability=:full,
52+
excluded=[
53+
:pushforward, :pullback, :gradient, :derivative, :hvp, :second_derivative
54+
],
55+
logging=LOGGING,
56+
)
57+
end
6558

66-
test_differentiation(
67-
[AutoZeroForward(), AutoZeroReverse()],
68-
zero.(gpu_scenarios());
69-
correctness=true,
70-
logging=LOGGING,
71-
)
59+
@testset "Weird arrays" begin
60+
test_differentiation(
61+
[AutoZeroForward(), AutoZeroReverse()],
62+
zero.(vcat(component_scenarios(), static_scenarios(), gpu_scenarios()));
63+
correctness=true,
64+
logging=LOGGING,
65+
)
66+
end

DifferentiationInterface/test/runtests.jl

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
using DifferentiationInterface
22
using Pkg
33
using Test
4-
using SparseMatrixColorings, SparseConnectivityTracer
5-
6-
function MyAutoSparse(backend)
7-
return AutoSparse(
8-
backend;
9-
sparsity_detector=TracerSparsityDetector(),
10-
coloring_algorithm=GreedyColoringAlgorithm(),
11-
)
12-
end
134

145
DIT_PATH = joinpath(@__DIR__, "..", "..", "DifferentiationInterfaceTest")
156
if isdir(DIT_PATH)
@@ -18,36 +9,36 @@ else
189
Pkg.add("DifferentiationInterfaceTest")
1910
end
2011

21-
GROUP = get(ENV, "JULIA_DI_TEST_GROUP", "All")
12+
include("testutils.jl")
2213

2314
## Main tests
2415

2516
@testset verbose = true "DifferentiationInterface.jl" begin
26-
if GROUP == "All"
27-
@testset verbose = true for category in readdir(@__DIR__)
28-
isdir(joinpath(@__DIR__, category)) || continue
29-
@testset verbose = true for folder in readdir(joinpath(@__DIR__, category))
30-
isdir(joinpath(@__DIR__, category, folder)) || continue
17+
if haskey(ENV, "JULIA_DI_TEST_GROUP")
18+
category, folder = split(ENV["JULIA_DI_TEST_GROUP"], '/')
19+
@testset verbose = true "$category" begin
20+
@testset verbose = true "$folder" begin
3121
@testset verbose = true "$file" for file in readdir(
3222
joinpath(@__DIR__, category, folder)
3323
)
3424
endswith(file, ".jl") || continue
3525
@info "Testing $category/$folder/$file"
3626
include(joinpath(@__DIR__, category, folder, file))
27+
yield()
3728
end
3829
end
3930
end
4031
else
41-
category, folder = split(GROUP, '/')
42-
@testset verbose = true "$category" begin
43-
@testset verbose = true "$folder" begin
44-
@testset verbose = true "$file" for file in readdir(
45-
joinpath(@__DIR__, category, folder)
46-
)
47-
endswith(file, ".jl") || continue
48-
@info "Testing $category/$folder/$file"
49-
include(joinpath(@__DIR__, category, folder, file))
50-
end
32+
category = "Core"
33+
@testset verbose = true for folder in readdir(joinpath(@__DIR__, category))
34+
isdir(joinpath(@__DIR__, category, folder)) || continue
35+
@testset verbose = true "$file" for file in readdir(
36+
joinpath(@__DIR__, category, folder)
37+
)
38+
endswith(file, ".jl") || continue
39+
@info "Testing $category/$folder/$file"
40+
include(joinpath(@__DIR__, category, folder, file))
41+
yield()
5142
end
5243
end
5344
end
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using ADTypes
2+
using SparseConnectivityTracer
3+
using SparseMatrixColorings
4+
5+
function MyAutoSparse(backend::AbstractADType)
6+
return AutoSparse(
7+
backend;
8+
sparsity_detector=TracerSparsityDetector(),
9+
coloring_algorithm=GreedyColoringAlgorithm(),
10+
)
11+
end

0 commit comments

Comments
 (0)