Skip to content

Commit

Permalink
chore: remove more deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
avik-pal committed Oct 21, 2024
1 parent 40b1475 commit d14bd87
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 38 deletions.
2 changes: 0 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
SciMLJacobianOperators = "19f34311-ddf3-4b8b-af20-060888a46c0e"
SciMLOperators = "c0aeaf25-5076-4817-a8d5-81caf7dfa961"
Setfield = "efcf1570-3423-57d1-acb7-fd33fddbac46"
SimpleNonlinearSolve = "727e6d20-b764-4bd8-a329-72de5adea6c7"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
SparseConnectivityTracer = "9f842d2f-2579-4b1d-911e-f412cf18a3f5"
Expand Down Expand Up @@ -104,7 +103,6 @@ SIAMFANLEquations = "1.0.1"
SciMLBase = "2.54.0"
SciMLJacobianOperators = "0.1"
SciMLOperators = "0.3.10"
Setfield = "1.1.1"
SimpleNonlinearSolve = "1.12.3"
SparseArrays = "1.10"
SparseConnectivityTracer = "0.6.5"
Expand Down
48 changes: 27 additions & 21 deletions src/NonlinearSolve.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
module NonlinearSolve

if isdefined(Base, :Experimental) && isdefined(Base.Experimental, Symbol("@max_methods"))
@eval Base.Experimental.@max_methods 1
end

using Reexport: @reexport
using PrecompileTools: @compile_workload, @setup_workload

Expand All @@ -23,7 +19,7 @@ using LinearAlgebra: LinearAlgebra, ColumnNorm, Diagonal, I, LowerTriangular, Sy
UpperTriangular, axpy!, cond, diag, diagind, dot, issuccess, istril,
istriu, lu, mul!, norm, pinv, tril!, triu!
using LineSearch: LineSearch, AbstractLineSearchAlgorithm, AbstractLineSearchCache,
NoLineSearch, RobustNonMonotoneLineSearch, BackTracking
NoLineSearch, RobustNonMonotoneLineSearch, BackTracking, LineSearchesJL
using LinearSolve: LinearSolve, LUFactorization, QRFactorization,
needs_concrete_A, AbstractFactorization,
DefaultAlgorithmChoice, DefaultLinearSolver
Expand All @@ -34,7 +30,6 @@ using RecursiveArrayTools: recursivecopy!
using SciMLBase: AbstractNonlinearAlgorithm, AbstractNonlinearProblem, _unwrap_val,
isinplace, NLStats
using SciMLOperators: AbstractSciMLOperator
using Setfield: @set!
using StaticArraysCore: StaticArray, SVector, SArray, MArray, Size, SMatrix
using SymbolicIndexingInterface: SymbolicIndexingInterface, ParameterIndexingProxy,
symbolic_container, parameter_values, state_values, getu,
Expand All @@ -44,8 +39,6 @@ using SymbolicIndexingInterface: SymbolicIndexingInterface, ParameterIndexingPro
using ADTypes: ADTypes, AbstractADType, AutoFiniteDiff, AutoForwardDiff,
AutoPolyesterForwardDiff, AutoZygote, AutoEnzyme, AutoSparse,
NoSparsityDetector, KnownJacobianSparsityDetector
using ADTypes: AutoSparseFiniteDiff, AutoSparseForwardDiff, AutoSparsePolyesterForwardDiff,
AutoSparseZygote # FIXME: deprecated, remove in future
using DifferentiationInterface: DifferentiationInterface, Constant
using FiniteDiff: FiniteDiff
using ForwardDiff: ForwardDiff, Dual
Expand Down Expand Up @@ -114,11 +107,20 @@ include("default.jl")
push!(probs_nls, NonlinearProblem(fn, u0, 2.0))
end

nls_algs = (NewtonRaphson(), TrustRegion(), LevenbergMarquardt(),
PseudoTransient(), Broyden(), Klement(), DFSane(), nothing)
nls_algs = (
NewtonRaphson(),
TrustRegion(),
LevenbergMarquardt(),
# PseudoTransient(),
Broyden(),
Klement(),
# DFSane(),
nothing
)

probs_nlls = NonlinearLeastSquaresProblem[]
nlfuncs = ((NonlinearFunction{false}((u, p) -> (u .^ 2 .- p)[1:1]), [0.1, 0.0]),
nlfuncs = (
(NonlinearFunction{false}((u, p) -> (u .^ 2 .- p)[1:1]), [0.1, 0.0]),
(NonlinearFunction{false}((u, p) -> vcat(u .* u .- p, u .* u .- p)), [0.1, 0.1]),
(
NonlinearFunction{true}(
Expand All @@ -127,15 +129,22 @@ include("default.jl")
(
NonlinearFunction{true}((du, u, p) -> du .= vcat(u .* u .- p, u .* u .- p),
resid_prototype = zeros(4)),
[0.1, 0.1]))
[0.1, 0.1]
)
)
for (fn, u0) in nlfuncs
push!(probs_nlls, NonlinearLeastSquaresProblem(fn, u0, 2.0))
end

nlls_algs = (LevenbergMarquardt(), GaussNewton(), TrustRegion(),
LevenbergMarquardt(; linsolve = LUFactorization()),
GaussNewton(; linsolve = LUFactorization()),
TrustRegion(; linsolve = LUFactorization()), nothing)
nlls_algs = (
LevenbergMarquardt(),
GaussNewton(),
TrustRegion(),
# LevenbergMarquardt(; linsolve = LUFactorization()),
# GaussNewton(; linsolve = LUFactorization()),
# TrustRegion(; linsolve = LUFactorization()),
nothing
)

@compile_workload begin
@sync begin
Expand Down Expand Up @@ -177,7 +186,7 @@ export LineSearch, BackTracking, NoLineSearch, RobustNonMonotoneLineSearch, Line
## Trust Region Algorithms
export RadiusUpdateSchemes

# Export the termination conditions from DiffEqBase
# Export the termination conditions from NonlinearSolveBase
export SteadyStateDiffEqTerminationMode, SimpleNonlinearSolveTerminationMode,
NormTerminationMode, RelTerminationMode, RelNormTerminationMode, AbsTerminationMode,
AbsNormTerminationMode, RelSafeTerminationMode, AbsSafeTerminationMode,
Expand All @@ -189,8 +198,5 @@ export TraceAll, TraceMinimal, TraceWithJacobianConditionNumber
# Reexport ADTypes
export AutoFiniteDiff, AutoForwardDiff, AutoPolyesterForwardDiff, AutoZygote, AutoEnzyme,
AutoSparse
# FIXME: deprecated, remove in future
export AutoSparseFiniteDiff, AutoSparseForwardDiff, AutoSparsePolyesterForwardDiff,
AutoSparseZygote

end # module
end
10 changes: 8 additions & 2 deletions test/core/nlls_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
using Reexport
@reexport using NonlinearSolve, LinearSolve, LinearAlgebra, StableRNGs, Random, ForwardDiff,
Zygote
using LineSearches: LineSearches, Static, HagerZhang, MoreThuente, StrongWolfe

linesearches = []
for ls in (Static(), HagerZhang(), MoreThuente(), StrongWolfe(), LineSearches.BackTracking())
push!(linesearches, LineSearchesJL(; method = ls))
end
push!(linesearches, BackTracking())

true_function(x, θ) = @. θ[1] * exp(θ[2] * x) * cos(θ[3] * x + θ[4])
true_function(y, x, θ) = (@. y = θ[1] * exp(θ[2] * x) * cos(θ[3] * x + θ[4]))
Expand Down Expand Up @@ -29,8 +36,7 @@ solvers = []
for linsolve in [nothing, LUFactorization(), KrylovJL_GMRES(), KrylovJL_LSMR()]
vjp_autodiffs = linsolve isa KrylovJL ? [nothing, AutoZygote(), AutoFiniteDiff()] :
[nothing]
for linesearch in [Static(), BackTracking(), HagerZhang(), StrongWolfe(), MoreThuente()],
vjp_autodiff in vjp_autodiffs
for linesearch in linesearches, vjp_autodiff in vjp_autodiffs

push!(solvers, GaussNewton(; linsolve, linesearch, vjp_autodiff))
end
Expand Down
41 changes: 28 additions & 13 deletions test/core/rootfind_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Reexport
@reexport using BenchmarkTools, LinearSolve, NonlinearSolve, StaticArrays, Random,
LinearAlgebra, ForwardDiff, Zygote, Enzyme, DiffEqBase
using LineSearches: LineSearches

_nameof(x) = applicable(nameof, x) ? nameof(x) : _nameof(typeof(x))

Expand Down Expand Up @@ -46,8 +47,19 @@ function nlprob_iterator_interface(f, p_range, ::Val{iip}, solver) where {iip}
return sols
end

for alg in (:Static, :StrongWolfe, :BackTracking, :MoreThuente, :HagerZhang)
algname = Symbol(:LineSearches, alg)
@eval function $(algname)(args...; autodiff = nothing, initial_alpha = true, kwargs...)
return LineSearch.LineSearchesJL(;
method = LineSearches.$(alg)(args...; kwargs...), autodiff, initial_alpha)
end
end

export nlprob_iterator_interface, benchmark_nlsolve_oop, benchmark_nlsolve_iip,
TERMINATION_CONDITIONS, _nameof, newton_fails, quadratic_f, quadratic_f!
export LineSearchesStatic, LineSearchesStrongWolfe, LineSearchesBackTracking,
LineSearchesMoreThuente, LineSearchesHagerZhang

end

# --- NewtonRaphson tests ---
Expand All @@ -57,9 +69,10 @@ end
AutoForwardDiff(), AutoZygote(), AutoFiniteDiff()
),
linesearch in (
Static(; autodiff = ad), StrongWolfe(; autodiff = ad),
BackTracking(; autodiff = ad), LineSearch.BackTracking(; autodiff = ad),
HagerZhang(; autodiff = ad), MoreThuente(; autodiff = ad)
LineSearchesStatic(; autodiff = ad), LineSearchesStrongWolfe(; autodiff = ad),
LineSearchesBackTracking(; autodiff = ad), BackTracking(; autodiff = ad),
LineSearchesHagerZhang(; autodiff = ad),
LineSearchesMoreThuente(; autodiff = ad)
)

u0s = ([1.0, 1.0], @SVector[1.0, 1.0], 1.0)
Expand Down Expand Up @@ -471,9 +484,10 @@ end
AutoForwardDiff(), AutoZygote(), AutoFiniteDiff()
),
linesearch in (
Static(; autodiff = ad), StrongWolfe(; autodiff = ad),
BackTracking(; autodiff = ad), LineSearch.BackTracking(; autodiff = ad),
HagerZhang(; autodiff = ad), MoreThuente(; autodiff = ad)
LineSearchesStatic(; autodiff = ad), LineSearchesStrongWolfe(; autodiff = ad),
LineSearchesBackTracking(; autodiff = ad), BackTracking(; autodiff = ad),
LineSearchesHagerZhang(; autodiff = ad),
LineSearchesMoreThuente(; autodiff = ad)
),
init_jacobian in (Val(:identity), Val(:true_jacobian)),
update_rule in (Val(:good_broyden), Val(:bad_broyden), Val(:diagonal))
Expand Down Expand Up @@ -524,9 +538,10 @@ end
AutoForwardDiff(), AutoZygote(), AutoFiniteDiff()
),
linesearch in (
Static(; autodiff = ad), StrongWolfe(; autodiff = ad),
BackTracking(; autodiff = ad), LineSearch.BackTracking(; autodiff = ad),
HagerZhang(; autodiff = ad), MoreThuente(; autodiff = ad)
LineSearchesStatic(; autodiff = ad), LineSearchesStrongWolfe(; autodiff = ad),
LineSearchesBackTracking(; autodiff = ad), BackTracking(; autodiff = ad),
LineSearchesHagerZhang(; autodiff = ad),
LineSearchesMoreThuente(; autodiff = ad)
),
init_jacobian in (Val(:identity), Val(:true_jacobian), Val(:true_jacobian_diagonal))

Expand Down Expand Up @@ -577,10 +592,10 @@ end
AutoForwardDiff(), AutoZygote(), AutoFiniteDiff()
),
linesearch in (
Static(; autodiff = ad), StrongWolfe(; autodiff = ad),
BackTracking(; autodiff = ad), LineSearch.BackTracking(; autodiff = ad),
HagerZhang(; autodiff = ad), MoreThuente(; autodiff = ad),
LiFukushimaLineSearch()
LineSearchesStatic(; autodiff = ad), LineSearchesStrongWolfe(; autodiff = ad),
LineSearchesBackTracking(; autodiff = ad), BackTracking(; autodiff = ad),
LineSearchesHagerZhang(; autodiff = ad),
LineSearchesMoreThuente(; autodiff = ad), LiFukushimaLineSearch()
)

u0s = ([1.0, 1.0], @SVector[1.0, 1.0], 1.0)
Expand Down

0 comments on commit d14bd87

Please sign in to comment.