Computational Science Stack Exchange is a question and answer site for scientists using computers to solve scientific problems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm looking for a decent implementation of Gillespie's Direct Method in Python, as if I code the algorithm myself I'm nigh positive I'll do it inefficiently.

Anyone have a favorite?

share|improve this question
up vote 4 down vote accepted

(Disclaimer: I haven't used any of the packages or code below.)

Finding any implementation of Gillespie's method in Python was a bit of a challenge; the most fruitful search terms seemed to be "tau leap" or "kinetic Monte Carlo." This blog post implements Gillespie's algorithm, though it's not clear that it's efficient. One of the commenters mentions some other Gillespie/SSA algorithm implementations in Python that solve problems out of a textbook; the relevant problems are 6.3 through 6.6 on this website.

The most promising implementations in Python that I found were StochPy and Python language bindings to COPASI. I also found what looked like promising C++ codes in SPPARKS, STOCKS, and StochKit; they're not Python, but maybe you can wrap around one of them in Python if it looks particularly promising to you.

share|improve this answer

I would warmly recommend to use StochKit, which is really extremely reliable and efficient. It implements the Gillespie's direct method as well as its most popular optimized variants. Furthermore, it has a built-in mechanism for selecting the appropriate simulation scheme depending on your network.

However, it is written in C++. If you really need to integrate it with a Python, that shouldn't be a problem. I use it extensively in MATLAB scripts (basically, MATLAB writes a descriptor of the simulation, calls StochKit, and finally performs the data analysis). I'm sure you could do pretty much the same thing with NumPy or SciPy.

share|improve this answer

As you may already know if you're asking this question, Gillespie's method is often used in computational systems biology. There are a number of software system that provide implementations; you may want to browse the SBML Software Guide to find some of them (specifically, the ones that are known to support SBML, something that I realize may not be relevant to your needs). However, Geoff Oxberry is correct that Python-based implementations of Gillespie's algorithms seem to be uncommon compared to C++ and Java implementations. In addition to StochPy, I'm aware of the following Python-based packages (in alphabetical order):

If, in your application, you can use software that's coded in something other than Python but can be wrapped with a Python interface, then there is

  • Cain — the core is C++, but it includes a Python-based interface
  • COPASI language bindings
  • several more options as mentioned by Geoff Oxberry in his reply on this page

Finally, if you don't need your simulation to be run locally and can instead use web services, then there are the following options:

  • (the simulation service is currently off-line, but will return) SBW
  • ByoDyn's online services (see link above)

These lists are still incomplete, but hopefully they will help.

share|improve this answer

As part of the lab the developed and maintains StochKit. I am happy to hear that it is highly recommended in the previous answers. However, I wanted to update everyone. There already is a python wrapper for StochKit: GillesPy.

I would also recommend you checkout StochSS, This is an fully functional modeling and simulation IDE that uses StochKit and as one of it's simulations engines. It also includes spatial simulation with the python package PyURDME. Model building, and 3D visualization tools (plus cloud computing integration).

share|improve this answer
@hardmath, thanks for the correction! – briandrawert Mar 20 at 22:39

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.