proxsuite-nlp  0.10.0
A primal-dual augmented Lagrangian-type solver for nonlinear programming on manifolds.
Loading...
Searching...
No Matches
expose-solver.cpp
Go to the documentation of this file.
3#include <eigenpy/std-unique-ptr.hpp>
4#include <eigenpy/deprecation-policy.hpp>
5
6namespace proxsuite {
7namespace nlp {
8namespace python {
9
12 using context::Scalar;
13 using ProxNLPSolver = context::ProxNLPSolverTpl;
15 using context::ConstVectorRef;
16 using context::Problem;
17 using context::VectorRef;
18 using eigenpy::deprecated_member;
19 using eigenpy::DeprecationType;
20 using eigenpy::ReturnInternalStdUniquePtr;
21
22 bp::enum_<VerboseLevel>("VerboseLevel", "Verbose level for the solver.")
23 .value("QUIET", QUIET)
24 .value("VERBOSE", VERBOSE)
25 .value("VERYVERBOSE", VERYVERBOSE)
26 .export_values();
27
28 bp::enum_<LinesearchStrategy>(
29 "LinesearchStrategy",
30 "Linesearch strategy. Only Armijo linesearch is implemented for now.")
31 .value("ARMIJO", LinesearchStrategy::ARMIJO);
32
33 bp::enum_<HessianApprox>("HessianApprox",
34 "Type of approximation of the Lagrangian Hessian.")
35 .value("HESSIAN_EXACT", HessianApprox::EXACT)
36 .value("HESSIAN_GAUSS_NEWTON", HessianApprox::GAUSS_NEWTON)
37 .export_values();
38
39 bp::enum_<MultiplierUpdateMode>("MultiplierUpdateMode",
40 "Type of multiplier update.")
41 .value("MUL_NEWTON", MultiplierUpdateMode::NEWTON)
42 .value("MUL_PRIMAL", MultiplierUpdateMode::PRIMAL)
43 .value("MUL_PRIMAL_DUAL", MultiplierUpdateMode::PRIMAL_DUAL)
44 .export_values();
45
46 bp::enum_<LSInterpolation>("LSInterpolation",
47 "Linesearch interpolation scheme.")
48 .value("BISECTION", LSInterpolation::BISECTION)
49 .value("QUADRATIC", LSInterpolation::QUADRATIC)
50 .value("CUBIC", LSInterpolation::CUBIC);
51
52 bp::enum_<LDLTChoice>("LDLTChoice", "Choice of LDLT solver.")
53 .value("LDLT_DENSE", LDLTChoice::DENSE)
54 .value("LDLT_BUNCHKAUFMAN", LDLTChoice::BUNCHKAUFMAN)
55 .value("LDLT_BLOCKSPARSE", LDLTChoice::BLOCKSPARSE)
56 .value("LDLT_EIGEN", LDLTChoice::EIGEN)
57 .value("LDLT_PROXSUITE", LDLTChoice::PROXSUITE)
58 .export_values();
59
61 using LinesearchOptions = Linesearch::Options;
62 bp::class_<Linesearch>("Linesearch", bp::no_init)
63 .def(bp::init<const LinesearchOptions &>(("self"_a, "options")))
64 .def_readwrite("options", &Linesearch::options_);
65 bp::class_<ArmijoLinesearch<Scalar>, bp::bases<Linesearch>>(
66 "ArmijoLinesearch", bp::no_init)
67 .def(bp::init<const LinesearchOptions &>(("self"_a, "options")));
68 bp::class_<LinesearchOptions>("LinesearchOptions", "Linesearch options.",
69 bp::init<>(("self"_a), "Default constructor."))
70 .def_readwrite("armijo_c1", &LinesearchOptions::armijo_c1)
71 .def_readwrite("wolfe_c2", &LinesearchOptions::wolfe_c2)
72 .def_readwrite(
73 "dphi_thresh", &LinesearchOptions::dphi_thresh,
74 "Threshold on the derivative at the initial point; the linesearch "
75 "will be early-terminated if the derivative is below this threshold.")
76 .def_readwrite("alpha_min", &LinesearchOptions::alpha_min,
77 "Minimum step size.")
78 .def_readwrite("max_num_steps", &LinesearchOptions::max_num_steps)
79 .def_readwrite("interp_type", &LinesearchOptions::interp_type,
80 "Interpolation type: bisection, quadratic or cubic.")
81 .def_readwrite("contraction_min", &LinesearchOptions::contraction_min,
82 "Minimum step contraction.")
83 .def_readwrite("contraction_max", &LinesearchOptions::contraction_max,
84 "Maximum step contraction.")
85 .def(bp::self_ns::str(bp::self));
86
87 using context::Results;
89 using solve_std_vec_ins_t = ConvergenceFlag (ProxNLPSolver::*)(
90 const ConstVectorRef &, const std::vector<VectorRef> &);
91 using solve_eig_vec_ins_t = ConvergenceFlag (ProxNLPSolver::*)(
92 const ConstVectorRef &, const ConstVectorRef &);
93
94#pragma GCC diagnostic push
95#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
96
97 bp::class_<ProxNLPSolver, boost::noncopyable>(
98 "ProxNLPSolver",
99 "Semi-smooth Newton-based solver for nonlinear optimization using a "
100 "primal-dual method of multipliers. This solver works by approximately "
101 "solving the proximal subproblems in the method of multipliers.",
102 bp::init<Problem &, Scalar, Scalar, Scalar, VerboseLevel, Scalar, Scalar,
103 Scalar, Scalar, Scalar, LDLTChoice>(
104 ("self"_a, "problem", "tol"_a = 1e-6, "mu_init"_a = 1e-2,
105 "rho_init"_a = 0., "verbose"_a = VerboseLevel::QUIET,
106 "mu_min"_a = 1e-9, "prim_alpha"_a = 0.1, "prim_beta"_a = 0.9,
107 "dual_alpha"_a = 1., "dual_beta"_a = 1.,
108 "ldlt_choice"_a = LDLTChoice::DENSE)))
109 .add_property("problem",
110 bp::make_function(&ProxNLPSolver::problem,
111 bp::return_internal_reference<>()),
112 "The general nonlinear program to solve.")
113 .add_property("manifold",
114 bp::make_function(&ProxNLPSolver::manifold,
115 bp::return_internal_reference<>()),
116 "The solver's working manifold.")
117 .def_readwrite("hess_approx", &ProxNLPSolver::hess_approx)
118 .def_readwrite("ls_strat", &ProxNLPSolver::ls_strat)
119 .def("register_callback", &ProxNLPSolver::registerCallback,
120 ("self"_a, "cb"), "Add a callback to the solver.")
121 .def("clear_callbacks", &ProxNLPSolver::clearCallbacks,
122 "Clear callbacks.", ("self"_a))
123 .def_readwrite("verbose", &ProxNLPSolver::verbose,
124 "Solver verbose setting.")
125 .def_readwrite("ldlt_choice", &ProxNLPSolver::ldlt_choice_,
126 "Use the BlockLDLT solver.")
127 .def("setup", &ProxNLPSolver::setup, ("self"_a),
128 "Initialize the solver workspace and results.")
129 .def("getResults", &ProxNLPSolver::getResults, ("self"_a),
130 deprecated_member<DeprecationType::DEPRECATION,
131 bp::return_internal_reference<>>(
132 "This getter has been deprecated."),
133 "Get a reference to the results object.")
134 .def("getWorkspace", &ProxNLPSolver::getWorkspace, ("self"_a),
135 deprecated_member<DeprecationType::DEPRECATION,
136 bp::return_internal_reference<>>(
137 "This getter has been deprecated."),
138 "Get a reference to the workspace object.")
139 .add_property("workspace", bp::make_getter(&ProxNLPSolver::workspace_,
140 ReturnInternalStdUniquePtr{}))
141 .add_property("results", bp::make_getter(&ProxNLPSolver::results_,
142 ReturnInternalStdUniquePtr{}))
143 .def<solve_std_vec_ins_t>(
144 "solve", &ProxNLPSolver::solve, ("self"_a, "x0", "lams0"),
145 "Run the solver (multiplier guesses given as a list).")
146 .def<solve_eig_vec_ins_t>(
147 "solve", &ProxNLPSolver::solve,
148 ("self"_a, "x0", "lams0"_a = context::VectorXs(0)), "Run the solver.")
149 .def("setPenalty", &ProxNLPSolver::setPenalty, ("self"_a, "mu"),
150 "Set the augmented Lagrangian penalty parameter.")
151 .def("setDualPenalty", &ProxNLPSolver::setDualPenalty,
152 ("self"_a, "gamma"),
153 "Set the dual variable penalty for the linesearch merit "
154 "function.")
155 .def("setProxParameter", &ProxNLPSolver::setProxParameter,
156 ("self"_a, "rho"), "Set the primal proximal penalty parameter.")
157 .def_readwrite("mu_init", &ProxNLPSolver::mu_init_,
158 "Initial AL parameter value.")
159 .def_readwrite("rho_init", &ProxNLPSolver::rho_init_,
160 "Initial proximal parameter value.")
161 .def_readwrite("mu_lower", &ProxNLPSolver::mu_lower_,
162 "Lower bound :math:`\\underline{\\mu} > 0` for the "
163 "AL parameter.")
164 .def_readwrite("mu_upper", &ProxNLPSolver::mu_upper_,
165 "Upper bound :math:`\\bar{\\mu}` for the AL parameter. "
166 "The tolerances for "
167 "each subproblem will be updated as :math:`\\eta^0 (\\mu "
168 "/ \\bar{\\mu})^\\gamma`")
169 // BCL parameters
170 .def_readwrite("bcl_params", &ProxNLPSolver::bcl_params,
171 "BCL parameters.")
172 .def_readwrite("target_tol", &ProxNLPSolver::target_tol,
173 "Target tolerance.")
174 .def_readwrite("ls_options", &ProxNLPSolver::ls_options,
175 "Linesearch options.")
176 .def_readwrite("mul_update_mode", &ProxNLPSolver::mul_update_mode,
177 "Type of multiplier update.")
178 .def_readwrite("kkt_system", &ProxNLPSolver::kkt_system_,
179 "KKT system type.")
180 .def_readwrite("max_refinement_steps",
181 &ProxNLPSolver::max_refinement_steps_,
182 "Maximum number of iterative refinement steps.")
183 .def_readwrite("kkt_tolerance", &ProxNLPSolver::kkt_tolerance_,
184 "Acceptable tolerance for the KKT linear system "
185 "(threshold for iterative refinement).")
186 .def_readwrite("max_iters", &ProxNLPSolver::max_iters,
187 "Maximum number of iterations.")
188 .def_readwrite("max_al_iters", &ProxNLPSolver::max_al_iters,
189 "Max augmented Lagrangian iterations.")
190 .def_readwrite("reg_init", &ProxNLPSolver::DELTA_INIT,
191 "Initial regularization.");
192#pragma GCC diagnostic pop
193
194 bp::enum_<KktSystem>("KktSystem")
195 .value("KKT_CLASSIC", KKT_CLASSIC)
196 .value("KKT_PRIMAL_DUAL", KKT_PRIMAL_DUAL)
197 .export_values();
198
199 bp::class_<BCLParams>("BCLParams",
200 "Parameters for the bound-constrained Lagrangian (BCL) "
201 "penalty update strategy.",
202 bp::init<>(("self"_a)))
203 .def_readwrite("prim_alpha", &BCLParams::prim_alpha)
204 .def_readwrite("prim_beta", &BCLParams::prim_beta)
205 .def_readwrite("dual_alpha", &BCLParams::dual_alpha)
206 .def_readwrite("dual_beta", &BCLParams::dual_beta)
207 .def_readwrite("mu_factor", &BCLParams::mu_update_factor,
208 "Multiplier update factor.")
209 .def_readwrite("rho_factor", &BCLParams::rho_update_factor,
210 "Proximal penalty update factor.");
211}
212} // namespace python
213} // namespace nlp
214} // namespace proxsuite
Base linesearch class. Design pattern inspired by Google Ceres-Solver.
Linesearch::Options options_
ProxNLPSolverTpl< Scalar > ProxNLPSolverTpl
Definition context.hpp:27
VerboseLevel
Verbosity level.
Definition fwd.hpp:126
@ GAUSS_NEWTON
Gauss-Newton (or rather SCQP) approximation.
@ EXACT
Exact Hessian construction from provided function Hessians.
@ DENSE
Use our dense LDLT.
@ BLOCKSPARSE
Use blocked LDLT.
@ PROXSUITE
Use Proxsuite's LDLT.
@ EIGEN
Use Eigen's implementation.
@ BUNCHKAUFMAN
Use Bunch-Kaufman factorization.
Main package namespace.
Definition bcl-params.hpp:5
Results struct, holding the returned data from the solver.
Definition results.hpp:20