Skip to content

Small Fix #120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 15, 2024
Merged
Changes from 1 commit
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
24 changes: 13 additions & 11 deletions src/main.jl
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can actually access the nlp_at_x by solver.stp.nlp_at_x , so I prefer callback(nlp, solver, stats)

# Pass the nlp_at_x so that we have access to xᵢₜₑᵣ
callback(nlp_at_x, solver, stats)

while !OK && (stats.status != :user)
preprocess!(nlp_stop, PData, workspace, ∇f, norm_∇f, α)
Expand Down Expand Up @@ -177,7 +177,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 +188,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 +205,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 # TODO: check if this makes sense
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,7 +235,11 @@ 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)
callback(nlp, solver, stats)
if !success & (unsuccinarow >= max_unsuccinarow)
# don't just cycle if we have to many unsucessful iterations
stats.status = :user
end
callback(nlp_at_x, solver, stats)
end # while !OK

stats
Expand Down