Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: only run Core tests upon pkg> test #659

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion DifferentiationInterface/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,21 @@ Tracker = "9f7883ad-71c0-57eb-9f7f-b5c9e6d3789c"
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"

[targets]
test = ["ADTypes", "Aqua", "ComponentArrays", "DataFrames", "ExplicitImports", "ForwardDiff", "JET", "JLArrays", "JuliaFormatter", "Pkg", "Random", "SparseArrays", "SparseConnectivityTracer", "SparseMatrixColorings", "StableRNGs", "StaticArrays", "Test", "Zygote"]
test = [
"ADTypes",
"Aqua",
"ComponentArrays",
"DataFrames",
"ExplicitImports",
"JET",
"JLArrays",
"JuliaFormatter",
"Pkg",
"Random",
"SparseArrays",
"SparseConnectivityTracer",
"SparseMatrixColorings",
"StableRNGs",
"StaticArrays",
"Test",
]
37 changes: 19 additions & 18 deletions DifferentiationInterface/test/Core/Internals/backends.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ using ADTypes
using ADTypes: mode
using DifferentiationInterface
using DifferentiationInterface:
AutoSimpleFiniteDiff,
AutoReverseFromPrimitive,
inner,
outer,
forward_backend,
Expand All @@ -11,39 +13,38 @@ using DifferentiationInterface:
pullback_performance,
hvp_mode
import DifferentiationInterface as DI
using ForwardDiff: ForwardDiff
using Zygote: Zygote
using Test

fb = AutoSimpleFiniteDiff()
rb = AutoReverseFromPrimitive(AutoSimpleFiniteDiff())

@testset "SecondOrder" begin
backend = SecondOrder(AutoForwardDiff(), AutoZygote())
@test ADTypes.mode(backend) isa ADTypes.ForwardMode
@test outer(backend) isa AutoForwardDiff
@test inner(backend) isa AutoZygote
backend = SecondOrder(fb, rb)
@test check_available(backend)
@test outer(backend) isa AutoSimpleFiniteDiff
@test inner(backend) isa AutoReverseFromPrimitive
@test mode(backend) isa ADTypes.ForwardMode
@test !Bool(inplace_support(backend))
@test Bool(inplace_support(backend))
@test_throws ArgumentError pushforward_performance(backend)
@test_throws ArgumentError pullback_performance(backend)
@test check_available(backend)
end

@testset "MixedMode" begin
backend = MixedMode(AutoForwardDiff(), AutoZygote())
@test ADTypes.mode(backend) isa DifferentiationInterface.ForwardAndReverseMode
@test forward_backend(backend) isa AutoForwardDiff
@test reverse_backend(backend) isa AutoZygote
@test !Bool(inplace_support(backend))
backend = MixedMode(fb, rb)
@test check_available(backend)
@test mode(backend) isa DifferentiationInterface.ForwardAndReverseMode
@test forward_backend(backend) isa AutoSimpleFiniteDiff
@test reverse_backend(backend) isa AutoReverseFromPrimitive
@test Bool(inplace_support(backend))
@test_throws MethodError pushforward_performance(backend)
@test_throws MethodError pullback_performance(backend)
@test check_available(backend)
end

@testset "Sparse" begin
for dense_backend in [AutoForwardDiff(), AutoZygote()]
for dense_backend in [fb, rb]
backend = AutoSparse(dense_backend)
@test ADTypes.mode(backend) == ADTypes.mode(dense_backend)
@test check_available(backend) == check_available(dense_backend)
@test inplace_support(backend) == inplace_support(dense_backend)
@test mode(backend) == ADTypes.mode(dense_backend)
@test Bool(inplace_support(backend))
@test_throws ArgumentError pushforward_performance(backend)
@test_throws ArgumentError pullback_performance(backend)
@test_throws ArgumentError hvp_mode(backend)
Expand Down
10 changes: 4 additions & 6 deletions DifferentiationInterface/test/Core/Internals/display.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ using DifferentiationInterface
using Test

backend = SecondOrder(AutoForwardDiff(), AutoZygote())
@test startswith(string(backend), "SecondOrder(")
@test endswith(string(backend), ")")
@test string(backend) == "SecondOrder(AutoForwardDiff(), AutoZygote())"

detector = DenseSparsityDetector(AutoForwardDiff(); atol=1e-23)
@test startswith(string(detector), "DenseSparsityDetector(")
@test endswith(string(detector), ")")
@test string(detector) ==
"DenseSparsityDetector(AutoForwardDiff(); atol=1.0e-23, method=:iterative)"

diffwith = DifferentiateWith(exp, AutoForwardDiff())
@test startswith(string(diffwith), "DifferentiateWith(")
@test endswith(string(diffwith), ")")
@test string(diffwith) == "DifferentiateWith(exp, AutoForwardDiff())"

@test DifferentiationInterface.package_name(AutoForwardDiff()) == "ForwardDiff"
@test DifferentiationInterface.package_name(AutoZygote()) == "Zygote"
Expand Down
72 changes: 36 additions & 36 deletions DifferentiationInterface/test/Core/SimpleFiniteDiff/test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,44 +35,44 @@ end

## Dense scenarios

test_differentiation(
vcat(backends, second_order_backends),
default_scenarios(; include_constantified=true);
logging=LOGGING,
);

## Sparse scenarios

test_differentiation(
MyAutoSparse.(adaptive_backends),
default_scenarios(; include_constantified=true);
logging=LOGGING,
);

test_differentiation(
MyAutoSparse.(
vcat(adaptive_backends, MixedMode(adaptive_backends[1], adaptive_backends[2]))
),
sparse_scenarios(; include_constantified=true);
sparsity=true,
logging=LOGGING,
);
@testset "Dense" begin
test_differentiation(
vcat(backends, second_order_backends),
default_scenarios(; include_constantified=true);
logging=LOGGING,
)
end

## Misc
@testset "Sparse" begin
test_differentiation(
MyAutoSparse.(adaptive_backends),
default_scenarios(; include_constantified=true);
logging=LOGGING,
)

@testset "SparseMatrixColorings access" begin
jac_for_prep = prepare_jacobian(copy, MyAutoSparse(adaptive_backends[1]), rand(10))
jac_rev_prep = prepare_jacobian(copy, MyAutoSparse(adaptive_backends[2]), rand(10))
hess_prep = prepare_hessian(
x -> sum(abs2, x), MyAutoSparse(adaptive_backends[1]), rand(10)
test_differentiation(
MyAutoSparse.(
vcat(adaptive_backends, MixedMode(adaptive_backends[1], adaptive_backends[2]))
),
sparse_scenarios(; include_constantified=true);
sparsity=true,
logging=LOGGING,
)

@test all(==(1), column_colors(jac_for_prep))
@test all(==(1), row_colors(jac_rev_prep))
@test all(==(1), column_colors(hess_prep))
@test ncolors(jac_for_prep) == 1
@test ncolors(hess_prep) == 1
@test only(column_groups(jac_for_prep)) == 1:10
@test only(row_groups(jac_rev_prep)) == 1:10
@test only(column_groups(hess_prep)) == 1:10
@testset "SparseMatrixColorings access" begin
jac_for_prep = prepare_jacobian(copy, MyAutoSparse(adaptive_backends[1]), rand(10))
jac_rev_prep = prepare_jacobian(copy, MyAutoSparse(adaptive_backends[2]), rand(10))
hess_prep = prepare_hessian(
x -> sum(abs2, x), MyAutoSparse(adaptive_backends[1]), rand(10)
)

@test all(==(1), column_colors(jac_for_prep))
@test all(==(1), row_colors(jac_rev_prep))
@test all(==(1), column_colors(hess_prep))
@test ncolors(jac_for_prep) == 1
@test ncolors(hess_prep) == 1
@test only(column_groups(jac_for_prep)) == 1:10
@test only(row_groups(jac_rev_prep)) == 1:10
@test only(column_groups(hess_prep)) == 1:10
end
end
93 changes: 44 additions & 49 deletions DifferentiationInterface/test/Core/ZeroBackends/test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,56 +16,51 @@ for backend in zero_backends
@test check_inplace(backend)
end

## Type stability
@testset "Type stability" begin
test_differentiation(
AutoZeroForward(),
default_scenarios(; include_batchified=false, include_constantified=true);
correctness=false,
type_stability=:full,
logging=LOGGING,
)

test_differentiation(
AutoZeroForward(),
default_scenarios(; include_batchified=false, include_constantified=true);
correctness=false,
type_stability=:full,
logging=LOGGING,
)
test_differentiation(
AutoZeroReverse(),
default_scenarios(; include_batchified=false, include_constantified=true);
correctness=false,
type_stability=:full,
logging=LOGGING,
)

test_differentiation(
AutoZeroReverse(),
default_scenarios(; include_batchified=false, include_constantified=true);
correctness=false,
type_stability=:full,
logging=LOGGING,
)
test_differentiation(
[
SecondOrder(AutoZeroForward(), AutoZeroReverse()),
SecondOrder(AutoZeroReverse(), AutoZeroForward()),
],
default_scenarios(; include_batchified=false, include_constantified=true);
correctness=false,
type_stability=:full,
logging=LOGGING,
)

test_differentiation(
[
SecondOrder(AutoZeroForward(), AutoZeroReverse()),
SecondOrder(AutoZeroReverse(), AutoZeroForward()),
],
default_scenarios(; include_batchified=false, include_constantified=true);
correctness=false,
type_stability=:full,
logging=LOGGING,
)

test_differentiation(
AutoSparse.(zero_backends, coloring_algorithm=GreedyColoringAlgorithm()),
default_scenarios(; include_constantified=true);
correctness=false,
type_stability=:full,
excluded=[:pushforward, :pullback, :gradient, :derivative, :hvp, :second_derivative],
logging=LOGGING,
)

## Weird arrays

test_differentiation(
[AutoZeroForward(), AutoZeroReverse()],
zero.(vcat(component_scenarios(), static_scenarios()));
correctness=true,
logging=LOGGING,
)
test_differentiation(
AutoSparse.(zero_backends, coloring_algorithm=GreedyColoringAlgorithm()),
default_scenarios(; include_constantified=true);
correctness=false,
type_stability=:full,
excluded=[
:pushforward, :pullback, :gradient, :derivative, :hvp, :second_derivative
],
logging=LOGGING,
)
end

test_differentiation(
[AutoZeroForward(), AutoZeroReverse()],
zero.(gpu_scenarios());
correctness=true,
logging=LOGGING,
)
@testset "Weird arrays" begin
test_differentiation(
[AutoZeroForward(), AutoZeroReverse()],
zero.(vcat(component_scenarios(), static_scenarios(), gpu_scenarios()));
correctness=true,
logging=LOGGING,
)
end
41 changes: 16 additions & 25 deletions DifferentiationInterface/test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
using DifferentiationInterface
using Pkg
using Test
using SparseMatrixColorings, SparseConnectivityTracer

function MyAutoSparse(backend)
return AutoSparse(
backend;
sparsity_detector=TracerSparsityDetector(),
coloring_algorithm=GreedyColoringAlgorithm(),
)
end

DIT_PATH = joinpath(@__DIR__, "..", "..", "DifferentiationInterfaceTest")
if isdir(DIT_PATH)
Expand All @@ -18,36 +9,36 @@
Pkg.add("DifferentiationInterfaceTest")
end

GROUP = get(ENV, "JULIA_DI_TEST_GROUP", "All")
include("testutils.jl")

## Main tests

@testset verbose = true "DifferentiationInterface.jl" begin
if GROUP == "All"
@testset verbose = true for category in readdir(@__DIR__)
isdir(joinpath(@__DIR__, category)) || continue
@testset verbose = true for folder in readdir(joinpath(@__DIR__, category))
isdir(joinpath(@__DIR__, category, folder)) || continue
if haskey(ENV, "JULIA_DI_TEST_GROUP")
category, folder = split(ENV["JULIA_DI_TEST_GROUP"], '/')
@testset verbose = true "$category" begin

Check warning on line 19 in DifferentiationInterface/test/runtests.jl

View check run for this annotation

Codecov / codecov/patch

DifferentiationInterface/test/runtests.jl#L19

Added line #L19 was not covered by tests
@testset verbose = true "$folder" begin
@testset verbose = true "$file" for file in readdir(
joinpath(@__DIR__, category, folder)
)
endswith(file, ".jl") || continue
@info "Testing $category/$folder/$file"
include(joinpath(@__DIR__, category, folder, file))
yield()
end
end
end
else
category, folder = split(GROUP, '/')
@testset verbose = true "$category" begin
@testset verbose = true "$folder" begin
@testset verbose = true "$file" for file in readdir(
joinpath(@__DIR__, category, folder)
)
endswith(file, ".jl") || continue
@info "Testing $category/$folder/$file"
include(joinpath(@__DIR__, category, folder, file))
end
category = "Core"
@testset verbose = true for folder in readdir(joinpath(@__DIR__, category))
isdir(joinpath(@__DIR__, category, folder)) || continue
@testset verbose = true "$file" for file in readdir(

Check warning on line 35 in DifferentiationInterface/test/runtests.jl

View check run for this annotation

Codecov / codecov/patch

DifferentiationInterface/test/runtests.jl#L32-L35

Added lines #L32 - L35 were not covered by tests
joinpath(@__DIR__, category, folder)
)
endswith(file, ".jl") || continue
@info "Testing $category/$folder/$file"
include(joinpath(@__DIR__, category, folder, file))
yield()

Check warning on line 41 in DifferentiationInterface/test/runtests.jl

View check run for this annotation

Codecov / codecov/patch

DifferentiationInterface/test/runtests.jl#L38-L41

Added lines #L38 - L41 were not covered by tests
end
end
end
Expand Down
11 changes: 11 additions & 0 deletions DifferentiationInterface/test/testutils.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using ADTypes
using SparseConnectivityTracer
using SparseMatrixColorings

function MyAutoSparse(backend::AbstractADType)
return AutoSparse(
backend;
sparsity_detector=TracerSparsityDetector(),
coloring_algorithm=GreedyColoringAlgorithm(),
)
end
Loading