aligator 0.19.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
62template <typename MatType, bool NoProxy = false>
63void exposeStdVectorEigenStdAlloc(const char *name) {
64 using vector_type = std::vector<MatType>;
65 auto full_name = std::string("StdVec_").append(name);
66 eigenpy::StdVectorPythonVisitor<vector_type, NoProxy>::expose(
67 full_name.c_str(),
68 eigenpy::details::overload_base_get_item_for_std_vector<vector_type>());
69}
70
71static void exposeContainers() {
72 using VecXBool = Eigen::Matrix<bool, Eigen::Dynamic, 1>;
73 using context::MatrixRef;
74 using context::MatrixXs;
75 using context::Scalar;
76 using context::Vector3s;
77 using context::VectorRef;
78 using context::VectorXs;
79
80 eigenpy::StdContainerFromPythonList<
81 std::vector<std::string>>::register_converter();
82 StdVectorPythonVisitor<std::vector<long>, true>::expose("StdVec_long");
83 StdVectorPythonVisitor<std::vector<bool>, true>::expose("StdVec_bool");
84 StdVectorPythonVisitor<std::vector<int>, true>::expose("StdVec_int");
85 StdVectorPythonVisitor<std::vector<Scalar>, true>::expose("StdVec_Scalar");
86
87 // Eigen types
92 StdVectorPythonVisitor<std::vector<VectorRef>, true>::expose("StdVec_VecRef");
93 StdVectorPythonVisitor<std::vector<MatrixRef>, true>::expose("StdVec_MatRef");
94}
95
97void exposeManifolds();
98
99} // namespace python
100} // namespace aligator
101
103 using namespace aligator::python;
104 using aligator::context::ConstVectorRef;
105
106 bp::docstring_options module_docstring_options(true, true, true);
107
108 bp::scope().attr("__version__") = ALIGATOR_VERSION;
109#ifdef ALIGATOR_MULTITHREADING
110 bp::def("get_available_threads", &aligator::omp::get_available_threads,
111 "Get the number of available threads.");
112 bp::def("get_current_threads", &aligator::omp::get_current_threads,
113 "Get the current number of threads.");
114 bp::def("set_omp_default_options", &aligator::omp::set_default_options,
115 ("num_threads"_a, "dynamic"_a = true));
116#endif
117 eigenpy::enableEigenPy();
118
119 eigenpy::OptionalConverter<ConstVectorRef, std::optional>::registration();
120 eigenpy::detail::NoneToPython<std::nullopt_t>::registration();
121
123 eigenpy::StdVectorPythonVisitor<std::vector<std::string_view>, true>::expose(
124 "StdVec_StringView");
125
126 bp::import("warnings");
127#ifdef ALIGATOR_WITH_PINOCCHIO
128 bp::import("pinocchio");
129#endif
130
131 bp::def(
132 "has_pinocchio_features",
133 +[]() constexpr -> bool {
134 return
135#ifdef ALIGATOR_WITH_PINOCCHIO
136 true;
137#else
138 false;
139#endif
140 },
141 "Whether Aligator (and its Python bindings) were compiled with support "
142 "for Pinocchio.");
143
144 {
145 bp::scope manifolds = get_namespace("manifolds");
147 }
149 exposeGAR();
150 exposeEnums();
152 exposeCosts();
154 exposeStage();
156 exposeFilter();
157 {
158 bp::scope dynamics = get_namespace("dynamics");
163 }
164 exposeUtils();
165
169
170#ifdef ALIGATOR_WITH_PINOCCHIO
174#endif
175
176#ifdef ALIGATOR_WITH_CROCODDYL_COMPAT
177 {
178 bp::scope croc_ns = get_namespace("croc");
179 exposeCrocoddylCompat();
180 }
181#endif
182}
BOOST_PYTHON_MODULE(MODULE_NAME)
Definition module.cpp:102
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 exposeStdVectorEigenStdAlloc(const char *name)
Definition module.cpp:63
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:71
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