Skip to content

Commit f9e6d2c

Browse files
nrummeltmigot
andauthored
Small Fix (#120)
* 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>
1 parent 72260d7 commit f9e6d2c

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/main.jl

+9-9
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ 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-
152151
callback(nlp, solver, stats)
153152

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

178177
if Δq < 0.0 # very unsucessful
179178
verbose > 0 &&
180-
mod(iter, verbose) == 0 &&
179+
mod(iter, verbose) == 0 &&
181180
@info log_row(Any[iter, ft, norm_∇f, λ, "VU", α, norm(d), Δq])
182181
unsucc += 1
183182
unsuccinarow += 1
@@ -188,7 +187,7 @@ function SolverCore.solve!(
188187
α = min(decrease(PData, α, TR), max(TR.large_decrease_factor, αbad) * α)
189188
elseif r < acceptance_threshold # unsucessful
190189
verbose > 0 &&
191-
mod(iter, verbose) == 0 &&
190+
mod(iter, verbose) == 0 &&
192191
@info log_row(Any[iter, ft, norm_∇f, λ, "U", α, norm(d), Δq])
193192
unsucc += 1
194193
unsuccinarow += 1
@@ -205,25 +204,23 @@ function SolverCore.solve!(
205204
∇f = grad!(nlp, xt, workspace)
206205
end
207206
norm_∇f = norm(∇f)
208-
209-
verysucc += 1
210207
if r > increase_threshold # very sucessful
211208
α = increase(PData, α, TR)
212209
verbose > 0 &&
213-
mod(iter, verbose) == 0 &&
210+
mod(iter, verbose) == 0 &&
214211
@info log_row(Any[iter, ft, norm_∇f, λ, "V", α, norm(d), Δq])
212+
verysucc += 1
215213
else # sucessful
216214
if r < reduce_threshold
217215
α = decrease(PData, α, TR)
218216
end
219-
verbose > 0 &&
220-
mod(iter, verbose) == 0 &&
217+
verbose > 0 &&
218+
mod(iter, verbose) == 0 &&
221219
@info log_row(Any[iter, ft, norm_∇f, λ, "S", α, norm(d), Δq])
222220
succ += 1
223221
end
224222
end
225223
end # while !success
226-
227224
nlp_stop.meta.nb_of_stop = iter
228225
set_x!(nlp_at_x, xt)
229226
set_fx!(nlp_at_x, ft)
@@ -237,6 +234,9 @@ function SolverCore.solve!(
237234
set_dual_residual!(stats, nlp_at_x.current_score)
238235
set_iter!(stats, nlp_stop.meta.nb_of_stop)
239236
set_time!(stats, nlp_at_x.current_time - nlp_stop.meta.start_time)
237+
if unsuccinarow >= max_unsuccinarow
238+
stats.status = :user
239+
end
240240
callback(nlp, solver, stats)
241241
end # while !OK
242242

0 commit comments

Comments
 (0)