Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/backtracking.jl
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ function CommonSolve.solve!(
return solution_at!(ev, u, du, α₂, ReturnCode.Success)
α_tmp = -(dϕ₀ * α₂^2) / (2 * (ϕx₁ - ϕ₀ - dϕ₀ * α₂))
α₁ = α₂
α_tmp = min(α_tmp, α₂ * T(cache.alg.ρ_hi))
α_tmp = isnan(α_tmp) ? α₂ * T(cache.alg.ρ_hi) : min(α_tmp, α₂ * T(cache.alg.ρ_hi))
α₂ = max(α_tmp, α₂ * T(cache.alg.ρ_lo))
ϕx₀, ϕx₁ = ϕx₁, ϕ(α₂)

Expand All @@ -121,7 +121,7 @@ function CommonSolve.solve!(
α_tmp = compute_alpha_backtracking(cache.alg.order, T, dϕ₀, ϕ₀, ϕx₀, ϕx₁, α₁, α₂)

α₁ = α₂
α_tmp = min(α_tmp, α₂ * T(cache.alg.ρ_hi))
α_tmp = isnan(α_tmp) ? α₂ * T(cache.alg.ρ_hi) : min(α_tmp, α₂ * T(cache.alg.ρ_hi))
α₂ = max(α_tmp, α₂ * T(cache.alg.ρ_lo))

ϕx₀, ϕx₁ = ϕx₁, ϕ(α₂)
Expand Down
15 changes: 15 additions & 0 deletions test/root_finding_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,21 @@ end
end
end

@testset "BackTracking step stays finite once Float32 interpolation underflows" begin
using CommonSolve: init, solve!
using SciMLBase: NonlinearProblem
using ADTypes: AutoForwardDiff
import ForwardDiff

# The residual jumps from 1 to 2 past u = 0, so no positive step passes Armijo. The shrinking
# trial steps underflow the cubic's divisor, and its NaN minimizer must not become the step.
r(u, p) = ifelse.(u .> 0, 2.0f0, 1.0f0)
u0 = Float32[0]
cache = init(NonlinearProblem(r, u0), BackTracking(; autodiff = AutoForwardDiff()), r(u0, nothing), u0)
sol = solve!(cache, u0, Float32[1]; ϕ0 = 0.5f0, dϕ0 = 0.0f0)
@test isfinite(sol.step_size)
end

@testset "Static Strong Wolfe residual mode" begin
using CommonSolve: init, solve!
using SciMLBase: NonlinearProblem, ReturnCode
Expand Down