Skip to content

Commit

Permalink
feat: remove LineSearches.jl dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
avik-pal committed Oct 21, 2024
1 parent 02323bb commit 3a680ef
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 67 deletions.
9 changes: 5 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -54,7 +54,7 @@ NonlinearSolveFixedPointAccelerationExt = "FixedPointAcceleration"
NonlinearSolveLeastSquaresOptimExt = "LeastSquaresOptim"
NonlinearSolveMINPACKExt = "MINPACK"
NonlinearSolveNLSolversExt = "NLSolvers"
NonlinearSolveNLsolveExt = "NLsolve"
NonlinearSolveNLsolveExt = ["NLsolve", "LineSearches"]
NonlinearSolveSIAMFANLEquationsExt = "SIAMFANLEquations"
NonlinearSolveSpeedMappingExt = "SpeedMapping"

Expand Down Expand Up @@ -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"
Expand All @@ -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"]
5 changes: 1 addition & 4 deletions docs/src/native/solvers.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions ext/NonlinearSolveNLsolveExt.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module NonlinearSolveNLsolveExt

using LineSearches: Static
using NonlinearSolve: NonlinearSolve, NLsolveJL, TraceMinimal
using NLsolve: NLsolve, OnceDifferentiable, nlsolve
using SciMLBase: SciMLBase, NonlinearProblem, ReturnCode
Expand Down Expand Up @@ -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))
Expand Down
7 changes: 2 additions & 5 deletions src/NonlinearSolve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
8 changes: 7 additions & 1 deletion src/algorithms/extension_algs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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`:
Expand Down Expand Up @@ -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
Expand Down
7 changes: 0 additions & 7 deletions src/algorithms/klement.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 0 additions & 6 deletions src/core/approximate_jacobian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 0 additions & 7 deletions src/core/generalized_first_order.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions src/default.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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))
Expand All @@ -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
Expand All @@ -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))
Expand Down Expand Up @@ -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...))
Expand Down
26 changes: 0 additions & 26 deletions src/globalization/line_search.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 3a680ef

Please sign in to comment.