Python Tools
Description and Overview
Python is an interpreted, general-purpose high-level programming language. Various of versions of Python are installed on most of the NERSC systems, usually accompanied with computational tool such as numpy and scipy.
Using Python on NERSC Systems
To use the python installed as module on NERSC systems, you need do
module load python
Remember, to run a python script on the Hopper compute nodes you must set an environment variable:
setenv CRAY_ROOTFS DSL. To execute a script on the Hopper compute nodes dedicated to your job you need to use aprun and add the option -a xt, e.g.,:
aprun -n 1 -a xt ./hello_world.py
Using Numpy, Scipy and Matplotlib
Several scientific computing tools for Python are installed with each Python release. You can get the version of these packages from the "Availability" table.
Numpy is a language extension that defines the numerical array and matrix type and basic operations on them.
An example numpy script:
#!/usr/bin/env python
''' Numpy example from: http://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.svd.html'''
import numpy as np
a = np.random.randn(9, 6) + 1j*np.random.randn(9, 6)
U, s, V = np.linalg.svd(a, full_matrices=True)
S = np.zeros((9, 6), dtype=complex)
S[:6, :6] = np.diag(s)
np.allclose(a, np.dot(U, np.dot(S, V)))
print "a:\n", a
print "U: \n", U
print "s: \n", s
print "V: \n", V
Scipy is another language extension that uses numpy to do advanced math, signal processing, optimization, statistics and much more.
Matplotlib is a language extension to facilitate plotting.
For details about these packages, please refer to their official documentations.
Installed Python Packages
Up to version 2.7.2, the python packages on Hopper, Carver and Euclid followed an all-in-one installation approach. The latest versions of selected popular packages such as numpy, scipy, ipython, matplotlib etc. were installed together with the python package under its site-packages directory. Therefore, using a particular python package meant using a certain fixed version of numpy, etc., tied to the base python package during installation. For example, using the python/2.7.1 package on Carver and Euclid means that you must use numpy/1.5.1, scipy/0.9.0b1, ipython/0.10.1, matplotlib/1.0.1, etc.
From python/2.7.3 we are taking a completely different approach. Individual packages are installed in their own directories, separate from the base python's site-packages directory. A module file is provided for each individual package to prepend its directory to PYTHONPATH, the search path of python for a python module. This allows multiple versions for each package, and users can mix and match by choosing the best or most suitable version for their work with any base python package.
To maintain consistency in core functionalities with pre-2.7.3 versions of python packages, a new python module (e.g., python/2.7.3) will load the following popular packages:
- python_base, which comprises of a fixed version of Python, nose, pycairo, pygobject, pygtk and setuptools
- numpy
- scipy
- matplotlib
- ipython
% module load python/2.7.3
% module list
Currently Loaded Modulefiles:
1) pgi/12.3 4) numpy/1.6.1-nothread 7) ipython/0.12.1
2) openmpi/1.4.5 5) scipy/0.10.1 8) python/2.7.3
3) python_base/2.7.3 6) matplotlib/1.1.0
The version numbers for the python module and its underlying python_base module (i.e., x.y.z in python/x.y.z and python_base/x.y.z, respectively) are taken from the version number of the distributed python software package (x.y.z in Python-x.y.z.tgz). The module file for python/x.y.z also loads the default version of numpy, scipy, matplotlib and ipython. Users can swich to a different version for numpy, etc. by using a module swap command:
% module swap numpy numpy/1.5.1
There are many individual packages provided under this framework. The current list includes
- ase
- cython
- gpaw
- h5py
- ipython
- matplotlib
- mercurial
- mpi4py
- mysqlpython
- numexpr
- numpy
- pil
- pycdf
- pyhdf
- pympi
- pytables
- scipy
- virtualenv
You can load these modules individually as shown below. Note that these modules should not be used with a pre-2.7.3 version of python.
% module load cython
% module list
Currently Loaded Modulefiles:
1) pgi/12.3 4) numpy/1.6.1-nothread 7) ipython/0.12.1
2) openmpi/1.4.5 5) scipy/0.10.1 8) python/2.7.3
3) python_base/2.7.3 6) matplotlib/1.1.0 9) cython/0.16
Installing Your Own Python Package
Users can install their own python packages in their home directories. Here is an example installing a python package called setuptools:
-
Un-tar the package and cd into the package directory
% tar xvf setuptools-0.6c11.tar.gz
% cd setuptools-0.6c11/
-
Create a directory hierarchy for your python module libraries. Example: $HOME/python_modules/machine_name/lib/python
-
Set the PYTHONPATH environment variable
% setenv PYTHONPATH $HOME/python_modules/machine_name/lib/python
-
Install your python package with the default version of python in /usr/bin/python
% python setup.py install --home=~/python_modules/machine_name
-
OR Install your python package with alternate version of python. (There could be a more recent version of python as a module)
% module load python % python setup.py install --home=~/python_modules/machine_name
-
Test your installation
% python >> import setuptools >> ...
Using the DLCache library tools for large scale python applications on Hopper
Large scale Python applications may spend huge time at startup on Hopper. The DLCache library is a set of functions that can be incorporated into a dynamically-linked application to provide improved performance during the loading of dynamic libraries when running the application at large scale on Cray XE6. To access this library, do
module load dlcache
Please read the user guide to use the tools provided by this library. This library is still in experimental stage, please report any problems, comments you see with this library to "consult at nersc dot gov".
Availability
You can check the availability of python by using the following command:
module avail python
You can also refer to the table below for the version of installed computational tools along with python.
| Package | Platform | Category | Version | Module | Install Date | Date Made Default |
|---|---|---|---|---|---|---|
| Python | carver | applications/ programming | 2.6.4 | python/2.6.4 | 2010-05-03 | 2010-08-25 |
| Python programming language | ||||||
| Python | carver | applications/ programming | 2.6.5 | python/2.6.5 | 2012-01-13 | |
| Python programming language | ||||||
| Python | carver | applications/ programming | 2.7.1 | python/2.7.1 | 2011-01-13 | 2011-08-06 |
| Python programming language | ||||||
| Python | carver | applications/ programming | 2.7.3 | python/2.7.3 | 2012-05-03 | 2013-01-28 |
| Python programming language | ||||||
| Python | carver | applications/ programming | 2.7.3 | python_base/2.7.3 | 2012-05-21 | 2012-05-21 |
| Base package for Python programming language | ||||||
| Python | carver | applications/ programming | epd_7.3 | python/epd_7.3 | 2012-11-05 | |
| Python programming language | ||||||
| Python | edison | applications/ programming | 2.7.3 | python/2.7.3 | 2013-01-17 | 2013-01-17 |
| Python programming language | ||||||
| Python | edison | applications/ programming | 2.7.3 | python_base/2.7.3 | 2013-01-17 | 2013-01-17 |
| Base package for Python programming language | ||||||
| Python | euclid | applications/ programming | 2.6.4 | python/2.6.4 | 2012-01-13 | |
| Python programming language | ||||||
| Python | euclid | applications/ programming | 2.7.1 | python/2.7.1 | 2011-02-15 | 2012-05-20 |
| Python programming language | ||||||
| Python | euclid | applications/ programming | 2.7.2 | python/2.7.2 | 2012-01-13 | |
| Python programming language | ||||||
| Python | euclid | applications/ programming | 2.7.3 | python/2.7.3 | 2012-05-04 | 2012-10-04 |
| Python programming language | ||||||
| Python | euclid | applications/ programming | 2.7.3 | python-base/2.7.3 | 2012-05-20 | 2012-05-20 |
| Base package for Python programming language | ||||||
| Python | euclid | applications/ programming | 2.7.3 | python_base/2.7.3 | 2012-05-20 | |
| Base package for Python programming language | ||||||
| python | genepool | applications/ programming | 2.7.3 | python/2.7.3 | 2012-07-05 | 2012-07-05 |
| Python Programming Language | ||||||
| python | genepool | applications/ programming | 2.7.3_1 | python/2.7.3_1 | 2012-07-20 | 2012-07-20 |
| Python Programming Language | ||||||
| python | genepool | applications/ programming | 2.7.3_2 | python/2.7.3_2 | 2013-01-24 | 2013-01-27 |
| Python Programming Language | ||||||
| python | genepool | applications/ programming | 3.2.3_1 | python/3.2.3_1 | 2012-07-28 | |
| Python3 Programming Language | ||||||
| Python | hopper | applications/ programming | 2.7.1 | python/2.7.1 | 2011-02-24 | 2011-03-15 |
| Python programming language | ||||||
| Python | hopper | applications/ programming | 2.7.1 | python/2.7.1 | 2011-02-24 | 2011-02-24 |
| Python programming language | ||||||
| Python | hopper | applications/ programming | 2.7.1 | python/2.7.1 | 2011-02-24 | 2011-02-24 |
| Python programming language | ||||||
| Python | hopper | applications/ programming | 2.7.1 | python/2.7.1 | 2011-02-24 | 2011-02-24 |
| Python programming language | ||||||
| Python | hopper | applications/ programming | 2.7.1 | python/2.7.1 | 2011-02-24 | 2011-02-24 |
| Python programming language | ||||||
| Python | hopper | applications/ programming | 2.7.1-test | python/2.7.1-test | 2011-04-04 | |
| Python programming language | ||||||
| Python | hopper | applications/ programming | 2.7.3 | python/2.7.3 | 2012-10-02 | 2013-01-28 |
| Python programming language | ||||||
| Python | hopper | applications/ programming | 2.7.3 | python_base/2.7.3 | 2012-10-02 | 2012-10-02 |
| Base package for Python programming language | ||||||
| Python | pdsf | applications/ programming | 2.6.2 | python/2.6.2 | 2012-03-12 | |
| Python built in sl44 | ||||||
| Python | pdsf | applications/ programming | 2.7 | python/2.7 | 2012-03-12 | |
| Python built in sl44 | ||||||
| Python | pdsf | applications/ programming | 2.7.1 | python/2.7.1 | 2012-03-12 | 2012-03-12 |
| Python built in sl44 | ||||||
| Python | pdsf_sl6 | applications/ programming | 2.7.3 | python/2.7.3 | 2012-10-08 | 2012-10-08 |
| Python programming language | ||||||
| python | phoebe | applications/ programming | 2.7.3 | python/2.7.3 | 2012-07-05 | 2012-07-05 |
| Python Programming Language | ||||||
| python | phoebe | applications/ programming | 2.7.3_1 | python/2.7.3_1 | 2012-07-28 | 2012-07-28 |
| Python Programming Language | ||||||
| python | phoebe | applications/ programming | 2.7.3_2 | python/2.7.3_2 | 2013-01-24 | 2013-01-27 |
| Python Programming Language | ||||||
| python | phoebe | applications/ programming | 3.2.3_1 | python/3.2.3_1 | 2012-07-28 | |
| Python3 Programming Language | ||||||


