PythonLinearNonLinearControl is a library implementing the linear and nonlinear control theories in python.





GitHub Stars



Last Commit

1mo ago







MIT License



Coverage Status GitHub issues open Build Status


PythonLinearNonlinearControl is a library implementing the linear and nonlinear control theories in python. Due to use only basic libralies (scipy, numpy), this library is easy to extend for your own situations.


AlgorithmUse Linear ModelUse Nonlinear ModelNeed Gradient (Hamiltonian)Need Gradient (Model)Need Hessian (Model)
Linear Model Predictive Control (MPC)xxxx
Cross Entropy Method (CEM)xxx
Model Predictive Path Integral Control of Nagabandi, A. (MPPI)xxx
Model Predictive Path Integral Control of Williams, G. (MPPIWilliams)xxx
Random Shooting Method (Random)xxx
Iterative LQR (iLQR)xxx
Differential Dynamic Programming (DDP)xx
Unconstrained Nonlinear Model Predictive Control (NMPC)xxx
Constrained Nonlinear Model Predictive Control CGMRES (NMPC-CGMRES)xxx
Constrained Nonlinear Model Predictive Control Newton (NMPC-Newton)xxxx

"Need Gradient" means that you have to implement the gradient of the model or the gradient of hamiltonian.

Following algorithms are implemented in PythonLinearNonlinearControl


There are 4 example environments, "FirstOrderLag", "TwoWheeledConst", "TwoWheeledTrack" and "Cartpole".

NameLinearNonlinearState SizeInput size
First Order Lag Systemx42
Two wheeled System (Constant Goal)x32
Two wheeled System (Moving Goal)x32
Cartpole (Swing up)x41
Nonlinear Sample System Envx21

All states and inputs of environments are continuous. It should be noted that the algorithms for linear model could be applied to nonlinear enviroments if you have linealized the model of nonlinear environments.

You could know abount our environmets more in


To install this package

$ pip install PythonLinearNonlinearControl

When developing the package

$ python develop


$ pip install -e .

Basic concepts

When we design control systems, we should have Model, Planner, Controller and Runner as shown in the figure. It should be noted that Model and Environment are different. As mentioned before, we the algorithms for linear model could be applied to nonlinear enviroments if you have linealized model of nonlinear environments. In addition, you can use Neural Network or any non-linear functions to the model, although this library can not deal with it now.


System model. For an instance, in the case that a model is linear, this model should have a form, "x[k+1] = Ax[k] + Bu[k]".

If you use gradient based control method, you are preferred to implement the gradients of the model, other wise the controllers use numeric gradients.


Planner make the goal states.


Controller calculate the optimal inputs by using the model by using the algorithms.


Runner runs the simulation.

Please, see more detail in each scripts.

Getting started

QuickStart Guide

This is a quickstart guide for users who just want to try PythonLinearNonlinearControl. If you have not installed PythonLinearNonLinearControl, please see the section of "how to setup" in

When we design control systems, we should have Environment, Model, Planner, Controller and Runner. Therefore your script contains those Modules.

First, import each Modules from PythonLinearNonlinearControl.

from PythonLinearNonlinearControl import configs 
from PythonLinearNonlinearControl import envs
from PythonLinearNonlinearControl import models
from PythonLinearNonlinearControl import planners
from PythonLinearNonlinearControl import controllers
from PythonLinearNonlinearControl import runners

Configs contains each modules configurations such as cost functions, prediction length, ...etc.

Then you can make each module. (This is example about CEM and CartPole env)

config = configs.CartPoleConfigModule()
env = envs.CartPoleEnv()
model = models.CartPoleModel(config)
controller = controllers.CEM(config, model)
planner = planners.ConstantPlanner(config)
runner = runners.ExpRunner()

The preparation for experiment has done! Please run the runner.

history_x, history_u, history_g =, controller, planner) 

You can get the results of history of state, history of input and history of goal. Use that histories to visualize the Animation or Figures. (Note FirstOrderEnv does not support animation)

# plot results
plot_results(history_x, history_u, history_g=history_g)
save_plot_data(history_x, history_u, history_g=history_g)

# create animation
animator = Animator(env)
animator.draw(history_x, history_g)

It should be noted that the controller parameters like Q, R and Sf strongly affect the performence of the controller. Please, check these parameters before you run the simulation.

Run Example Script

You can run the example script as follows:

python scripts/ --env CartPole --controller CEM --save_anim 1

figures and animations are saved in the ./result folder.

Old version

If you are interested in the old version of this library, that was not a library just examples, please see v1.0


Coming soon !!


  • numpy
  • scipy
  • matplotlib (for figures and animations)
  • ffmpeg (for animations)


PythonLinearNonlinearControl is licensed under the MIT License. However, some scripts are available under different license terms. See below.

The following parts are licensed under GPL3+:

See the licenses folder for the full text of the licenses.


author = {Shunichi Sekiguchi},
title = {PythonLinearNonlinearControl},
note = "\url{}",

Rate & Review

Great Documentation0
Easy to Use0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Unwelcoming Community0