Blog

We offer the articles below in the hope that they will be useful, but we cannot accept liability for any problems caused by the instructions that they contain. If you have a problem, question or feedback relating to one of our articles, please post a comment so that other readers can benefit. We regularly review comments and reply or update the articles, to ensure their continued usefulness. All articles are provided free, without any advertising or tracking, for the benefit of the technical community.

If you require paid commercial support, please contact us for assistance.

Compiling mixed Sage and Python code with Cython

At the moment I’m working on some maths code written in a combination of standard Python and its mathematical superset, Sage. The code is fairly computationally expensive (it’s essentially a brute force search for chemical reaction networks that are monotone). Consequently, after getting the code working as a proof-of-concept, I wanted to compile it to C using Cython to get a bit more speed out of it. I found the documentation on converting Sage and Python scripts to Cython a bit vague, particularly when it comes to combining the two, so this article gives step by step instructions based on my findings.