Tag Archives: python

Aug
30
2011

Growing crystals in Python

Diffusion-Limited AggregationAs part of my preparation for my PhD, I’ve decided to have a look at other programming languages, partially just out of curiosity, but also partly due to the frustrating length of time it seems to take to get code up and running in Java/C++. Python is often mentioned as suitable scientific programming language so I decided to dive straight in. I’ve only been using it for about a week and already I’ve been very impressed with the speed with which I can get prototypes up and running. Coding in python seems more eloquent, concise, almost like writing pseudo-code at times. The community encourages writing “pythonic” code where the finding simplest, cleanest (and often fastest) method is highly valued.

So to test out the new language I decided to have a go at implementing a basic lattice-based Diffusion-Limited Aggregation model. The basic idea is set off a series of random walkers around a central “seed” – if they come into contact with the seed they stick to it and a new walker is released. The colors in the above diagram show how new that part of the crystal is (hotter – new, colder – old). The code is available over at github; the curious should also have a look at the faster version rewritten in the NumPy numerical library.

Mar
02
2011

Scipy Weave: Compilation Error

New users of the python library Scipy may be having difficulty using the weave library which allows on the fly C++ compilation of python code. While trying to get this to work on Ubuntu, I was prompted with the following error:

scipy.weave.build_tools.CompileError: error: Command "g++ ..." failed with exit status 1

To fix this, I realised that I didn’t have the python header files required (specifically Python.h). These can easily be installed on ubuntu by installing the python dev package:

sudo apt-get install python-dev