GCC Code Coverage Report


Directory: ./
File: bindings/python/crocoddyl/core/optctrl/shooting-float.cpp
Date: 2025-04-18 16:41:15
Exec Total Coverage
Lines: 0 27 0.0%
Branches: 0 90 0.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, Heriot-Watt University
6 // Copyright note valid unless otherwise stated in individual files.
7 // All rights reserved.
8 ///////////////////////////////////////////////////////////////////////////////
9
10 // Auto-generated file for float
11 #include "crocoddyl/core/optctrl/shooting.hpp"
12
13 #include "python/crocoddyl/core/core.hpp"
14
15 namespace crocoddyl {
16 namespace python {
17
18 template <typename Problem>
19 struct ShootingProblemVisitor
20 : public bp::def_visitor<ShootingProblemVisitor<Problem>> {
21 typedef typename Problem::ActionModelAbstract ActionModel;
22 typedef typename Problem::ActionDataAbstract ActionData;
23 typedef typename Problem::VectorXs VectorXs;
24 template <class PyClass>
25 void visit(PyClass& cl) const {
26 cl.def(bp::init<VectorXs, std::vector<std::shared_ptr<ActionModel>>,
27 std::shared_ptr<ActionModel>,
28 std::vector<std::shared_ptr<ActionData>>,
29 std::shared_ptr<ActionData>>(
30 bp::args("self", "x0", "runningModels", "terminalModel",
31 "runningDatas", "terminalData"),
32 "Initialize the shooting problem (models and datas).\n\n"
33 ":param x0: initial state\n"
34 ":param runningModels: running action models (size T)\n"
35 ":param terminalModel: terminal action model\n"
36 ":param runningDatas: running action datas (size T)\n"
37 ":param terminalData: terminal action data"))
38 .def("calc", &Problem::calc, bp::args("self", "xs", "us"),
39 "Compute the cost and the next states.\n\n"
40 "For each node k, and along the state xs and control us "
41 "trajectories, it computes the next state x_{k+1} and cost l_k.\n"
42 ":param xs: time-discrete state trajectory (size T+1)\n"
43 ":param us: time-discrete control sequence (size T)\n"
44 ":returns the total cost value")
45 .def("calcDiff", &Problem::calcDiff, bp::args("self", "xs", "us"),
46 "Compute the derivatives of the cost and dynamics.\n\n"
47 "For each node k, and along the state x_s and control u_s "
48 "trajectories, it computes the derivatives of the cost (lx, lu, "
49 "lxx, lxu, luu) and dynamics (fx, fu).\n"
50 ":param xs: time-discrete state trajectory (size T+1)\n"
51 ":param us: time-discrete control sequence (size T)\n"
52 ":returns the total cost value")
53 .def("rollout", &Problem::rollout_us, bp::args("self", "us"),
54 "Integrate the dynamics given a control sequence.\n\n"
55 "Rollout the dynamics give a sequence of control commands\n"
56 ":param us: time-discrete control sequence (size T)")
57 .def("quasiStatic", &Problem::quasiStatic_xs, bp::args("self", "xs"),
58 "Compute the quasi static commands given a state trajectory.\n\n"
59 "Generally speaking, it uses Newton-Raphson method for computing "
60 "the quasi static commands.\n"
61 ":param xs: time-discrete state trajectory (size T)")
62 .def("circularAppend",
63 static_cast<void (Problem::*)(std::shared_ptr<ActionModel>,
64 std::shared_ptr<ActionData>)>(
65 &Problem::circularAppend),
66 bp::args("self", "model", "data"),
67 bp::args("self", "model", "data"),
68 "Circular append the model and data onto the end running node.\n\n"
69 "Once we update the end running node, the first running mode is "
70 "removed as in a circular buffer.\n"
71 ":param model: new model\n"
72 ":param data: new data")
73 .def("circularAppend",
74 static_cast<void (Problem::*)(std::shared_ptr<ActionModel>)>(
75 &Problem::circularAppend),
76 bp::args("self", "model"),
77 "Circular append the model and data onto the end running node.\n\n"
78 "Once we update the end running node, the first running mode is "
79 "removed as in a circular buffer. Note that this method allocates "
80 "new data for the end running node.\n"
81 ":param model: new model")
82 .def("updateNode", &Problem::updateNode,
83 bp::args("self", "i", "model", "data"),
84 "Update the model and data for a specific node.\n\n"
85 ":param i: index of the node (0 <= i <= T + 1)\n"
86 ":param model: new model\n"
87 ":param data: new data")
88 .def("updateModel", &Problem::updateModel,
89 bp::args("self", "i", "model"),
90 "Update a model and allocated new data for a specific node.\n\n"
91 ":param i: index of the node (0 <= i <= T + 1)\n"
92 ":param model: new model")
93 .add_property("T", bp::make_function(&Problem::get_T),
94 "number of running nodes")
95 .add_property("x0",
96 bp::make_function(&Problem::get_x0,
97 bp::return_internal_reference<>()),
98 &Problem::set_x0, "initial state")
99 .add_property(
100 "runningModels",
101 bp::make_function(&Problem::get_runningModels,
102 bp::return_value_policy<bp::return_by_value>()),
103 &Problem::set_runningModels, "running models")
104 .add_property(
105 "terminalModel",
106 bp::make_function(&Problem::get_terminalModel,
107 bp::return_value_policy<bp::return_by_value>()),
108 &Problem::set_terminalModel, "terminal model")
109 .add_property(
110 "runningDatas",
111 bp::make_function(&Problem::get_runningDatas,
112 bp::return_value_policy<bp::return_by_value>()),
113 "running datas")
114 .add_property(
115 "terminalData",
116 bp::make_function(&Problem::get_terminalData,
117 bp::return_value_policy<bp::return_by_value>()),
118 "terminal data")
119 .add_property(
120 "nthreads", bp::make_function(&Problem::get_nthreads),
121 bp::make_function(&Problem::set_nthreads),
122 "number of threads launch by the multi-threading support (if you "
123 "set nthreads <= 1, then nthreads=CROCODDYL_WITH_NTHREADS)")
124 .add_property("nx", bp::make_function(&Problem::get_nx),
125 "dimension of state tuple")
126 .add_property("ndx", bp::make_function(&Problem::get_ndx),
127 "dimension of the tangent space of the state manifold")
128 .add_property("is_updated", bp::make_function(&Problem::is_updated),
129 "Returns True if the shooting problem has been updated, "
130 "otherwise False");
131 }
132 };
133
134 #define CROCODDYL_SHOOTING_PROBLEM_PYTHON_BINDINGS(Scalar) \
135 typedef ShootingProblemTpl<Scalar> Problem; \
136 typedef ActionModelAbstractTpl<Scalar> ActionModel; \
137 typedef typename Problem::VectorXs VectorXs; \
138 bp::register_ptr_to_python<std::shared_ptr<Problem>>(); \
139 bp::class_<Problem>( \
140 "ShootingProblem", \
141 "Declare a shooting problem.\n\n" \
142 "A shooting problem declares the initial state, a set of running " \
143 "action models and a terminal action model. It has three main methods " \
144 "- calc, calcDiff and rollout. The first computes the set of next " \
145 "states and cost values per each action model. calcDiff updates the " \
146 "derivatives of all action models. The last rollouts the stacks of " \
147 "actions models.", \
148 bp::init<VectorXs, std::vector<std::shared_ptr<ActionModel>>, \
149 std::shared_ptr<ActionModel>>( \
150 bp::args("self", "x0", "runningModels", "terminalModel"), \
151 "Initialize the shooting problem and allocate its data.\n\n" \
152 ":param x0: initial state\n" \
153 ":param runningModels: running action models (size T)\n" \
154 ":param terminalModel: terminal action model")) \
155 .def(ShootingProblemVisitor<Problem>()) \
156 .def(PrintableVisitor<Problem>()) \
157 .def(CopyableVisitor<Problem>());
158
159 void exposeShootingProblem() {
160 CROCODDYL_SHOOTING_PROBLEM_PYTHON_BINDINGS(float)
161 }
162
163 } // namespace python
164 } // namespace crocoddyl
165