alpaqa pantr
Nonconvex constrained optimization
Loading...
Searching...
No Matches
panoc.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <alpaqa/export.hpp>
12
13#include <chrono>
14#include <iostream>
15#include <limits>
16#include <stdexcept>
17#include <string>
18#include <type_traits>
19
20namespace alpaqa {
21
22/// Tuning parameters for the PANOC algorithm.
23template <Config Conf = DefaultConfig>
26
27 /// Parameters related to the Lipschitz constant estimate and step size.
29 /// Maximum number of inner PANOC iterations.
30 unsigned max_iter = 100;
31 /// Maximum duration.
32 std::chrono::nanoseconds max_time = std::chrono::minutes(5);
33 /// Minimum weight factor between Newton step and projected gradient step.
35 /// Ignore the line search condition and always accept the accelerated step.
36 /// (For testing purposes only).
37 bool force_linesearch = false;
38 /// Parameter β used in the line search (see Algorithm 2 in
39 /// @cite de_marchi_proximal_2022). @f$ 0 < \beta < 1 @f$
41 /// Minimum Lipschitz constant estimate.
43 /// Maximum Lipschitz constant estimate.
45 /// What stopping criterion to use.
47 /// Maximum number of iterations without any progress before giving up.
48 unsigned max_no_progress = 10;
49
50 /// When to print progress. If set to zero, nothing will be printed.
51 /// If set to N != 0, progress is printed every N iterations.
52 unsigned print_interval = 0;
53 /// The precision of the floating point values printed by the solver.
54 int print_precision = std::numeric_limits<real_t>::max_digits10 / 2;
55
57 10 * std::numeric_limits<real_t>::epsilon();
59 10 * std::numeric_limits<real_t>::epsilon();
60
63};
64
65template <Config Conf = DefaultConfig>
66struct PANOCStats {
68
70 real_t ε = inf<config_t>;
71 std::chrono::nanoseconds elapsed_time{};
72 std::chrono::nanoseconds time_progress_callback{};
73 unsigned iterations = 0;
74 unsigned linesearch_failures = 0;
76 unsigned stepsize_backtracks = 0;
77 unsigned lbfgs_failures = 0;
78 unsigned lbfgs_rejected = 0;
79 unsigned τ_1_accepted = 0;
80 unsigned count_τ = 0;
86};
87
88template <Config Conf = DefaultConfig>
91
92 unsigned k;
110 unsigned outer_iter;
113};
114
115/// PANOC solver for ALM.
116/// @ingroup grp_InnerSolvers
117template <class DirectionT>
119 public:
120 USING_ALPAQA_CONFIG_TEMPLATE(DirectionT::config_t);
121
124 using Direction = DirectionT;
128
130 requires std::default_initializable<Direction>
131 : params(params) {}
133 : params(params), direction(std::move(direction)) {}
136
137 Stats operator()(const Problem &problem, // in
138 const SolveOptions &opts, // in
139 rvec x, // inout
140 rvec y, // inout
141 crvec Σ, // in
142 rvec err_z); // out
143
144 template <class P>
145 Stats operator()(const P &problem, const SolveOptions &opts, rvec x, rvec y,
146 crvec Σ, rvec e) {
147 return operator()(Problem::template make<P>(problem), opts, x, y, Σ, e);
148 }
149
150 template <class P>
151 Stats operator()(const P &problem, const SolveOptions &opts, rvec x) {
152 if (problem.get_m() != 0)
153 throw std::invalid_argument("Missing arguments y, Σ, e");
154 mvec y{nullptr, 0}, Σ{nullptr, 0}, e{nullptr, 0};
155 return operator()(problem, opts, x, y, Σ, e);
156 }
157
158 /// Specify a callable that is invoked with some intermediate results on
159 /// each iteration of the algorithm.
160 /// @see @ref ProgressInfo
162 set_progress_callback(std::function<void(const ProgressInfo &)> cb) {
163 this->progress_cb = cb;
164 return *this;
165 }
166
167 std::string get_name() const;
168
169 void stop() { stop_signal.stop(); }
170
171 const Params &get_params() const { return params; }
172
173 private:
176 std::function<void(const ProgressInfo &)> progress_cb;
178
179 public:
181 std::ostream *os = &std::cout;
182};
183
184template <class InnerSolverStats>
186
187template <Config Conf>
190
191 /// Total elapsed time in the inner solver.
192 std::chrono::nanoseconds elapsed_time{};
193 /// Total time spent in the user-provided progress callback.
194 std::chrono::nanoseconds time_progress_callback{};
195 /// Total number of inner PANOC iterations.
196 unsigned iterations = 0;
197 /// Total number of PANOC line search failures.
198 unsigned linesearch_failures = 0;
199 /// Total number of PANOC line search backtracking steps.
200 unsigned linesearch_backtracks = 0;
201 /// Total number of PANOC step size reductions.
202 unsigned stepsize_backtracks = 0;
203 /// Total number of times that the L-BFGS direction was not finite.
204 unsigned lbfgs_failures = 0;
205 /// Total number of times that the L-BFGS update was rejected (i.e. it
206 /// could have resulted in a non-positive definite Hessian estimate).
207 unsigned lbfgs_rejected = 0;
208 /// Total number of times that a line search parameter of @f$ \tau = 1 @f$
209 /// was accepted (i.e. no backtracking necessary).
210 unsigned τ_1_accepted = 0;
211 /// The total number of line searches performed (used for computing the
212 /// average value of @f$ \tau @f$).
213 unsigned count_τ = 0;
214 /// The sum of the line search parameter @f$ \tau @f$ in all iterations
215 /// (used for computing the average value of @f$ \tau @f$).
216 real_t sum_τ = 0;
217 /// The final PANOC step size γ.
218 real_t final_γ = 0;
219 /// Final value of the smooth cost @f$ \psi(\hat x) @f$.
220 real_t final_ψ = 0;
221 /// Final value of the nonsmooth cost @f$ h(\hat x) @f$.
222 real_t final_h = 0;
223 /// Final value of the forward-backward envelope, @f$ \varphi_\gamma(x) @f$
224 /// (note that this is in the point @f$ x @f$, not @f$ \hat x @f$).
225 real_t final_φγ = 0;
226};
227
228template <Config Conf>
231 const PANOCStats<Conf> &s) {
232 acc.iterations += s.iterations;
233 acc.elapsed_time += s.elapsed_time;
234 acc.time_progress_callback += s.time_progress_callback;
235 acc.linesearch_failures += s.linesearch_failures;
236 acc.linesearch_backtracks += s.linesearch_backtracks;
237 acc.stepsize_backtracks += s.stepsize_backtracks;
238 acc.lbfgs_failures += s.lbfgs_failures;
239 acc.lbfgs_rejected += s.lbfgs_rejected;
240 acc.τ_1_accepted += s.τ_1_accepted;
241 acc.count_τ += s.count_τ;
242 acc.sum_τ += s.sum_τ;
243 acc.final_γ = s.final_γ;
244 acc.final_ψ = s.final_ψ;
245 acc.final_h = s.final_h;
246 acc.final_φγ = s.final_φγ;
247 return acc;
248}
249
250ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANOCParams, DefaultConfig);
251ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANOCParams, EigenConfigf);
252ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANOCParams, EigenConfigd);
253ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANOCParams, EigenConfigl);
254#ifdef ALPAQA_WITH_QUAD_PRECISION
255ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANOCParams, EigenConfigq);
256#endif
257
258ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANOCStats, DefaultConfig);
259ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANOCStats, EigenConfigf);
260ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANOCStats, EigenConfigd);
261ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANOCStats, EigenConfigl);
262#ifdef ALPAQA_WITH_QUAD_PRECISION
263ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANOCStats, EigenConfigq);
264#endif
265
266ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANOCProgressInfo, DefaultConfig);
267ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANOCProgressInfo, EigenConfigf);
268ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANOCProgressInfo, EigenConfigd);
269ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANOCProgressInfo, EigenConfigl);
270#ifdef ALPAQA_WITH_QUAD_PRECISION
271ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANOCProgressInfo, EigenConfigq);
272#endif
273
274} // namespace alpaqa
PANOC solver for ALM.
Definition: panoc.hpp:118
std::string get_name() const
Definition: panoc.tpp:21
PANOCSolver(const Params &params, Direction &&direction)
Definition: panoc.hpp:132
PANOCSolver(const Params &params)
Definition: panoc.hpp:129
Stats operator()(const P &problem, const SolveOptions &opts, rvec x, rvec y, crvec Σ, rvec e)
Definition: panoc.hpp:145
PANOCStats< config_t > Stats
Definition: panoc.hpp:125
std::function< void(const ProgressInfo &)> progress_cb
Definition: panoc.hpp:176
Stats operator()(const Problem &problem, const SolveOptions &opts, rvec x, rvec y, crvec Σ, rvec err_z)
Definition: panoc.tpp:26
PANOCSolver & set_progress_callback(std::function< void(const ProgressInfo &)> cb)
Specify a callable that is invoked with some intermediate results on each iteration of the algorithm.
Definition: panoc.hpp:162
Direction direction
Definition: panoc.hpp:180
InnerSolveOptions< config_t > SolveOptions
Definition: panoc.hpp:127
PANOCSolver(const Params &params, const Direction &direction)
Definition: panoc.hpp:134
AtomicStopSignal stop_signal
Definition: panoc.hpp:175
DirectionT Direction
Definition: panoc.hpp:124
const Params & get_params() const
Definition: panoc.hpp:171
Stats operator()(const P &problem, const SolveOptions &opts, rvec x)
Definition: panoc.hpp:151
TypeErasedProblem< config_t > Problem
Definition: panoc.hpp:122
std::ostream * os
Definition: panoc.hpp:181
#define USING_ALPAQA_CONFIG(Conf)
Definition: config.hpp:42
#define USING_ALPAQA_CONFIG_TEMPLATE(Conf)
Definition: config.hpp:46
#define ALPAQA_EXPORT_EXTERN_TEMPLATE(...)
Definition: export.hpp:21
unsigned stepsize_backtracks
Definition: panoc.hpp:76
unsigned lbfgs_rejected
Definition: panoc.hpp:78
typename Conf::mvec mvec
Definition: config.hpp:53
@ ApproxKKT
Find an ε-approximate KKT point in the ∞-norm:
real_t linesearch_tolerance_factor
Definition: panoc.hpp:58
LipschitzEstimateParams< config_t > Lipschitz
Parameters related to the Lipschitz constant estimate and step size.
Definition: panoc.hpp:28
unsigned τ_1_accepted
Definition: panoc.hpp:79
unsigned lbfgs_failures
Definition: panoc.hpp:77
real_t final_φγ
Definition: panoc.hpp:85
const TypeErasedProblem< config_t > * problem
Definition: panoc.hpp:111
InnerStatsAccumulator< PANOCOCPStats< Conf > > & operator+=(InnerStatsAccumulator< PANOCOCPStats< Conf > > &acc, const PANOCOCPStats< Conf > &s)
Definition: panoc-ocp.hpp:255
unsigned max_no_progress
Maximum number of iterations without any progress before giving up.
Definition: panoc.hpp:48
const PANOCParams< config_t > * params
Definition: panoc.hpp:112
real_t L_max
Maximum Lipschitz constant estimate.
Definition: panoc.hpp:44
SolverStatus
Exit status of a numerical solver such as ALM or PANOC.
@ Busy
In progress.
std::chrono::nanoseconds time_progress_callback
Definition: panoc.hpp:72
bool recompute_last_prox_step_after_lbfgs_flush
Definition: panoc.hpp:62
std::chrono::nanoseconds elapsed_time
Definition: panoc.hpp:71
typename Conf::real_t real_t
Definition: config.hpp:51
unsigned linesearch_backtracks
Definition: panoc.hpp:75
real_t final_ψ
Definition: panoc.hpp:83
real_t min_linesearch_coefficient
Minimum weight factor between Newton step and projected gradient step.
Definition: panoc.hpp:34
std::chrono::nanoseconds max_time
Maximum duration.
Definition: panoc.hpp:32
real_t final_h
Definition: panoc.hpp:84
real_t quadratic_upperbound_tolerance_factor
Definition: panoc.hpp:56
bool force_linesearch
Ignore the line search condition and always accept the accelerated step.
Definition: panoc.hpp:37
real_t linesearch_strictness_factor
Parameter β used in the line search (see Algorithm 2 in ).
Definition: panoc.hpp:40
typename Conf::rvec rvec
Definition: config.hpp:55
typename Conf::crvec crvec
Definition: config.hpp:56
unsigned linesearch_failures
Definition: panoc.hpp:74
unsigned print_interval
When to print progress.
Definition: panoc.hpp:52
real_t final_γ
Definition: panoc.hpp:82
int print_precision
The precision of the floating point values printed by the solver.
Definition: panoc.hpp:54
real_t L_min
Minimum Lipschitz constant estimate.
Definition: panoc.hpp:42
bool update_direction_in_candidate
Definition: panoc.hpp:61
unsigned iterations
Definition: panoc.hpp:73
SolverStatus status
Definition: panoc.hpp:69
unsigned count_τ
Definition: panoc.hpp:80
unsigned max_iter
Maximum number of inner PANOC iterations.
Definition: panoc.hpp:30
PANOCStopCrit stop_crit
What stopping criterion to use.
Definition: panoc.hpp:46
Tuning parameters for the PANOC algorithm.
Definition: panoc.hpp:24