Skip to content

Commit 58244ce

Browse files
authored
Merge pull request #298 from Simple-Robotics/topic/aligator-py-extension-cmake-macro
Add CMake macro `aligator_create_python_extension()` to export
2 parents 3b6a8e8 + 2b96074 commit 58244ce

File tree

8 files changed

+91
-28
lines changed

8 files changed

+91
-28
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
### Added
1313

14+
- Add CMake macro `aligator_create_python_extension()` to export ([#298](https://github.com/Simple-Robotics/aligator/pull/298))
1415
- Add macro `ALIGATOR_OUT_OF_RANGE_ERROR` to throw `std::out_of_range` exceptions ([#294](https://github.com/Simple-Robotics/aligator/pull/294))
1516

1617
### Changed

CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (C) 2022-2024 LAAS-CNRS, INRIA
2+
# Copyright (C) 2022-2024 LAAS-CNRS, 2022-2025 INRIA
33
#
44

55
cmake_minimum_required(VERSION 3.16)
@@ -555,6 +555,11 @@ if(BUILD_TESTING)
555555
endif()
556556

557557
# --- PACKAGING ----------------------------------------------------------------
558+
559+
if(BUILD_PYTHON_INTERFACE)
560+
file(READ extra-python-macros.cmake PACKAGE_EXTRA_MACROS)
561+
endif()
562+
558563
macro(EXPORT_VARIABLE var_name var_value)
559564
get_directory_property(has_parent PARENT_DIRECTORY)
560565
if(has_parent)

README.md

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,21 +80,26 @@ cmake --build . -jNCPUS
8080
* [typed-argument-parser](https://github.com/swansonk14/typed-argument-parser)
8181
* [matplotlib](https://matplotlib.org)
8282

83-
### Notes
83+
### Notes on building
8484

8585
* For developers, add the `-DCMAKE_EXPORT_COMPILE_COMMANDS=1` when working with language servers e.g. clangd.
8686
* To use the Crocoddyl interface, add `-DBUILD_CROCODDYL_COMPAT=ON`
8787
* By default, building the library will instantiate the templates for the `double` scalar type.
8888
* To build against a Conda environment, activate the environment and run `export CMAKE_PREFIX_PATH=$CONDA_PREFIX` before running CMake and use `$CONDA_PREFIX` as your install folder.
8989

90+
## Usage
91+
92+
**aligator** can be used in both C++ (with CMake to create builds) and Python.
93+
94+
Users can refer to [examples](https://github.com/Simple-Robotics/aligator/tree/main/examples) in either language to see how to build a trajectory optimization problem, create a solver instance (with parameters), and solve their problem.
95+
96+
For how to use **aligator** in CMake, including creation of a Python extension module in C++, please refer to the [developer's guide](doc/developers-guide.md).
97+
9098
## Benchmarking
9199

92-
We recommend using [Flame Graphs](https://github.com/brendangregg/FlameGraph) to evaluate performance.
93-
If you have the Rust toolchain and `cargo` installed, we suggest you install [cargo-flamegraph](https://github.com/flamegraph-rs/flamegraph). Then, you can create a flame graph with the following command:
100+
The repo [aligator-bench](https://github.com/Simple-Robotics/aligator-bench) provides a comparison of aligator against other solvers.
94101

95-
```bash
96-
flamegraph -o my_flamegraph.svg -- ./build/examples/example-croc-talos-arm
97-
```
102+
For developer info on benchmarking, see [doc/developers-guide.md](doc/developers-guide.md).
98103

99104
## Citing Aligator
100105

@@ -110,13 +115,18 @@ To cite **Aligator** in your academic research, please use the following bibtex
110115
Please also consider citing the reference paper for the ProxDDP algorithm:
111116

112117
```bibtex
113-
@misc{jalletPROXDDPProximalConstrained2023,
114-
title = {{PROXDDP: Proximal Constrained Trajectory Optimization}},
118+
@article{jalletPROXDDPProximalConstrained2025,
119+
title = {PROXDDP: Proximal Constrained Trajectory Optimization},
120+
shorttitle = {PROXDDP},
115121
author = {Jallet, Wilson and Bambade, Antoine and Arlaud, Etienne and {El-Kazdadi}, Sarah and Mansard, Nicolas and Carpentier, Justin},
116-
year = {2023},
117-
abstract = {Trajectory optimization (TO) has proven, over the last decade, to be a versatile and effective framework for robot control. Several numerical solvers have been demonstrated to be fast enough to allow recomputing full-dynamics trajectories for various systems at control time, enabling model predictive control (MPC) of complex robots. These first implementations of MPC in robotics predominantly utilize some differential dynamic programming (DDP) variant for its computational speed and ease of use in constraint-free settings. Nevertheless, many scenarios in robotics call for adding hard constraints in TO problems (e.g., torque limits, obstacle avoidance), which existing solvers, based on DDP, often struggle to handle. Effectively addressing path constraints still poses optimization challenges (e.g., numerical stability, efficiency, accuracy of constraint satisfaction) that we propose to solve by combining advances in numerical optimization with the foundational efficiency of DDP. In this article, we leverage proximal methods for constrained optimization and introduce a DDP-like method to achieve fast, constrained trajectory optimization with an efficient warm-starting strategy particularly suited for MPC applications. Compared to earlier solvers, our approach effectively manages hard constraints without warm-start limitations and exhibits commendable convergence accuracy. Additionally, we leverage the computational efficiency of DDP, enabling real-time resolution of complex problems such as whole-body quadruped locomotion. We provide a complete implementation as part of an open-source and flexible C++ trajectory optimization library called ALIGATOR. These algorithmic contributions are validated through several trajectory planning scenarios from the robotics literature and the real-time whole-body MPC of a quadruped robot.},
118-
langid = {english},
119-
note = {https://inria.hal.science/hal-04332348v1}
122+
year = {2025},
123+
month = mar,
124+
journal = {IEEE Transactions on Robotics},
125+
volume = {41},
126+
pages = {2605--2624},
127+
issn = {1941-0468},
128+
doi = {10.1109/TRO.2025.3554437},
129+
urldate = {2025-04-04}
120130
}
121131
```
122132

@@ -145,7 +155,7 @@ The development of **Aligator** is actively supported by the [Willow team](https
145155
* W. Jallet, N. Mansard, and J. Carpentier, ‘Implicit Differential Dynamic Programming’, in 2022 International Conference on Robotics and Automation (ICRA), Philadelphia, United States: IEEE Robotics and Automation Society, May 2022. doi: 10.1109/ICRA46639.2022.9811647.
146156
* W. Jallet, A. Bambade, N. Mansard, and J. Carpentier, ‘Constrained Differential Dynamic Programming: A primal-dual augmented Lagrangian approach’, in 2022 IEEE/RSJ International Conference on Intelligent Robots and Systems, Kyoto, Japan, Oct. 2022. doi: 10.1109/IROS47612.2022.9981586.
147157
* W. Jallet, A. Bambade, N. Mansard, and J. Carpentier, ‘ProxNLP: a primal-dual augmented Lagrangian solver for nonlinear programming in Robotics and beyond’, in 6th Legged Robots Workshop, Philadelphia, Pennsylvania, United States, May 2022. Accessed: Oct. 10, 2022. [Online]. Available: https://hal.archives-ouvertes.fr/hal-03680510
148-
* W. Jallet, A. Bambade, E. Arlaud, S. El-Kazdadi, N. Mansard, and J. Carpentier, ‘PROXDDP: Proximal Constrained Trajectory Optimization’. 2023. [Online]. Available: https://inria.hal.science/hal-04332348v1
158+
* W. Jallet, A. Bambade, E. Arlaud, S. El-Kazdadi, N. Mansard, and J. Carpentier, ‘PROXDDP: Proximal Constrained Trajectory Optimization’, IEEE Transactions on Robotics, vol. 41, pp. 2605–2624, Mar. 2025, doi: 10.1109/TRO.2025.3554437.
149159
* S. Kazdadi, J. Carpentier, and J. Ponce, ‘Equality Constrained Differential Dynamic Programming’, presented at the ICRA 2021 - IEEE International Conference on Robotics and Automation, May 2021. Accessed: Sep. 07, 2021. [Online]. Available: https://hal.inria.fr/hal-03184203
150160
* A. Bambade, S. El-Kazdadi, A. Taylor, and J. Carpentier, ‘PROX-QP: Yet another Quadratic Programming Solver for Robotics and beyond’, in Robotics: Science and Systems XVIII, Robotics: Science and Systems Foundation, Jun. 2022. doi: 10.15607/RSS.2022.XVIII.040.
151161
* W. Jallet, E. Dantec, E. Arlaud, N. Mansard, and J. Carpentier, ‘Parallel and Proximal Constrained Linear-Quadratic Methods for Real-Time Nonlinear MPC’, in Proceedings of Robotics: Science and Systems, Delft, Netherlands, Jul. 2024. doi: 10.15607/RSS.2024.XX.002.

bindings/python/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (C) 2022-2024 LAAS-CNRS, INRIA
2+
# Copyright (C) 2022-2024 LAAS-CNRS, 2022-2025 INRIA
33
#
44
include(${JRL_CMAKE_MODULES}/python.cmake)
55
if(GENERATE_PYTHON_STUBS)

doc/benchmarks.md

Lines changed: 0 additions & 10 deletions
This file was deleted.

doc/developers-guide.md

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,25 @@
22

33
When creating the CMake build, make sure to add the `-DCMAKE_EXPORT_COMPILE_COMMANDS=1` flag. See its documentation [here](https://cmake.org/cmake/help/latest/variable/CMAKE_EXPORT_COMPILE_COMMANDS.html).
44

5-
## Debugging a C++ executable
5+
A template project for using **aligator** with CMake and C++ can be found in the [aligator-cmake-example-project](https://github.com/Simple-Robotics/aligator-cmake-example-project) repository.
6+
7+
## Creating a Python extension module
8+
9+
When **aligator** is installed, the CMake configuration file (`aligatorConfig.cmake`) provides a CMake function to help users easily create a [Python extension module](https://docs.python.org/3/extending/extending.html).
10+
Users can write an extension module in C++ for performance reasons when providing e.g. custom constraints, cost functions, dynamics, and so on.
11+
12+
The CMake function is called as follows:
13+
```cmake
14+
aligator_create_python_extension(<name> [WITH_SOABI] <sources...>)
15+
```
16+
17+
This will create a CMake `MODULE` target named `<name>` on which the user can set properties and add an `install` directive.
18+
19+
An usage example can be found in [this repo](https://github.com/Simple-Robotics/aligator-cmake-example-project).
20+
21+
## Debugging
22+
23+
### Debugging a C++ executable
624

725
This project builds some C++ examples and tests. Debugging them is fairly straightforward using GDB:
826

@@ -18,7 +36,7 @@ If you want to catch `std::exception` instances thrown, enter the following comm
1836
(gdb) catch throw std::exception
1937
```
2038

21-
## Debugging a Python example or test
39+
### Debugging a Python example or test
2240

2341
In order for debug symbols to be loaded and important variables not being optimized out, you will want to compile in `DEBUG` mode.
2442

@@ -30,6 +48,23 @@ gdb --args python example/file.py
3048

3149
If you want to look at Eigen types such as vectors and matrices, you should look into the [`eigengdb`](https://github.com/dmillard/eigengdb) plugin for GDB.
3250

33-
## Hybrid debugging with Visual Studio Code
51+
### Hybrid debugging with Visual Studio Code
3452

3553
**TODO** Finish documenting this
54+
55+
## Profiling
56+
57+
We use [google benchmark](https://github.com/google/benchmark/tree/v1.5.0) to define C++ benchmarks
58+
which are able to aggregate data from runs, and [Flame Graphs](https://github.com/brendangregg/FlameGraph) to produce a breakdown of the various function calls and their importance as a proportion of the call stack.
59+
60+
If you have the Rust toolchain and `cargo` installed, we suggest you install [cargo-flamegraph](https://github.com/flamegraph-rs/flamegraph). Then, you can create a flame graph with the following command:
61+
62+
```bash
63+
flamegraph -o my_flamegraph.svg -- ./build/examples/example-croc-talos-arm
64+
```
65+
66+
67+
Here's Crocoddyl's flame graph:
68+
![croc-talos-arm](images/flamegraph-croc.svg)
69+
Here's for `aligator::SolverFDDP`:
70+
![prox-talos-arm](images/flamegraph-prox.svg)

extra-python-macros.cmake

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# ------
2+
# aligator_add_python_extension
3+
#
4+
#
5+
# ------
6+
function(aligator_create_python_extension name)
7+
message(STATUS "Adding aligator Python C++ extension ${name}")
8+
set(options WITH_SOABI)
9+
cmake_parse_arguments(arg "${options}" "" "" ${ARGN})
10+
set(_parse_oneValueArgs)
11+
foreach(op IN LISTS options)
12+
if(${arg_${op}})
13+
list(APPEND _parse_oneValueArgs ${op})
14+
endif()
15+
endforeach()
16+
set(_sources ${arg_UNPARSED_ARGUMENTS})
17+
18+
Python3_add_library(${name} ${_parse_oneValueArgs} ${_sources})
19+
target_link_libraries(${name} PRIVATE eigenpy::eigenpy aligator::aligator)
20+
target_compile_definitions(${name} PRIVATE PYTHON_MODULE_NAME=${name})
21+
endfunction()

flake.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
./bench
3232
./bindings
3333
./CMakeLists.txt
34+
./extra-python-macros.cmake
3435
./doc
3536
./examples
3637
./include

0 commit comments

Comments
 (0)