Skip to content

Commit 120d073

Browse files
add callback docstring
1 parent 03bd516 commit 120d073

File tree

3 files changed

+22
-32
lines changed

3 files changed

+22
-32
lines changed

src/RegularizedOptimization.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,24 @@ using LinearOperators,
1111
NLPModels, NLPModelsModifiers, RegularizedProblems, ShiftedProximalOperators, SolverCore
1212
using Percival: AugLagModel, update_y!, update_μ!
1313

14+
const callback_docstring = "
15+
The callback is called at each iteration.
16+
The expected signature of the callback is `callback(nlp, solver, stats)`, and its output is ignored.
17+
Changing any of the input arguments will affect the subsequent iterations.
18+
In particular, setting `stats.status = :user` will stop the algorithm.
19+
All relevant information should be available in `nlp` and `solver`.
20+
Notably, you can access, and modify, the following:
21+
- `solver.xk`: current iterate;
22+
- `solver.∇fk`: current gradient;
23+
- `stats`: structure holding the output of the algorithm (`GenericExecutionStats`), which contains, among other things:
24+
- `stats.iter`: current iteration counter;
25+
- `stats.objective`: current objective function value;
26+
- `stats.solver_specific[:smooth_obj]`: current value of the smooth part of the objective function;
27+
- `stats.solver_specific[:nonsmooth_obj]`: current value of the nonsmooth part of the objective function;
28+
- `stats.status`: current status of the algorithm. Should be `:unknown` unless the algorithm has attained a stopping criterion. Changing this to anything other than `:unknown` will stop the algorithm, but you should use `:user` to properly indicate the intention;
29+
- `stats.elapsed_time`: elapsed time in seconds.
30+
"
31+
1432
include("utils.jl")
1533
include("input_struct.jl")
1634
include("PG_alg.jl")

src/TRDH_alg.jl

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ For advanced usage, first define a solver "TRDHSolver" to preallocate the memory
133133
- `Δk::T = T(1)`: initial value of the trust-region radius;
134134
- `η1::T = √√eps(T)`: successful iteration threshold;
135135
- `η2::T = T(0.9)`: very successful iteration threshold;
136-
- `γ::T = T(3)`: trust-region radius parameter multiplier, Δ := Δ*γ when the iteration is very successful and Δ := Δ/γ when the iteration is unsuccessful;
136+
- `γ::T = T(3)`: trust-region radius parameter multiplier. Must satisfy `γ > 1`. The trust-region radius is updated as Δ := Δ*γ when the iteration is very successful and Δ := Δ/γ when the iteration is unsuccessful;
137137
- `α::T = 1/eps(T)`: TODO
138138
- `β::T = 1/eps(T)`: TODO
139139
- `reduce_TR::Bool = True`: TODO
@@ -146,21 +146,7 @@ The algorithm stops either when `√(ξₖ/νₖ) < atol + rtol*√(ξ₀/ν₀)
146146
The value returned is a `GenericExecutionStats`, see `SolverCore.jl`.
147147
148148
# Callback
149-
The callback is called at each iteration.
150-
The expected signature of the callback is `callback(nlp, solver, stats)`, and its output is ignored.
151-
Changing any of the input arguments will affect the subsequent iterations.
152-
In particular, setting `stats.status = :user` will stop the algorithm.
153-
All relevant information should be available in `nlp` and `solver`.
154-
Notably, you can access, and modify, the following:
155-
- `solver.xk`: current iterate;
156-
- `solver.∇fk`: current gradient;
157-
- `stats`: structure holding the output of the algorithm (`GenericExecutionStats`), which contains, among other things:
158-
- `stats.iter`: current iteration counter;
159-
- `stats.objective`: current objective function value;
160-
- `stats.solver_specific[:smooth_obj]`: current value of the smooth part of the objective function;
161-
- `stats.solver_specific[:nonsmooth_obj]`: current value of the nonsmooth part of the objective function;
162-
- `stats.status`: current status of the algorithm. Should be `:unknown` unless the algorithm has attained a stopping criterion. Changing this to anything other than `:unknown` will stop the algorithm, but you should use `:user` to properly indicate the intention;
163-
- `stats.elapsed_time`: elapsed time in seconds.
149+
$(callback_docstring)
164150
"""
165151
function TRDH(
166152
nlp::AbstractDiagonalQNModel{T, V},

src/TR_alg.jl

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ For advanced usage, first define a solver "TRSolver" to preallocate the memory u
126126
- `Δk::T = T(1)`: initial value of the trust-region radius;
127127
- `η1::T = √√eps(T)`: successful iteration threshold;
128128
- `η2::T = T(0.9)`: very successful iteration threshold;
129-
- `γ::T = T(3)`: trust-region radius parameter multiplier, Δ := Δ*γ when the iteration is very successful and Δ := Δ/γ when the iteration is unsuccessful;
129+
- `γ::T = T(3)`: trust-region radius parameter multiplier. Must satisfy `γ > 1`. The trust-region radius is updated as Δ := Δ*γ when the iteration is very successful and Δ := Δ/γ when the iteration is unsuccessful;
130130
- `α::T = 1/eps(T)`: TODO
131131
- `β::T = 1/eps(T)`: TODO
132132
- `χ::F = NormLinf(1)`: norm used to define the trust-region;`
@@ -138,21 +138,7 @@ The algorithm stops either when `√(ξₖ/νₖ) < atol + rtol*√(ξ₀/ν₀)
138138
The value returned is a `GenericExecutionStats`, see `SolverCore.jl`.
139139
140140
# Callback
141-
The callback is called at each iteration.
142-
The expected signature of the callback is `callback(nlp, solver, stats)`, and its output is ignored.
143-
Changing any of the input arguments will affect the subsequent iterations.
144-
In particular, setting `stats.status = :user` will stop the algorithm.
145-
All relevant information should be available in `nlp` and `solver`.
146-
Notably, you can access, and modify, the following:
147-
- `solver.xk`: current iterate;
148-
- `solver.∇fk`: current gradient;
149-
- `stats`: structure holding the output of the algorithm (`GenericExecutionStats`), which contains, among other things:
150-
- `stats.iter`: current iteration counter;
151-
- `stats.objective`: current objective function value;
152-
- `stats.solver_specific[:smooth_obj]`: current value of the smooth part of the objective function;
153-
- `stats.solver_specific[:nonsmooth_obj]`: current value of the nonsmooth part of the objective function;
154-
- `stats.status`: current status of the algorithm. Should be `:unknown` unless the algorithm has attained a stopping criterion. Changing this to anything other than `:unknown` will stop the algorithm, but you should use `:user` to properly indicate the intention;
155-
- `stats.elapsed_time`: elapsed time in seconds.
141+
$(callback_docstring)
156142
"""
157143
function TR(
158144
f::AbstractNLPModel,

0 commit comments

Comments
 (0)