Integrate learning-based Python models into acados for real-time model predictive control.
-
Define your
AcadosOcp, including the nominal dynamics modelfrom acados_template import AcadosOcp ocp = AcadosOcp() # ...
-
Define the residual model using the
L4acadosResidualModel(here as a PyTorchResidualModel example):import l4acados as l4a residual_model = l4a.PyTorchResidualModel(your_pytorch_model)
Other models can be straightforwardly implemented using as a
ResidualModelinstance; see here for already available residual models. -
Generate the
L4acadossolver objectl4acados_solver = l4a.ResidualLearningMPC( ocp=ocp, residual_model=residual_model, use_cython=True, # accelerate get/set operations by using the acados Cython interface )
-
Done! The
ResidualLearningMPCobject can be interfaced like theAcadosOcpSolver:l4acados_solver.set(...)l4acados_solver.solve()l4acados_solver.get(...)
Not all solver interface functions are mapped by the
ResidualLearningMPC. You can still access the underlyingAcadosOcpSolverobject through thel4acados_solver.ocp_solverproperty. Besides the dynamics model and parameter definition, thel4acados_solver.ocp_solveris equivalent to theacados_solver.ocp_solvergenerated from the originalocp.
- Install
acadosand its Python interface.
Install L4acados with optional dependencies of your choice
pip install -e .[<optional-dependencies>]Available options:
- (without optional dependencies): Basic ResidualLearningMPC for custom implementations (e.g. Jacobian approximations, finite-difference approximations for e.g. models without sensitivity information)
[pytorch]: PyTorch models.[gpytorch]: GPyTorch models.[gpytorch-exo]: GpyTorch models with online-learning improvements.- not supported yet: JAX, TensorFlow
Consider the
Dockerfilefor a full example installation including all test and development dependencies.
If you would like to contribute features to L4acados, please follow the development installation instructions below to set up your working environment.
-
Install
L4CasADi(for tests). -
Install
L4acadoswith development dependencies (in addition to the used learning framework, see above):pip install -e .[dev,gpytorch-exo]
-
Sync notebooks with jupytext:
jupytext --set-formats ipynb,py examples/*/*.ipynb
-
Add pre-commit hooks
pre-commit install
-
Run tests
pytest --ignore external/
Consider the
Dockerfilefor a full example installation including all test and development dependencies.
If you use this software, please cite our corresponding articles as written below.
@online{lahr_l4acados_2024,
title = {L4acados: {{Learning-based}} Models for Acados, Applied to {{Gaussian}} Process-Based Predictive Control},
shorttitle = {L4acados},
author = {Lahr, Amon and Näf, Joshua and Wabersich, Kim P. and Frey, Jonathan and Siehl, Pascal and Carron, Andrea and Diehl, Moritz and Zeilinger, Melanie N.},
date = {2024-11-28},
eprint = {2411.19258},
eprinttype = {arXiv},
doi = {10.48550/arXiv.2411.19258},
pubstate = {prepublished}
}
@article{lahr_zero-order_2023,
title = {Zero-Order optimization for {{Gaussian}} process-based model predictive control},
author = {Lahr, Amon and Zanelli, Andrea and Carron, Andrea and Zeilinger, Melanie N.},
year = {2023},
journal = {European Journal of Control},
pages = {100862},
issn = {0947-3580},
doi = {10.1016/j.ejcon.2023.100862}
}