Skip to content

Commit a512106

Browse files
authored
Merge pull request #243 from Simple-Robotics/topic/gar-optimizations
Add memory allocator support for LQ subproblem types, merge `gar` into main aligator library, slight refactor of `DenseRiccatiSolver`
2 parents a26c4af + 577db1e commit a512106

File tree

103 files changed

+1883
-1244
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+1883
-1244
lines changed

CHANGELOG.md

+35
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,30 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- Add CMake macro `aligator_create_python_extension()` to export ([#298](https://github.com/Simple-Robotics/aligator/pull/298))
1313
- Add `LqrProblemTpl::isApprox()` and helper `lqrKnotsSameDim`, check dimensions in `LqrKnotTpl::isApprox()` ([#300](https://github.com/Simple-Robotics/aligator/pull/300))
14+
- Add class `aligator::polymorphic_allocator` leveraging C++17 memory resources
15+
- Add memory allocator support for `LqrKnot` and `LqrProblem`
16+
- Add class `DenseKernel` for the stagewise-dense Riccati algo -- rework `DenseRiccatiSolver` class
1417
- Add `gar/fwd.hpp` header ([#301](https://github.com/Simple-Robotics/aligator/pull/301/))
1518

1619
### Changed
1720

1821
- Rename `{ riccati-impl.hpp => riccati-kernel }` (and associated files) ([#301](https://github.com/Simple-Robotics/aligator/pull/301/))
22+
- Rename `LQRKnotTpl` (C++)/`LqrKnot` (Python) to `LqrKnot(Tpl)`
23+
- Move `HistoryCallbackTpl` to `aligator/core`
24+
- Move headers `results-base`, `solver-util`, `value-function`, `workspace-base` to `aligator/core`
25+
- Rename `LQRProblemTpl` (C++)/`LQRProblem` (Python) to `LqrProblem(Tpl)`
26+
- `fwd.hpp`: do not include `<pinocchio/config.hpp>` header anymore
27+
- `blk-matrix.hpp`: remove protected ctors, add conversion ops
28+
- Headers `aligator/gar/*.hpp` merged into main library
29+
- CMake: rework declaration of examples & benchmarks (applying liberal use of `cmake_parse_arguments()`)
30+
- CMake: add `bench/CMakeLists.txt` to gersemi defs, apply formatting
31+
- CMake: apply compile definitions to `aligator` target directly (reduce use of global compile definitions)
32+
33+
### Removed
34+
35+
- Removed `gar` as a separate CMake target and shared library, merge into main library
36+
- Remove subdirectory `aligator/helpers` from include dir
37+
- Remove function `allocate_shared_eigen_aligned()`
1938

2039
## [0.13.0] - 2025-04-26
2140

@@ -44,6 +63,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4463

4564
### Changed
4665

66+
- Only link against needed pinocchio libraries ([#260](https://github.com/Simple-Robotics/aligator/pull/260))
67+
- Use Pinocchio instantiated functions ([#261](https://github.com/Simple-Robotics/aligator/pull/261))
68+
- Rename `LQRKnotTpl` (C++)/`LqrKnot` (Python) to `LqrKnot(Tpl)`
69+
- Move `HistoryCallbackTpl` to `aligator/core`
70+
- Move headers `results-base`, `solver-util`, `value-function`, `workspace-base` to `aligator/core`
71+
- Rename `LQRProblemTpl` (C++)/`LQRProblem` (Python) to `LqrProblem(Tpl)`
72+
- Add class `aligator::polymorphic_allocator` leveraging C++17 memory resources
73+
- Add memory allocator support for `LqrKnot` and `LqrProblem`
74+
- `fwd.hpp`: do not include `<pinocchio/config.hpp>` header anymore
75+
- `blk-matrix.hpp`: remove protected ctors, add conversion ops
76+
- Headers `aligator/gar/*.hpp` merged into main library
77+
- Add class `DenseKernel` for the stagewise-dense Riccati algo -- rework `DenseRiccatiSolver` class
78+
- CMake: rework declaration of examples & benchmarks (applying liberal use of `cmake_parse_arguments()`)
79+
- CMake: add `bench/CMakeLists.txt` to gersemi defs, apply formatting
80+
- CMake: apply compile definitions to `aligator` target directly (reduce use of global compile definitions)
81+
- Add `LqrProblemTpl::isApprox()`
4782
- Only link against needed pinocchio libraries ([#260](https://github.com/Simple-Robotics/aligator/pull/260))
4883
- Use Pinocchio instantiated functions ([#261](https://github.com/Simple-Robotics/aligator/pull/261))
4984
- Link to pinocchio collision

CMakeLists.txt

+49-34
Original file line numberDiff line numberDiff line change
@@ -239,12 +239,12 @@ if(BUILD_WITH_PINOCCHIO_SUPPORT)
239239
"If you didn't build proxsuite-nlp yourself, please contact the maintainer for the distribution you used."
240240
)
241241
endif()
242-
add_compile_definitions(ALIGATOR_WITH_PINOCCHIO)
243-
list(APPEND CFLAGS_DEPENDENCIES "-DALIGATOR_WITH_PINOCCHIO")
244-
set(PINOCCHIO_V3 ${pinocchio_VERSION} VERSION_GREATER "3.0.0")
245-
if(PINOCCHIO_V3)
246-
add_compile_definitions(ALIGATOR_PINOCCHIO_V3)
242+
243+
if(${pinocchio_VERSION} VERSION_GREATER "3.0.0")
244+
set(PINOCCHIO_V3 TRUE)
247245
endif()
246+
247+
list(APPEND CFLAGS_DEPENDENCIES "-DALIGATOR_WITH_PINOCCHIO")
248248
elseif(PROXSUITE_NLP_WITH_PINOCCHIO_SUPPORT)
249249
message(
250250
WARNING
@@ -255,7 +255,6 @@ endif()
255255

256256
if(BUILD_CROCODDYL_COMPAT)
257257
message(STATUS "Building with Crocoddyl support.")
258-
add_compile_definitions(ALIGATOR_WITH_CROCODDYL_COMPAT)
259258
list(APPEND CFLAGS_DEPENDENCIES "-DALIGATOR_WITH_CROCODDYL_COMPAT")
260259
endif()
261260

@@ -270,7 +269,6 @@ if(BUILD_WITH_CHOLMOD_SUPPORT)
270269
STATUS
271270
"Build with CHOLMOD support (LGPL). See CHOLMOD/Doc/License.txt for further details."
272271
)
273-
add_compile_definitions(ALIGATOR_WITH_CHOLMOD)
274272
endif()
275273

276274
if(BUILD_PYTHON_INTERFACE)
@@ -285,6 +283,7 @@ if(BUILD_PYTHON_INTERFACE)
285283
set(${PYLIB_NAME}_INSTALL_DIR ${PYTHON_SITELIB}/${PROJECT_NAME})
286284
endif()
287285

286+
# Without template instantiation, library only compiles exceptions and logging.
288287
set(LIB_SOURCES src/utils/exceptions.cpp src/utils/logger.cpp)
289288

290289
file(
@@ -299,8 +298,8 @@ if(ENABLE_TEMPLATE_INSTANTIATION)
299298
GLOB_RECURSE LIB_TEMPLATE_SOURCES
300299
CONFIGURE_DEPENDS
301300
${PROJECT_SOURCE_DIR}/src/core/*.cpp
302-
${PROJECT_SOURCE_DIR}/src/solvers/fddp/*.cpp
303-
${PROJECT_SOURCE_DIR}/src/solvers/proxddp/*.cpp
301+
${PROJECT_SOURCE_DIR}/src/gar/*.cpp
302+
${PROJECT_SOURCE_DIR}/src/solvers/*.cpp
304303
${PROJECT_SOURCE_DIR}/src/modelling/*.cpp
305304
)
306305
file(
@@ -367,8 +366,6 @@ elseif(ALIGATOR_TRACY_ENABLE)
367366
endif()
368367
endif()
369368

370-
add_subdirectory(gar)
371-
372369
# Create the main shared library.
373370
function(create_library)
374371
add_library(${PROJECT_NAME} SHARED ${LIB_HEADERS} ${LIB_SOURCES})
@@ -382,7 +379,6 @@ function(create_library)
382379
)
383380
set_standard_output_directory(${PROJECT_NAME})
384381

385-
target_link_libraries(${PROJECT_NAME} PUBLIC aligator::gar)
386382
# Extract the compile definitions of the project for export
387383
get_directory_property(CURRENT_COMPILE_DEFINITIONS COMPILE_DEFINITIONS)
388384
target_compile_definitions(
@@ -395,6 +391,15 @@ function(create_library)
395391
${PROJECT_NAME}
396392
PUBLIC pinocchio::pinocchio_default pinocchio::pinocchio_collision
397393
)
394+
target_compile_definitions(${PROJECT_NAME} PUBLIC ALIGATOR_WITH_PINOCCHIO)
395+
if(PINOCCHIO_V3)
396+
target_compile_definitions(${PROJECT_NAME} PUBLIC ALIGATOR_PINOCCHIO_V3)
397+
endif()
398+
endif()
399+
400+
if(BUILD_WITH_CHOLMOD_SUPPORT)
401+
target_link_libraries(${PROJECT_NAME} PUBLIC CHOLMOD::CHOLMOD)
402+
target_compile_definitions(${PROJECT_NAME} PUBLIC ALIGATOR_WITH_CHOLMOD)
398403
endif()
399404

400405
if(BUILD_WITH_OPENMP_SUPPORT)
@@ -463,29 +468,37 @@ add_subdirectory(bindings)
463468

464469
# benchmarks, examples, and tests
465470

466-
macro(create_ex_or_bench is_bench exfile exname)
471+
macro(create_ex_or_bench exfile exname)
472+
cmake_parse_arguments(arg_ex "BENCHMARK" "" "DEPENDENCIES" ${ARGN})
473+
467474
add_executable(${exname} ${exfile})
468-
if(${is_bench})
469-
set(ex_type "bench")
475+
if(${arg_ex_BENCHMARK})
476+
set(ex_type "benchmark")
470477
else()
471478
set(ex_type "example")
472479
endif()
473-
message(STATUS "Adding cpp ${ex_type} ${exname}")
480+
message(STATUS "Adding cpp ${ex_type} ${exname} (${exfile})")
474481
set_target_properties(${exname} PROPERTIES LINKER_LANGUAGE CXX)
475482
set_standard_output_directory(${exname})
476483
target_include_directories(${exname} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
477484

478-
target_link_libraries(${exname} PUBLIC ${PROJECT_NAME})
485+
target_link_libraries(
486+
${exname}
487+
PRIVATE ${PROJECT_NAME} ${arg_ex_DEPENDENCIES}
488+
)
489+
if(${arg_ex_BENCHMARK})
490+
target_link_libraries(${exname} PRIVATE benchmark::benchmark)
491+
endif()
492+
if(DEFINED arg_ex_DEPENDENCIES)
493+
message(" Dependencies:")
494+
foreach(_dep ${arg_ex_DEPENDENCIES})
495+
message(" ${_dep}")
496+
endforeach()
497+
endif()
479498
endmacro()
480499

481500
if(BUILD_WITH_PINOCCHIO_SUPPORT AND (BUILD_EXAMPLES OR BUILD_BENCHMARKS))
482501
ADD_PROJECT_PRIVATE_DEPENDENCY(example-robot-data 4.0.9 REQUIRED)
483-
macro(target_add_example_robot_data target_name)
484-
target_link_libraries(
485-
${target_name}
486-
PRIVATE example-robot-data::example-robot-data
487-
)
488-
endmacro()
489502
endif()
490503

491504
# create an utility library to avoid recompiling crocoddyl talos arm problem
@@ -503,10 +516,13 @@ if(BUILD_CROCODDYL_COMPAT AND (BUILD_EXAMPLES OR BUILD_BENCHMARKS))
503516
)
504517
target_link_libraries(
505518
croc_talos_arm_utils
506-
PUBLIC ${PROJECT_NAME} Boost::boost crocoddyl::crocoddyl
519+
PUBLIC
520+
${PROJECT_NAME}
521+
Boost::boost
522+
crocoddyl::crocoddyl
523+
example-robot-data::example-robot-data
507524
)
508525
set_standard_output_directory(croc_talos_arm_utils)
509-
target_add_example_robot_data(croc_talos_arm_utils)
510526
endif()
511527

512528
if(BUILD_BENCHMARKS OR BUILD_TESTING)
@@ -515,7 +531,7 @@ if(BUILD_BENCHMARKS OR BUILD_TESTING)
515531
STATIC
516532
${PROJECT_SOURCE_DIR}/tests/gar/test_util.cpp
517533
)
518-
target_link_libraries(gar_test_utils PRIVATE aligator::gar)
534+
target_link_libraries(gar_test_utils PRIVATE ${PROJECT_NAME})
519535
set_standard_output_directory(gar_test_utils)
520536
endif()
521537

@@ -531,14 +547,13 @@ if(PINOCCHIO_V3 AND (BUILD_EXAMPLES OR BUILD_BENCHMARKS))
531547
PUBLIC ${PROJECT_SOURCE_DIR}/examples
532548
)
533549
set_standard_output_directory(talos_walk_utils)
534-
target_link_libraries(talos_walk_utils PUBLIC ${PROJECT_NAME})
535-
target_add_example_robot_data(talos_walk_utils)
536-
function(target_add_talos_walk target)
537-
target_link_libraries(
538-
${target}
539-
PRIVATE talos_walk_utils pinocchio::pinocchio_parsers
540-
)
541-
endfunction()
550+
target_link_libraries(
551+
talos_walk_utils
552+
PUBLIC
553+
${PROJECT_NAME}
554+
pinocchio::pinocchio_parsers
555+
example-robot-data::example-robot-data
556+
)
542557
endif()
543558

544559
if(BUILD_EXAMPLES)

bench/CMakeLists.txt

+20-32
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,35 @@
33
#
44

55
# Create a benchmark
6-
function(create_bench exfile croc)
7-
get_filename_component(exname ${exfile} NAME_WE)
8-
set(exname "bench-${exname}")
9-
create_ex_or_bench(TRUE ${exfile} ${exname})
6+
function(create_bench exfile)
7+
cmake_parse_arguments(arg_ex "CROC" "" "DEPENDENCIES" ${ARGN})
8+
set(dependencies ${arg_ex_DEPENDENCIES})
109

11-
target_include_directories(${exname} PRIVATE ../examples)
12-
target_link_libraries(${exname} PRIVATE benchmark::benchmark)
13-
if(croc)
14-
target_link_libraries(
15-
${exname}
16-
PRIVATE aligator::croc_compat croc_talos_arm_utils
17-
)
10+
get_filename_component(_exname ${exfile} NAME_WE)
11+
set(_exname "bench-${_exname}")
12+
if(${arg_ex_CROC})
13+
list(APPEND dependencies aligator::croc_compat croc_talos_arm_utils)
1814
endif()
15+
create_ex_or_bench(
16+
${exfile}
17+
${_exname}
18+
BENCHMARK
19+
DEPENDENCIES ${dependencies}
20+
)
21+
target_include_directories(${_exname} PRIVATE ../examples)
1922
endfunction()
2023

2124
function(create_gar_bench exfile)
22-
get_filename_component(exname ${exfile} NAME_WE)
23-
set(exname "bench-${exname}")
24-
add_executable(${exname} ${exfile})
25-
message(STATUS "Adding cpp bench ${exname}")
26-
set_target_properties(${exname} PROPERTIES LINKER_LANGUAGE CXX)
27-
set_standard_output_directory(${exname})
28-
target_include_directories(${exname} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
29-
30-
target_link_libraries(
31-
${exname}
32-
PRIVATE aligator::gar benchmark::benchmark gar_test_utils
33-
)
25+
create_bench(${exfile} DEPENDENCIES gar_test_utils)
3426
endfunction()
3527

36-
create_bench("lqr.cpp" FALSE)
37-
create_bench("se2-car.cpp" FALSE)
28+
create_bench(lqr.cpp)
29+
create_bench(se2-car.cpp)
3830
if(BUILD_CROCODDYL_COMPAT)
39-
create_bench("croc-talos-arm.cpp" TRUE)
40-
target_add_example_robot_data(bench-croc-talos-arm)
31+
create_bench(croc-talos-arm.cpp CROC)
4132
endif()
4233
if(PINOCCHIO_V3)
43-
create_bench("talos-walk.cpp" FALSE)
44-
target_add_example_robot_data(bench-talos-walk)
45-
target_add_talos_walk(bench-talos-walk)
34+
create_bench(talos-walk.cpp DEPENDENCIES talos_walk_utils)
4635
endif()
4736

48-
create_gar_bench("gar-riccati.cpp")
49-
create_gar_bench("gar-impl-multithread.cpp")
37+
create_gar_bench(gar-riccati.cpp)

bench/gar-impl-multithread.cpp

-37
This file was deleted.

bindings/python/src/expose-callbacks.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// @copyright Copyright (C) 2022-2023 LAAS-CNRS, INRIA
22
#include "aligator/python/callbacks.hpp"
3-
#include "aligator/helpers/history-callback.hpp"
3+
#include "aligator/core/history-callback.hpp"
44

55
#include "aligator/solvers/proxddp/solver-proxddp.hpp"
66
#include "aligator/solvers/fddp/solver-fddp.hpp"

bindings/python/src/expose-solvers-base.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#include "aligator/python/fwd.hpp"
22
#include "aligator/python/visitors.hpp"
33

4-
#include "aligator/solvers/proxddp/results.hpp"
5-
#include "aligator/core/workspace-base.hpp"
4+
#include "aligator/solvers/results-base.hpp"
5+
#include "aligator/solvers/workspace-base.hpp"
66

77
namespace aligator {
88
namespace python {

bindings/python/src/gar/expose-gar.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ void exposeGAR() {
5959
exposeBlockMatrices();
6060

6161
bp::class_<knot_t>("LqrKnot", bp::no_init)
62-
.def(bp::init<uint, uint, uint>(("nx"_a, "nu", "nc")))
63-
.def(bp::init<uint, uint, uint, uint>(("nx"_a, "nu", "nc", "nx2")))
62+
.def(bp::init<uint, uint, uint>(("self"_a, "nx", "nu", "nc")))
63+
.def(bp::init<uint, uint, uint, uint, uint>(
64+
("self"_a, "nx"_a, "nu", "nc", "nx2", "nth"_a = 0)))
6465
.def_readonly("nx", &knot_t::nx)
6566
.def_readonly("nu", &knot_t::nu)
6667
.def_readonly("nc", &knot_t::nc)
@@ -95,7 +96,7 @@ void exposeGAR() {
9596

9697
StdVectorPythonVisitor<knot_vec_t, false>::expose("StdVec_LqrKnot");
9798

98-
bp::class_<lqr_t>("LqrProblem", bp::no_init)
99+
bp::class_<lqr_t, boost::noncopyable>("LqrProblem", bp::no_init)
99100
.def(bp::init<const knot_vec_t &, long>(("self"_a, "stages", "nc0")))
100101
.def_readwrite("stages", &lqr_t::stages)
101102
.add_property("horizon", &lqr_t::horizon)
@@ -110,8 +111,7 @@ void exposeGAR() {
110111
.add_property("ntheta", &lqr_t::ntheta)
111112
.def("evaluate", &lqr_t::evaluate,
112113
("self"_a, "xs", "us", "theta"_a = std::nullopt),
113-
"Evaluate the problem objective.")
114-
.def(CopyableVisitor<lqr_t>());
114+
"Evaluate the problem objective.");
115115

116116
bp::class_<riccati_base_t, boost::noncopyable>("RiccatiSolverBase",
117117
bp::no_init)

0 commit comments

Comments
 (0)