From 94a36d9a52bb520f9a4ed4f1f790084cfdfdc51f Mon Sep 17 00:00:00 2001 From: Guillaume Dalle <22795598+gdalle@users.noreply.github.com> Date: Sat, 1 Jun 2024 10:14:58 +0200 Subject: [PATCH 1/6] Restructure test folder --- .../test.jl} | 0 .../ForwardDiff-Zygote/differentiatewith.jl | 26 ++++++++++ .../test.jl} | 25 ---------- .../test.jl} | 0 .../{Diffractor.jl => Diffractor/test.jl} | 0 .../test/Single/{Enzyme.jl => Enzyme/test.jl} | 0 .../test.jl} | 0 .../{FiniteDiff.jl => FiniteDiff/test.jl} | 0 .../test.jl} | 0 .../{ForwardDiff.jl => ForwardDiff/test.jl} | 6 --- .../test.jl} | 0 .../{ReverseDiff.jl => ReverseDiff/test.jl} | 0 .../{Symbolics.jl => Symbolics/test.jl} | 6 --- .../test/Single/{Tapir.jl => Tapir/test.jl} | 0 .../Single/{Tracker.jl => Tracker/test.jl} | 0 .../test/Single/{Zygote.jl => Zygote/test.jl} | 0 DifferentiationInterface/test/runtests.jl | 47 +++++++++++-------- 17 files changed, 53 insertions(+), 57 deletions(-) rename DifferentiationInterface/test/Double/{Enzyme-ForwardDiff.jl => Enzyme-ForwardDiff/test.jl} (100%) create mode 100644 DifferentiationInterface/test/Double/ForwardDiff-Zygote/differentiatewith.jl rename DifferentiationInterface/test/Double/{ForwardDiff-Zygote.jl => ForwardDiff-Zygote/test.jl} (54%) rename DifferentiationInterface/test/Double/{ReverseDiff-Zygote.jl => ReverseDiff-Zygote/test.jl} (100%) rename DifferentiationInterface/test/Single/{Diffractor.jl => Diffractor/test.jl} (100%) rename DifferentiationInterface/test/Single/{Enzyme.jl => Enzyme/test.jl} (100%) rename DifferentiationInterface/test/Single/{FastDifferentiation.jl => FastDifferentiation/test.jl} (100%) rename DifferentiationInterface/test/Single/{FiniteDiff.jl => FiniteDiff/test.jl} (100%) rename DifferentiationInterface/test/Single/{FiniteDifferences.jl => FiniteDifferences/test.jl} (100%) rename DifferentiationInterface/test/Single/{ForwardDiff.jl => ForwardDiff/test.jl} (94%) rename DifferentiationInterface/test/Single/{PolyesterForwardDiff.jl => PolyesterForwardDiff/test.jl} (100%) rename DifferentiationInterface/test/Single/{ReverseDiff.jl => ReverseDiff/test.jl} (100%) rename DifferentiationInterface/test/Single/{Symbolics.jl => Symbolics/test.jl} (85%) rename DifferentiationInterface/test/Single/{Tapir.jl => Tapir/test.jl} (100%) rename DifferentiationInterface/test/Single/{Tracker.jl => Tracker/test.jl} (100%) rename DifferentiationInterface/test/Single/{Zygote.jl => Zygote/test.jl} (100%) diff --git a/DifferentiationInterface/test/Double/Enzyme-ForwardDiff.jl b/DifferentiationInterface/test/Double/Enzyme-ForwardDiff/test.jl similarity index 100% rename from DifferentiationInterface/test/Double/Enzyme-ForwardDiff.jl rename to DifferentiationInterface/test/Double/Enzyme-ForwardDiff/test.jl diff --git a/DifferentiationInterface/test/Double/ForwardDiff-Zygote/differentiatewith.jl b/DifferentiationInterface/test/Double/ForwardDiff-Zygote/differentiatewith.jl new file mode 100644 index 000000000..43a850ba8 --- /dev/null +++ b/DifferentiationInterface/test/Double/ForwardDiff-Zygote/differentiatewith.jl @@ -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 +) diff --git a/DifferentiationInterface/test/Double/ForwardDiff-Zygote.jl b/DifferentiationInterface/test/Double/ForwardDiff-Zygote/test.jl similarity index 54% rename from DifferentiationInterface/test/Double/ForwardDiff-Zygote.jl rename to DifferentiationInterface/test/Double/ForwardDiff-Zygote/test.jl index 86b556623..ec9313ca9 100644 --- a/DifferentiationInterface/test/Double/ForwardDiff-Zygote.jl +++ b/DifferentiationInterface/test/Double/ForwardDiff-Zygote/test.jl @@ -1,6 +1,4 @@ using DifferentiationInterface, DifferentiationInterfaceTest -import DifferentiationInterface as DI -import DifferentiationInterfaceTest as DIT using ForwardDiff: ForwardDiff using SparseConnectivityTracer using SparseMatrixColorings @@ -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 -) diff --git a/DifferentiationInterface/test/Double/ReverseDiff-Zygote.jl b/DifferentiationInterface/test/Double/ReverseDiff-Zygote/test.jl similarity index 100% rename from DifferentiationInterface/test/Double/ReverseDiff-Zygote.jl rename to DifferentiationInterface/test/Double/ReverseDiff-Zygote/test.jl diff --git a/DifferentiationInterface/test/Single/Diffractor.jl b/DifferentiationInterface/test/Single/Diffractor/test.jl similarity index 100% rename from DifferentiationInterface/test/Single/Diffractor.jl rename to DifferentiationInterface/test/Single/Diffractor/test.jl diff --git a/DifferentiationInterface/test/Single/Enzyme.jl b/DifferentiationInterface/test/Single/Enzyme/test.jl similarity index 100% rename from DifferentiationInterface/test/Single/Enzyme.jl rename to DifferentiationInterface/test/Single/Enzyme/test.jl diff --git a/DifferentiationInterface/test/Single/FastDifferentiation.jl b/DifferentiationInterface/test/Single/FastDifferentiation/test.jl similarity index 100% rename from DifferentiationInterface/test/Single/FastDifferentiation.jl rename to DifferentiationInterface/test/Single/FastDifferentiation/test.jl diff --git a/DifferentiationInterface/test/Single/FiniteDiff.jl b/DifferentiationInterface/test/Single/FiniteDiff/test.jl similarity index 100% rename from DifferentiationInterface/test/Single/FiniteDiff.jl rename to DifferentiationInterface/test/Single/FiniteDiff/test.jl diff --git a/DifferentiationInterface/test/Single/FiniteDifferences.jl b/DifferentiationInterface/test/Single/FiniteDifferences/test.jl similarity index 100% rename from DifferentiationInterface/test/Single/FiniteDifferences.jl rename to DifferentiationInterface/test/Single/FiniteDifferences/test.jl diff --git a/DifferentiationInterface/test/Single/ForwardDiff.jl b/DifferentiationInterface/test/Single/ForwardDiff/test.jl similarity index 94% rename from DifferentiationInterface/test/Single/ForwardDiff.jl rename to DifferentiationInterface/test/Single/ForwardDiff/test.jl index fdfc80c7c..42711d334 100644 --- a/DifferentiationInterface/test/Single/ForwardDiff.jl +++ b/DifferentiationInterface/test/Single/ForwardDiff/test.jl @@ -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 diff --git a/DifferentiationInterface/test/Single/PolyesterForwardDiff.jl b/DifferentiationInterface/test/Single/PolyesterForwardDiff/test.jl similarity index 100% rename from DifferentiationInterface/test/Single/PolyesterForwardDiff.jl rename to DifferentiationInterface/test/Single/PolyesterForwardDiff/test.jl diff --git a/DifferentiationInterface/test/Single/ReverseDiff.jl b/DifferentiationInterface/test/Single/ReverseDiff/test.jl similarity index 100% rename from DifferentiationInterface/test/Single/ReverseDiff.jl rename to DifferentiationInterface/test/Single/ReverseDiff/test.jl diff --git a/DifferentiationInterface/test/Single/Symbolics.jl b/DifferentiationInterface/test/Single/Symbolics/test.jl similarity index 85% rename from DifferentiationInterface/test/Single/Symbolics.jl rename to DifferentiationInterface/test/Single/Symbolics/test.jl index e86a0942f..34a2d8acb 100644 --- a/DifferentiationInterface/test/Single/Symbolics.jl +++ b/DifferentiationInterface/test/Single/Symbolics/test.jl @@ -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 diff --git a/DifferentiationInterface/test/Single/Tapir.jl b/DifferentiationInterface/test/Single/Tapir/test.jl similarity index 100% rename from DifferentiationInterface/test/Single/Tapir.jl rename to DifferentiationInterface/test/Single/Tapir/test.jl diff --git a/DifferentiationInterface/test/Single/Tracker.jl b/DifferentiationInterface/test/Single/Tracker/test.jl similarity index 100% rename from DifferentiationInterface/test/Single/Tracker.jl rename to DifferentiationInterface/test/Single/Tracker/test.jl diff --git a/DifferentiationInterface/test/Single/Zygote.jl b/DifferentiationInterface/test/Single/Zygote/test.jl similarity index 100% rename from DifferentiationInterface/test/Single/Zygote.jl rename to DifferentiationInterface/test/Single/Zygote/test.jl diff --git a/DifferentiationInterface/test/runtests.jl b/DifferentiationInterface/test/runtests.jl index 11e0b5390..10814d0aa 100644 --- a/DifferentiationInterface/test/runtests.jl +++ b/DifferentiationInterface/test/runtests.jl @@ -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 @@ -31,25 +46,13 @@ 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 "$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") @@ -57,14 +60,18 @@ GROUP = get(ENV, "JULIA_DI_TEST_GROUP", "All") @testset "Single/$b1" begin @info "Testing Single/$b1" Pkg.add(b1) - include(joinpath(@__DIR__, "Single", "$b1.jl")) + @testset "$file" for file in readdir(joinpath(@__DIR__, "Single", "$b1")) + 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" Pkg.add([b1, b2]) - include(joinpath(@__DIR__, "Double", "$b1-$b2.jl")) + @testset "$file" for file in readdir(joinpath(@__DIR__, "Single", "$b1-$b2")) + include(joinpath(@__DIR__, "Double", "$b1-$b2", file)) + end end end end; From e2c202ca233d1112584709faf67d761b46902783 Mon Sep 17 00:00:00 2001 From: Guillaume Dalle <22795598+gdalle@users.noreply.github.com> Date: Sat, 1 Jun 2024 10:15:27 +0200 Subject: [PATCH 2/6] Rename translation into misc --- DifferentiationInterface/src/DifferentiationInterface.jl | 2 +- .../src/{translation => misc}/differentiate_with.jl | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename DifferentiationInterface/src/{translation => misc}/differentiate_with.jl (100%) diff --git a/DifferentiationInterface/src/DifferentiationInterface.jl b/DifferentiationInterface/src/DifferentiationInterface.jl index 6628042d2..90712b1b1 100644 --- a/DifferentiationInterface/src/DifferentiationInterface.jl +++ b/DifferentiationInterface/src/DifferentiationInterface.jl @@ -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 diff --git a/DifferentiationInterface/src/translation/differentiate_with.jl b/DifferentiationInterface/src/misc/differentiate_with.jl similarity index 100% rename from DifferentiationInterface/src/translation/differentiate_with.jl rename to DifferentiationInterface/src/misc/differentiate_with.jl From a0f4875817074cd184eefb1bf754c05d03505c3f Mon Sep 17 00:00:00 2001 From: Guillaume Dalle <22795598+gdalle@users.noreply.github.com> Date: Sat, 1 Jun 2024 10:16:21 +0200 Subject: [PATCH 3/6] Typo --- DifferentiationInterface/test/runtests.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DifferentiationInterface/test/runtests.jl b/DifferentiationInterface/test/runtests.jl index 10814d0aa..b5d79b49d 100644 --- a/DifferentiationInterface/test/runtests.jl +++ b/DifferentiationInterface/test/runtests.jl @@ -69,7 +69,7 @@ ALL_BACKENDS = [ @testset "Single/$b1-$b2" begin @info "Testing Double/$b1-$b2" Pkg.add([b1, b2]) - @testset "$file" for file in readdir(joinpath(@__DIR__, "Single", "$b1-$b2")) + @testset "$file" for file in readdir(joinpath(@__DIR__, "Double", "$b1-$b2")) include(joinpath(@__DIR__, "Double", "$b1-$b2", file)) end end From 85bb36ebe0f851e3701e90888b5fe804cb59084a Mon Sep 17 00:00:00 2001 From: Guillaume Dalle <22795598+gdalle@users.noreply.github.com> Date: Sat, 1 Jun 2024 10:21:14 +0200 Subject: [PATCH 4/6] More verbose --- DifferentiationInterface/test/runtests.jl | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/DifferentiationInterface/test/runtests.jl b/DifferentiationInterface/test/runtests.jl index b5d79b49d..308c3ca1e 100644 --- a/DifferentiationInterface/test/runtests.jl +++ b/DifferentiationInterface/test/runtests.jl @@ -48,7 +48,8 @@ ALL_BACKENDS = [ if GROUP == "All" Pkg.add(ALL_BACKENDS) @testset verbose = true "$folder" for folder in ("Single", "Double") - @testset "$subfolder" for subfolder in readdir(joinpath(@__DIR__, folder)) + @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)) @@ -57,19 +58,19 @@ ALL_BACKENDS = [ 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) @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 "Single/$b1-$b2" begin Pkg.add([b1, b2]) @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 From 1f96f8b94016f8c86e64deb606e587f3ad92f6a5 Mon Sep 17 00:00:00 2001 From: Guillaume Dalle <22795598+gdalle@users.noreply.github.com> Date: Sat, 1 Jun 2024 10:26:32 +0200 Subject: [PATCH 5/6] Typo --- DifferentiationInterface/test/runtests.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DifferentiationInterface/test/runtests.jl b/DifferentiationInterface/test/runtests.jl index 308c3ca1e..89211b9d9 100644 --- a/DifferentiationInterface/test/runtests.jl +++ b/DifferentiationInterface/test/runtests.jl @@ -67,7 +67,7 @@ ALL_BACKENDS = [ end elseif startswith(GROUP, "Double") b1, b2 = split(split(GROUP, '/')[2], '-') - @testset verbose = true "Single/$b1-$b2" begin + @testset verbose = true "Double/$b1-$b2" begin Pkg.add([b1, b2]) @testset "$file" for file in readdir(joinpath(@__DIR__, "Double", "$b1-$b2")) @info "Testing Double/$b1-$b2/$file" From 50ab0fd7395841e4be28827504421ccacc83c95d Mon Sep 17 00:00:00 2001 From: Guillaume Dalle <22795598+gdalle@users.noreply.github.com> Date: Sat, 1 Jun 2024 10:37:56 +0200 Subject: [PATCH 6/6] Fix 1.6 --- .../test/Single/ForwardDiff/efficiency.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DifferentiationInterface/test/Single/ForwardDiff/efficiency.jl b/DifferentiationInterface/test/Single/ForwardDiff/efficiency.jl index c6a8d4987..0eb16f514 100644 --- a/DifferentiationInterface/test/Single/ForwardDiff/efficiency.jl +++ b/DifferentiationInterface/test/Single/ForwardDiff/efficiency.jl @@ -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 @@ -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