Skip to content

Commit

Permalink
Small Fix (#120)
Browse files Browse the repository at this point in the history
* Pass the nlp_at_x the callback
Bug Fix: exit if too many unsuccessful iterations in a row

* Apply suggestions from code review

* Update src/main.jl

---------

Co-authored-by: Tangi Migot <tangi.migot@gmail.com>
  • Loading branch information
nrummel and tmigot authored Sep 15, 2024
1 parent 72260d7 commit f9e6d2c
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/main.jl
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ function SolverCore.solve!(
[Int64, T, T, T, String, T, T, T],
)
verbose > 0 && @info log_row(Any[iter, ft, norm_∇f, 0.0, "First iteration", α])

callback(nlp, solver, stats)

while !OK && (stats.status != :user)
Expand Down Expand Up @@ -177,7 +176,7 @@ function SolverCore.solve!(

if Δq < 0.0 # very unsucessful
verbose > 0 &&
mod(iter, verbose) == 0 &&
mod(iter, verbose) == 0 &&
@info log_row(Any[iter, ft, norm_∇f, λ, "VU", α, norm(d), Δq])
unsucc += 1
unsuccinarow += 1
Expand All @@ -188,7 +187,7 @@ function SolverCore.solve!(
α = min(decrease(PData, α, TR), max(TR.large_decrease_factor, αbad) * α)
elseif r < acceptance_threshold # unsucessful
verbose > 0 &&
mod(iter, verbose) == 0 &&
mod(iter, verbose) == 0 &&
@info log_row(Any[iter, ft, norm_∇f, λ, "U", α, norm(d), Δq])
unsucc += 1
unsuccinarow += 1
Expand All @@ -205,25 +204,23 @@ function SolverCore.solve!(
∇f = grad!(nlp, xt, workspace)
end
norm_∇f = norm(∇f)

verysucc += 1
if r > increase_threshold # very sucessful
α = increase(PData, α, TR)
verbose > 0 &&
mod(iter, verbose) == 0 &&
mod(iter, verbose) == 0 &&
@info log_row(Any[iter, ft, norm_∇f, λ, "V", α, norm(d), Δq])
verysucc += 1
else # sucessful
if r < reduce_threshold
α = decrease(PData, α, TR)
end
verbose > 0 &&
mod(iter, verbose) == 0 &&
verbose > 0 &&
mod(iter, verbose) == 0 &&
@info log_row(Any[iter, ft, norm_∇f, λ, "S", α, norm(d), Δq])
succ += 1
end
end
end # while !success

nlp_stop.meta.nb_of_stop = iter
set_x!(nlp_at_x, xt)
set_fx!(nlp_at_x, ft)
Expand All @@ -237,6 +234,9 @@ function SolverCore.solve!(
set_dual_residual!(stats, nlp_at_x.current_score)
set_iter!(stats, nlp_stop.meta.nb_of_stop)
set_time!(stats, nlp_at_x.current_time - nlp_stop.meta.start_time)
if unsuccinarow >= max_unsuccinarow
stats.status = :user
end
callback(nlp, solver, stats)
end # while !OK

Expand Down

0 comments on commit f9e6d2c

Please sign in to comment.