aligator  0.16.0
A versatile and efficient C++ library for real-time constrained trajectory optimization.
Loading...
Searching...
No Matches
module.cpp
Go to the documentation of this file.
1
5
8
9#include <eigenpy/optional.hpp>
10
11namespace aligator {
12namespace python {
13
15#ifdef ALIGATOR_WITH_CROCODDYL_COMPAT
16void exposeCrocoddylCompat();
17#endif
18
19static void exposeEnums() {
20#define _c(Enum, name) value(#name, Enum::name)
21
22 bp::enum_<VerboseLevel>("VerboseLevel",
23 "Verbosity level to be used in solvers.")
27 .export_values();
28
29 bp::enum_<MultiplierUpdateMode>(
30 "MultiplierUpdateMode", "Enum for the kind of multiplier update to use.")
34
35 bp::enum_<LinesearchMode>("LinesearchMode", "Linesearch mode.")
38
39 bp::enum_<RolloutType>("RolloutType", "Rollout type.")
40 .value("ROLLOUT_LINEAR", RolloutType::LINEAR)
41 .value("ROLLOUT_NONLINEAR", RolloutType::NONLINEAR)
42 .export_values();
43
44 bp::enum_<HessianApprox>("HessianApprox",
45 "Level of approximation for the Hessian.")
46 .value("HESSIAN_EXACT", HessianApprox::EXACT)
47 .value("HESSIAN_GAUSS_NEWTON", HessianApprox::GAUSS_NEWTON)
48 .value("HESSIAN_BFGS", HessianApprox::BFGS)
49 .export_values();
50
51 bp::enum_<StepAcceptanceStrategy>("StepAcceptanceStrategy",
52 "Step acceptance strategy.")
53 .value("SA_LINESEARCH_ARMIJO", StepAcceptanceStrategy::LINESEARCH_ARMIJO)
54 .value("SA_LINESEARCH_NONMONOTONE",
56 .value("SA_FILTER", StepAcceptanceStrategy::FILTER)
57 .export_values();
58
59#undef _c
60}
61
62static void exposeContainers() {
63 using VecXBool = Eigen::Matrix<bool, Eigen::Dynamic, 1>;
64 using context::MatrixRef;
65 using context::Scalar;
66 using context::VectorRef;
67
68 StdVectorPythonVisitor<std::vector<long>, true>::expose("StdVec_long");
69 eigenpy::exposeStdVectorEigenSpecificType<context::Vector3s>(
70 "StdVec_Vector3s");
71 StdVectorPythonVisitor<std::vector<bool>, true>::expose("StdVec_bool");
72 StdVectorPythonVisitor<std::vector<int>, true>::expose("StdVec_int");
73 StdVectorPythonVisitor<std::vector<Scalar>, true>::expose("StdVec_Scalar");
74 StdVectorPythonVisitor<context::VectorOfVectors, true>::expose(
75 "StdVec_Vector");
76 StdVectorPythonVisitor<std::vector<context::MatrixXs>, true>::expose(
77 "StdVec_Matrix");
78 StdVectorPythonVisitor<std::vector<VecXBool>, false>::expose(
79 "StdVec_VecBool");
80 StdVectorPythonVisitor<std::vector<VectorRef>, true>::expose("StdVec_VecRef");
81 StdVectorPythonVisitor<std::vector<MatrixRef>, true>::expose("StdVec_MatRef");
82}
83
85void exposeManifolds();
86
87} // namespace python
88} // namespace aligator
89
90BOOST_PYTHON_MODULE(MODULE_NAME) {
91 using namespace aligator::python;
92 using aligator::context::ConstVectorRef;
93
94 bp::docstring_options module_docstring_options(true, true, true);
95
96 bp::scope().attr("__version__") = ALIGATOR_VERSION;
97#ifdef ALIGATOR_MULTITHREADING
98 bp::def("get_available_threads", &aligator::omp::get_available_threads,
99 "Get the number of available threads.");
100 bp::def("get_current_threads", &aligator::omp::get_current_threads,
101 "Get the current number of threads.");
102 bp::def("set_omp_default_options", &aligator::omp::set_default_options,
103 ("num_threads"_a, "dynamic"_a = true));
104#endif
105 eigenpy::enableEigenPy();
106
107 eigenpy::OptionalConverter<ConstVectorRef, std::optional>::registration();
108 eigenpy::detail::NoneToPython<std::nullopt_t>::registration();
109
111 eigenpy::StdVectorPythonVisitor<std::vector<std::string_view>, true>::expose(
112 "StdVec_StringView");
113
114 bp::import("warnings");
115
116 bp::def(
117 "has_pinocchio_features",
118 +[]() constexpr -> bool {
119 return
120#ifdef ALIGATOR_WITH_PINOCCHIO
121 true;
122#else
123 false;
124#endif
125 },
126 "Whether Aligator (and its Python bindings) were compiled with support "
127 "for Pinocchio.");
128
129 {
130 bp::scope manifolds = get_namespace("manifolds");
132 }
134 exposeGAR();
135 exposeEnums();
138 exposeCosts();
140 exposeStage();
142 exposeFilter();
143 {
144 bp::scope dynamics = get_namespace("dynamics");
149 }
150 exposeUtils();
151
155
156#ifdef ALIGATOR_WITH_PINOCCHIO
157 {
158 bp::import("pinocchio");
162 }
163#endif
164
165#ifdef ALIGATOR_WITH_CROCODDYL_COMPAT
166 {
167 bp::scope croc_ns = get_namespace("croc");
168 exposeCrocoddylCompat();
169 }
170#endif
171}
BOOST_PYTHON_MODULE(MODULE_NAME)
Definition module.cpp:90
Namespace for modelling system dynamics.
std::size_t get_current_threads()
Get the current number of threads.
Definition threads.hpp:18
void set_default_options(std::size_t num_threads, bool dynamic=true)
Definition threads.hpp:25
std::size_t get_available_threads()
Definition threads.hpp:13
The Python bindings.
Definition blk-matrix.hpp:7
void exposeGAR()
Expose GAR module.
void exposeConstraint()
Expose constraints.
void exposeStage()
Expose StageModel and StageData.
static void exposeEnums()
Definition module.cpp:19
static void exposeContainers()
Definition module.cpp:62
void exposeUtils()
Expose utils.
void exposeCosts()
Expose cost functions.
void exposeManifolds()
Expose manifolds.
bp::object get_namespace(const std::string &name)
Create or retrieve a Python scope (that is, a class or module namespace).
Definition utils.hpp:22
void exposeSolvers()
Expose solvers.
void exposeDynamics()
Expose discrete dynamics.
void exposeIntegrators()
Expose numerical integrators.
void exposeCallbacks()
Expose solver callbacks.
void exposeFilter()
Expose filter strategy.
void exposeProblem()
Expose TrajOptProblem.
void exposeContinuousDynamics()
Expose continuous dynamics.
void exposeAutodiff()
Expose autodiff helpers.
void exposeFunctions()
Expose stagewise function classes.
Main package namespace.
MultiplierUpdateMode
Definition enums.hpp:23
VerboseLevel
Verbosity level.
Definition fwd.hpp:82
@ QUIET
Definition fwd.hpp:82
@ VERYVERBOSE
Definition fwd.hpp:82
@ VERBOSE
Definition fwd.hpp:82
@ LINEAR
Linear rollout.
Definition enums.hpp:7
@ NONLINEAR
Nonlinear rollout, using the full dynamics.
Definition enums.hpp:9
@ GAUSS_NEWTON
Use the Gauss-Newton approximation.
Definition enums.hpp:18
@ BFGS
Use a BFGS-type approximation.
Definition enums.hpp:20
@ EXACT
Use exact Hessian.
Definition enums.hpp:16
LinesearchMode
Whether to use merit functions in primal or primal-dual mode.
Definition enums.hpp:26