alpaqa pantr
Nonconvex constrained optimization
Loading...
Searching...
No Matches
pantr.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <alpaqa/export.hpp>
11
12#include <chrono>
13#include <iostream>
14#include <limits>
15#include <string>
16#include <type_traits>
17
18namespace alpaqa {
19
20/// Tuning parameters for the PANTR algorithm.
21template <Config Conf = DefaultConfig>
24
25 /// Parameters related to the Lipschitz constant estimate and step size.
27 /// Maximum number of inner PANTR iterations.
28 unsigned max_iter = 100;
29 /// Maximum duration.
30 std::chrono::nanoseconds max_time = std::chrono::minutes(5);
31 /// Minimum Lipschitz constant estimate.
33 /// Maximum Lipschitz constant estimate.
35 /// What stopping criterion to use.
37 /// Maximum number of iterations without any progress before giving up.
38 unsigned max_no_progress = 10;
39
40 /// When to print progress. If set to zero, nothing will be printed.
41 /// If set to N != 0, progress is printed every N iterations.
42 unsigned print_interval = 0;
43 /// The precision of the floating point values printed by the solver.
44 int print_precision = std::numeric_limits<real_t>::max_digits10 / 2;
45
47 10 * std::numeric_limits<real_t>::epsilon();
48 real_t TR_tolerance_factor = 10 * std::numeric_limits<real_t>::epsilon();
49
50 /// Minimal TR ratio to be accepted (successful).
52 /// Minimal TR ratio to increase radius (very successful).
54
55 /// TR radius decrease coefficient when unsuccessful.
57 /// TR radius decrease coefficient when successful.
59 /// TR radius increase coefficient when very successful.
61
62 /// Initial trust radius.
63 real_t initial_radius = NaN<config_t>;
64 /// Minimum trust radius.
65 real_t min_radius = 100 * std::numeric_limits<real_t>::epsilon();
66
67 /// Check the quadratic upperbound and update γ before computing the
68 /// reduction of the TR step.
70
73
75};
76
77template <Config Conf = DefaultConfig>
78struct PANTRStats {
80
82 real_t ε = inf<config_t>;
83 std::chrono::nanoseconds elapsed_time{};
84 std::chrono::nanoseconds time_progress_callback{};
85 unsigned iterations = 0;
87 unsigned stepsize_backtracks = 0;
88 unsigned direction_failures = 0;
94};
95
96template <Config Conf = DefaultConfig>
99
100 unsigned k;
119 unsigned outer_iter;
122};
123
124/// PANTR solver for ALM.
125/// @ingroup grp_InnerSolvers
126template <class DirectionT>
128 public:
129 USING_ALPAQA_CONFIG_TEMPLATE(DirectionT::config_t);
130
133 using Direction = DirectionT;
137
139 requires std::default_initializable<Direction>
140 : params(params) {}
142 : params(params), direction(std::move(direction)) {}
145
146 Stats operator()(const Problem &problem, // in
147 const SolveOptions &opts, // in
148 rvec x, // inout
149 rvec y, // inout
150 crvec Σ, // in
151 rvec err_z); // out
152
153 template <class P>
154 Stats operator()(const P &problem, const SolveOptions &opts, rvec x, rvec y,
155 crvec Σ, rvec e) {
156 return operator()(Problem::template make<P>(problem), opts, x, y, Σ, e);
157 }
158
159 template <class P>
160 Stats operator()(const P &problem, const SolveOptions &opts, rvec x) {
161 if (problem.get_m() != 0)
162 throw std::invalid_argument("Missing arguments y, Σ, e");
163 mvec y{nullptr, 0}, Σ{nullptr, 0}, e{nullptr, 0};
164 return operator()(problem, opts, x, y, Σ, e);
165 }
166
167 /// Specify a callable that is invoked with some intermediate results on
168 /// each iteration of the algorithm.
169 /// @see @ref ProgressInfo
171 set_progress_callback(std::function<void(const ProgressInfo &)> cb) {
172 this->progress_cb = cb;
173 return *this;
174 }
175
176 std::string get_name() const;
177
178 void stop() { stop_signal.stop(); }
179
180 const Params &get_params() const { return params; }
181
182 private:
185 std::function<void(const ProgressInfo &)> progress_cb;
187
188 public:
190 std::ostream *os = &std::cout;
191};
192
193template <class InnerSolverStats>
195
196template <Config Conf>
199
200 /// Total elapsed time in the inner solver.
201 std::chrono::nanoseconds elapsed_time{};
202 /// Total time spent in the user-provided progress callback.
203 std::chrono::nanoseconds time_progress_callback{};
204 /// Total number of inner PANTR iterations.
205 unsigned iterations = 0;
206 /// Total number of PANTR rejected accelerated steps.
207 unsigned accelerated_step_rejected = 0;
208 /// Total number of FB step size reductions.
209 unsigned stepsize_backtracks = 0;
210 /// Total number of times that the accelerated direction was not finite.
211 unsigned direction_failures = 0;
212 /// Total number of times that the direction update was rejected (e.g. it
213 /// could have resulted in a non-positive definite Hessian estimate).
214 unsigned direction_update_rejected = 0;
215 /// The final FB step size γ.
216 real_t final_γ = 0;
217 /// Final value of the smooth cost @f$ \psi(\hat x) @f$.
218 real_t final_ψ = 0;
219 /// Final value of the nonsmooth cost @f$ h(\hat x) @f$.
220 real_t final_h = 0;
221 /// Final value of the forward-backward envelope, @f$ \varphi_\gamma(x) @f$
222 /// (note that this is in the point @f$ x @f$, not @f$ \hat x @f$).
223 real_t final_φγ = 0;
224};
225
226template <Config Conf>
229 const PANTRStats<Conf> &s) {
230 acc.elapsed_time += s.elapsed_time;
231 acc.time_progress_callback += s.time_progress_callback;
232 acc.iterations += s.iterations;
233 acc.accelerated_step_rejected += s.accelerated_step_rejected;
234 acc.stepsize_backtracks += s.stepsize_backtracks;
235 acc.direction_failures += s.direction_failures;
236 acc.direction_update_rejected += s.direction_update_rejected;
237 acc.final_γ = s.final_γ;
238 acc.final_ψ = s.final_ψ;
239 acc.final_h = s.final_h;
240 acc.final_φγ = s.final_φγ;
241 return acc;
242}
243
244ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANTRParams, DefaultConfig);
245ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANTRParams, EigenConfigf);
246ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANTRParams, EigenConfigd);
247ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANTRParams, EigenConfigl);
248#ifdef ALPAQA_WITH_QUAD_PRECISION
249ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANTRParams, EigenConfigq);
250#endif
251
252ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANTRStats, DefaultConfig);
253ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANTRStats, EigenConfigf);
254ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANTRStats, EigenConfigd);
255ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANTRStats, EigenConfigl);
256#ifdef ALPAQA_WITH_QUAD_PRECISION
257ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANTRStats, EigenConfigq);
258#endif
259
260ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANTRProgressInfo, DefaultConfig);
261ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANTRProgressInfo, EigenConfigf);
262ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANTRProgressInfo, EigenConfigd);
263ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANTRProgressInfo, EigenConfigl);
264#ifdef ALPAQA_WITH_QUAD_PRECISION
265ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANTRProgressInfo, EigenConfigq);
266#endif
267
268} // namespace alpaqa
PANTR solver for ALM.
Definition: pantr.hpp:127
std::string get_name() const
Definition: pantr.tpp:21
Stats operator()(const P &problem, const SolveOptions &opts, rvec x, rvec y, crvec Σ, rvec e)
Definition: pantr.hpp:154
std::function< void(const ProgressInfo &)> progress_cb
Definition: pantr.hpp:185
Stats operator()(const Problem &problem, const SolveOptions &opts, rvec x, rvec y, crvec Σ, rvec err_z)
Definition: pantr.tpp:26
PANTRSolver(const Params &params, Direction &&direction)
Definition: pantr.hpp:141
Direction direction
Definition: pantr.hpp:189
InnerSolveOptions< config_t > SolveOptions
Definition: pantr.hpp:136
PANTRSolver(const Params &params, const Direction &direction)
Definition: pantr.hpp:143
PANTRSolver & 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: pantr.hpp:171
AtomicStopSignal stop_signal
Definition: pantr.hpp:184
DirectionT Direction
Definition: pantr.hpp:133
const Params & get_params() const
Definition: pantr.hpp:180
PANTRStats< config_t > Stats
Definition: pantr.hpp:134
PANTRSolver(const Params &params)
Definition: pantr.hpp:138
Stats operator()(const P &problem, const SolveOptions &opts, rvec x)
Definition: pantr.hpp:160
TypeErasedProblem< config_t > Problem
Definition: pantr.hpp:131
std::ostream * os
Definition: pantr.hpp:190
#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: pantr.hpp:87
unsigned direction_update_rejected
Definition: pantr.hpp:89
typename Conf::mvec mvec
Definition: config.hpp:53
@ ApproxKKT
Find an ε-approximate KKT point in the ∞-norm:
LipschitzEstimateParams< config_t > Lipschitz
Parameters related to the Lipschitz constant estimate and step size.
Definition: pantr.hpp:26
real_t final_φγ
Definition: pantr.hpp:93
real_t TR_tolerance_factor
Definition: pantr.hpp:48
unsigned accelerated_step_rejected
Definition: pantr.hpp:86
const TypeErasedProblem< config_t > * problem
Definition: pantr.hpp:120
real_t ratio_threshold_good
Minimal TR ratio to increase radius (very successful).
Definition: pantr.hpp:53
bool disable_acceleration
Definition: pantr.hpp:74
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: pantr.hpp:38
real_t L_max
Maximum Lipschitz constant estimate.
Definition: pantr.hpp:34
bool recompute_last_prox_step_after_direction_reset
Definition: pantr.hpp:72
SolverStatus
Exit status of a numerical solver such as ALM or PANOC.
@ Busy
In progress.
bool update_direction_on_prox_step
Definition: pantr.hpp:71
std::chrono::nanoseconds time_progress_callback
Definition: pantr.hpp:84
real_t initial_radius
Initial trust radius.
Definition: pantr.hpp:63
std::chrono::nanoseconds elapsed_time
Definition: pantr.hpp:83
typename Conf::real_t real_t
Definition: config.hpp:51
unsigned direction_failures
Definition: pantr.hpp:88
real_t final_ψ
Definition: pantr.hpp:91
std::chrono::nanoseconds max_time
Maximum duration.
Definition: pantr.hpp:30
real_t final_h
Definition: pantr.hpp:92
real_t quadratic_upperbound_tolerance_factor
Definition: pantr.hpp:46
real_t radius_factor_rejected
TR radius decrease coefficient when unsuccessful.
Definition: pantr.hpp:56
typename Conf::rvec rvec
Definition: config.hpp:55
const PANTRParams< config_t > * params
Definition: pantr.hpp:121
typename Conf::crvec crvec
Definition: config.hpp:56
unsigned print_interval
When to print progress.
Definition: pantr.hpp:42
real_t ratio_threshold_acceptable
Minimal TR ratio to be accepted (successful).
Definition: pantr.hpp:51
real_t final_γ
Definition: pantr.hpp:90
int print_precision
The precision of the floating point values printed by the solver.
Definition: pantr.hpp:44
real_t min_radius
Minimum trust radius.
Definition: pantr.hpp:65
real_t L_min
Minimum Lipschitz constant estimate.
Definition: pantr.hpp:32
real_t radius_factor_good
TR radius increase coefficient when very successful.
Definition: pantr.hpp:60
bool compute_ratio_using_new_stepsize
Check the quadratic upperbound and update γ before computing the reduction of the TR step.
Definition: pantr.hpp:69
unsigned iterations
Definition: pantr.hpp:85
real_t radius_factor_acceptable
TR radius decrease coefficient when successful.
Definition: pantr.hpp:58
SolverStatus status
Definition: pantr.hpp:81
unsigned max_iter
Maximum number of inner PANTR iterations.
Definition: pantr.hpp:28
PANOCStopCrit stop_crit
What stopping criterion to use.
Definition: pantr.hpp:36
Tuning parameters for the PANTR algorithm.
Definition: pantr.hpp:22