RepositoryPythonJPJapan
ohtsukalab

ohtsukalab/autogenu-jupyter

An automatic code generator for nonlinear model predictive control (NMPC) and the continuation/GMRES method (C/GMRES) based numerical solvers for NMPC

179stars
38forks
1issues
1views

Featured achievements

The project's latest awards

1
TINIX TRENDING·Topic: nonlinear-model-predictive-control

#1 Repository of the month

1
TINIX TRENDING·Topic: c-gmres

#1 Repository of the month

1
TINIX TRENDING·Topic: code-generator

#1 Repository of the month

AutoGenU for Jupyter

build doxygen

Introduction

This project provides the continuation/GMRES method (C/GMRES method) based solvers for nonlinear model predictive control (NMPC) and an automatic code generator for NMPC, called AutoGenU.

The following C/GMRES based solvers are provided:

  • MultipleShootingCGMRESSolver : The multiple shooting based C/GMRES method with condensing of the state and costate directions.
  • SingleShootingCGMRESSolver : The original C/GMRES method (single shooting).

Requirement

  • C++17 (MinGW or MSYS and PATH to either are required for Windows users)
  • CMake, git
  • Python 3.8 or later, Jupyter Lab or Jupyter Notebook, SymPy, NumPy, and collection (to generate ocp.hpp, main.cpp, and CMakeLists.txt by AutoGenU.ipynb)
  • Matplotlib, seaborn (to plot simulation data on AutoGenU.ipynb)
  • ffmpeg (to generate animations in the example notebooks)
  • Doxygen (optional, to generate C++ docs)

Usage

1. Setup requirements

Please confirm that you clone this repository as

git clone https://github.com/ohtsukalab/autogenu-jupyter --recursive

Otherwise, please do the following command:

git submodule update --init --recursive

The python modules can be installed via

python3 -m pip install -r requirements.txt

2. Code generation

AutoGenU.ipynb generates the following source files under your setting state equation, constraints, cost function, and parameters:

  • ocp.hpp : A definition of the optimal control problem (OCP).
  • main.cpp : An executablb of the closed-loop simulation.
  • CMakeLists.txt : Scripts to build C++ projects.
  • Files in python directory : Source files of Python interface via pybind11.

You can generate these files, run simulations, plot results, and install the Python interfaces through AutoGenU.ipynb.

3. Python bindings

Python bindings are installed via .ipynb files. To use the installed Python bindings, set PYTHONPATH as

export PYTHONPATH=$PYTHONPATH:$DESTINATION/lib/python3.x/site-packages

Then you can use python interfaces as

import cgmres.common # this includes horizon, solver settings, etc.
import cgmres.your_ocp_name # this includes OCP definition and NMPC solvers 

4. Install header-only cgmres C++ library

Aside from the notebook for the code-generation, the C++ cgmres library, which is a header-only library, can be installed by running

mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=YOUR_INSTALL_DESTINATION
make install 

at the project root directory of autogenu-jupyter.
Then you can build the NMPC code with the generated ocp.hpp file and without .ipynb notebook files.
The examples are found in examples/cpp directory.

5. Install autogenu Python module

The pythton module autogenu can be instatlled by running

python3 -m pip install setuptools
python3 -m pip install .

at the project root directory of autogenu-jupyter. Further, if you install have installed header-only cgmres C++ library as step 4, then you can run .ipynb files for the code generation in everywhere.

Documentation

C++ API documentation of cgmres library is found at https://ohtsukalab.github.io/autogenu-jupyter/.
Python interfaces are almost the same as the C++ API, so please refere to https://ohtsukalab.github.io/autogenu-jupyter/ even for Python interfaces as well as the tips for conversions between C++ and Python.

Demos

Demos are presented in cartpole.ipynb, pendubot.ipynb, hexacopter.ipynb, and mobilerobot.ipynb. You can obtain the following simulation results jusy by runnig these .ipynb files. The details of the each OCP formulations are described in each .ipynb files.

 

License

MIT

Citing autogenu-jupyter

We'd appriciate if you use cite the following conference paper:

@inproceedings{katayama2020autogenu,
  title={Automatic code generation tool for nonlinear model predictive control with {J}upyter},
  author={Sotaro Katayama and Toshiyuki Ohtsuka},
  booktitle={{The 21st IFAC World Congress 2020}},
  pages={7033-7040},
  year={2020}}

References

  1. T. Ohtsuka A continuation/GMRES method for fast computation of nonlinear receding horizon control, Automatica, Vol. 40, No. 4, pp. 563-574 (2004)
  2. C. T. Kelly, Iterative methods for linear and nonlinear equations, Frontiers in Apllied Mathematics, SIAM (1995)
  3. Y. Shimizu, T. Ohtsuka, M. Diehl, A real‐time algorithm for nonlinear receding horizon control using multiple shooting and continuation/Krylov method, International Journal of Robust and Nonlinear Control, Vol. 19, No. 8, pp. 919-936 (2008)

Similar Projects

Discover other similar projects and AI models.

RepositoryPython
elijah-waichong-chan/go2-convex-mpc

A convex MPC locomotion controller implemented in MuJoCo with Unitree Go2 quadruped

140
Apr 17, 2026
RepositoryPython
bzarr/TUM-CONTROL

A modular and scalable simulation framework for ultra-rapid prototyping of self-adaptive, stochastic and robust Nonlinear Model Predictive Control for Autonomous Vehicle Motion Control

84
Jul 23, 2026
RepositoryJava
javaparser/javaparser

Java 1-25 Parser and Abstract Syntax Tree for Java with advanced analysis functionalities.

6.2k
Dec 2, 2026
RepositoryGo
dave/jennifer

Jennifer is a code generator for Go

3.6k
Oct 7, 2026
RepositoryC++
google-deepmind/mujoco_mpc

Real-time behaviour synthesis with MuJoCo, using Predictive Control

1.8k
Dec 1, 2026
RepositoryC++
google-deepmind/mujoco_mpc

Real-time behaviour synthesis with MuJoCo, using Predictive Control

1.8k
Dec 1, 2026
RepositoryMATLAB
junhengl/Cart_Pole_Simulink

Optimal Control Strategies on Cart-pole System in Simscape Multibody Simulation

168
Jul 23, 2023
RepositoryC++
DhruvaKumar/model-predictive-control

MPC in vehicle to track reference trajectory

148
Apr 22, 2018
RepositoryPython
microsoft/markitdown

Python tool for converting files and office documents to Markdown.

199.6k
Dec 3, 2026