Stockholm university logo, link to start page

Commentary in Nature Astronomy on the use of Python

In a commentary and reply paper in Nature Astronomy, French and German researchers P. Augier, C. F. Bolz-Tereick, S. Guelton, and SU Dept of Meteorology researcher Ashwin Mohanan defend the use of Python in scientific codes.

Augier et al. (2021) acknowledge that ecological impact of computing is an important problem, but object to criticism drawn against use of Python in a comment by Portegies Zwart in Nature Astronomy who estimated CO2 production in a benchmark N-body problem implemented in various programming languages. According to Zwart, the algorithm required an lengthy "loop" with the order of N^2 operations where Python performed poorly. Therefore, the author suggested to avoid Python in scientific codes.

In order to prove their point, Augier et al. (2021) chose to do a few things differently:

  1. Use optimized compilers along with minimal change to the same Python benchmark code. This leads to remarkable improvement in performance, comparable to FORTRAN and C++.
  2. Include an implementation in Julia, which also performs well.
  3. Use super-computing clusters equipped with wattmeters to accurately measure the energy consumption. We see that use of parallelism does not severely increase CO2 production; rather a mild decrease was observed due to reduced time to solution.
Graph of energy consumption measurements, from Augier et al 2021.
Graph of energy consumption measurements, from Augier et al 2021.

In conclusion, their take-home messages from the study are:

  • Rewriting existing high-level codes to other programming languages for simply the sake of performance would be counter-productive.
  • Programming languages are not 'interpreted' or 'compiled', only specific implementations are.
  • Some basic thumb rules: Premature optimization is the root of all evil. Measure, don’t guess.
  • Python can be made multi-threaded, ahead-of-time (AOT) or just-in-time (JIT) compiled with Transonic, Pythran, Numba and PyPy.
  • Better knowledge of these tool-chains would lead to less missed optimizations

Read the full article:

P. Augier, C. F. Bolz-Tereick, S. Guelton, and A. V. Mohanan, “Reducing the ecological impact of computing through education and Python compilers,” Nature Astronomy, vol. 5, no. 4, Art. no. 4, Apr. 2021, doi: 10.1038/s41550-021-01342-y.