Control Libraries for Python: A bleak situation (fortunately with a workardound)

matthias on 2012/12/15

In a continuation of my recent work on verification of control systems, I now want to integrate the model checker and the controller design more closely.

I have therefore started a parametrized Python tool that creates the input files for the model checking tool SAL.

To integrate this with the controller design, I would have liked to have an easy integration with Riccati equation solvers (if not lqr/dlqr frontends as in MATLAB) and SDP optimization routines that solve linear matrix inequalities.

The most promising library I found was Murray’s Control Systems Library for Python

It relies on scipy and uses slycot in the background. Unfortunately, the Riccati equation solver that was implemented there did not prove reliable once I subjected it to some random tests.

I then saw that scipy itself is planning a Riccati equation solver in its upcoming release v.011:

Scipy v0.11 Docu (DRAFT)

I encountered the same trouble there when I ran tests.

I filed a bug report, but the behavior I observed is apparently an algorithm problem and not just a minor bug that is easy to be fixed, so I guess we’ll have to wait on that end.

Now finally, let’s discuss the options that do work.

For the Riccati equation, I finally managed to call Octave from Python using oct2py (I used easy_install).

There were minor issues at first as well, but the package author was very helpful in resolving them!

I also tried the comparable MATLAB implementations such as mlabwrap, but they posed way more trouble than oct2py - leave alone the fact that I couldn’t do work at home anymore if I required MATLAB.

Finally, as an LMI solver, I finally settled with Vandenberghe’s cvxopt.

I installed it using

apt-get install python-cxvopt

Pulling out the individual matrices from my LMI formulation and transforming them to cvxopt’s formulation in sdp seemed hard at first, but it’s actually quite simple once you figure out that the standard LMI formulation (as on wikipedia)

\[ F_1 x_1 + \ldots + F_n x_n \leq F_0 \]

corresponds to base matrices, such as

\[ X_1 = \begin{bmatrix} 1 & 0 & 0 \\ 0 & 0 & 0 \\ 0 & 0 & 0\end{bmatrix} \]

From there, you only need to flatten the standard formulation’s matrices and combine them to get cvxopt’s format. And boom, there you have your LMI solver ready to go.