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

Put backend tests into folders #292

Merged
merged 6 commits into from
Jun 1, 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
2 changes: 1 addition & 1 deletion DifferentiationInterface/src/DifferentiationInterface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ include("sparse/matrices.jl")
include("sparse/jacobian.jl")
include("sparse/hessian.jl")

include("translation/differentiate_with.jl")
include("misc/differentiate_with.jl")

function __init__()
@require_extensions
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using DifferentiationInterface, DifferentiationInterfaceTest
import DifferentiationInterfaceTest as DIT
using ForwardDiff: ForwardDiff
using Zygote: Zygote
using Test

function zygote_breaking_scenarios()
onearg_scens = filter(default_scenarios()) do scen
DIT.nb_args(scen) == 1
end
bad_onearg_scens = map(onearg_scens) do scen
function bad_f(x)
a = Vector{eltype(x)}(undef, 1)
a[1] = sum(x)
return scen.f(x)
end
wrapped_bad_f = DifferentiateWith(bad_f, AutoForwardDiff())
bad_scen = DIT.change_function(scen, wrapped_bad_f)
return bad_scen
end
return bad_onearg_scens
end

test_differentiation(
AutoZygote(), zygote_breaking_scenarios(); second_order=false, logging=LOGGING
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using DifferentiationInterface, DifferentiationInterfaceTest
import DifferentiationInterface as DI
import DifferentiationInterfaceTest as DIT
using ForwardDiff: ForwardDiff
using SparseConnectivityTracer
using SparseMatrixColorings
Expand Down Expand Up @@ -32,26 +30,3 @@ test_differentiation(dense_backends; first_order=false, logging=LOGGING);
test_differentiation(
sparse_backends, sparse_scenarios(); first_order=false, sparsity=true, logging=LOGGING
);

## Translation

function zygote_breaking_scenarios()
onearg_scens = filter(default_scenarios()) do scen
DIT.nb_args(scen) == 1
end
bad_onearg_scens = map(onearg_scens) do scen
function bad_f(x)
a = Vector{eltype(x)}(undef, 1)
a[1] = sum(x)
return scen.f(x)
end
wrapped_bad_f = DifferentiateWith(bad_f, AutoForwardDiff())
bad_scen = DIT.change_function(scen, wrapped_bad_f)
return bad_scen
end
return bad_onearg_scens
end

test_differentiation(
AutoZygote(), zygote_breaking_scenarios(); second_order=false, logging=LOGGING
)
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ sumexp(x) = sum(exp, x)
for row in eachrow(useful_data)
scen = row[:scenario]
@testset "$(row[:operator]) - $(string(scen.f)) : $(typeof(scen.x)) -> $(typeof(scen.y))" begin
@test row[:allocs] == 0
VERSION >= v"1.10" && @test row[:allocs] == 0
end
end
end
Expand Down Expand Up @@ -80,7 +80,7 @@ end
for row in eachrow(useful_data)
scen = row[:scenario]
@testset "$(row[:operator]) - $(string(scen.f)) : $(typeof(scen.x)) -> $(typeof(scen.y))" begin
@test row[:allocs] == 0
VERSION >= v"1.10" && @test row[:allocs] == 0
@test row[:calls] < prod(size(scen.x))
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,3 @@ test_differentiation(
);

test_differentiation(sparse_backends, sparse_scenarios(); sparsity=true, logging=LOGGING);

## Bonus

if VERSION >= v"1.10"
include("ForwardDiff/efficiency.jl")
end
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,3 @@ test_differentiation(AutoSymbolics(); logging=LOGGING);
test_differentiation(
AutoSparse(AutoSymbolics()), sparse_scenarios(); sparsity=true, logging=LOGGING
);

## Bonus

if VERSION >= v"1.10"
include("Symbolics/detector.jl")
end
56 changes: 32 additions & 24 deletions DifferentiationInterface/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,21 @@ LOGGING = get(ENV, "CI", "false") == "false"

GROUP = get(ENV, "JULIA_DI_TEST_GROUP", "All")

ALL_BACKENDS = [
"Diffractor",
"Enzyme",
"FiniteDiff",
"FiniteDifferences",
"FastDifferentiation",
"ForwardDiff",
"PolyesterForwardDiff",
"ReverseDiff",
"Symbolics",
"Tapir",
"Tracker",
"Zygote",
]

## Main tests

@testset verbose = true "DifferentiationInterface.jl" begin
Expand All @@ -31,40 +46,33 @@ GROUP = get(ENV, "JULIA_DI_TEST_GROUP", "All")
end

if GROUP == "All"
Pkg.add([
"Diffractor",
"Enzyme",
"FiniteDiff",
"FiniteDifferences",
"FastDifferentiation",
"ForwardDiff",
"PolyesterForwardDiff",
"ReverseDiff",
"Symbolics",
"Tapir",
"Tracker",
"Zygote",
])
Pkg.add(ALL_BACKENDS)
@testset verbose = true "$folder" for folder in ("Single", "Double")
files = filter(f -> endswith(f, ".jl"), readdir(joinpath(@__DIR__, folder)))
@testset "$file" for file in files
@info "Testing $folder/$file"
include(joinpath(@__DIR__, folder, file))
@testset verbose = true "$subfolder" for subfolder in
readdir(joinpath(@__DIR__, folder))
@testset "$file" for file in readdir(joinpath(@__DIR__, folder, subfolder))
@info "Testing $folder/$subfolder/$file"
include(joinpath(@__DIR__, folder, subfolder, file))
end
end
end
elseif startswith(GROUP, "Single")
b1 = split(GROUP, '/')[2]
@testset "Single/$b1" begin
@info "Testing Single/$b1"
@testset verbose = true "Single/$b1" begin
Pkg.add(b1)
include(joinpath(@__DIR__, "Single", "$b1.jl"))
@testset "$file" for file in readdir(joinpath(@__DIR__, "Single", "$b1"))
@info "Testing Single/$b1/$file"
include(joinpath(@__DIR__, "Single", "$b1", file))
end
end
elseif startswith(GROUP, "Double")
b1, b2 = split(split(GROUP, '/')[2], '-')
@testset "Single/$b1-$b2" begin
@info "Testing Double/$b1-$b2"
@testset verbose = true "Double/$b1-$b2" begin
Pkg.add([b1, b2])
include(joinpath(@__DIR__, "Double", "$b1-$b2.jl"))
@testset "$file" for file in readdir(joinpath(@__DIR__, "Double", "$b1-$b2"))
@info "Testing Double/$b1-$b2/$file"
include(joinpath(@__DIR__, "Double", "$b1-$b2", file))
end
end
end
end;
Loading