20. Options, Reports and Errors Reference
This chapter collects the defaults of every public option and the report fields into lookup tables. Chapters 14–19 cover entry usage, and the corresponding Part I chapters give the mathematical definitions. The published API reference is https://docs.rs/nlopt4r/1.0.1/nlopt4r/.
20.1 Module map
| Module | Contents |
|---|---|
| root | Vector, Matrix, Objective, Evaluator, Function, ValueOnly, value_only, Bounds, EvaluationCounts, StopOptions, TerminationReason, Tolerance, EvaluationError, Solution, Status, Error, minimize, Method, Options |
line_search | armijo, minimize_scalar, minimize_scalar_with_options, ScalarMethod, ScalarOptions, ScalarSolution |
local | lbfgs, newton_cg, trust_region_cg, steihaug, strong_wolfe, HessianVector, SteihaugTermination |
bounded | projected_gradient, projected_gradient_norm |
trust_region | Dense Newton trust region minimize, subproblem, plus Steihaug-family re-exports |
problem | Bounds (construction, projection, unit-box mapping, sampling) |
derivative_free | pattern_search, nelder_mead |
global | differential_evolution, particle_swarm and observer variants |
least_squares | LeastSquares, the two LM entries |
quadratic | QuadraticProgram, minimize, equality_constrained |
constrained | ConstrainedProblem, Constraints, SQP/PHR entries |
core | EvaluationContext, BudgetOptions, EvaluatedPoint, Control, EvaluationEvent, Observer, SearchTermination |
utils | validate_slice, solve_dense, directional_difference, RNG re-exports |
Each module page lists its functions, structs, traits and enums.
20.2 Stopping and tolerances
StopOptions:
| Field | Default | Constraint |
|---|---|---|
max_iterations | 5000 | Zero allowed, still running the initial evaluation and convergence check |
max_evaluations | None | Some(0) invalid |
gradient_tolerance | 1e-6 | Positive finite |
value_tolerance | None | Tolerance |
step_tolerance | None | Tolerance |
Tolerance: absolute and relative finite and nonnegative with at least one positive; criterion difference <= absolute + relative * scale.
BudgetOptions (value-search): max_evaluations default 10000, target_value default None.
StopOptions, Tolerance and BudgetOptions expose a public validate(): entry points call it before the first callback and reject nonpositive budgets, non-finite targets, negative tolerances and all-zero tolerances with Error::InvalidInput.
ArmijoOptions: 1, 0.5, 0.2, 60 (initial step, contraction factor, sufficient-decrease coefficient, trial cap).
StrongWolfeOptions: sufficient_decrease = 1e-4, curvature = 0.9, initial_step = 1, maximum_step = 1e20, max_evaluations = 80.
ScalarOptions: interval_tolerance = {absolute: 1e-8, relative: sqrt(ε)}.
API pages (docs.rs): StopOptions, Tolerance, BudgetOptions, ArmijoOptions, StrongWolfeOptions, ScalarOptions.
20.3 Per-solver options
| Option type | Defaults |
|---|---|
LbfgsOptions | history_size = 10, curvature_tolerance = 1e-10, remaining fields from the stopping/strong-Wolfe defaults |
NewtonCgOptions | max_cg_iterations = 100, cg_tolerance = 0.1 |
SteihaugOptions | max_iterations = 100, relative_tolerance = 0.1 |
TrustRegionCgOptions | radius 1→100, acceptance threshold 0.1, subproblem SteihaugOptions::default() |
TrustRegionOptions | initial_radius = 1, maximum_radius = 2, acceptance_threshold = 0.15 |
LmOptions | initial_damping = 1e-3, minimum_damping = 1e-15, acceptance_ratio = 1e-4, max_damping_trials = 40 |
derivative_free::Options | budget 10000, max_iterations = 2000, initial_step = 0.1, step_tolerance = 1e-8 |
DeOptions | population 40, generations 1000, weight = 0.8, crossover = 0.9, seed 0, budget 10000 |
PsoOptions | population 40, generations 1000, inertia = 0.7, cognitive = 1.5, social = 1.5, velocity_limit = 0.2, seed 0, budget 10000 |
ConstrainedOptions | feasibility_tolerance = 1e-6, max_inner_iterations = 1000, initial_penalty = 2, outer Options::default() |
SqpOptions | subproblem iterations 1000, subproblem evaluations 10000, restoration iterations 100, restoration reduction 0.1, restoration damping 1e-3 |
Valid domains:
| Quantity | Allowed range |
|---|---|
StrongWolfeOptions | \(0<c_1<c_2<1\), initial_step ≤ maximum_step |
NewtonCgOptions::cg_tolerance | \((0,1)\) |
SteihaugOptions::relative_tolerance | \((0,1)\) |
TrustRegionOptions::acceptance_threshold | \([0,0.75)\) |
TrustRegionCgOptions::acceptance_threshold | \([0,0.25)\) |
LmOptions::acceptance_ratio | \([0,1)\) |
DeOptions::weight | \((0,2]\) |
DeOptions::crossover | \([0,1]\) |
PsoOptions::inertia | \([0,1)\) |
PsoOptions::velocity_limit | \((0,1]\) |
derivative_free::Options::initial_step | \((0,1]\) |
Broyden { phi } | \([0,1]\) |
The solver option types expose validate(): LbfgsOptions, NewtonCgOptions, StrongWolfeOptions, SteihaugOptions, TrustRegionCgOptions, derivative_free::Options. Entry points call this check before the first callback, covering budgets, out-of-range parameters and tolerances.
API pages (docs.rs): LbfgsOptions, NewtonCgOptions, SteihaugOptions, TrustRegionCgOptions, TrustRegionOptions, LmOptions, derivative_free::Options, DeOptions, PsoOptions, ConstrainedOptions, SqpOptions.
20.4 Report types
| Type | Key fields |
|---|---|
Solution | x, value, gradient_norm, iterations, status, termination_reason, evaluations |
GlobalSolution | the point/value/counts above + generations, seed, diversity, termination_reason: SearchTermination |
derivative_free::Solution | x, value, iterations, evaluations, termination_reason |
ScalarSolution | x, value, bracket, iterations, status, termination_reason, evaluations |
QuadraticSolution | solution, equality_multipliers, inequality_multipliers, constraint_violation |
ConstrainedSolution | solution, multipliers, constraint_violation, complementarity, inner_iterations |
SqpSolution | constrained, restoration |
gradient_norm by solver family:
| Solver family | gradient_norm |
|---|---|
| Unconstrained and trust region | \(\lVert\nabla f\rVert\) |
| Bounded projected gradient | Gradient mapping \(\lVert x-P(x-g)\rVert\) |
| Adaptive QR LM | \(\lVert D^{-1}J^\top r\rVert\) |
| Constrained methods | Lagrangian stationarity norm \(\lVert\nabla_xL\rVert\) |
| QP | KKT stationarity norm |
| Scalar search | No gradient evaluation, NaN in error checkpoints |
API pages (docs.rs): Solution, GlobalSolution, derivative_free::Solution, ScalarSolution, QuadraticSolution, ConstrainedSolution, SqpSolution.
20.5 Status enums
Status: Converged, MaxIterations, MaxEvaluations, Stagnated, Failed.
TerminationReason:
| Variant | Mapped status | Trigger |
|---|---|---|
GradientTolerance | Converged | Stationarity norm meets tolerance |
KktTolerance | Converged | The three KKT conditions meet tolerance |
IntervalTolerance | Converged | Scalar interval meets tolerance |
MaxIterations | MaxIterations | Outer iteration cap |
MaxEvaluations | MaxEvaluations | Objective budget cap |
ObjectiveStagnation | Stagnated | Value tolerance triggered |
StepStagnation | Stagnated | Step tolerance triggered |
Failed | Failed | Error-checkpoint marker |
SearchTermination (value-domain methods): TargetReached, MaxEvaluations, MaxIterations, Stagnated, Cancelled.
API pages (docs.rs): Status, TerminationReason, SearchTermination.
20.6 Evaluation counts
Seven EvaluationCounts fields:
| Field | Counted content |
|---|---|
objective | Objective calls; least-squares residual calls; QP model states |
gradient | Gradient requests; least-squares Jacobians |
hessian | Dense Hessians or Hessian-vector products |
constraints | Nonlinear constraint values or QP constraint states |
residuals | Residual vector requests |
jacobian | Residual/constraint Jacobian requests |
subproblem | Synthesized subproblem evaluations, outside the outer objective budget |
Combined value/gradient requests count once in each of the two categories. Only objective consumes max_evaluations.
API page (docs.rs): EvaluationCounts.
20.7 Errors and recovery
| Variant | Meaning |
|---|---|
InvalidInput(&'static str) | Option/domain/direction outside its valid set |
DimensionMismatch { context, expected, actual } | Shape error, vectors recorded as (n,1) |
NonFinite(&'static str) | Non-finite input/output/intermediate quantity |
MissingHessian | Dense Newton method with an absent analytic Hessian |
SingularSystem | Linear system singular, inconsistent or unsolvable |
Infeasible | Constraint system or linearized subproblem infeasible |
LineSearchFailed { evaluations, last_step } | No accepted step |
IterationLimit { solver, iterations } | Nested solver iterations exhausted |
SubproblemStopped { solver, reason, iterations } | Subproblem below its convergence criterion |
EvaluationBudgetExceeded | Internal budget signal, converted to a report when a valid state exists |
SearchStopped(SearchTermination) | Value-domain evaluation request after a stop |
SearchFailure { source, last_point, evaluations } | Value-domain search failure + best point |
Evaluation { operation, source } | Application callback error, source carrying the display message |
SolverFailure { solver, source, last_solution } | Local solver failure + complete checkpoint |
Recovery methods:
#![allow(unused)]
fn main() {
use nlopt4r::{Method, Options, Vector, minimize};
let problem = (
|x: &Vector| x[0] * x[0],
|x: &Vector| Vector::from_vec(vec![2.0 * x[0]]),
);
match minimize(&problem, &Vector::from_element(1, 1.0), Method::Bfgs, &Options::default()) {
Ok(report) => println!("status {:?}, f = {}", report.status, report.value),
Err(error) => {
if let Some(point) = error.last_point() {
eprintln!("best value-only point: {}", point.value);
}
if let Some(report) = error.last_solution() {
eprintln!("checkpoint {:?}", report.status);
}
eprintln!("root cause: {}", error.root_cause());
}
}
}
Rules:
root_cause()unwrapsSolverFailure/SearchFailure;last_solution()returns the full local checkpoint of aSolverFailure;last_point()returns the best valid point of a value-domain search;- the checkpoint is a fully evaluated state usable as a restart seed; with an exhausted budget it can hold an objective above the smallest value seen;
Evaluationoperationvalues:"objective","gradient","Hessian","residuals","Jacobian","constraints","observer".
API page (docs.rs): Error.
20.8 Configuration migration
Stop fields that earlier versions kept at the top level of Options now live in Options::stopping; TrustRegionOptions.solver became TrustRegionOptions.stopping; QP receives &options.stopping; shared constraint criteria live in ConstrainedOptions.solver.stopping.
20.9 Textbook and program cross-reference
The course materials for 最优化方法及其 Matlab 程序设计 (Ma Changfeng, 2010) are external study references; they are not included in this repository or crate. The table below records textbook chapters, MATLAB program names used as mathematical references, and the matching nlopt4r entries. Program names are attribution labels, not redistributed source files.
| Textbook chapter | Matlab programs | nlopt4r entries and components |
|---|---|---|
| 1 Foundations of optimization | fun.m, gfun.m, Hess.m | StopOptions, TerminationReason; chapter 1 |
| 2 Line-search techniques | golds.m, qmin.m, armijo.m | line_search::{minimize_scalar_with_options, armijo}; chapter 2 |
| 3 Steepest descent and Newton methods | grad.m, dampnm.m, revisenm.m | Method::{SteepestDescent, DampedNewton, ModifiedNewton}; chapters 3–4 |
| 4 Conjugate gradient methods | frcg.m | Method::FletcherReeves; chapter 3 |
| 5 Quasi-Newton methods | bfgs.m, dfp.m, sr1.m, broyden.m | Method::{Bfgs, Dfp, Sr1, Broyden}; chapter 4 |
| 6 Trust-region methods | trustq.m, trustm.m | trust_region::{subproblem, minimize}, local::{steihaug, trust_region_cg}; chapter 5 |
| 7 Nonlinear least squares | lmm.m | least_squares::{levenberg_marquardt, levenberg_marquardt_with_options}; chapter 7 |
| 8 Optimality conditions | theoretical derivations | the three KKT diagnostics in ConstrainedSolution; chapter 1 |
| 9 Penalty function methods | multphr.m | constrained::augmented_lagrangian; chapter 11 |
| 10 Feasible direction methods | theoretical derivations | bounded::{projected_gradient, projected_gradient_norm}, quadratic::minimize; chapters 8 and 10 |
| 11 Quadratic programming | qpact.m, qlag.m, callqpact.m | quadratic::{QuadraticProgram, minimize, equality_constrained}; chapter 10 |
| 12 Sequential quadratic programming | sqpm.m, qpsubp.m, newtlagr.m, lagsqp.m | constrained::{sqp_with_restoration, minimize}; chapter 11 |
Chapters 2, 3, 5, 7, 10, and 11 contain original diagrams drawn for this book to illustrate the cited derivations; each caption names the relevant textbook section and program file.
Theory background
- Mathematical definitions of stopping criteria: see chapter 12.
- Convergence quantities per solver: see the corresponding sections of chapters 3–11.