alpaqa 1.0.0a10
Nonconvex constrained optimization
Loading...
Searching...
No Matches
lbfgsb-driver.cpp
Go to the documentation of this file.
1#if WITH_LBFGSB
2
5
6#include "alm-driver.hpp"
7#include "cancel.hpp"
8#include "lbfgsb-driver.hpp"
9#include "solver-driver.hpp"
10#include "util.hpp"
11
12namespace {
13
14using InnerLBFGSBSolver = alpaqa::lbfgsb::LBFGSBSolver;
15
16auto make_inner_lbfgsb_solver(Options &opts) {
17 // Settings for the solver
18 InnerLBFGSBSolver::Params solver_param;
19 solver_param.max_iter = 50'000;
20 solver_param.print_interval = 0;
21 solver_param.stop_crit = alpaqa::PANOCStopCrit::ProjGradUnitNorm;
22 set_params(solver_param, "solver", opts);
23 return InnerLBFGSBSolver{solver_param};
24}
25
26template <class LoadedProblem>
27solver_func_t make_lbfgsb_driver_impl(std::string_view direction,
28 Options &opts) {
29 if (!direction.empty())
30 throw std::invalid_argument(
31 "L-BFGS-B solver does not support any directions");
32 auto inner_solver = make_inner_lbfgsb_solver(opts);
33 auto solver = make_alm_solver(std::move(inner_solver), opts);
34 unsigned N_exp = 0;
35 set_params(N_exp, "num_exp", opts);
36 return [solver{std::move(solver)},
37 N_exp](LoadedProblem &problem,
38 std::ostream &os) mutable -> SolverResults {
39 auto cancel = alpaqa::attach_cancellation(solver);
40 return run_alm_solver(problem, solver, os, N_exp);
41 };
42}
43
44} // namespace
45
46solver_func_t make_lbfgsb_driver(std::string_view direction, Options &opts) {
47 static constexpr bool valid_config =
48 std::is_same_v<LoadedProblem::config_t, InnerLBFGSBSolver::config_t>;
49 if constexpr (valid_config)
50 return make_lbfgsb_driver_impl<LoadedProblem>(direction, opts);
51 else
52 throw std::invalid_argument(
53 "L-BFGS-B solver only supports double precision");
54}
55
57
58#else
59
60#include "solver-driver.hpp"
61
63 throw std::invalid_argument(
64 "This version of alpaqa was compiled without L-BFGS-B support.");
65}
66
67#endif
SolverResults run_alm_solver(LoadedProblem &problem, Solver &solver, std::ostream &os, unsigned N_exp)
Definition: alm-driver.hpp:56
auto make_alm_solver(InnerSolver &&inner_solver, Options &opts)
Definition: alm-driver.hpp:12
Augmented Lagrangian Method solver.
Definition: alm.hpp:96
L-BFGS-B solver for ALM.
solver_func_t make_lbfgsb_driver(std::string_view, Options &)
@ ProjGradUnitNorm
∞-norm of the projected gradient with unit step size:
auto attach_cancellation(Solver &solver)
Attach SIGINT and SIGTERM handlers to stop the given solver.
Definition: cancel.hpp:21
decltype(auto) set_params(T &t, std::string_view prefix, Options &opts)
Definition: options.hpp:27
std::function< solver_free_func_t > solver_func_t