GCC Code Coverage Report


Directory: ./
File: bindings/python/crocoddyl/core/integrator/rk.cpp
Date: 2025-01-16 08:47:40
Exec Total Coverage
Lines: 87 87 100.0%
Branches: 63 126 50.0%

Line Branch Exec Source
1 ///////////////////////////////////////////////////////////////////////////////
2 // BSD 3-Clause License
3 //
4 // Copyright (C) 2019-2023, University of Edinburgh, University of Trento,
5 // LAAS-CNRS, IRI: CSIC-UPC, Heriot-Watt University
6 // Copyright note valid unless otherwise stated in individual files.
7 // All rights reserved.
8 ///////////////////////////////////////////////////////////////////////////////
9
10 #include "crocoddyl/core/integrator/rk.hpp"
11
12 #include "python/crocoddyl/core/core.hpp"
13 #include "python/crocoddyl/core/integ-action-base.hpp"
14 #include "python/crocoddyl/utils/copyable.hpp"
15
16 namespace crocoddyl {
17 namespace python {
18
19 10 void exposeIntegratedActionRK() {
20 10 bp::register_ptr_to_python<boost::shared_ptr<IntegratedActionModelRK> >();
21
22 20 bp::enum_<RKType>("RKType")
23
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .value("two", two)
24
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .value("three", three)
25
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .value("four", four)
26
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .export_values();
27
28
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::class_<IntegratedActionModelRK,
29 bp::bases<IntegratedActionModelAbstract, ActionModelAbstract> >(
30 "IntegratedActionModelRK",
31 "RK integrator for differential action models.\n\n"
32 "This class implements different RK integrator schemes.\n"
33 "The available integrators are: RK2, RK3, and RK4.",
34
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::init<boost::shared_ptr<DifferentialActionModelAbstract>, RKType,
35 bp::optional<double, bool> >(
36 20 bp::args("self", "diffModel", "rktype", "stepTime",
37 "withCostResidual"),
38 "Initialize the RK integrator.\n\n"
39 ":param diffModel: differential action model\n"
40 ":param rktype: type of RK integrator (options are two, three, and "
41 "four)\n"
42 ":param stepTime: step time (default 1e-3)\n"
43 ":param withCostResidual: includes the cost residuals and "
44 "derivatives (default True)."))
45
2/4
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
10 .def(bp::init<boost::shared_ptr<DifferentialActionModelAbstract>,
46 boost::shared_ptr<ControlParametrizationModelAbstract>,
47 RKType, bp::optional<double, bool> >(
48
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "diffModel", "control", "rktype", "stepTime",
49 "withCostResidual"),
50 "Initialize the RK integrator.\n\n"
51 ":param diffModel: differential action model\n"
52 ":param control: the control parametrization\n"
53 ":param rktype: type of RK integrator (options are two, three, and "
54 "four)\n"
55 ":param stepTime: step time (default 1e-3)\n"
56 ":param withCostResidual: includes the cost residuals and "
57 "derivatives (default True)."))
58 .def<void (IntegratedActionModelRK::*)(
59 const boost::shared_ptr<ActionDataAbstract>&,
60 const Eigen::Ref<const Eigen::VectorXd>&,
61 20 const Eigen::Ref<const Eigen::VectorXd>&)>(
62 "calc", &IntegratedActionModelRK::calc,
63
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "data", "x", "u"),
64 "Compute the time-discrete evolution of a differential action "
65 "model.\n\n"
66 "It describes the time-discrete evolution of action model.\n"
67 ":param data: action data\n"
68 ":param x: state point (dim. state.nx)\n"
69 ":param u: control input (dim. nu)")
70 .def<void (IntegratedActionModelRK::*)(
71 const boost::shared_ptr<ActionDataAbstract>&,
72
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 const Eigen::Ref<const Eigen::VectorXd>&)>(
73
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 "calc", &ActionModelAbstract::calc, bp::args("self", "data", "x"))
74 .def<void (IntegratedActionModelRK::*)(
75 const boost::shared_ptr<ActionDataAbstract>&,
76 const Eigen::Ref<const Eigen::VectorXd>&,
77
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 const Eigen::Ref<const Eigen::VectorXd>&)>(
78 "calcDiff", &IntegratedActionModelRK::calcDiff,
79
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "data", "x", "u"),
80 "Computes the derivatives of the integrated action model wrt state "
81 "and control. \n\n"
82 "This function builds a quadratic approximation of the\n"
83 "action model (i.e. dynamical system and cost function).\n"
84 "It assumes that calc has been run first.\n"
85 ":param data: action data\n"
86 ":param x: state point (dim. state.nx)\n"
87 ":param u: control input (dim. nu)")
88 .def<void (IntegratedActionModelRK::*)(
89 const boost::shared_ptr<ActionDataAbstract>&,
90
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 const Eigen::Ref<const Eigen::VectorXd>&)>(
91 "calcDiff", &ActionModelAbstract::calcDiff,
92
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "data", "x"))
93
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("createData", &IntegratedActionModelRK::createData, bp::args("self"),
94 "Create the RK integrator data.")
95
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property(
96 "ni",
97
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_function(&IntegratedActionModelRK::get_ni,
98 10 bp::return_value_policy<bp::return_by_value>()),
99 "number of nodes to be integrated")
100
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .def(CopyableVisitor<IntegratedActionModelRK>());
101
102 10 bp::register_ptr_to_python<boost::shared_ptr<IntegratedActionDataRK> >();
103
104
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::class_<IntegratedActionDataRK, bp::bases<IntegratedActionDataAbstract> >(
105 "IntegratedActionDataRK", "RK integrator data.",
106
1/2
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
20 bp::init<IntegratedActionModelRK*>(bp::args("self", "model"),
107 "Create RK integrator data.\n\n"
108 ":param model: RK integrator model"))
109
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property(
110 "differential",
111
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&IntegratedActionDataRK::differential,
112 10 bp::return_value_policy<bp::return_by_value>()),
113 "list of differential action data")
114
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property(
115 "control",
116
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&IntegratedActionDataRK::control,
117 10 bp::return_value_policy<bp::return_by_value>()),
118 "list of control parametrization data")
119
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property(
120 "integral",
121
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&IntegratedActionDataRK::integral,
122 10 bp::return_value_policy<bp::return_by_value>()),
123 "list of RK terms related to the cost")
124
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("dx",
125
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&IntegratedActionDataRK::dx,
126 10 bp::return_internal_reference<>()),
127 "state rate.")
128
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("ki",
129
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&IntegratedActionDataRK::ki,
130 10 bp::return_internal_reference<>()),
131 "list of RK terms related to system dynamics")
132
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("y",
133
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&IntegratedActionDataRK::y,
134 10 bp::return_internal_reference<>()),
135 "list of states where f is evaluated in the RK integration")
136
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("ws",
137
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&IntegratedActionDataRK::ws,
138 10 bp::return_internal_reference<>()),
139 "control inputs evaluated in the RK integration")
140
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("dki_dx",
141
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&IntegratedActionDataRK::dki_dx,
142 10 bp::return_internal_reference<>()),
143 "list of partial derivatives of RK nodes with respect to "
144 "the state of the RK "
145 "integration. dki/dx")
146
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("dki_du",
147
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&IntegratedActionDataRK::dki_du,
148 10 bp::return_internal_reference<>()),
149 "list of partial derivatives of RK nodes with respect to "
150 "the control parameters of the RK "
151 "integration. dki/du")
152
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("dyi_dx",
153
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&IntegratedActionDataRK::dyi_dx,
154 10 bp::return_internal_reference<>()),
155 "list of partial derivatives of RK dynamics with respect "
156 "to the state of the RK integrator. dyi/dx")
157
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("dyi_du",
158
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&IntegratedActionDataRK::dyi_du,
159 10 bp::return_internal_reference<>()),
160 "list of partial derivatives of RK dynamics with respect "
161 "to the control parameters of the "
162 "RK integrator. dyi/du")
163
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("dli_dx",
164
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&IntegratedActionDataRK::dli_dx,
165 10 bp::return_internal_reference<>()),
166 "list of partial derivatives of the cost with respect to "
167 "the state of the RK "
168 "integration. dli_dx")
169
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("dli_du",
170
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&IntegratedActionDataRK::dli_du,
171 10 bp::return_internal_reference<>()),
172 "list of partial derivatives of the cost with respect to "
173 "the control input of the RK "
174 "integration. dli_du")
175
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("ddli_ddx",
176
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&IntegratedActionDataRK::ddli_ddx,
177 10 bp::return_internal_reference<>()),
178 "list of second partial derivatives of the cost with "
179 "respect to the state of the RK "
180 "integration. ddli_ddx")
181
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("ddli_ddw",
182
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&IntegratedActionDataRK::ddli_ddw,
183 10 bp::return_internal_reference<>()),
184 "list of second partial derivatives of the cost with "
185 "respect to the control of the differential"
186 "action model w. ddli_ddw")
187
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("ddli_ddu",
188
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&IntegratedActionDataRK::ddli_ddu,
189 10 bp::return_internal_reference<>()),
190 "list of second partial derivatives of the cost with "
191 "respect to the control input of the RK "
192 "integration. ddli_ddu")
193
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("ddli_dxdw",
194
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&IntegratedActionDataRK::ddli_dxdw,
195 10 bp::return_internal_reference<>()),
196 "list of second partial derivatives of the cost with "
197 "respect to the state and control of the differential"
198 "action model. ddli_dxdw")
199
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("ddli_dxdu",
200
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&IntegratedActionDataRK::ddli_dxdu,
201 10 bp::return_internal_reference<>()),
202 "list of second partial derivatives of the cost with "
203 "respect to the state and control input "
204 "of the RK integration. ddli_dxdu")
205
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property(
206 "ddli_dwdu",
207
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&IntegratedActionDataRK::ddli_dwdu,
208 10 bp::return_internal_reference<>()),
209 "list of second partial derivatives of the cost with respect to the "
210 "control of the differential action"
211 "model and the control inputs of the RK integration. ddli_dwdu")
212
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .def(CopyableVisitor<IntegratedActionDataRK>());
213 10 }
214
215 } // namespace python
216 } // namespace crocoddyl
217