Pythran: Enabling Static Optimization of Scientific Python Programs

Authors: Serge Guelton, ENS; Pierrick Brunet, Télécom Bretagne; Alan Raynaud, Télécom Bretagne; Adrien Merlini, Télécom Bretagne; Mehdi Amini, SILKAN

Track: General



Pythran is a young open source static compiler that turns Python modules into native ones. Based on the fact that scientific modules do not rely much on the dynamic features of the language, it trades them against powerful, eventually inter procedural, optimizations, such as:

In addition to these compilation steps, Pythran provides a C++ runtime that leverages on the C++ STL for generic containers, and the Numeric Template Toolbox (nt2) for numpy support. It takes advantage of modern C++11 features such as variadic templates, type inference, move semantics and perfect forwarding, as well as classical ones such as expression templates.

The input code remains compatible with the Python interpreter, and output code is generally as efficient as the annotated Cython equivalent, if not more, without the backward compatibility loss. Numpy expressions runs as fast as if compiled with numexpr, without change on the original code.