GCC Code Coverage Report


Directory: ./
File: bindings/python/crocoddyl/core/diff-action-base.cpp
Date: 2025-01-16 08:47:40
Exec Total Coverage
Lines: 108 124 87.1%
Branches: 101 202 50.0%

Line Branch Exec Source
1 ///////////////////////////////////////////////////////////////////////////////
2 // BSD 3-Clause License
3 //
4 // Copyright (C) 2019-2024, LAAS-CNRS, University of Edinburgh,
5 // University of Oxford, Heriot-Watt University
6 // Copyright note valid unless otherwise stated in individual files.
7 // All rights reserved.
8 ///////////////////////////////////////////////////////////////////////////////
9
10 #include "python/crocoddyl/core/diff-action-base.hpp"
11
12 #include "python/crocoddyl/core/core.hpp"
13 #include "python/crocoddyl/utils/copyable.hpp"
14 #include "python/crocoddyl/utils/printable.hpp"
15 #include "python/crocoddyl/utils/vector-converter.hpp"
16
17 namespace crocoddyl {
18 namespace python {
19
20 10 void exposeDifferentialActionAbstract() {
21 // Register custom converters between std::vector and Python list
22 typedef boost::shared_ptr<DifferentialActionModelAbstract>
23 DifferentialActionModelPtr;
24 typedef boost::shared_ptr<DifferentialActionDataAbstract>
25 DifferentialActionDataPtr;
26
3/6
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 10 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 10 times.
✗ Branch 10 not taken.
10 StdVectorPythonVisitor<std::vector<DifferentialActionModelPtr>, true>::expose(
27 "StdVec_DiffActionModel");
28
3/6
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 10 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 10 times.
✗ Branch 10 not taken.
10 StdVectorPythonVisitor<std::vector<DifferentialActionDataPtr>, true>::expose(
29 "StdVec_DiffActionData");
30
31 bp::register_ptr_to_python<
32 10 boost::shared_ptr<DifferentialActionModelAbstract> >();
33
34
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::class_<DifferentialActionModelAbstract_wrap, boost::noncopyable>(
35 "DifferentialActionModelAbstract",
36 "Abstract class for the differential action model.\n\n"
37 "A differential action model is the time-continuous version of an action "
38 "model. Each\n"
39 "node, in our optimal control problem, is described through an action "
40 "model. Every\n"
41 "time that we want describe a problem, we need to provide ways of "
42 "computing the\n"
43 "dynamics, cost functions, constraints and their derivatives. These "
44 "computations are\n"
45 "mainly carried out inside calc() and calcDiff(), respectively.",
46
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::init<boost::shared_ptr<StateAbstract>, std::size_t,
47 bp::optional<std::size_t, std::size_t, std::size_t, std::size_t,
48 std::size_t> >(
49 20 bp::args("self", "state", "nu", "nr", "ng", "nh", "ng_T", "nh_T"),
50 "Initialize the differential action model.\n\n"
51 "We can also describe autonomous systems by setting nu = 0.\n"
52 ":param state: state\n"
53 ":param nu: dimension of control vector\n"
54 ":param nr: dimension of cost-residual vector (default 1)\n"
55 ":param ng: number of inequality constraints (default 0)\n"
56 ":param nh: number of equality constraints (default 0)\n"
57 ":param ng_T: number of inequality terminal constraints (default 0)\n"
58 ":param nh_T: number of equality terminal constraints (default 0)"))
59
2/4
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
10 .def("calc", pure_virtual(&DifferentialActionModelAbstract_wrap::calc),
60
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "data", "x", "u"),
61 "Compute the system acceleration and cost value.\n\n"
62 ":param data: differential action data\n"
63 ":param x: state point (dim. state.nx)\n"
64 ":param u: control input (dim. nu)")
65 .def<void (DifferentialActionModelAbstract::*)(
66 const boost::shared_ptr<DifferentialActionDataAbstract>&,
67 20 const Eigen::Ref<const Eigen::VectorXd>&)>(
68 "calc", &DifferentialActionModelAbstract::calc,
69
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "data", "x"),
70 "Compute the total cost value for nodes that depends only on the "
71 "state.\n\n"
72 "It updates the total cost and the system acceleration is not "
73 "updated as the control\n"
74 "input is undefined. This function is used in the terminal nodes of "
75 "an optimal\n"
76 "control problem.\n"
77 ":param data: differential action data\n"
78 ":param x: state point (dim. state.nx)")
79
3/6
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 10 times.
✗ Branch 8 not taken.
20 .def("calcDiff",
80 pure_virtual(&DifferentialActionModelAbstract_wrap::calcDiff),
81
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "data", "x", "u"),
82 "Compute the derivatives of the dynamics and cost functions.\n\n"
83 "It computes the partial derivatives of the dynamical system and "
84 "the cost\n"
85 "function. It assumes that calc has been run first.\n"
86 "This function builds a quadratic approximation of the\n"
87 "time-continuous action model (i.e. dynamical system and cost "
88 "function).\n"
89 ":param data: differential action data\n"
90 ":param x: state point (dim. state.nx)\n"
91 ":param u: control input (dim. nu)")
92 .def<void (DifferentialActionModelAbstract::*)(
93 const boost::shared_ptr<DifferentialActionDataAbstract>&,
94 20 const Eigen::Ref<const Eigen::VectorXd>&)>(
95 "calcDiff", &DifferentialActionModelAbstract::calcDiff,
96
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "data", "x"),
97 "Compute the derivatives of the cost functions with respect to the "
98 "state only.\n\n"
99 "It updates the derivatives of the cost function with respect to the "
100 "state only.\n"
101 "This function is used in the terminal nodes of an optimal control "
102 "problem.\n"
103 ":param data: action data\n"
104 ":param x: state point (dim. state.nx)")
105
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .def("createData", &DifferentialActionModelAbstract_wrap::createData,
106
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 &DifferentialActionModelAbstract_wrap::default_createData,
107
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self"),
108 "Create the differential action data.\n\n"
109 "Each differential action model has its own data that needs to be\n"
110 "allocated. This function returns the allocated data for a "
111 "predefined\n"
112 "DAM.\n"
113 ":return DAM data.")
114
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .def("quasiStatic", &DifferentialActionModelAbstract_wrap::quasiStatic_x,
115
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 DifferentialActionModel_quasiStatic_wraps(
116
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "data", "x", "maxiter", "tol"),
117 "Compute the quasic-static control given a state.\n\n"
118 "It runs an iterative Newton step in order to compute the "
119 "quasic-static regime\n"
120 "given a state configuration.\n"
121 ":param data: action data\n"
122 ":param x: discrete-time state vector\n"
123 ":param maxiter: maximum allowed number of iterations\n"
124 ":param tol: stopping tolerance criteria (default 1e-9)\n"
125 ":return u: quasic-static control"))
126 20 .def("quasiStatic", &DifferentialActionModelAbstract_wrap::quasiStatic,
127
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 &DifferentialActionModelAbstract_wrap::default_quasiStatic,
128
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "data", "u", "x", "maxiter", "tol"))
129
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property(
130 "nu",
131
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::make_function(&DifferentialActionModelAbstract_wrap::get_nu),
132 "dimension of control vector")
133
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property(
134 "nr",
135
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::make_function(&DifferentialActionModelAbstract_wrap::get_nr),
136 "dimension of cost-residual vector")
137
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property(
138 "ng",
139
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::make_function(&DifferentialActionModelAbstract_wrap::get_ng),
140 "number of inequality constraints")
141
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property(
142 "nh",
143
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::make_function(&DifferentialActionModelAbstract_wrap::get_nh),
144 "number of equality constraints")
145
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property(
146 "ng_T",
147
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::make_function(&DifferentialActionModelAbstract_wrap::get_ng_T),
148 "number of inequality terminal constraints")
149
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property(
150 "nh_T",
151
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::make_function(&DifferentialActionModelAbstract_wrap::get_nh_T),
152 "number of equality terminal constraints")
153
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property(
154 "state",
155
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_function(&DifferentialActionModelAbstract_wrap::get_state,
156 10 bp::return_value_policy<bp::return_by_value>()),
157 "state")
158
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property(
159 "g_lb",
160
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_function(&DifferentialActionModelAbstract_wrap::get_g_lb,
161 10 bp::return_internal_reference<>()),
162 &DifferentialActionModelAbstract_wrap::set_g_lb,
163 "lower bound of the inequality constraints")
164
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property(
165 "g_ub",
166
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_function(&DifferentialActionModelAbstract_wrap::get_g_ub,
167 10 bp::return_internal_reference<>()),
168 &DifferentialActionModelAbstract_wrap::set_g_ub,
169 "upper bound of the inequality constraints")
170
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property(
171 "u_lb",
172
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_function(&DifferentialActionModelAbstract_wrap::get_u_lb,
173 10 bp::return_internal_reference<>()),
174 &DifferentialActionModelAbstract_wrap::set_u_lb,
175 "lower control limits")
176
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property(
177 "u_ub",
178
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_function(&DifferentialActionModelAbstract_wrap::get_u_ub,
179 10 bp::return_internal_reference<>()),
180 &DifferentialActionModelAbstract_wrap::set_u_ub,
181 "upper control limits")
182
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property(
183 "has_control_limits",
184
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::make_function(
185 &DifferentialActionModelAbstract_wrap::get_has_control_limits),
186 "indicates whether problem has finite control limits")
187
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .def(PrintableVisitor<DifferentialActionModelAbstract>());
188
189 bp::register_ptr_to_python<
190 10 boost::shared_ptr<DifferentialActionDataAbstract> >();
191
192
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::class_<DifferentialActionDataAbstract>(
193 "DifferentialActionDataAbstract",
194 "Abstract class for differential action data.\n\n"
195 "In crocoddyl, an action data contains all the required information for "
196 "processing an\n"
197 "user-defined action model. The action data typically is allocated onces "
198 "by running\n"
199 "model.createData() and contains the first- and second- order "
200 "derivatives of the dynamics\n"
201 "and cost function, respectively.",
202
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::init<DifferentialActionModelAbstract*>(
203 20 bp::args("self", "model"),
204 "Create common data shared between DAMs.\n\n"
205 "The differential action data uses the model in order to first "
206 "process it.\n"
207 ":param model: differential action model"))
208
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property(
209 "cost",
210
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&DifferentialActionDataAbstract::cost,
211 bp::return_value_policy<bp::return_by_value>()),
212
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::make_setter(&DifferentialActionDataAbstract::cost), "cost value")
213
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("xout",
214
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&DifferentialActionDataAbstract::xout,
215 bp::return_internal_reference<>()),
216
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::make_setter(&DifferentialActionDataAbstract::xout),
217 "evolution state")
218
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("r",
219
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&DifferentialActionDataAbstract::r,
220 bp::return_internal_reference<>()),
221
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::make_setter(&DifferentialActionDataAbstract::r),
222 "cost residual")
223
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("Fx",
224
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&DifferentialActionDataAbstract::Fx,
225 bp::return_internal_reference<>()),
226
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::make_setter(&DifferentialActionDataAbstract::Fx),
227 "Jacobian of the dynamics w.r.t. the state")
228
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("Fu",
229
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&DifferentialActionDataAbstract::Fu,
230 bp::return_internal_reference<>()),
231
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::make_setter(&DifferentialActionDataAbstract::Fu),
232 "Jacobian of the dynamics w.r.t. the control")
233
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("Lx",
234
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&DifferentialActionDataAbstract::Lx,
235 bp::return_internal_reference<>()),
236
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::make_setter(&DifferentialActionDataAbstract::Lx),
237 "Jacobian of the cost w.r.t. the state")
238
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("Lu",
239
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&DifferentialActionDataAbstract::Lu,
240 bp::return_internal_reference<>()),
241
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::make_setter(&DifferentialActionDataAbstract::Lu),
242 "Jacobian of the cost w.r.t. the control")
243
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("Lxx",
244
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&DifferentialActionDataAbstract::Lxx,
245 bp::return_internal_reference<>()),
246
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::make_setter(&DifferentialActionDataAbstract::Lxx),
247 "Hessian of the cost w.r.t. the state")
248
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("Lxu",
249
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&DifferentialActionDataAbstract::Lxu,
250 bp::return_internal_reference<>()),
251
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::make_setter(&DifferentialActionDataAbstract::Lxu),
252 "Hessian of the cost w.r.t. the state and control")
253
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("Luu",
254
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&DifferentialActionDataAbstract::Luu,
255 bp::return_internal_reference<>()),
256
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::make_setter(&DifferentialActionDataAbstract::Luu),
257 "Hessian of the cost w.r.t. the control")
258
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("g",
259
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&DifferentialActionDataAbstract::g,
260 bp::return_internal_reference<>()),
261
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::make_setter(&DifferentialActionDataAbstract::g),
262 "Inequality constraint values")
263
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("Gx",
264
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&DifferentialActionDataAbstract::Gx,
265 bp::return_internal_reference<>()),
266
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::make_setter(&DifferentialActionDataAbstract::Gx),
267 "Jacobian of the inequality constraint w.r.t. the state")
268
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("Gu",
269
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&DifferentialActionDataAbstract::Gu,
270 bp::return_internal_reference<>()),
271
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::make_setter(&DifferentialActionDataAbstract::Gu),
272 "Jacobian of the inequality constraint w.r.t. the control")
273
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("h",
274
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&DifferentialActionDataAbstract::h,
275 bp::return_internal_reference<>()),
276
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::make_setter(&DifferentialActionDataAbstract::h),
277 "Equality constraint values")
278
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("Hx",
279
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&DifferentialActionDataAbstract::Hx,
280 bp::return_internal_reference<>()),
281
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::make_setter(&DifferentialActionDataAbstract::Hx),
282 "Jacobian of the equality constraint w.r.t. the state")
283
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("Hu",
284
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&DifferentialActionDataAbstract::Hu,
285 bp::return_internal_reference<>()),
286
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::make_setter(&DifferentialActionDataAbstract::Hu),
287 "Jacobian of the equality constraint w.r.t. the control")
288
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .def(CopyableVisitor<DifferentialActionDataAbstract>());
289 10 }
290
291 } // namespace python
292 } // namespace crocoddyl
293