Dear all,
PyPy (http://pypy.org) offers a highly compatible version of the Python 2.7 interpreter and comes with a just-in-time compiler (JIT) that can greatly speed up certain types of computing tasks. In particular, mathematics done in loops, as is common in HEP analysis codes.
Where PyPy breaks compatibility, is in the use of extension libraries, especially when those rely on the internals of the CPython interpreter. PyROOT being on of them, it did so far not work on PyPy.
Now, a first beta release of PyPy supporting PyROOT is available here:
/afs/.cern.ch/sw/lcg/external/pypy
Run the setup script (which sets up the proper CPython, ROOT, and GCC):
/afs/.cern.ch/sw/lcg/external/pypy/x86_64-slc6/setup-pypyroot.sh
which will make the executable ‘pypyroot’ available, which can be used as the normal CPython Python interpreter. For example:
[code] $ pypyroot
import ROOT
c1 = ROOT.TCanvas()etc.[/code]
I hope to collect feedback over a period of about a month or so, then cut a release 1.0 by CHEP. Please help out by trying it out!
For performance improvements, the “compilation” part of the JIT is only half the story. Far more important are the recognition of use cases by PyPy and specialization of them. One such case is ROOT I/O and TTree reading, for example, runs at C++ speeds in pypyroot (it can be 50x slower in PyROOT). As you can imagine, that is a long (but worthwhile) work in progress.
Other developments by the PyPy team, that are important for the future of high performance python codes, include automatic thread safety using software transactional memory and use of vector instructions in the JIT for numpy code. Likewise, these are a works in progress, but are coming along nicely.
Compatibility with PyROOT is not 100%, and in some ways never will be. For example the fact that PyPy uses a garbage collector rather than reference counting, and that “from ROOT import *” can not work together with the JIT. However, both these can simply be worked around to have code that works fine on both interpreters (e.g. consistently use “import ROOT”) and the list of remaining features to-be-done is rather small and shrinking. (1)
Furthermore, comparing pypyroot today to what PyROOT had in functionality when it was first included in ROOT, back in 2004, it is clear that pypyroot is light years ahead of that version. As such, it is already very useful for any standalone ROOT work. (2)
A list of C++ features supported can be found here (this is documenting the Reflex backend, but it’s the same feature-list for CINT):
http://doc.pypy.org/en/latest/cppyy.html#features
In addition, for the CINT backend, pypyroot has several ROOT-specific pythonizations, such as for TObject, TTree, TString, etc.
When ROOT6 comes out, the CINT backend of pypyroot is ready to be swapped out for a Cling backend. The latter allows for a tighter integration with the JIT (as has been shown with the Reflex backend, which is part of PyPy by default since release 2.0).
Please try it out and give me feedback. Thanks!
Best regards,
Wim Lavrijsen
(1) See: http://root.cern.ch/drupal/content/pypyroot for a short-list
(2) If you use a lot of (C-)extension modules, not bound using rootcint, some of your favorite ones may not (yet) be available for PyPy.