aligator  0.9.0
A primal-dual augmented Lagrangian-type solver for nonlinear trajectory optimization.
Loading...
Searching...
No Matches
solvers.hpp
Go to the documentation of this file.
1
3#pragma once
4
5#include <eigenpy/fwd.hpp>
6#include <proxsuite-nlp/python/deprecation-policy.hpp>
7#include <fmt/format.h>
8
9namespace aligator::python {
10namespace bp = boost::python;
11
12// fwd-declaration
13bp::arg operator""_a(const char *argname, std::size_t);
14
15template <typename SolverType>
16struct SolverVisitor : bp::def_visitor<SolverVisitor<SolverType>> {
17 using CallbackPtr = typename SolverType::CallbackPtr;
18 static auto getCallback(const SolverType &obj, const std::string &name)
19 -> CallbackPtr {
20 const CallbackPtr &cb = obj.getCallback(name);
21 if (!cb) {
22 PyErr_SetString(PyExc_KeyError,
23 fmt::format("Key {} not found.", name).c_str());
24 bp::throw_error_already_set();
25 }
26 return cb;
27 }
28
29 template <typename... Args> void visit(bp::class_<Args...> &obj) const {
30 obj.def_readwrite("verbose", &SolverType::verbose_,
31 "Verbosity level of the solver.")
32 .def_readwrite("max_iters", &SolverType::max_iters,
33 "Maximum number of iterations.")
34 .def_readwrite("ls_params", &SolverType::ls_params,
35 "Linesearch parameters.")
36 .def_readwrite("target_tol", &SolverType::target_tol_,
37 "Target tolerance.")
38 .def_readwrite("reg_init", &SolverType::reg_init)
39 .def_readwrite("preg", &SolverType::preg_)
40 .def_readwrite("force_initial_condition",
41 &SolverType::force_initial_condition_,
42 "Set x0 to be fixed to the initial condition.")
43 .add_property("num_threads", &SolverType::getNumThreads)
44 .def("setNumThreads", &SolverType::setNumThreads,
45 ("self"_a, "num_threads"))
46 .def_readonly("results", &SolverType::results_, "Solver results.")
47 .def_readonly("workspace", &SolverType::workspace_, "Solver workspace.")
48 .def("setup", &SolverType::setup, ("self"_a, "problem"),
49 "Allocate solver workspace and results data for the problem.")
50 .def("registerCallback", &SolverType::registerCallback,
51 ("self"_a, "name", "cb"), "Add a callback to the solver.")
52 .def("getCallbackNames", &SolverType::getCallbackNames, "self"_a,
53 "Get names of registered callbacks.")
54 .def("removeCallback", &SolverType::removeCallback, ("self"_a, "key"),
55 "Remove a callback.")
56 .def("getCallback", getCallback, ("self"_a, "key"))
57 .def("clearCallbacks", &SolverType::clearCallbacks, ("self"_a),
58 "Clear callbacks.");
59 }
60};
61
62} // namespace aligator::python
The Python bindings.
Definition blk-matrix.hpp:5
typename SolverType::CallbackPtr CallbackPtr
Definition solvers.hpp:17
void visit(bp::class_< Args... > &obj) const
Definition solvers.hpp:29
static auto getCallback(const SolverType &obj, const std::string &name) -> CallbackPtr
Definition solvers.hpp:18