aligator
0.19.0
A versatile and efficient C++ library for real-time constrained trajectory optimization.
Toggle main menu visibility
Loading...
Searching...
No Matches
module.cpp
Go to the documentation of this file.
1
2
#include "
aligator/python/fwd.hpp
"
3
#include "
aligator/python/utils.hpp
"
4
#include "
aligator/python/string-view-converter.hpp
"
5
6
#include "
aligator/core/enums.hpp
"
7
#include "
aligator/threads.hpp
"
8
9
#include <eigenpy/optional.hpp>
10
11
namespace
aligator
{
12
namespace
python
{
13
14
void
exposeExplicitIntegrators
();
15
#ifdef ALIGATOR_WITH_CROCODDYL_COMPAT
16
void
exposeCrocoddylCompat();
17
#endif
18
19
static
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."
)
24
._c(
VerboseLevel
,
QUIET
)
25
._c(
VerboseLevel
,
VERBOSE
)
26
._c(
VerboseLevel
,
VERYVERBOSE
)
27
.export_values();
28
29
bp::enum_<MultiplierUpdateMode>(
30
"MultiplierUpdateMode"
,
"Enum for the kind of multiplier update to use."
)
31
._c(
MultiplierUpdateMode
,
NEWTON
)
32
._c(
MultiplierUpdateMode
,
PRIMAL
)
33
._c(
MultiplierUpdateMode
,
PRIMAL_DUAL
);
34
35
bp::enum_<LinesearchMode>(
"LinesearchMode"
,
"Linesearch mode."
)
36
._c(
LinesearchMode
,
PRIMAL
)
37
._c(
LinesearchMode
,
PRIMAL_DUAL
);
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"
,
55
StepAcceptanceStrategy::LINESEARCH_NONMONOTONE
)
56
.value(
"SA_FILTER"
,
StepAcceptanceStrategy::FILTER
)
57
.export_values();
58
59
#undef _c
60
}
61
62
template
<
typename
MatType,
bool
NoProxy = false>
63
void
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
71
static
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
88
exposeStdVectorEigenStdAlloc<Vector3s>
(
"Vector3s"
);
89
exposeStdVectorEigenStdAlloc<VectorXs>
(
"Vector"
);
90
exposeStdVectorEigenStdAlloc<MatrixXs>
(
"Matrix"
);
91
exposeStdVectorEigenStdAlloc<VecXBool>
(
"VecBool"
);
92
StdVectorPythonVisitor<std::vector<VectorRef>,
true
>::expose(
"StdVec_VecRef"
);
93
StdVectorPythonVisitor<std::vector<MatrixRef>,
true
>::expose(
"StdVec_MatRef"
);
94
}
95
97
void
exposeManifolds
();
98
99
}
// namespace python
100
}
// namespace aligator
101
102
BOOST_PYTHON_MODULE
(MODULE_NAME) {
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
122
register_string_view_converter
();
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"
);
146
exposeManifolds
();
147
}
148
exposeContainers
();
149
exposeGAR
();
150
exposeEnums
();
151
exposeFunctions
();
152
exposeCosts
();
153
exposeConstraint
();
154
exposeStage
();
155
exposeProblem
();
156
exposeFilter
();
157
{
158
bp::scope
dynamics
=
get_namespace
(
"dynamics"
);
159
exposeContinuousDynamics
();
160
exposeDynamics
();
161
exposeExplicitIntegrators
();
162
exposeIntegrators
();
163
}
164
exposeUtils
();
165
166
exposeSolvers
();
167
exposeCallbacks
();
168
exposeAutodiff
();
169
170
#ifdef ALIGATOR_WITH_PINOCCHIO
171
exposePinocchioSpaces
();
172
exposePinocchioFunctions
();
173
exposePinocchioDynamics
();
174
#endif
175
176
#ifdef ALIGATOR_WITH_CROCODDYL_COMPAT
177
{
178
bp::scope croc_ns =
get_namespace
(
"croc"
);
179
exposeCrocoddylCompat();
180
}
181
#endif
182
}
fwd.hpp
utils.hpp
enums.hpp
BOOST_PYTHON_MODULE
BOOST_PYTHON_MODULE(MODULE_NAME)
Definition
module.cpp:102
aligator::context::Scalar
double Scalar
Definition
context.hpp:9
aligator::dynamics
Namespace for modelling system dynamics.
Definition
centroidal-fwd.hpp:10
aligator::omp::get_current_threads
std::size_t get_current_threads()
Get the current number of threads.
Definition
threads.hpp:18
aligator::omp::set_default_options
void set_default_options(std::size_t num_threads, bool dynamic=true)
Definition
threads.hpp:25
aligator::omp::get_available_threads
std::size_t get_available_threads()
Definition
threads.hpp:13
aligator::python
The Python bindings.
Definition
blk-matrix.hpp:7
aligator::python::exposeStdVectorEigenStdAlloc
void exposeStdVectorEigenStdAlloc(const char *name)
Definition
module.cpp:63
aligator::python::exposeGAR
void exposeGAR()
Expose GAR module.
Definition
expose-gar.cpp:51
aligator::python::exposeConstraint
void exposeConstraint()
Expose constraints.
Definition
expose-constraint.cpp:18
aligator::python::exposeStage
void exposeStage()
Expose StageModel and StageData.
Definition
expose-stage.cpp:31
aligator::python::register_string_view_converter
void register_string_view_converter()
Definition
string-view-converter.hpp:46
aligator::python::exposeEnums
static void exposeEnums()
Definition
module.cpp:19
aligator::python::exposeContainers
static void exposeContainers()
Definition
module.cpp:71
aligator::python::exposeUtils
void exposeUtils()
Expose utils.
Definition
expose-utils.cpp:8
aligator::python::exposeCosts
void exposeCosts()
Expose cost functions.
Definition
expose-costs.cpp:138
aligator::python::exposeManifolds
void exposeManifolds()
Expose manifolds.
Definition
expose-manifold.cpp:24
aligator::python::get_namespace
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
aligator::python::exposeSolvers
void exposeSolvers()
Expose solvers.
Definition
expose-solvers-base.cpp:55
aligator::python::exposeDynamics
void exposeDynamics()
Expose discrete dynamics.
Definition
expose-dynamics.cpp:16
aligator::python::exposeIntegrators
void exposeIntegrators()
Expose numerical integrators.
Definition
expose-integrators.cpp:18
aligator::python::exposePinocchioDynamics
void exposePinocchioDynamics()
Definition
expose-pinocchio-dynamics.cpp:19
aligator::python::exposeCallbacks
void exposeCallbacks()
Expose solver callbacks.
Definition
expose-callbacks.cpp:44
aligator::python::exposePinocchioFunctions
void exposePinocchioFunctions()
Definition
expose-pinocchio-functions.cpp:210
aligator::python::exposeFilter
void exposeFilter()
Expose filter strategy.
Definition
expose-filter.cpp:11
aligator::python::exposeProblem
void exposeProblem()
Expose TrajOptProblem.
Definition
expose-problem.cpp:11
aligator::python::exposeContinuousDynamics
void exposeContinuousDynamics()
Expose continuous dynamics.
Definition
expose-continuous-dynamics.cpp:26
aligator::python::exposeAutodiff
void exposeAutodiff()
Expose autodiff helpers.
Definition
expose-autodiff.cpp:10
aligator::python::exposeFunctions
void exposeFunctions()
Expose stagewise function classes.
Definition
expose-functions.cpp:119
aligator::python::exposeExplicitIntegrators
void exposeExplicitIntegrators()
Definition
expose-explicit-integrators.cpp:24
aligator::python::exposePinocchioSpaces
void exposePinocchioSpaces()
Definition
expose-pinocchio-manifolds.cpp:53
aligator
Main package namespace.
Definition
action-model-wrap.hpp:14
aligator::MultiplierUpdateMode
MultiplierUpdateMode
Definition
enums.hpp:23
aligator::MultiplierUpdateMode::NEWTON
@ NEWTON
Definition
enums.hpp:23
aligator::MultiplierUpdateMode::PRIMAL
@ PRIMAL
Definition
enums.hpp:23
aligator::MultiplierUpdateMode::PRIMAL_DUAL
@ PRIMAL_DUAL
Definition
enums.hpp:23
aligator::VerboseLevel
VerboseLevel
Verbosity level.
Definition
fwd.hpp:82
aligator::QUIET
@ QUIET
Definition
fwd.hpp:82
aligator::VERYVERBOSE
@ VERYVERBOSE
Definition
fwd.hpp:82
aligator::VERBOSE
@ VERBOSE
Definition
fwd.hpp:82
aligator::StepAcceptanceStrategy::LINESEARCH_NONMONOTONE
@ LINESEARCH_NONMONOTONE
Definition
enums.hpp:31
aligator::StepAcceptanceStrategy::FILTER
@ FILTER
Definition
enums.hpp:32
aligator::StepAcceptanceStrategy::LINESEARCH_ARMIJO
@ LINESEARCH_ARMIJO
Definition
enums.hpp:30
aligator::RolloutType::LINEAR
@ LINEAR
Linear rollout.
Definition
enums.hpp:7
aligator::RolloutType::NONLINEAR
@ NONLINEAR
Nonlinear rollout, using the full dynamics.
Definition
enums.hpp:9
aligator::HessianApprox::GAUSS_NEWTON
@ GAUSS_NEWTON
Use the Gauss-Newton approximation.
Definition
enums.hpp:18
aligator::HessianApprox::BFGS
@ BFGS
Use a BFGS-type approximation.
Definition
enums.hpp:20
aligator::HessianApprox::EXACT
@ EXACT
Use exact Hessian.
Definition
enums.hpp:16
aligator::LinesearchMode
LinesearchMode
Whether to use merit functions in primal or primal-dual mode.
Definition
enums.hpp:26
string-view-converter.hpp
threads.hpp
bindings
python
src
module.cpp
Generated by
1.17.0