1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//! The [`Solver`] trait every concrete solver implements. See the trait
//! contract for the lifecycle (`init` once, then repeated `next_iter`,
//! with an optional `terminate` hook) and the
//! [`executor`](crate::core::executor) module for the canonical iteration
//! ordering.
use crateState;
use crateTerminationReason;
/// A concrete optimization algorithm. Implementations carry the
/// solver's configuration and any internal scratch state; the iterate
/// itself lives in `S: State`.
///
/// # Contract
///
/// - **Caller must:** drive the solver through
/// [`Executor`](crate::core::executor::Executor) (or
/// [`run_loop`](crate::core::executor::run_loop) for composed
/// solvers). The executor calls [`init`](Self::init) exactly once
/// before any [`next_iter`](Self::next_iter) call, and runs
/// termination checks before each iteration including iter 0. See the
/// [`executor`](crate::core::executor) module docs for the canonical
/// loop ordering.
/// - **Implementor must:** populate every state field termination
/// criteria might read before returning from
/// [`init`](Self::init) — at minimum [`State::cost`] for any state
/// whose `cost()` panics on missing data, and
/// [`GradientState::gradient`](crate::core::state::GradientState::gradient)
/// for first-order solvers. After every successful
/// [`next_iter`](Self::next_iter), the same fields must again
/// correspond to the *current* [`State::param`].
/// - **Implementor must:** report mid-iteration failures
/// (line-search bailout, non-descent direction, etc.) via
/// [`next_iter`](Self::next_iter)'s `Option<TerminationReason>`
/// return rather than panicking; and use [`terminate`](Self::terminate)
/// only for clean convergence tests on the current state.