aligator 0.17.1
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 eigenpy::StdContainerFromPythonList<
69 std::vector<std::string>>::register_converter();
70 StdVectorPythonVisitor<std::vector<long>, true>::expose("StdVec_long");
71 eigenpy::exposeStdVectorEigenSpecificType<context::Vector3s>(
72 "StdVec_Vector3s");
73 StdVectorPythonVisitor<std::vector<bool>, true>::expose("StdVec_bool");
74 StdVectorPythonVisitor<std::vector<int>, true>::expose("StdVec_int");
75 StdVectorPythonVisitor<std::vector<Scalar>, true>::expose("StdVec_Scalar");
76 StdVectorPythonVisitor<context::VectorOfVectors, true>::expose(
77 "StdVec_Vector");
78 StdVectorPythonVisitor<std::vector<context::MatrixXs>, true>::expose(
79 "StdVec_Matrix");
80 StdVectorPythonVisitor<std::vector<VecXBool>, false>::expose(
81 "StdVec_VecBool");
82 StdVectorPythonVisitor<std::vector<VectorRef>, true>::expose("StdVec_VecRef");
83 StdVectorPythonVisitor<std::vector<MatrixRef>, true>::expose("StdVec_MatRef");
84}
85
87void exposeManifolds();
88
89} // namespace python
90} // namespace aligator
91
92BOOST_PYTHON_MODULE(MODULE_NAME) {
93 using namespace aligator::python;
94 using aligator::context::ConstVectorRef;
95
96 bp::docstring_options module_docstring_options(true, true, true);
97
98 bp::scope().attr("__version__") = ALIGATOR_VERSION;
99#ifdef ALIGATOR_MULTITHREADING
100 bp::def("get_available_threads", &aligator::omp::get_available_threads,
101 "Get the number of available threads.");
102 bp::def("get_current_threads", &aligator::omp::get_current_threads,
103 "Get the current number of threads.");
104 bp::def("set_omp_default_options", &aligator::omp::set_default_options,
105 ("num_threads"_a, "dynamic"_a = true));
106#endif
107 eigenpy::enableEigenPy();
108
109 eigenpy::OptionalConverter<ConstVectorRef, std::optional>::registration();
110 eigenpy::detail::NoneToPython<std::nullopt_t>::registration();
111
113 eigenpy::StdVectorPythonVisitor<std::vector<std::string_view>, true>::expose(
114 "StdVec_StringView");
115
116 bp::import("warnings");
117
118 bp::def(
119 "has_pinocchio_features",
120 +[]() constexpr -> bool {
121 return
122#ifdef ALIGATOR_WITH_PINOCCHIO
123 true;
124#else
125 false;
126#endif
127 },
128 "Whether Aligator (and its Python bindings) were compiled with support "
129 "for Pinocchio.");
130
131 {
132 bp::scope manifolds = get_namespace("manifolds");
134 }
136 exposeGAR();
137 exposeEnums();
140 exposeCosts();
142 exposeStage();
144 exposeFilter();
145 {
146 bp::scope dynamics = get_namespace("dynamics");
151 }
152 exposeUtils();
153
157
158#ifdef ALIGATOR_WITH_PINOCCHIO
159 {
160 bp::import("pinocchio");
164 }
165#endif
166
167#ifdef ALIGATOR_WITH_CROCODDYL_COMPAT
168 {
169 bp::scope croc_ns = get_namespace("croc");
170 exposeCrocoddylCompat();
171 }
172#endif
173}
BOOST_PYTHON_MODULE(MODULE_NAME)
Definition module.cpp:92
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