aligator  0.6.1
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,
19 const std::string &name) -> CallbackPtr {
20 const auto &cbs = obj.getCallbacks();
21 auto cb = cbs.find(name);
22 if (cb == cbs.end()) {
23 PyErr_SetString(PyExc_KeyError,
24 fmt::format("Key {} not found.", name).c_str());
25 bp::throw_error_already_set();
26 }
27 return cb->second;
28 }
29
30 template <typename PyClass> void visit(PyClass &obj) const {
31 using proxsuite::nlp::deprecation_warning_policy;
32 using proxsuite::nlp::DeprecationType;
33 obj.def_readwrite("verbose", &SolverType::verbose_,
34 "Verbosity level of the solver.")
35 .def_readwrite("max_iters", &SolverType::max_iters,
36 "Maximum number of iterations.")
37 .def_readwrite("ls_params", &SolverType::ls_params,
38 "Linesearch parameters.")
39 .def_readwrite("target_tol", &SolverType::target_tol_,
40 "Target tolerance.")
41 .def_readwrite("reg_init", &SolverType::reg_init)
42 .def_readwrite("force_initial_condition",
43 &SolverType::force_initial_condition_,
44 "Set x0 to be fixed to the initial condition.")
45 .add_property("num_threads", &SolverType::getNumThreads)
46 .def("setNumThreads", &SolverType::setNumThreads,
47 ("self"_a, "num_threads"))
48 .def("getResults", &SolverType::getResults, ("self"_a),
49 deprecation_warning_policy<DeprecationType::DEPRECATION,
50 bp::return_internal_reference<>>(
51 "This getter is deprecated. Access the results using "
52 "`solver.results` instead."),
53 "Get the results instance.")
54 .def("getWorkspace", &SolverType::getWorkspace, ("self"_a),
55 deprecation_warning_policy<DeprecationType::DEPRECATION,
56 bp::return_internal_reference<>>(
57 "This getter is deprecated. Access the workspace using "
58 "`solver.workspace` instead."),
59 "Get the workspace instance.")
60 .def_readonly("results", &SolverType::results_, "Solver results.")
61 .def_readonly("workspace", &SolverType::workspace_, "Solver workspace.")
62 .def("setup", &SolverType::setup, ("self"_a, "problem"),
63 "Allocate solver workspace and results data for the problem.")
64 .def("registerCallback", &SolverType::registerCallback,
65 ("self"_a, "name", "cb"), "Add a callback to the solver.")
66 .def("removeCallback", &SolverType::removeCallback, ("self"_a, "key"),
67 "Remove a callback.")
68 .def("getCallback", getCallback, ("self"_a, "key"))
69 .def("clearCallbacks", &SolverType::clearCallbacks, ("self"_a),
70 "Clear callbacks.");
71 }
72};
73
74} // namespace aligator::python
The Python bindings.
Definition blk-matrix.hpp:5
void visit(PyClass &obj) const
Definition solvers.hpp:30
typename SolverType::CallbackPtr CallbackPtr
Definition solvers.hpp:17
static auto getCallback(const SolverType &obj, const std::string &name) -> CallbackPtr
Definition solvers.hpp:18