Skip to content

Commit 5771fd0

Browse files
committed
refactor: LiFukushimaLineSearch moved to LineSearch.jl
1 parent 865bc1b commit 5771fd0

File tree

3 files changed

+12
-102
lines changed

3 files changed

+12
-102
lines changed

src/core/approximate_jacobian.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ function SciMLBase.__init(
199199
if alg.linesearch !== missing
200200
supports_line_search(alg.descent) || error("Line Search not supported by \
201201
$(alg.descent).")
202-
linesearch_cache = __internal_init(
203-
prob, alg.linesearch, f, fu, u, p; stats, internalnorm, kwargs...)
202+
linesearch_cache = init(
203+
prob, alg.linesearch, fu, u; stats, internalnorm, kwargs...)
204204
GB = :LineSearch
205205
end
206206

@@ -317,7 +317,9 @@ function __step!(cache::ApproximateJacobianSolveCache{INV, GB, iip};
317317
if descent_result.success
318318
if GB === :LineSearch
319319
@static_timeit cache.timer "linesearch" begin
320-
needs_reset, α = __internal_solve!(cache.linesearch_cache, cache.u, δu)
320+
linesearch_sol = solve!(cache.linesearch_cache, cache.u, δu)
321+
needs_reset = !SciMLBase.successful_retcode(linesearch_sol.retcode)
322+
α = linesearch_sol.step_size
321323
end
322324
if needs_reset && cache.steps_since_last_reset > 5 # Reset after a burn-in period
323325
cache.force_reinit = true

src/default.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ function FastShortcutNonlinearPolyalg(
405405
else
406406
algs = (NewtonRaphson(; concrete_jac, linsolve, precs, autodiff),
407407
NewtonRaphson(; concrete_jac, linsolve, precs,
408-
linesearch = LineSearchesJL(; method = BackTracking()), autodiff),
408+
linesearch = BackTracking(), autodiff),
409409
TrustRegion(; concrete_jac, linsolve, precs, autodiff),
410410
TrustRegion(; concrete_jac, linsolve, precs,
411411
radius_update_scheme = RadiusUpdateSchemes.Bastin, autodiff))
@@ -426,7 +426,7 @@ function FastShortcutNonlinearPolyalg(
426426
SimpleKlement(),
427427
NewtonRaphson(; concrete_jac, linsolve, precs, autodiff),
428428
NewtonRaphson(; concrete_jac, linsolve, precs,
429-
linesearch = LineSearchesJL(; method = BackTracking()), autodiff),
429+
linesearch = BackTracking(), autodiff),
430430
TrustRegion(; concrete_jac, linsolve, precs,
431431
radius_update_scheme = RadiusUpdateSchemes.Bastin, autodiff))
432432
end
@@ -444,7 +444,7 @@ function FastShortcutNonlinearPolyalg(
444444
Klement(; linsolve, precs, autodiff),
445445
NewtonRaphson(; concrete_jac, linsolve, precs, autodiff),
446446
NewtonRaphson(; concrete_jac, linsolve, precs,
447-
linesearch = LineSearchesJL(; method = BackTracking()), autodiff),
447+
linesearch = BackTracking(), autodiff),
448448
TrustRegion(; concrete_jac, linsolve, precs, autodiff),
449449
TrustRegion(; concrete_jac, linsolve, precs,
450450
radius_update_scheme = RadiusUpdateSchemes.Bastin, autodiff))

src/globalization/line_search.jl

Lines changed: 4 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@ for alg in (:Static, :HagerZhang, :MoreThuente, :BackTracking, :StrongWolfe)
1515
depmsg = "`$(alg)(args...; kwargs...)` is deprecated. Please use `LineSearchesJL(; \
1616
method = $(alg)(args...; kwargs...))` instead."
1717
@eval function $(alg)(args...; autodiff = nothing, initial_alpha = true, kwargs...)
18-
Base.depwarn($(depmsg), $(alg))
18+
Base.depwarn($(depmsg), $(Meta.quot(alg)))
1919
return LineSearch.LineSearchesJL(;
2020
method = LineSearches.$(alg)(args...; kwargs...), autodiff, initial_alpha)
2121
end
2222
end
2323

24+
Base.@deprecate LiFukushimaLineSearch(; nan_max_iter::Int = 5, kwargs...) LineSearch.LiFukushimaLineSearch(;
25+
nan_maxiters = nan_max_iter, kwargs...)
26+
2427
# """
2528
# RobustNonMonotoneLineSearch(; gamma = 1 // 10000, sigma_0 = 1, M::Int = 10,
2629
# tau_min = 1 // 10, tau_max = 1 // 2, n_exp::Int = 2, maxiters::Int = 100,
@@ -142,98 +145,3 @@ end
142145
# cache.nsteps += 1
143146
# return
144147
# end
145-
146-
# """
147-
# LiFukushimaLineSearch(; lambda_0 = 1, beta = 1 // 2, sigma_1 = 1 // 1000,
148-
# sigma_2 = 1 // 1000, eta = 1 // 10, nan_max_iter::Int = 5, maxiters::Int = 100)
149-
150-
# A derivative-free line search and global convergence of Broyden-like method for nonlinear
151-
# equations [li2000derivative](@cite).
152-
# """
153-
# @kwdef @concrete struct LiFukushimaLineSearch <: AbstractNonlinearSolveLineSearchAlgorithm
154-
# lambda_0 = 1
155-
# beta = 1 // 2
156-
# sigma_1 = 1 // 1000
157-
# sigma_2 = 1 // 1000
158-
# eta = 1 // 10
159-
# rho = 9 // 10
160-
# nan_max_iter::Int = 5 # TODO (breaking): Change this to nan_maxiters for uniformity
161-
# maxiters::Int = 100
162-
# end
163-
164-
# @concrete mutable struct LiFukushimaLineSearchCache <: AbstractNonlinearSolveLineSearchCache
165-
# ϕ
166-
# f
167-
# p
168-
# internalnorm
169-
# u_cache
170-
# fu_cache
171-
# λ₀
172-
# β
173-
# σ₁
174-
# σ₂
175-
# η
176-
# ρ
177-
# α
178-
# nan_maxiters::Int
179-
# maxiters::Int
180-
# stats::NLStats
181-
# end
182-
183-
# function __internal_init(
184-
# prob::AbstractNonlinearProblem, alg::LiFukushimaLineSearch, f::F, fu, u, p,
185-
# args...; stats, internalnorm::IN = DEFAULT_NORM, kwargs...) where {F, IN}
186-
# @bb u_cache = similar(u)
187-
# @bb fu_cache = similar(fu)
188-
# T = promote_type(eltype(fu), eltype(u))
189-
190-
# ϕ = @closure (f, p, u, du, α, u_cache, fu_cache) -> begin
191-
# @bb @. u_cache = u + α * du
192-
# fu_cache = evaluate_f!!(f, fu_cache, u_cache, p)
193-
# stats.nf += 1
194-
# return internalnorm(fu_cache)
195-
# end
196-
197-
# return LiFukushimaLineSearchCache(
198-
# ϕ, f, p, internalnorm, u_cache, fu_cache, T(alg.lambda_0),
199-
# T(alg.beta), T(alg.sigma_1), T(alg.sigma_2), T(alg.eta),
200-
# T(alg.rho), T(true), alg.nan_max_iter, alg.maxiters, stats)
201-
# end
202-
203-
# function __internal_solve!(cache::LiFukushimaLineSearchCache, u, du; kwargs...)
204-
# T = promote_type(eltype(u), eltype(du))
205-
# ϕ = @closure α -> cache.ϕ(cache.f, cache.p, u, du, α, cache.u_cache, cache.fu_cache)
206-
207-
# fx_norm = ϕ(T(0))
208-
209-
# # Non-Blocking exit if the norm is NaN or Inf
210-
# !isfinite(fx_norm) && return (true, cache.α)
211-
212-
# # Early Terminate based on Eq. 2.7
213-
# du_norm = cache.internalnorm(du)
214-
# fxλ_norm = ϕ(cache.α)
215-
# fxλ_norm ≤ cache.ρ * fx_norm - cache.σ₂ * du_norm^2 && return (false, cache.α)
216-
217-
# λ₂, λ₁ = cache.λ₀, cache.λ₀
218-
# fxλp_norm = ϕ(λ₂)
219-
220-
# if !isfinite(fxλp_norm)
221-
# nan_converged = false
222-
# for _ in 1:(cache.nan_maxiters)
223-
# λ₁, λ₂ = λ₂, cache.β * λ₂
224-
# fxλp_norm = ϕ(λ₂)
225-
# nan_converged = isfinite(fxλp_norm)
226-
# nan_converged && break
227-
# end
228-
# nan_converged || return (true, cache.α)
229-
# end
230-
231-
# for i in 1:(cache.maxiters)
232-
# fxλp_norm = ϕ(λ₂)
233-
# converged = fxλp_norm ≤ (1 + cache.η) * fx_norm - cache.σ₁ * λ₂^2 * du_norm^2
234-
# converged && return (false, λ₂)
235-
# λ₁, λ₂ = λ₂, cache.β * λ₂
236-
# end
237-
238-
# return true, cache.α
239-
# end

0 commit comments

Comments
 (0)