GCC Code Coverage Report


Directory: ./
File: bindings/python/crocoddyl/core/integrator/euler.cpp
Date: 2025-03-26 19:23:43
Exec Total Coverage
Lines: 22 22 100.0%
Branches: 50 100 50.0%

Line Branch Exec Source
1 ///////////////////////////////////////////////////////////////////////////////
2 // BSD 3-Clause License
3 //
4 // Copyright (C) 2019-2025, LAAS-CNRS, University of Edinburgh,
5 // University of Oxford, University of Trento,
6 // Heriot-Watt University
7 // Copyright note valid unless otherwise stated in individual files.
8 // All rights reserved.
9 ///////////////////////////////////////////////////////////////////////////////
10
11 #include "crocoddyl/core/integrator/euler.hpp"
12
13 #include "python/crocoddyl/core/core.hpp"
14 #include "python/crocoddyl/core/integ-action-base.hpp"
15
16 namespace crocoddyl {
17 namespace python {
18
19 template <typename Model>
20 struct IntegratedActionModelEulerVisitor
21 : public bp::def_visitor<IntegratedActionModelEulerVisitor<Model>> {
22 typedef typename Model::Scalar Scalar;
23 typedef typename Model::ActionDataAbstract Data;
24 typedef
25 typename Model::DifferentialActionModelAbstract DifferentialActionModel;
26 typedef typename Model::ControlParametrizationModelAbstract
27 ControlParametrizationModel;
28 typedef typename Model::VectorXs VectorXs;
29 template <class PyClass>
30 40 void visit(PyClass& cl) const {
31
2/4
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 20 times.
✗ Branch 6 not taken.
40 cl.def(bp::init<std::shared_ptr<DifferentialActionModel>,
32 std::shared_ptr<ControlParametrizationModel>,
33 bp::optional<Scalar, bool>>(
34 bp::args("self", "diffModel", "control", "stepTime",
35 "withCostResidual"),
36 "Initialize the Euler integrator.\n\n"
37 ":param diffModel: differential action model\n"
38 ":param control: the control parametrization\n"
39 ":param stepTime: step time (default 1e-3)\n"
40 ":param withCostResidual: includes the cost residuals and "
41 "derivatives (default True)."))
42
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
80 .def(
43 "calc",
44 static_cast<void (Model::*)(
45 const std::shared_ptr<Data>&, const Eigen::Ref<const VectorXs>&,
46 const Eigen::Ref<const VectorXs>&)>(&Model::calc),
47 bp::args("self", "data", "x", "u"),
48 "Compute the time-discrete evolution of a differential action "
49 "model.\n\n"
50 "It describes the time-discrete evolution of action model.\n"
51 ":param data: action data\n"
52 ":param x: state point (dim. state.nx)\n"
53 ":param u: control input (dim. nu)")
54
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
80 .def("calc",
55 static_cast<void (Model::*)(const std::shared_ptr<Data>&,
56 const Eigen::Ref<const VectorXs>&)>(
57 &Model::calc),
58 bp::args("self", "data", "x"))
59
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
80 .def(
60 "calcDiff",
61 static_cast<void (Model::*)(
62 const std::shared_ptr<Data>&, const Eigen::Ref<const VectorXs>&,
63 const Eigen::Ref<const VectorXs>&)>(&Model::calcDiff),
64 bp::args("self", "data", "x", "u"),
65 "Computes the derivatives of the integrated action model wrt state "
66 "and control. \n\n"
67 "This function builds a quadratic approximation of the action "
68 "model (i.e. dynamical system and cost function). It assumes that "
69 "calc has been run first.\n"
70 ":param data: action data\n"
71 ":param x: state point (dim. state.nx)\n"
72 ":param u: control input (dim. nu)")
73
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
80 .def("calcDiff",
74 static_cast<void (Model::*)(const std::shared_ptr<Data>&,
75 const Eigen::Ref<const VectorXs>&)>(
76 &Model::calcDiff),
77 bp::args("self", "data", "x"))
78
3/6
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 20 times.
✗ Branch 8 not taken.
40 .def("createData", &Model::createData, bp::args("self"),
79 "Create the Euler integrator data.");
80 40 }
81 };
82
83 template <typename Data>
84 struct IntegratedActionDataEulerVisitor
85 : public bp::def_visitor<IntegratedActionDataEulerVisitor<Data>> {
86 template <class PyClass>
87 40 void visit(PyClass& cl) const {
88
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
40 cl.add_property(
89 "differential",
90 bp::make_getter(&Data::differential,
91 40 bp::return_value_policy<bp::return_by_value>()),
92 "differential action data")
93
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
40 .add_property(
94 "control",
95 bp::make_getter(&Data::control,
96 40 bp::return_value_policy<bp::return_by_value>()),
97 "control parametrization data")
98
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
40 .add_property(
99 40 "dx", bp::make_getter(&Data::dx, bp::return_internal_reference<>()),
100 "state rate.")
101
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
40 .add_property(
102 "Lwu",
103 40 bp::make_getter(&Data::Lwu, bp::return_internal_reference<>()),
104 "Hessian of the cost wrt the differential control (w) and "
105 "the control parameters (u).");
106 40 }
107 };
108
109 #define CROCODDYL_INTACTION_MODEL_EULER_PYTHON_BINDINGS(Scalar) \
110 typedef IntegratedActionModelEulerTpl<Scalar> Model; \
111 typedef IntegratedActionModelAbstractTpl<Scalar> ModelBase; \
112 typedef ActionModelAbstractTpl<Scalar> ActionBase; \
113 typedef DifferentialActionModelAbstractTpl<Scalar> DiffActionBase; \
114 bp::register_ptr_to_python<std::shared_ptr<Model>>(); \
115 bp::class_<Model, bp::bases<ModelBase, ActionBase>>( \
116 "IntegratedActionModelEuler", \
117 "Sympletic Euler integrator for differential action models.\n\n" \
118 "This class implements a sympletic Euler integrator (a.k.a " \
119 "semi-implicit integrator) give a differential action model, i.e.:\n" \
120 " [q+, v+] = State.integrate([q, v], [v + a * dt, a * dt] * dt).", \
121 bp::init<std::shared_ptr<DiffActionBase>, bp::optional<Scalar, bool>>( \
122 bp::args("self", "diffModel", "stepTime", "withCostResidual"), \
123 "Initialize the sympletic Euler integrator.\n\n" \
124 ":param diffModel: differential action model\n" \
125 ":param stepTime: step time (default 1e-3)\n" \
126 ":param withCostResidual: includes the cost residuals and " \
127 "derivatives (default True).")) \
128 .def(IntegratedActionModelEulerVisitor<Model>()) \
129 .def(CastVisitor<Model>()) \
130 .def(PrintableVisitor<Model>()) \
131 .def(CopyableVisitor<Model>());
132
133 #define CROCODDYL_INTACTION_DATA_EULER_PYTHON_BINDINGS(Scalar) \
134 typedef IntegratedActionDataEulerTpl<Scalar> Data; \
135 typedef IntegratedActionDataAbstractTpl<Scalar> DataBase; \
136 typedef IntegratedActionModelEulerTpl<Scalar> Model; \
137 bp::register_ptr_to_python<std::shared_ptr<Data>>(); \
138 bp::class_<Data, bp::bases<DataBase>>( \
139 "IntegratedActionDataEuler", "Sympletic Euler integrator data.", \
140 bp::init<Model*>(bp::args("self", "model"), \
141 "Create sympletic Euler integrator data.\n\n" \
142 ":param model: sympletic Euler integrator model")) \
143 .def(IntegratedActionDataEulerVisitor<Data>()) \
144 .def(CopyableVisitor<Data>());
145
146 10 void exposeIntegratedActionEuler() {
147
17/34
✓ Branch 3 taken 10 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 10 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 10 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 10 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 10 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 10 times.
✗ Branch 19 not taken.
✓ Branch 24 taken 10 times.
✗ Branch 25 not taken.
✓ Branch 27 taken 10 times.
✗ Branch 28 not taken.
✓ Branch 30 taken 10 times.
✗ Branch 31 not taken.
✓ Branch 35 taken 10 times.
✗ Branch 36 not taken.
✓ Branch 38 taken 10 times.
✗ Branch 39 not taken.
✓ Branch 41 taken 10 times.
✗ Branch 42 not taken.
✓ Branch 44 taken 10 times.
✗ Branch 45 not taken.
✓ Branch 47 taken 10 times.
✗ Branch 48 not taken.
✓ Branch 50 taken 10 times.
✗ Branch 51 not taken.
✓ Branch 53 taken 10 times.
✗ Branch 54 not taken.
✓ Branch 56 taken 10 times.
✗ Branch 57 not taken.
20 CROCODDYL_PYTHON_SCALARS(CROCODDYL_INTACTION_MODEL_EULER_PYTHON_BINDINGS)
148
13/26
✓ Branch 3 taken 10 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 10 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 10 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 10 times.
✗ Branch 13 not taken.
✓ Branch 18 taken 10 times.
✗ Branch 19 not taken.
✓ Branch 21 taken 10 times.
✗ Branch 22 not taken.
✓ Branch 24 taken 10 times.
✗ Branch 25 not taken.
✓ Branch 29 taken 10 times.
✗ Branch 30 not taken.
✓ Branch 32 taken 10 times.
✗ Branch 33 not taken.
✓ Branch 35 taken 10 times.
✗ Branch 36 not taken.
✓ Branch 38 taken 10 times.
✗ Branch 39 not taken.
✓ Branch 41 taken 10 times.
✗ Branch 42 not taken.
✓ Branch 44 taken 10 times.
✗ Branch 45 not taken.
20 CROCODDYL_PYTHON_SCALARS(CROCODDYL_INTACTION_DATA_EULER_PYTHON_BINDINGS)
149 10 }
150
151 } // namespace python
152 } // namespace crocoddyl
153