From 38a88585aa97d3f8aa9f7bd4c0a1e5e5f4c5a6f8 Mon Sep 17 00:00:00 2001 From: Oliver Schulz Date: Fri, 12 Sep 2025 15:29:36 +0200 Subject: [PATCH 1/3] Support ADTypes.NoAutoDiff --- DifferentiationInterface/src/utils/check.jl | 8 ++++++++ DifferentiationInterface/test/Core/ZeroBackends/test.jl | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/DifferentiationInterface/src/utils/check.jl b/DifferentiationInterface/src/utils/check.jl index 9e0510533..1772558a0 100644 --- a/DifferentiationInterface/src/utils/check.jl +++ b/DifferentiationInterface/src/utils/check.jl @@ -16,9 +16,17 @@ function check_available(backend::MixedMode) check_available(reverse_backend(backend)) end +@static if isdefined(ADTypes, :NoAutoDiff) + check_available(::ADTypes.NoAutoDiff) = throw(ADTypes.NoAutoDiffSelectedError()) +end + """ check_inplace(backend) Check whether `backend` supports differentiation of in-place functions and return a `Bool`. """ check_inplace(backend::AbstractADType) = Bool(inplace_support(backend)) + +@static if isdefined(ADTypes, :NoAutoDiff) + check_inplace(::ADTypes.NoAutoDiff) = throw(ADTypes.NoAutoDiffSelectedError()) +end diff --git a/DifferentiationInterface/test/Core/ZeroBackends/test.jl b/DifferentiationInterface/test/Core/ZeroBackends/test.jl index 396e7d455..4a7ecb3ad 100644 --- a/DifferentiationInterface/test/Core/ZeroBackends/test.jl +++ b/DifferentiationInterface/test/Core/ZeroBackends/test.jl @@ -10,6 +10,11 @@ using Test LOGGING = get(ENV, "CI", "false") == "false" +if isdefined(ADTypes, :NoAutoDiff) + @test_throws NoAutoDiffSelectedError check_available(NoAutoDiff()) + @test_throws NoAutoDiffSelectedError check_inplace(NoAutoDiff()) +end + zero_backends = [AutoZeroForward(), AutoZeroReverse()] for backend in zero_backends From 393039801b5aa9dbc6b998f2452e79b9cc9386a0 Mon Sep 17 00:00:00 2001 From: Oliver Schulz Date: Thu, 18 Sep 2025 13:42:14 +0200 Subject: [PATCH 2/3] Require ADTypes v1.17 for NoAutoDiff --- DifferentiationInterface/Project.toml | 2 +- DifferentiationInterface/src/utils/check.jl | 8 ++------ DifferentiationInterface/test/Core/ZeroBackends/test.jl | 6 ++---- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/DifferentiationInterface/Project.toml b/DifferentiationInterface/Project.toml index 372a97de8..3654bf71f 100644 --- a/DifferentiationInterface/Project.toml +++ b/DifferentiationInterface/Project.toml @@ -56,7 +56,7 @@ DifferentiationInterfaceTrackerExt = "Tracker" DifferentiationInterfaceZygoteExt = ["Zygote", "ForwardDiff"] [compat] -ADTypes = "1.17.0" +ADTypes = "1.18.0" ChainRulesCore = "1.23.0" DiffResults = "1.1.0" Diffractor = "=0.2.6" diff --git a/DifferentiationInterface/src/utils/check.jl b/DifferentiationInterface/src/utils/check.jl index 1772558a0..ed11dd10a 100644 --- a/DifferentiationInterface/src/utils/check.jl +++ b/DifferentiationInterface/src/utils/check.jl @@ -16,9 +16,7 @@ function check_available(backend::MixedMode) check_available(reverse_backend(backend)) end -@static if isdefined(ADTypes, :NoAutoDiff) - check_available(::ADTypes.NoAutoDiff) = throw(ADTypes.NoAutoDiffSelectedError()) -end +check_available(::ADTypes.NoAutoDiff) = throw(ADTypes.NoAutoDiffSelectedError()) """ check_inplace(backend) @@ -27,6 +25,4 @@ Check whether `backend` supports differentiation of in-place functions and retur """ check_inplace(backend::AbstractADType) = Bool(inplace_support(backend)) -@static if isdefined(ADTypes, :NoAutoDiff) - check_inplace(::ADTypes.NoAutoDiff) = throw(ADTypes.NoAutoDiffSelectedError()) -end +check_inplace(::ADTypes.NoAutoDiff) = throw(ADTypes.NoAutoDiffSelectedError()) diff --git a/DifferentiationInterface/test/Core/ZeroBackends/test.jl b/DifferentiationInterface/test/Core/ZeroBackends/test.jl index 4a7ecb3ad..771d265c5 100644 --- a/DifferentiationInterface/test/Core/ZeroBackends/test.jl +++ b/DifferentiationInterface/test/Core/ZeroBackends/test.jl @@ -10,10 +10,8 @@ using Test LOGGING = get(ENV, "CI", "false") == "false" -if isdefined(ADTypes, :NoAutoDiff) - @test_throws NoAutoDiffSelectedError check_available(NoAutoDiff()) - @test_throws NoAutoDiffSelectedError check_inplace(NoAutoDiff()) -end +@test_throws NoAutoDiffSelectedError check_available(NoAutoDiff()) +@test_throws NoAutoDiffSelectedError check_inplace(NoAutoDiff()) zero_backends = [AutoZeroForward(), AutoZeroReverse()] From 8c13b66417bbcc84b23ffbe9b3c376318b49af48 Mon Sep 17 00:00:00 2001 From: Oliver Schulz Date: Mon, 22 Sep 2025 15:17:27 +0200 Subject: [PATCH 3/3] Specialize inplace_support for NoAutoDiff, update ChangeLog --- DifferentiationInterface/CHANGELOG.md | 2 ++ DifferentiationInterface/src/utils/check.jl | 2 -- DifferentiationInterface/src/utils/traits.jl | 2 ++ DifferentiationInterface/test/Core/Internals/backends.jl | 5 +++++ DifferentiationInterface/test/Core/ZeroBackends/test.jl | 3 --- 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/DifferentiationInterface/CHANGELOG.md b/DifferentiationInterface/CHANGELOG.md index c60369666..a5405599f 100644 --- a/DifferentiationInterface/CHANGELOG.md +++ b/DifferentiationInterface/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased](https://github.com/JuliaDiff/DifferentiationInterface.jl/compare/DifferentiationInterface-v0.7.7...main) + - Support the new `ADTypes.NoAutoDiff` ([#851](https://github.com/JuliaDiff/DifferentiationInterface.jl/pull/851)) + ## [0.7.7](https://github.com/JuliaDiff/DifferentiationInterface.jl/compare/DifferentiationInterface-v0.7.6...DifferentiationInterface-v0.7.7) - Improve support for empty inputs (still not guaranteed) ([#835](https://github.com/JuliaDiff/DifferentiationInterface.jl/pull/835)) diff --git a/DifferentiationInterface/src/utils/check.jl b/DifferentiationInterface/src/utils/check.jl index ed11dd10a..311da5ef6 100644 --- a/DifferentiationInterface/src/utils/check.jl +++ b/DifferentiationInterface/src/utils/check.jl @@ -24,5 +24,3 @@ check_available(::ADTypes.NoAutoDiff) = throw(ADTypes.NoAutoDiffSelectedError()) Check whether `backend` supports differentiation of in-place functions and return a `Bool`. """ check_inplace(backend::AbstractADType) = Bool(inplace_support(backend)) - -check_inplace(::ADTypes.NoAutoDiff) = throw(ADTypes.NoAutoDiffSelectedError()) diff --git a/DifferentiationInterface/src/utils/traits.jl b/DifferentiationInterface/src/utils/traits.jl index 8a059870c..b1f4ed5b5 100644 --- a/DifferentiationInterface/src/utils/traits.jl +++ b/DifferentiationInterface/src/utils/traits.jl @@ -23,6 +23,8 @@ Return [`InPlaceSupported`](@ref) or [`InPlaceNotSupported`](@ref) in a statical """ inplace_support(::AbstractADType) = InPlaceSupported() +inplace_support(::ADTypes.NoAutoDiff) = throw(ADTypes.NoAutoDiffSelectedError()) + function inplace_support(backend::SecondOrder) if inplace_support(inner(backend)) isa InPlaceSupported && inplace_support(outer(backend)) isa InPlaceSupported diff --git a/DifferentiationInterface/test/Core/Internals/backends.jl b/DifferentiationInterface/test/Core/Internals/backends.jl index 5ce73706f..43bb4f1f3 100644 --- a/DifferentiationInterface/test/Core/Internals/backends.jl +++ b/DifferentiationInterface/test/Core/Internals/backends.jl @@ -18,6 +18,11 @@ using Test fb = AutoSimpleFiniteDiff() rb = AutoReverseFromPrimitive(AutoSimpleFiniteDiff()) +@testset "NoAutoDiff" begin + @test_throws NoAutoDiffSelectedError check_available(NoAutoDiff()) + @test_throws NoAutoDiffSelectedError inplace_support(NoAutoDiff()) +end + @testset "SecondOrder" begin backend = SecondOrder(fb, rb) @test check_available(backend) diff --git a/DifferentiationInterface/test/Core/ZeroBackends/test.jl b/DifferentiationInterface/test/Core/ZeroBackends/test.jl index 771d265c5..396e7d455 100644 --- a/DifferentiationInterface/test/Core/ZeroBackends/test.jl +++ b/DifferentiationInterface/test/Core/ZeroBackends/test.jl @@ -10,9 +10,6 @@ using Test LOGGING = get(ENV, "CI", "false") == "false" -@test_throws NoAutoDiffSelectedError check_available(NoAutoDiff()) -@test_throws NoAutoDiffSelectedError check_inplace(NoAutoDiff()) - zero_backends = [AutoZeroForward(), AutoZeroReverse()] for backend in zero_backends