Skip to content

Commit

Permalink
extract docstring (#263)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmigot authored Mar 22, 2024
1 parent b9aeef0 commit 51e4865
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 86 deletions.
17 changes: 17 additions & 0 deletions src/JSOSolvers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@ using Krylov, LinearOperators, NLPModels, NLPModelsModifiers, SolverCore, Solver
import SolverCore.solve!
export solve!

const Callback_docstring = "
The callback is called at each iteration.
The expected signature of the callback is `callback(nlp, solver, stats)`, and its output is ignored.
Changing any of the input arguments will affect the subsequent iterations.
In particular, setting `stats.status = :user` will stop the algorithm.
All relevant information should be available in `nlp` and `solver`.
Notably, you can access, and modify, the following:
- `solver.x`: current iterate;
- `solver.gx`: current gradient;
- `stats`: structure holding the output of the algorithm (`GenericExecutionStats`), which contains, among other things:
- `stats.dual_feas`: norm of the residual, for instance, the norm of the gradient for unconstrained problems;
- `stats.iter`: current iteration counter;
- `stats.objective`: current objective function value;
- `stats.status`: current status of the algorithm. Should be `:unknown` unless the algorithm attained a stopping criterion. Changing this to anything will stop the algorithm, but you should use `:user` to properly indicate the intention.
- `stats.elapsed_time`: elapsed time in seconds.
"

# Unconstrained solvers
include("lbfgs.jl")
include("trunk.jl")
Expand Down
17 changes: 3 additions & 14 deletions src/fomo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ The value returned is a `GenericExecutionStats`, see `SolverCore.jl`.
# Callback
$(Callback_docstring)
The callback is called at each iteration.
The expected signature of the callback is `callback(nlp, solver, stats)`, and its output is ignored.
Changing any of the input arguments will affect the subsequent iterations.
Expand Down Expand Up @@ -170,20 +172,7 @@ The value returned is a `GenericExecutionStats`, see `SolverCore.jl`.
# Callback
The callback is called at each iteration.
The expected signature of the callback is `callback(nlp, solver, stats)`, and its output is ignored.
Changing any of the input arguments will affect the subsequent iterations.
In particular, setting `stats.status = :user || stats.stats = :unknown` will stop the algorithm.
All relevant information should be available in `nlp` and `solver`.
Notably, you can access, and modify, the following:
- `solver.x`: current iterate;
- `solver.gx`: current gradient;
- `stats`: structure holding the output of the algorithm (`GenericExecutionStats`), which contains, among other things:
- `stats.dual_feas`: norm of current gradient;
- `stats.iter`: current iteration counter;
- `stats.objective`: current objective function value;
- `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.
- `stats.elapsed_time`: elapsed time in seconds.
$(Callback_docstring)
# Examples
Expand Down
15 changes: 1 addition & 14 deletions src/lbfgs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,7 @@ The keyword arguments may include
The returned value is a `GenericExecutionStats`, see `SolverCore.jl`.
# Callback
The callback is called at each iteration.
The expected signature of the callback is `callback(nlp, solver, stats)`, and its output is ignored.
Changing any of the input arguments will affect the subsequent iterations.
In particular, setting `stats.status = :user` will stop the algorithm.
All relevant information should be available in `nlp` and `solver`.
Notably, you can access, and modify, the following:
- `solver.x`: current iterate;
- `solver.gx`: current gradient;
- `stats`: structure holding the output of the algorithm (`GenericExecutionStats`), which contains, among other things:
- `stats.dual_feas`: norm of current gradient;
- `stats.iter`: current iteration counter;
- `stats.objective`: current objective function value;
- `stats.status`: current status of the algorithm. Should be `:unknown` unless the algorithm has found a stopping criteria. Changing this to anything will stop the algorithm, but you should use `:user` to properly indicate the intention.
- `stats.elapsed_time`: elapsed time in seconds.
$(Callback_docstring)
# Examples
```jldoctest
Expand Down
17 changes: 2 additions & 15 deletions src/tron.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ The keyword arguments may include
- `use_only_objgrad::Bool = false`: If `true`, the algorithm uses only the function `objgrad` instead of `obj` and `grad`.
- `cgtol::T = T(0.1)`: subproblem tolerance.
- `atol::T = √eps(T)`: absolute tolerance.
- `rtol::T = √eps(T)`: relative tolerance, the algorithm stops when ‖∇f(xᵏ)‖ ≤ atol + rtol * ‖∇f(x⁰)‖.
- `rtol::T = √eps(T)`: relative tolerance, the algorithm stops when ‖x - Proj(x - ∇f(xᵏ))‖ ≤ atol + rtol * ‖∇f(x⁰)‖. Proj denotes here the projection over the bounds.
- `verbose::Int = 0`: if > 0, display iteration details every `verbose` iteration.
- `subsolver_verbose::Int = 0`: if > 0, display iteration information every `subsolver_verbose` iteration of the subsolver.
Expand All @@ -41,20 +41,7 @@ The keyword arguments of `TronSolver` are passed to the [`TRONTrustRegion`](http
The value returned is a `GenericExecutionStats`, see `SolverCore.jl`.
# Callback
The callback is called at each iteration.
The expected signature of the callback is `callback(nlp, solver, stats)`, and its output is ignored.
Changing any of the input arguments will affect the subsequent iterations.
In particular, setting `stats.status = :user` will stop the algorithm.
All relevant information should be available in `nlp` and `solver`.
Notably, you can access, and modify, the following:
- `solver.x`: current iterate;
- `solver.gx`: current gradient;
- `stats`: structure holding the output of the algorithm (`GenericExecutionStats`), which contains, among other things:
- `stats.dual_feas`: norm of current gradient;
- `stats.iter`: current iteration counter;
- `stats.objective`: current objective function value;
- `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.
- `stats.elapsed_time`: elapsed time in seconds.
$(Callback_docstring)
# References
TRON is described in
Expand Down
17 changes: 2 additions & 15 deletions src/tronls.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ The keyword arguments may include
- `max_cgiter::Int = 50`: subproblem iteration limit.
- `cgtol::T = T(0.1)`: subproblem tolerance.
- `atol::T = √eps(T)`: absolute tolerance.
- `rtol::T = √eps(T)`: relative tolerance, the algorithm stops when ‖∇f(xᵏ)‖ ≤ atol + rtol * ‖∇f(x⁰)‖.
- `rtol::T = √eps(T)`: relative tolerance, the algorithm stops when ‖x - Proj(x - ∇f(xᵏ))‖ ≤ atol + rtol * ‖∇f(x⁰)‖. Proj denotes here the projection over the bounds.
- `Fatol::T = √eps(T)`: absolute tolerance on the residual.
- `Frtol::T = eps(T)`: relative tolerance on the residual, the algorithm stops when ‖F(xᵏ)‖ ≤ Fatol + Frtol * ‖F(x⁰)‖.
- `verbose::Int = 0`: if > 0, display iteration details every `verbose` iteration.
Expand All @@ -42,20 +42,7 @@ The keyword arguments of `TronSolverNLS` are passed to the [`TRONTrustRegion`](h
The value returned is a `GenericExecutionStats`, see `SolverCore.jl`.
# Callback
The callback is called at each iteration.
The expected signature of the callback is `callback(nlp, solver, stats)`, and its output is ignored.
Changing any of the input arguments will affect the subsequent iterations.
In particular, setting `stats.status = :user` will stop the algorithm.
All relevant information should be available in `nlp` and `solver`.
Notably, you can access, and modify, the following:
- `solver.x`: current iterate;
- `solver.gx`: current gradient;
- `stats`: structure holding the output of the algorithm (`GenericExecutionStats`), which contains, among other things:
- `stats.dual_feas`: norm of current gradient;
- `stats.iter`: current iteration counter;
- `stats.objective`: current objective function value;
- `stats.status`: current status of the algorithm. Should be `:unknown` unless the algorithm attained a stopping criterion. Changing this to anything will stop the algorithm, but you should use `:user` to properly indicate the intention.
- `stats.elapsed_time`: elapsed time in seconds.
$(Callback_docstring)
# References
This is an adaptation for bound-constrained nonlinear least-squares problems of the TRON method described in
Expand Down
15 changes: 1 addition & 14 deletions src/trunk.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,7 @@ The keyword arguments may include
The returned value is a `GenericExecutionStats`, see `SolverCore.jl`.
# Callback
The callback is called at each iteration.
The expected signature of the callback is `callback(nlp, solver, stats)`, and its output is ignored.
Changing any of the input arguments will affect the subsequent iterations.
In particular, setting `stats.status = :user` will stop the algorithm.
All relevant information should be available in `nlp` and `solver`.
Notably, you can access, and modify, the following:
- `solver.x`: current iterate;
- `solver.gx`: current gradient;
- `stats`: structure holding the output of the algorithm (`GenericExecutionStats`), which contains, among other things:
- `stats.dual_feas`: norm of current gradient;
- `stats.iter`: current iteration counter;
- `stats.objective`: current objective function value;
- `stats.status`: current status of the algorithm. Should be `:unknown` unless the algorithm attained a stopping criterion. Changing this to anything will stop the algorithm, but you should use `:user` to properly indicate the intention.
- `stats.elapsed_time`: elapsed time in seconds.
$(Callback_docstring)
# References
This implementation follows the description given in
Expand Down
15 changes: 1 addition & 14 deletions src/trunkls.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,7 @@ See `JSOSolvers.trunkls_allowed_subsolvers` for a list of available `KrylovSolve
The value returned is a `GenericExecutionStats`, see `SolverCore.jl`.
# Callback
The callback is called at each iteration.
The expected signature of the callback is `callback(nlp, solver, stats)`, and its output is ignored.
Changing any of the input arguments will affect the subsequent iterations.
In particular, setting `stats.status = :user` will stop the algorithm.
All relevant information should be available in `nlp` and `solver`.
Notably, you can access, and modify, the following:
- `solver.x`: current iterate;
- `solver.gx`: current gradient;
- `stats`: structure holding the output of the algorithm (`GenericExecutionStats`), which contains, among other things:
- `stats.dual_feas`: norm of current gradient;
- `stats.iter`: current iteration counter;
- `stats.objective`: current objective function value;
- `stats.status`: current status of the algorithm. Should be `:unknown` unless the algorithm attained a stopping criterion. Changing this to anything will stop the algorithm, but you should use `:user` to properly indicate the intention.
- `stats.elapsed_time`: elapsed time in seconds.
$(Callback_docstring)
# References
This implementation follows the description given in
Expand Down

0 comments on commit 51e4865

Please sign in to comment.