alpaqa 1.0.0a12
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 /// When evaluating ψ(x̂) in a candidate point, always evaluate ∇ψ(x̂) as
64 /// well. Can be beneficial if computing ∇ψ(x̂) is not much more expensive
65 /// than computing just ψ(x), and if ∇ψ(x̂) is required in the next iteration
66 /// (e.g. for the stopping criterion, or when using the NoopDirection).
67 bool eager_gradient_eval = false;
68};
69
70template <Config Conf = DefaultConfig>
71struct PANOCStats {
73
76 std::chrono::nanoseconds elapsed_time{};
77 std::chrono::nanoseconds time_progress_callback{};
78 unsigned iterations = 0;
79 unsigned linesearch_failures = 0;
81 unsigned stepsize_backtracks = 0;
82 unsigned lbfgs_failures = 0;
83 unsigned lbfgs_rejected = 0;
84 unsigned τ_1_accepted = 0;
85 unsigned count_τ = 0;
91};
92
93template <Config Conf = DefaultConfig>
119
120/// PANOC solver for ALM.
121/// @ingroup grp_InnerSolvers
122template <class DirectionT>
124 public:
125 USING_ALPAQA_CONFIG_TEMPLATE(DirectionT::config_t);
126
133
135 requires std::default_initializable<Direction>
136 : params(params) {}
141
142 Stats operator()(const Problem &problem, // in
143 const SolveOptions &opts, // in
144 rvec x, // inout
145 rvec y, // inout
146 crvec Σ, // in
147 rvec err_z); // out
148
149 template <class P>
150 Stats operator()(const P &problem, const SolveOptions &opts, rvec x, rvec y,
151 crvec Σ, rvec e) {
152 return operator()(Problem::template make<P>(problem), opts, x, y, Σ, e);
153 }
154
155 template <class P>
156 Stats operator()(const P &problem, const SolveOptions &opts, rvec x) {
157 if (problem.get_m() != 0)
158 throw std::invalid_argument("Missing arguments y, Σ, e");
159 mvec y{nullptr, 0}, Σ{nullptr, 0}, e{nullptr, 0};
160 return operator()(problem, opts, x, y, Σ, e);
161 }
162
163 /// Specify a callable that is invoked with some intermediate results on
164 /// each iteration of the algorithm.
165 /// @see @ref ProgressInfo
167 set_progress_callback(std::function<void(const ProgressInfo &)> cb) {
168 this->progress_cb = cb;
169 return *this;
170 }
171
172 std::string get_name() const;
173
174 void stop() { stop_signal.stop(); }
175
176 const Params &get_params() const { return params; }
177
178 private:
181 std::function<void(const ProgressInfo &)> progress_cb;
183
184 public:
186 std::ostream *os = &std::cout;
187};
188
189template <class InnerSolverStats>
191
192template <Config Conf>
195
196 /// Total elapsed time in the inner solver.
197 std::chrono::nanoseconds elapsed_time{};
198 /// Total time spent in the user-provided progress callback.
199 std::chrono::nanoseconds time_progress_callback{};
200 /// Total number of inner PANOC iterations.
201 unsigned iterations = 0;
202 /// Total number of PANOC line search failures.
203 unsigned linesearch_failures = 0;
204 /// Total number of PANOC line search backtracking steps.
205 unsigned linesearch_backtracks = 0;
206 /// Total number of PANOC step size reductions.
207 unsigned stepsize_backtracks = 0;
208 /// Total number of times that the L-BFGS direction was not finite.
209 unsigned lbfgs_failures = 0;
210 /// Total number of times that the L-BFGS update was rejected (i.e. it
211 /// could have resulted in a non-positive definite Hessian estimate).
212 unsigned lbfgs_rejected = 0;
213 /// Total number of times that a line search parameter of @f$ \tau = 1 @f$
214 /// was accepted (i.e. no backtracking necessary).
215 unsigned τ_1_accepted = 0;
216 /// The total number of line searches performed (used for computing the
217 /// average value of @f$ \tau @f$).
218 unsigned count_τ = 0;
219 /// The sum of the line search parameter @f$ \tau @f$ in all iterations
220 /// (used for computing the average value of @f$ \tau @f$).
221 real_t sum_τ = 0;
222 /// The final PANOC step size γ.
223 real_t final_γ = 0;
224 /// Final value of the smooth cost @f$ \psi(\hat x) @f$.
225 real_t final_ψ = 0;
226 /// Final value of the nonsmooth cost @f$ h(\hat x) @f$.
227 real_t final_h = 0;
228 /// Final value of the forward-backward envelope, @f$ \varphi_\gamma(x) @f$
229 /// (note that this is in the point @f$ x @f$, not @f$ \hat x @f$).
230 real_t final_φγ = 0;
231};
232
233template <Config Conf>
236 const PANOCStats<Conf> &s) {
238 acc.elapsed_time += s.elapsed_time;
239 acc.time_progress_callback += s.time_progress_callback;
240 acc.linesearch_failures += s.linesearch_failures;
241 acc.linesearch_backtracks += s.linesearch_backtracks;
242 acc.stepsize_backtracks += s.stepsize_backtracks;
243 acc.lbfgs_failures += s.lbfgs_failures;
244 acc.lbfgs_rejected += s.lbfgs_rejected;
245 acc.τ_1_accepted += s.τ_1_accepted;
246 acc.count_τ += s.count_τ;
247 acc.sum_τ += s.sum_τ;
248 acc.final_γ = s.final_γ;
249 acc.final_ψ = s.final_ψ;
250 acc.final_h = s.final_h;
251 acc.final_φγ = s.final_φγ;
252 return acc;
253}
254
255// clang-format off
256ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANOCParams, EigenConfigd);
257ALPAQA_IF_FLOAT(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANOCParams, EigenConfigf);)
258ALPAQA_IF_LONGD(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANOCParams, EigenConfigl);)
260
261ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANOCStats, EigenConfigd);
262ALPAQA_IF_FLOAT(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANOCStats, EigenConfigf);)
263ALPAQA_IF_LONGD(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANOCStats, EigenConfigl);)
265
266ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANOCProgressInfo, EigenConfigd);
267ALPAQA_IF_FLOAT(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANOCProgressInfo, EigenConfigf);)
268ALPAQA_IF_LONGD(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANOCProgressInfo, EigenConfigl);)
270// clang-format on
271
272} // namespace alpaqa
PANOC solver for ALM.
Definition panoc.hpp:123
std::string get_name() const
Definition panoc.tpp:20
PANOCSolver(const Params &params, Direction &&direction)
Definition panoc.hpp:137
PANOCSolver(const Params &params)
Definition panoc.hpp:134
Stats operator()(const P &problem, const SolveOptions &opts, rvec x, rvec y, crvec Σ, rvec e)
Definition panoc.hpp:150
PANOCStats< config_t > Stats
Definition panoc.hpp:130
std::function< void(const ProgressInfo &)> progress_cb
Definition panoc.hpp:181
Stats operator()(const Problem &problem, const SolveOptions &opts, rvec x, rvec y, crvec Σ, rvec err_z)
Definition panoc.tpp:25
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:167
Direction direction
Definition panoc.hpp:185
InnerSolveOptions< config_t > SolveOptions
Definition panoc.hpp:132
PANOCSolver(const Params &params, const Direction &direction)
Definition panoc.hpp:139
AtomicStopSignal stop_signal
Definition panoc.hpp:180
DirectionT Direction
Definition panoc.hpp:129
const Params & get_params() const
Definition panoc.hpp:176
Stats operator()(const P &problem, const SolveOptions &opts, rvec x)
Definition panoc.hpp:156
TypeErasedProblem< config_t > Problem
Definition panoc.hpp:127
std::ostream * os
Definition panoc.hpp:186
The main polymorphic minimization problem interface.
#define USING_ALPAQA_CONFIG(Conf)
Definition config.hpp:56
#define ALPAQA_IF_QUADF(...)
Definition config.hpp:182
#define ALPAQA_IF_LONGD(...)
Definition config.hpp:194
#define ALPAQA_IF_FLOAT(...)
Definition config.hpp:188
#define USING_ALPAQA_CONFIG_TEMPLATE(Conf)
Definition config.hpp:60
#define ALPAQA_EXPORT_EXTERN_TEMPLATE(...)
Definition export.hpp:21
unsigned stepsize_backtracks
Definition panoc.hpp:81
unsigned lbfgs_rejected
Definition panoc.hpp:83
typename Conf::mvec mvec
Definition config.hpp:67
@ 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:84
unsigned lbfgs_failures
Definition panoc.hpp:82
real_t final_φγ
Definition panoc.hpp:90
const TypeErasedProblem< config_t > * problem
Definition panoc.hpp:116
InnerStatsAccumulator< PANOCOCPStats< Conf > > & operator+=(InnerStatsAccumulator< PANOCOCPStats< Conf > > &acc, const PANOCOCPStats< Conf > &s)
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:117
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:77
bool recompute_last_prox_step_after_lbfgs_flush
Definition panoc.hpp:62
std::chrono::nanoseconds elapsed_time
Definition panoc.hpp:76
typename Conf::real_t real_t
Definition config.hpp:65
unsigned linesearch_backtracks
Definition panoc.hpp:80
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 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
constexpr const auto inf
Definition config.hpp:85
typename Conf::rvec rvec
Definition config.hpp:69
typename Conf::crvec crvec
Definition config.hpp:70
unsigned linesearch_failures
Definition panoc.hpp:79
unsigned print_interval
When to print progress.
Definition panoc.hpp:52
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:78
bool eager_gradient_eval
When evaluating ψ(x̂) in a candidate point, always evaluate ∇ψ(x̂) as well.
Definition panoc.hpp:67
SolverStatus status
Definition panoc.hpp:74
unsigned count_τ
Definition panoc.hpp:85
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