[Numpy-discussion] matlab vs. python question

Gael Varoquaux gael.varoquaux@normalesup....
Thu Apr 26 08:16:33 CDT 2007


On Thu, Apr 26, 2007 at 12:06:56PM +0200, Zdeněk Hurák wrote:
> But what makes Matlab difficult to be replaced is that lots of other
> projects (commercial: Mathematica, Maple, ... and free: octave, maxima,
> scipy, ...) only offer computation and visualization, while engineers in my
> field also need INTERACTION OF THE SYSTEM WITH EXTERNAL WORLD. That is,
> compatibility with a real-time operating system and MOST available
> input-output (AD-DA) cards. Being able to acquire measurement data from an
> external industrial system, process them computationally (for instance,
> solving some Riccati matrix differential equations), visualize the data and
> put the computed results back to the real system, this is what we need.

I am very surprised that you think Matlab is more suited for such a task.
I have had the opposite experience. 

I work in an experimental lab where we do rather heavy experimental
physics (Bose Einstein condensation). I am building an experiment from
scratch and had to build a control framework for the experiment. It is
fully automated and with need some reasonably sophisticated logics to
scan parameters, do on the fly processing of the data, store it on the
disk, display all this in a useful interface for the user, and feed all
this back to the experiment.

Due to legacy reasons I built the software in Matlab. It was a bad
experience. 

First of all linking to C libraries to control hardware is really a pain.
Writing Mex files is not that much fun and the memory management of
MatLab is flawed. I have had segfaults for no obvious reasons, and the
problems where neither in my code nor in the drivers (I worked with the
engineer who wrote the driver to diagnose this). Matlab is single
threaded so all your calls to the hardware are blocking (unless you are
willing to add threads in you mex file, but this is very dangerous as you
are playing with a loop-hole in matlab's mex loader which keeps the mex
in the memory after it is executed). Finally the lack of proper object
oriented programming and separated namespaces make it hard to write good
code to control instruments.

The lack of object oriented programming, passing by reference, threads,
and proper control of the GUI event-loop also makes it very hard to write
a complex interactive GUI.

Python provides all this. What it does not provide are pre-linked
libraries to control hardware, but if you are trying to control exotic
hardware, all you have is a C or C++ SDK. It is even worse when the
hardware is homemade, as you have to write the library yourself, and
trust me, I'd much better write a hardware control library that speak to
my custom made electronic over a bus in Python than in Matlab (GPIB,
ethernet, serial, Python has bindings for all that).

I have had a second choice to build the computer control framework of a
similar experiment. I took my chance to build it in Python (it was a
different lab, and I was replacing an existing C software that had become
impossible to maintain). I never regretted it. Python has really been
very good at it due to all the different libraries available, the ease to
link to C, and the possibility to do proper OOP.

I have written an article about this, that I submitted a month ago to CiSE.
I have no news from them. The article is very poorly written (I had no
hindsight about these matters when I started writing it, submitted it
because I was tired to see it dragging along, and now I wish I had
reworked it a bit), but I think I raise some points about what you need
to build a control framework for an experiment, and how python can
address those needs.

Anyway, IANAL, and I am not to sure if releasing a preprint on a mailing
list renders the article ineligible for CiSE or not but I just put a
version on
http://gael-varoquaux.info/computers/agile_computer_control_of_an_experiment.pdf
. I hope it can help understanding what is needed to control an
experiment from Python, what can be improved, and what already exists and
is so incredibly useful.

I am interested in comments. Keep in mind that I am working in a field
where nobody is interested in computing and I sure could use some advice.
I have written quite a few softwares to control experiments in different
labs with different languages, and I think I have acquired some
experience, and made a lot of progress, but I also have had to reinvent
the wheel more than once. We all know that good software engineering
books or article readable by some one who nows little about computing are
hard to find. Let us address this issue !

Gaël


More information about the Numpy-discussion mailing list