Introduction

The different siconos libraries may be imported as python modules. To import all Siconos modules, one may write for example:

The python bindings for siconos try to be as close as possible to the C and C++ API of the different libraries, but some discrepancies exist. These are explained in the sequel of this introduction.

Dense matrices and vectors

Standard python sequences as well as numpy arrays and matrices may be used as input for matrices and vectors in the C and C++ API. For example, with numerics module a linear complementarity problem :

with

and

may be declared like this:

In this python declaration, the M matrix of the linear complementary problem is:

It is a simple python list of list of float numbers where the rows of the matrix are the inner lists.

The q vector of the linear complementary problem is:

It is a python list of float numbers.

numpy arrays may also be used in inputs:

This is important: where the parameter is an input as well as an output parameter, numpy array must be used!

With the kernel and mechanics modules every SimpleMatrix and SiconosVector may be replaced by python standard sequences or numpy arrays. For example, we can build a Lagrangian dynamical system with 3 degrees of freedom like this:

It is possible to use SimpleMatrix and SiconosVector arguments:

Please note that kernel.SimpleMatrix and kernel.SiconosVector objects cannot be used as arguments to numerics module functions. The instantiation of previous numerics.LCP can only be done with standard python sequences or numpy arrays.

Sparse matrices

Scipy sparse matrices must be used in input where cs_sparse is needed in the C API.

Here is for example the conversion from a sparse compressed column matrix into a sparse block matrix with blocks of 3 rows and 3 columns:

Omitted parameters

This concerns the C API of the numerics library:

  1. Where the size of an input vector may be inferred, the size must not be given in the arguments list.
  2. Output only parameters given in the argument list in the C API are python return parameters

Here is an example that shows both cases:

C++ Visitors

Siconos C++ visitors are not binded. The class of a returned object on the python side is always the true class and never a more general class, so the visitor pattern is not relevant here:

Shared pointers

For Siconos C++ libraries (kernel, io, mechanics, control) the shared pointer mechanisms is totally hidden and the namespaces SP, SPC, SPA are not present in the Python modules.

Other differences specific to Siconos Libraries are documented in relevant sections.