diff --git a/Project.toml b/Project.toml index 725aa5c9d..6bf13d3a3 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "NonlinearSolve" uuid = "8913a72c-1f9b-4ce2-8d82-65094dcecaec" authors = ["SciML"] -version = "3.15.2" +version = "4.0.0" [deps] ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b" @@ -15,7 +15,6 @@ FiniteDiff = "6a86dc24-6348-571c-b903-95158fe2bd41" ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210" LazyArrays = "5078a376-72f3-5289-bfd5-ec5146d43c02" LineSearch = "87fe0de2-c867-4266-b59a-2f0a94fc965b" -LineSearches = "d3d80556-e9d4-5f37-9878-2ab0fcc64255" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" LinearSolve = "7ed4a6bd-45f5-4d41-b270-4a48e9bafcae" MaybeInplace = "bb5d69b7-63fc-4a16-80bd-7e42200c7bdb" @@ -41,6 +40,7 @@ BandedMatrices = "aae01518-5342-5314-be14-df237901396f" FastLevenbergMarquardt = "7a0df574-e128-4d35-8cbd-3d84502bf7ce" FixedPointAcceleration = "817d07cb-a79a-5c30-9a31-890123675176" LeastSquaresOptim = "0fc2ff8b-aaa3-5acd-a817-1944a5e08891" +LineSearches = "d3d80556-e9d4-5f37-9878-2ab0fcc64255" MINPACK = "4854310b-de5a-5eb6-a2a5-c1dee2bd17f9" NLSolvers = "337daf1e-9722-11e9-073e-8b9effe078ba" NLsolve = "2774e3e8-f4cf-5e23-947b-6d7e65073b56" @@ -54,7 +54,7 @@ NonlinearSolveFixedPointAccelerationExt = "FixedPointAcceleration" NonlinearSolveLeastSquaresOptimExt = "LeastSquaresOptim" NonlinearSolveMINPACKExt = "MINPACK" NonlinearSolveNLSolversExt = "NLSolvers" -NonlinearSolveNLsolveExt = "NLsolve" +NonlinearSolveNLsolveExt = ["NLsolve", "LineSearches"] NonlinearSolveSIAMFANLEquationsExt = "SIAMFANLEquations" NonlinearSolveSpeedMappingExt = "SpeedMapping" @@ -132,6 +132,7 @@ FixedPointAcceleration = "817d07cb-a79a-5c30-9a31-890123675176" Hwloc = "0e44f5e4-bd66-52a0-8798-143a42290a1d" InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240" LeastSquaresOptim = "0fc2ff8b-aaa3-5acd-a817-1944a5e08891" +LineSearches = "d3d80556-e9d4-5f37-9878-2ab0fcc64255" MINPACK = "4854310b-de5a-5eb6-a2a5-c1dee2bd17f9" ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78" NLSolvers = "337daf1e-9722-11e9-073e-8b9effe078ba" @@ -151,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", "MINPACK", "ModelingToolkit", "NLSolvers", "NLsolve", "NaNMath", "NonlinearProblemLibrary", "OrdinaryDiffEqTsit5", "Pkg", "Random", "ReTestItems", "SIAMFANLEquations", "SpeedMapping", "StableRNGs", "StaticArrays", "Sundials", "Test", "Zygote"] +test = ["Aqua", "BandedMatrices", "BenchmarkTools", "CUDA", "Enzyme", "ExplicitImports", "FastLevenbergMarquardt", "FixedPointAcceleration", "Hwloc", "InteractiveUtils", "LeastSquaresOptim", "LineSearches", "MINPACK", "ModelingToolkit", "NLSolvers", "NLsolve", "NaNMath", "NonlinearProblemLibrary", "OrdinaryDiffEqTsit5", "Pkg", "Random", "ReTestItems", "SIAMFANLEquations", "SpeedMapping", "StableRNGs", "StaticArrays", "Sundials", "Test", "Zygote"] diff --git a/docs/src/native/solvers.md b/docs/src/native/solvers.md index a5deca141..aebaee379 100644 --- a/docs/src/native/solvers.md +++ b/docs/src/native/solvers.md @@ -23,10 +23,7 @@ documentation. algorithms, consult the [LinearSolve.jl documentation](https://docs.sciml.ai/LinearSolve/stable/). - `linesearch`: the line search algorithm to use. Defaults to [`NoLineSearch()`](@extref LineSearch.NoLineSearch), - which means that no line search is performed. Algorithms from - [`LineSearches.jl`](https://github.com/JuliaNLSolvers/LineSearches.jl/) must be - wrapped in [`LineSearchesJL`](@ref) before being supplied. For a detailed documentation - refer to [Line Search Algorithms](@ref line-search). + which means that no line search is performed. - `autodiff`/`jacobian_ad`: etermines the backend used for the Jacobian. Note that this argument is ignored if an analytical Jacobian is passed, as that will be used instead. Defaults to `nothing` which means that a default is selected according to the problem diff --git a/ext/NonlinearSolveNLsolveExt.jl b/ext/NonlinearSolveNLsolveExt.jl index 77ed4a56f..95de37055 100644 --- a/ext/NonlinearSolveNLsolveExt.jl +++ b/ext/NonlinearSolveNLsolveExt.jl @@ -1,5 +1,6 @@ module NonlinearSolveNLsolveExt +using LineSearches: Static using NonlinearSolve: NonlinearSolve, NLsolveJL, TraceMinimal using NLsolve: NLsolve, OnceDifferentiable, nlsolve using SciMLBase: SciMLBase, NonlinearProblem, ReturnCode @@ -31,9 +32,11 @@ function SciMLBase.__solve( store_trace = StT || alg.store_trace extended_trace = !(trace_level isa TraceMinimal) || alg.extended_trace + linesearch = alg.linesearch === missing ? Static() : alg.linesearch + original = nlsolve(df, vec(u0); ftol = abstol, iterations = maxiters, alg.method, - store_trace, extended_trace, alg.linesearch, alg.linsolve, - alg.factor, alg.autoscale, alg.m, alg.beta, show_trace) + store_trace, extended_trace, linesearch, alg.linsolve, alg.factor, + alg.autoscale, alg.m, alg.beta, show_trace) f!(vec(resid), original.zero) u = prob.u0 isa Number ? original.zero[1] : reshape(original.zero, size(prob.u0)) diff --git a/src/NonlinearSolve.jl b/src/NonlinearSolve.jl index 5e2dc5555..1f48371e6 100644 --- a/src/NonlinearSolve.jl +++ b/src/NonlinearSolve.jl @@ -23,8 +23,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 -using LineSearches: LineSearches + NoLineSearch, RobustNonMonotoneLineSearch, BackTracking using LinearSolve: LinearSolve, LUFactorization, QRFactorization, needs_concrete_A, AbstractFactorization, DefaultAlgorithmChoice, DefaultLinearSolver @@ -174,9 +173,7 @@ export NewtonDescent, SteepestDescent, Dogleg, DampedNewtonDescent, GeodesicAcce # Globalization ## Line Search Algorithms -export LineSearchesJL, LiFukushimaLineSearch # FIXME: deprecated. use LineSearch.jl directly -export Static, HagerZhang, MoreThuente, StrongWolfe, BackTracking # FIXME: deprecated -export LineSearch, NoLineSearch, RobustNonMonotoneLineSearch +export LineSearch, BackTracking, NoLineSearch, RobustNonMonotoneLineSearch, LineSearchesJL ## Trust Region Algorithms export RadiusUpdateSchemes diff --git a/src/algorithms/extension_algs.jl b/src/algorithms/extension_algs.jl index 46ebc8dae..9c08c5202 100644 --- a/src/algorithms/extension_algs.jl +++ b/src/algorithms/extension_algs.jl @@ -203,6 +203,12 @@ end acceleration of the fixed-point iteration xₙ₊₁ = xₙ + beta*f(xₙ), where by default beta = 1. +!!! warning + + Line Search Algorithms from [`LineSearch.jl`](https://github.com/SciML/LineSearch.jl) + aren't supported by `NLsolveJL`. Instead, use the line search algorithms from + [`LineSearches.jl`](https://github.com/JuliaNLSolvers/LineSearches.jl). + ### Submethod Choice Choices for methods in `NLsolveJL`: @@ -234,7 +240,7 @@ For more information on these arguments, consult the end function NLsolveJL(; method = :trust_region, autodiff = :central, store_trace = missing, - extended_trace = missing, linesearch = LineSearches.Static(), + extended_trace = missing, linesearch = missing, linsolve = (x, A, b) -> copyto!(x, A \ b), factor = 1.0, autoscale = true, m = 10, beta = one(Float64), show_trace = missing) if Base.get_extension(@__MODULE__, :NonlinearSolveNLsolveExt) === nothing diff --git a/src/algorithms/klement.jl b/src/algorithms/klement.jl index 5e911d8c0..f5d3edf3d 100644 --- a/src/algorithms/klement.jl +++ b/src/algorithms/klement.jl @@ -27,13 +27,6 @@ over this. function Klement(; max_resets::Int = 100, linsolve = nothing, alpha = nothing, linesearch = NoLineSearch(), precs = DEFAULT_PRECS, autodiff = nothing, init_jacobian::Val{IJ} = Val(:identity)) where {IJ} - if !(linesearch isa AbstractLineSearchAlgorithm) - Base.depwarn( - "Passing in a `LineSearches.jl` algorithm directly is deprecated. \ - Please use `LineSearchesJL` instead.", :Klement) - linesearch = LineSearchesJL(; method = linesearch) - end - if IJ === :identity initialization = IdentityInitialization(alpha, DiagonalStructure()) elseif IJ === :true_jacobian diff --git a/src/core/approximate_jacobian.jl b/src/core/approximate_jacobian.jl index 6484c0408..2e0c64a82 100644 --- a/src/core/approximate_jacobian.jl +++ b/src/core/approximate_jacobian.jl @@ -59,12 +59,6 @@ function ApproximateJacobianSolveAlgorithm{concrete_jac, name}(; linesearch = missing, trustregion = missing, descent, update_rule, reinit_rule, initialization, max_resets::Int = typemax(Int), max_shrink_times::Int = typemax(Int)) where {concrete_jac, name} - if linesearch !== missing && !(linesearch isa AbstractLineSearchAlgorithm) - Base.depwarn("Passing in a `LineSearches.jl` algorithm directly is deprecated. \ - Please use `LineSearchesJL` instead.", - :GeneralizedFirstOrderAlgorithm) - linesearch = LineSearchesJL(; method = linesearch) - end return ApproximateJacobianSolveAlgorithm{concrete_jac, name}( linesearch, trustregion, descent, update_rule, reinit_rule, max_resets, max_shrink_times, initialization) diff --git a/src/core/generalized_first_order.jl b/src/core/generalized_first_order.jl index a485c7c65..ebdaf1fc8 100644 --- a/src/core/generalized_first_order.jl +++ b/src/core/generalized_first_order.jl @@ -66,13 +66,6 @@ function GeneralizedFirstOrderAlgorithm{concrete_jac, name}(; jacobian_ad !== nothing && ADTypes.mode(jacobian_ad) isa ADTypes.ReverseMode, jacobian_ad, nothing)) - if linesearch !== missing && !(linesearch isa AbstractLineSearchAlgorithm) - Base.depwarn("Passing in a `LineSearches.jl` algorithm directly is deprecated. \ - Please use `LineSearchesJL` instead.", - :GeneralizedFirstOrderAlgorithm) - linesearch = LineSearchesJL(; method = linesearch) - end - return GeneralizedFirstOrderAlgorithm{concrete_jac, name}( linesearch, trustregion, descent, max_shrink_times, jacobian_ad, forward_ad, reverse_ad) diff --git a/src/default.jl b/src/default.jl index c0924e2ff..967b2e0e8 100644 --- a/src/default.jl +++ b/src/default.jl @@ -364,7 +364,7 @@ function RobustMultiNewton(::Type{T} = Float64; concrete_jac = nothing, linsolve radius_update_scheme = RadiusUpdateSchemes.Bastin), NewtonRaphson(; concrete_jac, linsolve, precs, autodiff), NewtonRaphson(; concrete_jac, linsolve, precs, - linesearch = LineSearch.BackTracking(), autodiff), + linesearch = BackTracking(), autodiff), TrustRegion(; concrete_jac, linsolve, precs, radius_update_scheme = RadiusUpdateSchemes.NLsolve, autodiff), TrustRegion(; concrete_jac, linsolve, precs, @@ -405,7 +405,7 @@ function FastShortcutNonlinearPolyalg( else algs = (NewtonRaphson(; concrete_jac, linsolve, precs, autodiff), NewtonRaphson(; concrete_jac, linsolve, precs, - linesearch = LineSearch.BackTracking(), autodiff), + linesearch = BackTracking(), autodiff), TrustRegion(; concrete_jac, linsolve, precs, autodiff), TrustRegion(; concrete_jac, linsolve, precs, radius_update_scheme = RadiusUpdateSchemes.Bastin, autodiff)) @@ -426,7 +426,7 @@ function FastShortcutNonlinearPolyalg( SimpleKlement(), NewtonRaphson(; concrete_jac, linsolve, precs, autodiff), NewtonRaphson(; concrete_jac, linsolve, precs, - linesearch = LineSearch.BackTracking(), autodiff), + linesearch = BackTracking(), autodiff), TrustRegion(; concrete_jac, linsolve, precs, radius_update_scheme = RadiusUpdateSchemes.Bastin, autodiff)) end @@ -445,7 +445,7 @@ function FastShortcutNonlinearPolyalg( Klement(; linsolve, precs, autodiff), NewtonRaphson(; concrete_jac, linsolve, precs, autodiff), NewtonRaphson(; concrete_jac, linsolve, precs, - linesearch = LineSearch.BackTracking(), autodiff), + linesearch = BackTracking(), autodiff), TrustRegion(; concrete_jac, linsolve, precs, autodiff), TrustRegion(; concrete_jac, linsolve, precs, radius_update_scheme = RadiusUpdateSchemes.Bastin, autodiff)) @@ -481,7 +481,7 @@ function FastShortcutNLLSPolyalg( linsolve, precs, disable_geodesic = Val(true), autodiff, kwargs...), TrustRegion(; concrete_jac, linsolve, precs, autodiff, kwargs...), GaussNewton(; concrete_jac, linsolve, precs, - linesearch = LineSearch.BackTracking(), autodiff, kwargs...), + linesearch = BackTracking(), autodiff, kwargs...), TrustRegion(; concrete_jac, linsolve, precs, radius_update_scheme = RadiusUpdateSchemes.Bastin, autodiff, kwargs...), LevenbergMarquardt(; linsolve, precs, autodiff, kwargs...)) diff --git a/src/globalization/line_search.jl b/src/globalization/line_search.jl index c7c342bee..7549f1f9d 100644 --- a/src/globalization/line_search.jl +++ b/src/globalization/line_search.jl @@ -1,29 +1,3 @@ -LineSearchesJL(method; kwargs...) = LineSearchesJL(; method, kwargs...) -function LineSearchesJL(; method = LineSearches.Static(), autodiff = nothing, α = true) - Base.depwarn("`LineSearchesJL(...)` is deprecated. Please use `LineSearchesJL` from \ - LineSearch.jl instead.", - :LineSearchesJL) - - # Prevent breaking old code - method isa LineSearch.LineSearchesJL && - return LineSearch.LineSearchesJL(method.method, α, autodiff) - method isa AbstractLineSearchAlgorithm && return method - return LineSearch.LineSearchesJL(method, α, autodiff) -end - -for alg in (:Static, :HagerZhang, :MoreThuente, :BackTracking, :StrongWolfe) - depmsg = "`$(alg)(args...; kwargs...)` is deprecated. Please use `LineSearchesJL(; \ - method = $(alg)(args...; kwargs...))` instead." - @eval function $(alg)(args...; autodiff = nothing, initial_alpha = true, kwargs...) - Base.depwarn($(depmsg), $(Meta.quot(alg))) - return LineSearch.LineSearchesJL(; - method = LineSearches.$(alg)(args...; kwargs...), autodiff, initial_alpha) - end -end - -Base.@deprecate LiFukushimaLineSearch(; nan_max_iter::Int = 5, kwargs...) LineSearch.LiFukushimaLineSearch(; - nan_maxiters = nan_max_iter, kwargs...) - function callback_into_cache!(topcache, cache::AbstractLineSearchCache, args...) LineSearch.callback_into_cache!(cache, get_fu(topcache)) end