Skip to content

Commit 7302327

Browse files
aldmadpo
authored andcommitted
add solver_specific in stats
1 parent 03362a0 commit 7302327

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

examples/demo-cutest.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,11 @@ callback =
3636
stats = AL(nlp, h, atol = 1e-6, verbose = 1, callback = callback)
3737
print(stats)
3838

39+
callback =
40+
(regnlp, solver, stats) -> begin
41+
@info "iter $(stats.iter), f $(stats.solver_specific[:smooth_obj]), h $(stats.solver_specific[:nonsmooth_obj])"
42+
end
43+
stats = AL(nlp, h, atol = 1e-6, verbose = 1, callback = callback)
44+
print(stats)
45+
3946
finalize(nlp)

src/AL_alg.jl

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,9 @@ Notably, you can access, and modify, the following:
134134
- `stats.iter`: current iteration counter;
135135
- `stats.objective`: current objective function value;
136136
- `stats.status`: current status of the algorithm. Should be `:unknown` unless the algorithm has attained a stopping criterion. Changing this to anything will stop the algorithm, but you should use `:user` to properly indicate the intention;
137-
- `stats.elapsed_time`: elapsed time in seconds.
137+
- `stats.elapsed_time`: elapsed time in seconds;
138+
- `stats.solver_specific[:smooth_obj]`: current value of the smooth part of the objective function;
139+
- `stats.solver_specific[:nonsmooth_obj]`: current value of the nonsmooth part of the objective function.
138140
"""
139141
mutable struct ALSolver{T, V, M, ST} <: AbstractOptimizationSolver
140142
x::V
@@ -244,9 +246,12 @@ function SolverCore.solve!(
244246
set_constraint_multipliers!(stats, solver.y)
245247
subout = solver.sub_stats
246248

247-
objx, _ = objcons!(nlp, solver.x, solver.cx)
248-
objx += @views h(solver.x[selected])
249+
fx, _ = objcons!(nlp, solver.x, solver.cx)
250+
hx = @views h(solver.x[selected])
251+
objx = fx + hx
249252
set_objective!(stats, objx)
253+
set_solver_specific!(stats, :smooth_obj, fx)
254+
set_solver_specific!(stats, :nonsmooth_obj, hx)
250255

251256
mu = init_penalty
252257
solver.sub_model.y .= solver.y
@@ -297,9 +302,12 @@ function SolverCore.solve!(
297302
subiters += subout.iter
298303

299304
# objective
300-
objx = obj(nlp, solver.x)
301-
objx += @views h(solver.x[selected])
305+
fx = obj(nlp, solver.x)
306+
hx = @views h(solver.x[selected])
307+
objx = fx + hx
302308
set_objective!(stats, objx)
309+
set_solver_specific!(stats, :smooth_obj, fx)
310+
set_solver_specific!(stats, :nonsmooth_obj, hx)
303311

304312
# dual estimate
305313
update_y!(solver.sub_model)

0 commit comments

Comments
 (0)