aligator  0.14.0
A primal-dual augmented Lagrangian-type solver for nonlinear trajectory optimization.
Loading...
Searching...
No Matches
module.cpp
Go to the documentation of this file.
1
4
7
8#include <eigenpy/optional.hpp>
9
10namespace aligator {
11namespace python {
12
14#ifdef ALIGATOR_WITH_CROCODDYL_COMPAT
15void exposeCrocoddylCompat();
16#endif
17
18static void exposeEnums() {
19#define _c(Enum, name) value(#name, Enum::name)
20
21 bp::enum_<VerboseLevel>("VerboseLevel",
22 "Verbosity level to be used in solvers.")
26 .export_values();
27
28 bp::enum_<MultiplierUpdateMode>(
29 "MultiplierUpdateMode", "Enum for the kind of multiplier update to use.")
33
34 bp::enum_<LinesearchMode>("LinesearchMode", "Linesearch mode.")
37
38 bp::enum_<RolloutType>("RolloutType", "Rollout type.")
39 .value("ROLLOUT_LINEAR", RolloutType::LINEAR)
40 .value("ROLLOUT_NONLINEAR", RolloutType::NONLINEAR)
41 .export_values();
42
43 bp::enum_<HessianApprox>("HessianApprox",
44 "Level of approximation for the Hessian.")
45 .value("HESSIAN_EXACT", HessianApprox::EXACT)
46 .value("HESSIAN_GAUSS_NEWTON", HessianApprox::GAUSS_NEWTON)
47 .value("HESSIAN_BFGS", HessianApprox::BFGS)
48 .export_values();
49
50 bp::enum_<StepAcceptanceStrategy>("StepAcceptanceStrategy",
51 "Step acceptance strategy.")
52 .value("SA_LINESEARCH_ARMIJO", StepAcceptanceStrategy::LINESEARCH_ARMIJO)
53 .value("SA_LINESEARCH_NONMONOTONE",
55 .value("SA_FILTER", StepAcceptanceStrategy::FILTER)
56 .export_values();
57
58#undef _c
59}
60
61static void exposeContainers() {
62 using VecXBool = Eigen::Matrix<bool, Eigen::Dynamic, 1>;
63 using context::MatrixRef;
64 using context::Scalar;
65 using context::VectorRef;
66
67 StdVectorPythonVisitor<std::vector<long>, true>::expose("StdVec_long");
68 eigenpy::exposeStdVectorEigenSpecificType<context::Vector3s>(
69 "StdVec_Vector3s");
70 StdVectorPythonVisitor<std::vector<bool>, true>::expose("StdVec_bool");
71 StdVectorPythonVisitor<std::vector<int>, true>::expose("StdVec_int");
72 StdVectorPythonVisitor<std::vector<Scalar>, true>::expose("StdVec_Scalar");
73 StdVectorPythonVisitor<context::VectorOfVectors, true>::expose(
74 "StdVec_Vector");
75 StdVectorPythonVisitor<std::vector<context::MatrixXs>, true>::expose(
76 "StdVec_Matrix");
77 StdVectorPythonVisitor<std::vector<VecXBool>, false>::expose(
78 "StdVec_VecBool");
79 StdVectorPythonVisitor<std::vector<VectorRef>, true>::expose("StdVec_VecRef");
80 StdVectorPythonVisitor<std::vector<MatrixRef>, true>::expose("StdVec_MatRef");
81}
82
84void exposeManifolds();
85
86} // namespace python
87} // namespace aligator
88
89BOOST_PYTHON_MODULE(MODULE_NAME) {
90 using namespace aligator::python;
91 using aligator::context::ConstVectorRef;
92
93 bp::docstring_options module_docstring_options(true, true, true);
94
95 bp::scope().attr("__version__") = ALIGATOR_VERSION;
96#ifdef ALIGATOR_MULTITHREADING
97 bp::def("get_available_threads", &aligator::omp::get_available_threads,
98 "Get the number of available threads.");
99 bp::def("get_current_threads", &aligator::omp::get_current_threads,
100 "Get the current number of threads.");
101 bp::def("set_omp_default_options", &aligator::omp::set_default_options,
102 ("num_threads"_a, "dynamic"_a = true));
103#endif
104 eigenpy::enableEigenPy();
105
106 eigenpy::OptionalConverter<ConstVectorRef, std::optional>::registration();
107 eigenpy::detail::NoneToPython<std::nullopt_t>::registration();
108
109 bp::import("warnings");
110
111 bp::def(
112 "has_pinocchio_features",
113 +[]() constexpr -> bool {
114 return
115#ifdef ALIGATOR_WITH_PINOCCHIO
116 true;
117#else
118 false;
119#endif
120 },
121 "Whether Aligator (and its Python bindings) were compiled with support "
122 "for Pinocchio.");
123
124 {
125 bp::scope manifolds = get_namespace("manifolds");
127 }
129 exposeGAR();
130 exposeEnums();
133 exposeCosts();
135 exposeStage();
137 exposeFilter();
138 {
139 bp::scope dynamics = get_namespace("dynamics");
144 }
145 exposeUtils();
146
150
151#ifdef ALIGATOR_WITH_PINOCCHIO
152 exposePinocchioFeatures();
153#endif
154
155#ifdef ALIGATOR_WITH_CROCODDYL_COMPAT
156 {
157 bp::scope croc_ns = get_namespace("croc");
158 exposeCrocoddylCompat();
159 }
160#endif
161}
BOOST_PYTHON_MODULE(MODULE_NAME)
Definition module.cpp:89
Namespace for modelling system dynamics.
std::size_t get_current_threads()
Get the current number of threads.
Definition threads.hpp:33
void set_default_options(std::size_t, bool=true)
Definition threads.hpp:38
std::size_t get_available_threads()
Definition threads.hpp:30
The Python bindings.
Definition blk-matrix.hpp:5
void exposeGAR()
Expose GAR module.
void exposeConstraint()
Expose constraints.
void exposeStage()
Expose StageModel and StageData.
static void exposeEnums()
Definition module.cpp:18
static void exposeContainers()
Definition module.cpp:61
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