From 75c0fb610f9b93d2070290d3859e7d8a25843f6a Mon Sep 17 00:00:00 2001 From: Avik Pal Date: Tue, 5 Mar 2024 16:04:24 -0500 Subject: [PATCH] Export wrappers over LineSearches --- Project.toml | 2 +- src/NonlinearSolve.jl | 8 +++++--- src/globalization/line_search.jl | 16 ++++++++++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/Project.toml b/Project.toml index bc1919c29..1294701b1 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "NonlinearSolve" uuid = "8913a72c-1f9b-4ce2-8d82-65094dcecaec" authors = ["SciML"] -version = "3.7.3" +version = "3.8.0" [deps] ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b" diff --git a/src/NonlinearSolve.jl b/src/NonlinearSolve.jl index 991783672..e7fa9bd3e 100644 --- a/src/NonlinearSolve.jl +++ b/src/NonlinearSolve.jl @@ -9,8 +9,8 @@ import PrecompileTools: @recompile_invalidations, @compile_workload, @setup_work @recompile_invalidations begin using ADTypes, ConcreteStructs, DiffEqBase, FastBroadcast, FastClosures, LazyArrays, - LineSearches, LinearAlgebra, LinearSolve, MaybeInplace, Preferences, Printf, - SciMLBase, SimpleNonlinearSolve, SparseArrays, SparseDiffTools + LinearAlgebra, LinearSolve, MaybeInplace, Preferences, Printf, SciMLBase, + SimpleNonlinearSolve, SparseArrays, SparseDiffTools import ArrayInterface: undefmatrix, can_setindex, restructure, fast_scalar_indexing import DiffEqBase: AbstractNonlinearTerminationMode, @@ -20,6 +20,7 @@ import PrecompileTools: @recompile_invalidations, @compile_workload, @setup_work import FiniteDiff import ForwardDiff import ForwardDiff: Dual + import LineSearches import LinearSolve: ComposePreconditioner, InvPreconditioner, needs_concrete_A import RecursiveArrayTools: recursivecopy!, recursivefill! @@ -29,7 +30,7 @@ import PrecompileTools: @recompile_invalidations, @compile_workload, @setup_work import StaticArraysCore: StaticArray, SVector, SArray, MArray, Size, SMatrix, MMatrix end -@reexport using ADTypes, LineSearches, SciMLBase, SimpleNonlinearSolve +@reexport using ADTypes, SciMLBase, SimpleNonlinearSolve const AbstractSparseADType = Union{ADTypes.AbstractSparseFiniteDifferences, ADTypes.AbstractSparseForwardMode, ADTypes.AbstractSparseReverseMode} @@ -157,6 +158,7 @@ export NewtonDescent, SteepestDescent, Dogleg, DampedNewtonDescent, GeodesicAcce # Globalization ## Line Search Algorithms export LineSearchesJL, NoLineSearch, RobustNonMonotoneLineSearch, LiFukushimaLineSearch +export Static, HagerZhang, MoreThuente, StrongWolfe, BackTracking ## Trust Region Algorithms export RadiusUpdateSchemes diff --git a/src/globalization/line_search.jl b/src/globalization/line_search.jl index 9d4f52e71..56bb98cf6 100644 --- a/src/globalization/line_search.jl +++ b/src/globalization/line_search.jl @@ -53,6 +53,10 @@ end LineSearchesJL(method; kwargs...) = LineSearchesJL(; method, kwargs...) function LineSearchesJL(; method = LineSearches.Static(), autodiff = nothing, α = true) + if method isa LineSearchesJL # Prevent breaking old code + return LineSearchesJL(method.method, α, autodiff) + end + if method isa AbstractNonlinearSolveLineSearchAlgorithm Base.depwarn("Passing a native NonlinearSolve line search algorithm to \ `LineSearchesJL` or `LineSearch` is deprecated. Pass the method \ @@ -65,6 +69,18 @@ end Base.@deprecate_binding LineSearch LineSearchesJL true +Static(args...; kwargs...) = LineSearchesJL(LineSearches.Static(args...; kwargs...)) +HagerZhang(args...; kwargs...) = LineSearchesJL(LineSearches.HagerZhang(args...; kwargs...)) +function MoreThuente(args...; kwargs...) + return LineSearchesJL(LineSearches.MoreThuente(args...; kwargs...)) +end +function BackTracking(args...; kwargs...) + return LineSearchesJL(LineSearches.BackTracking(args...; kwargs...)) +end +function StrongWolfe(args...; kwargs...) + return LineSearchesJL(LineSearches.StrongWolfe(args...; kwargs...)) +end + # Wrapper over LineSearches.jl algorithms @concrete mutable struct LineSearchesJLCache <: AbstractNonlinearSolveLineSearchCache f