Skip to content

Commit

Permalink
fix: PolyesterForwardDiff shouldn't be the default for static arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
avik-pal committed Nov 7, 2024
1 parent 810eeb3 commit 1368494
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ PETSc = "0.3"
Pkg = "1.10"
PrecompileTools = "1.2"
Preferences = "1.4"
PolyesterForwardDiff = "0.1"
Random = "1.10"
ReTestItems = "1.24"
Reexport = "1.2"
Expand Down Expand Up @@ -138,6 +139,7 @@ NonlinearProblemLibrary = "b7050fa9-e91f-4b37-bcee-a89a063da141"
OrdinaryDiffEqTsit5 = "b1df2697-797e-41e3-8120-5422d3b24e4a"
PETSc = "ace2c81b-2b5f-4b1e-a30d-d662738edfe0"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
PolyesterForwardDiff = "98d1487c-24ca-40b6-b7ab-df2af84e126b"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
ReTestItems = "817f1d60-ba6b-4fd5-9520-3cf149f6a823"
SIAMFANLEquations = "084e46ad-d928-497d-ad5e-07fa361a48c4"
Expand All @@ -150,4 +152,4 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"

[targets]
test = ["Aqua", "BandedMatrices", "BenchmarkTools", "CUDA", "Enzyme", "ExplicitImports", "FastLevenbergMarquardt", "FixedPointAcceleration", "Hwloc", "InteractiveUtils", "LeastSquaresOptim", "LineSearches", "MINPACK", "NLSolvers", "NLsolve", "NaNMath", "NonlinearProblemLibrary", "OrdinaryDiffEqTsit5", "PETSc", "Pkg", "Random", "ReTestItems", "SIAMFANLEquations", "SparseConnectivityTracer", "SpeedMapping", "StableRNGs", "StaticArrays", "Sundials", "Test", "Zygote"]
test = ["Aqua", "BandedMatrices", "BenchmarkTools", "CUDA", "Enzyme", "ExplicitImports", "FastLevenbergMarquardt", "FixedPointAcceleration", "Hwloc", "InteractiveUtils", "LeastSquaresOptim", "LineSearches", "MINPACK", "NLSolvers", "NLsolve", "NaNMath", "NonlinearProblemLibrary", "OrdinaryDiffEqTsit5", "PETSc", "Pkg", "PolyesterForwardDiff", "Random", "ReTestItems", "SIAMFANLEquations", "SparseConnectivityTracer", "SpeedMapping", "StableRNGs", "StaticArrays", "Sundials", "Test", "Zygote"]
2 changes: 1 addition & 1 deletion lib/NonlinearSolveBase/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "NonlinearSolveBase"
uuid = "be0214bd-f91f-a760-ac4e-3421ce2b2da0"
authors = ["Avik Pal <[email protected]> and contributors"]
version = "1.3.0"
version = "1.3.1"

[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
Expand Down
5 changes: 5 additions & 0 deletions lib/NonlinearSolveBase/src/autodiff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ function additional_incompatible_backend_check(prob::AbstractNonlinearProblem,
end
return hasbranching(prob.f, prob.u0, prob.p)
end
function additional_incompatible_backend_check(
prob::AbstractNonlinearProblem, ::ADTypes.AutoPolyesterForwardDiff)
prob.u0 isa SArray && return true # promotes to a mutable array
return false
end

is_finite_differences_backend(ad::AbstractADType) = false
is_finite_differences_backend(::ADTypes.AutoFiniteDiff) = true
Expand Down
13 changes: 13 additions & 0 deletions test/core_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -414,3 +414,16 @@ end
solve(prob)
@test sol.u[1.0, 0.25] atol=1e-3 rtol=1e-3
end

@testset "No PolyesterForwardDiff for SArray" tags=[:core] begin
using StaticArrays, PolyesterForwardDiff

f_oop(u, p) = u .* u .- p

N = 4
u0 = SVector{N, Float64}(ones(N) .+ randn(N) * 0.01)

nlprob = NonlinearProblem(f_oop, u0, 2.0)

@test !(solve(nlprob, NewtonRaphson()).alg.autodiff isa AutoPolyesterForwardDiff)
end

0 comments on commit 1368494

Please sign in to comment.