Skip to content

Commit 827ebd4

Browse files
committed
Pass the nlp_at_x the callback
Bug Fix: exit if too many unsuccessful iterations in a row
1 parent 72260d7 commit 827ebd4

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/main.jl

+13-11
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ function SolverCore.solve!(
148148
[Int64, T, T, T, String, T, T, T],
149149
)
150150
verbose > 0 && @info log_row(Any[iter, ft, norm_∇f, 0.0, "First iteration", α])
151-
152-
callback(nlp, solver, stats)
151+
# Pass the nlp_at_x so that we have access to xᵢₜₑᵣ
152+
callback(nlp_at_x, solver, stats)
153153

154154
while !OK && (stats.status != :user)
155155
preprocess!(nlp_stop, PData, workspace, ∇f, norm_∇f, α)
@@ -177,7 +177,7 @@ function SolverCore.solve!(
177177

178178
if Δq < 0.0 # very unsucessful
179179
verbose > 0 &&
180-
mod(iter, verbose) == 0 &&
180+
mod(iter, verbose) == 0 &&
181181
@info log_row(Any[iter, ft, norm_∇f, λ, "VU", α, norm(d), Δq])
182182
unsucc += 1
183183
unsuccinarow += 1
@@ -188,7 +188,7 @@ function SolverCore.solve!(
188188
α = min(decrease(PData, α, TR), max(TR.large_decrease_factor, αbad) * α)
189189
elseif r < acceptance_threshold # unsucessful
190190
verbose > 0 &&
191-
mod(iter, verbose) == 0 &&
191+
mod(iter, verbose) == 0 &&
192192
@info log_row(Any[iter, ft, norm_∇f, λ, "U", α, norm(d), Δq])
193193
unsucc += 1
194194
unsuccinarow += 1
@@ -205,25 +205,23 @@ function SolverCore.solve!(
205205
∇f = grad!(nlp, xt, workspace)
206206
end
207207
norm_∇f = norm(∇f)
208-
209-
verysucc += 1
210208
if r > increase_threshold # very sucessful
211209
α = increase(PData, α, TR)
212210
verbose > 0 &&
213-
mod(iter, verbose) == 0 &&
211+
mod(iter, verbose) == 0 &&
214212
@info log_row(Any[iter, ft, norm_∇f, λ, "V", α, norm(d), Δq])
213+
verysucc += 1 # TODO: check if this makes sense
215214
else # sucessful
216215
if r < reduce_threshold
217216
α = decrease(PData, α, TR)
218217
end
219-
verbose > 0 &&
220-
mod(iter, verbose) == 0 &&
218+
verbose > 0 &&
219+
mod(iter, verbose) == 0 &&
221220
@info log_row(Any[iter, ft, norm_∇f, λ, "S", α, norm(d), Δq])
222221
succ += 1
223222
end
224223
end
225224
end # while !success
226-
227225
nlp_stop.meta.nb_of_stop = iter
228226
set_x!(nlp_at_x, xt)
229227
set_fx!(nlp_at_x, ft)
@@ -237,7 +235,11 @@ function SolverCore.solve!(
237235
set_dual_residual!(stats, nlp_at_x.current_score)
238236
set_iter!(stats, nlp_stop.meta.nb_of_stop)
239237
set_time!(stats, nlp_at_x.current_time - nlp_stop.meta.start_time)
240-
callback(nlp, solver, stats)
238+
if !success & (unsuccinarow >= max_unsuccinarow)
239+
# don't just cycle if we have to many unsucessful iterations
240+
stats.status = :user
241+
end
242+
callback(nlp_at_x, solver, stats)
241243
end # while !OK
242244

243245
stats

0 commit comments

Comments
 (0)