A Python Interface

Python is a powerful, high-level interpreted language that is widely used within the particle physics community. It is particularly useful as an interactive language that provides fast proto-typing of code. An experimental Python interface to PYTHIA is available. This interface has been generated using SWIG (Simplified Wrapper and Interface Generator). Please note that this interface has not been extensively tested and consequently issues may arise. If bugs are found or additional features are required, as usual, please report them to the PYTHIA authors.

Features

An attempt has been made to translate all PYTHIA classes and functions to the Python interface as directly as possible. The following features are included in the Python interface:

Limitations

A variety of methods to interface C++ code with Python exist, each with its own advantages and disadvantages, some of which are being rapidly developed. Currently, for the purposes of an interface to PYTHIA, SWIG provides the best option. However, this may not remain the case, and the technical interface may be changed to some other method, e.g. cppyy, in the future. The Python interface to PYTHIA currently suffers the following limitations:

Installation

To install the Python interface, both the python command, as well as the Python system header Python.h must be available. The directory containing the python command can be passed to the PYTHIA configuration via the option --with-python-bin, while the directory containing Python.h can be set with the option --with-python-include. An example configuration could be as follows,
 
    ./configure --with-python-include=/usr/include/python2.7 \ 
    --with-python-bin=/usr/bin 
where the paths must be changed accordingly for the local system. If the location of Python.h is unknown, oftentimes the command python-config --includes will supply the correct path. Please note that the Python versions for the python command and Python.h header must match. This is of particular importance when compiling against Python 3. Many systems will provide the Python 3 command via python3 rather than python, so either a temporary alias should be made, or a soft link of the python3 command to python could also be made. However, take care, as many systems rely on Python 2 for things such as package managers, etc. Also note that if one wishes to utilize GZIP support (needed for the LHAupMadgraph plugin) then the option --with-gzip should also be provided.

After configuring the Python interface for PYTHIA to be built and running make as usual, the following files should be generated in the directory lib.

To ensure that the pythia8.py module is available to Python, the system variable PYTHONPATH should be set similar to

 
    export PYTHONPATH=$(PREFIX_LIB):$PYTHONPATH 
where PREFIX_LIB is the directory lib which contains pythia8.py. Generally, the library paths should be set correctly, but it also may be necessary to set
 
    export LD_LIBRARY_PATH=$(PREFIX_LIB):$LD_LIBRARY_PATH 
where DYLD should be substituted for LD in OS X. Alternatively, it is also possible to define the Python path from within Python, as is done within the provided examples.

Examples

To use the Python interface for PYTHIA, start Python and import pythia8. The provided examples can be run by python mainXX.py where XX is the number of the example.