Skip to content

Commit a2f3071

Browse files
Debug instability
1 parent 910d1cd commit a2f3071

File tree

5 files changed

+18
-12
lines changed

5 files changed

+18
-12
lines changed

lib/NonlinearSolveFirstOrder/src/eisenstat_walker.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Algorithm 2 from the classical work by Eisenstat and Walker (1996) as described
1212
safeguard_threshold
1313
end
1414

15-
function EisenstatWalkerForcing2(; η₀ = 0.5, ηₘₐₓ = 0.99, γ = 0.9, α = 2, safeguard = true, safeguard_threshold = 0.1)
15+
function EisenstatWalkerForcing2(; η₀ = 0.5, ηₘₐₓ = 0.9, γ = 0.9, α = 2, safeguard = true, safeguard_threshold = 0.1)
1616
EisenstatWalkerForcing2(η₀, ηₘₐₓ, γ, α, safeguard, safeguard_threshold)
1717
end
1818

@@ -32,6 +32,7 @@ function pre_step_forcing!(cache::EisenstatWalkerForcing2Cache, descend_cache::N
3232
# On the first iteration we initialize η with the default initial value and stop.
3333
if iter == 0
3434
cache.η = cache.p.η₀
35+
@SciMLMessage("Eisenstat-Walker initial iteration to η=$(cache.η).", cache.verbosity, :linear_verbosity)
3536
LinearSolve.update_tolerances!(descend_cache.lincache; reltol=cache.η)
3637
return nothing
3738
end
@@ -56,7 +57,7 @@ function pre_step_forcing!(cache::EisenstatWalkerForcing2Cache, descend_cache::N
5657
# Far away from the root we also need to respect η ∈ [0,1)
5758
cache.η = clamp(cache.η, 0.0, cache.p.ηₘₐₓ)
5859

59-
@SciMLMessage("Eisenstat-Walker update to η=$(cache.η).", cache.verbosity, :linear_verbosity)
60+
@SciMLMessage("Eisenstat-Walker iter $iter update to η=$(cache.η).", cache.verbosity, :linear_verbosity)
6061

6162
# Communicate new relative tolerance to linear solve
6263
LinearSolve.update_tolerances!(descend_cache.lincache; reltol=cache.η)
@@ -69,8 +70,9 @@ end
6970
function post_step_forcing!(cache::EisenstatWalkerForcing2Cache, J, u, fu, δu, iter)
7071
# Cache previous residual norm
7172
cache.rnorm_prev = cache.rnorm
72-
# And update the current one
7373
cache.rnorm = cache.internalnorm(fu)
74+
75+
# @SciMLMessage("Eisenstat-Walker sanity check: $(cache.internalnorm(fu + J*δu)) ≤ $(cache.η * cache.internalnorm(fu)).", cache.verbosity, :linear_verbosity)
7476
end
7577

7678

lib/NonlinearSolveFirstOrder/src/levenberg_marquardt.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ function LevenbergMarquardt(;
5757
vjp_autodiff,
5858
jvp_autodiff,
5959
name = :LevenbergMarquardt,
60-
concrete_jac = Val(true)
60+
concrete_jac = Val(true),
61+
6162
)
6263
end
6364

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
"""
22
NewtonRaphson(;
33
concrete_jac = nothing, linsolve = nothing, linesearch = missing,
4-
autodiff = nothing, vjp_autodiff = nothing, jvp_autodiff = nothing
4+
autodiff = nothing, vjp_autodiff = nothing, jvp_autodiff = nothing,
5+
forcing = nothing,
56
)
67
78
An advanced NewtonRaphson implementation with support for efficient handling of sparse
@@ -10,13 +11,15 @@ for large-scale and numerically-difficult nonlinear systems.
1011
"""
1112
function NewtonRaphson(;
1213
concrete_jac = nothing, linsolve = nothing, linesearch = missing,
13-
autodiff = nothing, vjp_autodiff = nothing, jvp_autodiff = nothing
14+
autodiff = nothing, vjp_autodiff = nothing, jvp_autodiff = nothing,
15+
forcing = nothing,
1416
)
1517
return GeneralizedFirstOrderAlgorithm(;
1618
linesearch,
1719
descent = NewtonDescent(; linsolve),
1820
autodiff, vjp_autodiff, jvp_autodiff,
1921
concrete_jac,
22+
forcing,
2023
name = :NewtonRaphson
2124
)
2225
end

lib/NonlinearSolveFirstOrder/src/solve.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,10 @@ function InternalAPI.step!(
314314
δu, descent_intermediates = descent_result.δu, descent_result.extras
315315

316316
if descent_result.success
317+
if has_forcing
318+
post_step_forcing!(cache.forcing_cache, J, cache.u, cache.fu, δu, cache.nsteps)
319+
end
320+
317321
cache.make_new_jacobian = true
318322
if cache.globalization isa Val{:LineSearch}
319323
@static_timeit cache.timer "linesearch" begin
@@ -360,10 +364,6 @@ function InternalAPI.step!(
360364
are (:LineSearch, :TrustRegion, :None)")
361365
end
362366
NonlinearSolveBase.check_and_update!(cache, cache.fu, cache.u, cache.u_cache)
363-
364-
if has_forcing
365-
post_step_forcing!(cache.forcing_cache, J, cache.u, cache.fu, δu, cache.nsteps)
366-
end
367367
else
368368
α = false
369369
cache.make_new_jacobian = false

lib/NonlinearSolveFirstOrder/src/trust_region.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
shrink_threshold::Real = 1 // 4, expand_threshold::Real = 3 // 4,
77
shrink_factor::Real = 1 // 4, expand_factor::Real = 2 // 1,
88
max_shrink_times::Int = 32,
9-
vjp_autodiff = nothing, autodiff = nothing, jvp_autodiff = nothing
9+
vjp_autodiff = nothing, autodiff = nothing, jvp_autodiff = nothing,
1010
)
1111
1212
An advanced TrustRegion implementation with support for efficient handling of sparse
@@ -29,7 +29,7 @@ function TrustRegion(;
2929
shrink_threshold::Real = 1 // 4, expand_threshold::Real = 3 // 4,
3030
shrink_factor::Real = 1 // 4, expand_factor::Real = 2 // 1,
3131
max_shrink_times::Int = 32,
32-
autodiff = nothing, vjp_autodiff = nothing, jvp_autodiff = nothing
32+
autodiff = nothing, vjp_autodiff = nothing, jvp_autodiff = nothing,
3333
)
3434
descent = Dogleg(; linsolve)
3535
trustregion = GenericTrustRegionScheme(;

0 commit comments

Comments
 (0)