Skip to Content

Python

Description

The Blue Waters Python software stack (bwpy) is an expansive suite of Python software components supporting a large class of high performance and scientific computing applications. The bwpy suite implements the scipy stack specification plus many other scientific Python packages. Over 300 Python packages are avalable, including mpi4py, pycuda, h5py, netcdf4-python, and pandas. The core numerical libraries are linked against Cray's libsci, and the stack is built for running on both login and compute nodes.

How to use the bwpy suite

The components of the bwpy suite are installed into two main modules, "bwpy" and "bwpy-mpi". The base module, "bwpy" provides the python interpreters plus most packages. The module "bwpy-mpi" adds an additional Python sites directory at higher priority to override packages with optional MPI functionality and to provide MPI-only modules such as mpi4py. This way, packages like mpi4py can be optionally imported and not break on login nodes. The "bwpy" module must be loaded first to gain access to the "bwpy-mpi" module.

Besides bwpy, there are several other installations of Python, and so users should take care and ensure that they are using the correct Python software environment. Anaconda should not be used on Blue Waters for it will not work well and is entirely unsupported. The paths to bwpy python will begin with either /sw/bw/bwpy or /mnt/bwpy.

One may load bwpy with:

1
module load bwpy

To load bwpy with MPI functionality:

1
2
module load bwpy
module load bwpy-mpi

After which, the path to the Python binary should be different:

1
2
which python
/mnt/bwpy/single/usr/bin/python

And the version reported by Python should be the latest version of the Python3 branch:

1
2
python --version
Python 3.5.4

Entering the full bwpy environment with bwpy-environ

BWPY is now installed into ext3 images which must be mounted before use. This change dramatically improves Python start-up times and allows for more frequent updates. To do this, a small program, bwpy-environ, is needed to perform these operations. It acts as a wrapper and should be invoked as bwpy-environ -- program [args...]. If no arguments are given, it will open a new bash instance within the mount namespace it creates, which is useful for interactive tasks. There are some wrappers for some commonly used executables, but bwpy-environ is needed to access the full range of executables and should be used if python is to be invoked multiple times.

Note: It is necessary to pass aprun the -b flag for bwpy-environ to run with the correct permissions.

Example 1:

1
aprun -b -n 1 -- bwpy-environ -- python -c "import numpy"

Example 2:

1
2
3
4
5
aprun -b -n 1 -- bwpy-environ -- myscript.sh
cat myscript.sh
#!/bin/bash
python script1.py
python script2.py

When possible, it is still advisable to condense multiple invocations of Python into a single Python script.

Example:

job.pbs:

1
2
3
...
module load bwpy
aprun -b -n 1 bwpy-environ myscript.sh

myscript.sh:

1
2
3
#!/bin/bash
for i in {0..999}; do python script1.py; done
for i in {0..499}; do python script2.py; done

script1.py:

1
2
3
#!/usr/bin/env python
import sys
print("script 1 %s" % sys.argv[1])

script2.py:

1
2
3
#!/usr/bin/env python
import sys
print("script 2 %s" % sys.argv[1])

This should be rewritten to:

myscript.sh:

1
2
#!/bin/bash
python outer.py

outer.py:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
#!/usr/bin/env python
from script1 import script1_main
from script2 import script2_main
def outer_main(range1,range2):
    for i in range(range1):
        script1_main(i)
    for i in range(range2):
        script2_main(i)
if __name__ == "__main__":
    import sys
    outer_main(int(sys.argv[1]),int(sys.argv[2]))

script1.py:

1
2
3
4
5
6
#!/usr/bin/env python
def script1_main(arg):
    print("script 1 %s" % arg)
if __name__ == "__main__":
    import sys
    script1_main(sys.argv[1])

script2.py:

1
2
3
4
5
6
#!/usr/bin/env python
def script2_main(arg):
    print("script 2 %s" % arg)
if __name__ == "__main__":
    import sys
    script2_main(sys.argv[1])

This can be made to run in parallel with minimal changes:

outer.py:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
#!/usr/bin/env python
import os
from script1 import script1_main
from script2 import script2_main

pes = int(os.environ.get("PBS_NP",1))
rank = int(os.environ.get("ALPS_APP_PE",0))

def outer_main(range1,range2):
    for i in range(range1):
        if i % pes == rank:
            script1_main(i)
    for i in range(range2):
        if i % pes == rank:
            script2_main(i)

if __name__ == "__main__":
    import sys
    outer_main(int(sys.argv[1]),int(sys.argv[2]))

Numba example wrapper script:

 1
 2
 3
 4
 5
 6
 7
#!/bin/bash
#https://numba.readthedocs.io/en/stable/cuda/random.html#a-simple-example
module load craype-accel-nvidia35
module load bwpy/2.0.4
export NUMBAPRO_NVVM=$CUDATOOLKIT_HOME/nvvm/lib64/libnvvm.so
export NUMBAPRO_LIBDEVICE=$CUDATOOLKIT_HOME/nvvm/libdevice/ 
python3.6 ./numba_rng.py

Python Implementations and Packages

The bwpy module provides several implementations and versions of Python. Currently in versions 1.2.4 and 2.0.2 of bwpy these are are:

  • Python 2.7
  • Python 3.4
  • Python 3.5
  • Python 3.6
  • Pypy
  • Pypy3

Note that Python 2 is End of Life!!! All Python 2 programs should be migrated to Python 3!

These can be accessed via python, python2, python3, python2.7, python3.5, python3.6, pypy, pypy3. The default python is Python 3.5.

The default python version can be changed by exporting EPYTHON=pythonver. This is also reflected in the execution of interpreted programs of bwpy, such as jupyter-notebook:

1
2
3
4
5
6
python --version
Python 3.5.4
EPYTHON="python2.7" python --version
Python 2.7.14
jupyter-notebook                   # Python 3.5 notebook
EPYTHON="python2.7" jupyter-notebook # Python 2.7 notebook

It is recommended to use #!/usr/bin/env python, #!/usr/bin/env python2 or #!/usr/bin/env python3 for your shebangs depending on your code compatibility.

To list the available packages for each implementation, use the command pip list. Pypy and pypy3 only have a limited numpy implementation, but is much better optimized than CPython with JIT compilation to machine code.

Virtualenv

Simply being able to use the pip and python executables is enough for most users. However, the bwpy module also supports the usage of virtualenv. The example below uses the  --system-site-packages option to give the newly created Python container access to the packages provided by the bwpy module. It should always be used when installing Python packages not already provided by bwpy.

1
2
3
4
5
6
mkdir myvirtualenv
cd myvirtualenv
virtualenv --system-site-packages $PWD
source bin/activate
pip install myfavoritypackage
deactivate # once done

Virtualenv creates Python containers for building multiple Python environments with different packages and package versions. The containers have python and pip wrappers which set up the environment for the active virtualenv. For information on virtualenv, please read its package documentation.

Building software against bwpy libraries

To build software against the bwpy Python libraries, use the matching PrgEnv-gnu compiler and library environment modules

1
2
3
module load PrgEnv-gnu/5.2.82-gcc.4.9.3
# for all bwpy/2.X:
# module swap gcc gcc/5.3.0 

and export the following variables:

1
2
3
export CPATH="${CPATH}:${BWPY_INCLUDE_PATH}"
export LIBRARY_PATH="${LIBRARY_PATH}:${BWPY_LIBRARY_PATH}"
export LDFLAGS="${LDFLAGS} -Wl,--rpath,${BWPY_LIBRARY_PATH}"

Note: A bwpy-environ session is required to make /mnt/bwpy accessible.

To build software that uses other libraries in bwpy (for example Boost), export the following variables (or in -I and -L options):

1
2
3
4
export CPATH="${CPATH}:${BWPY_DIR}/usr/include"
export LIBRARY_PATH="${LIBRARY_PATH}:${BWPY_DIR}/usr/lib"
export LDFLAGS="${LDFLAGS} -Wl,--rpath,${BWPY_DIR}/usr/lib"
export PKG_CONFIG_PATH="${PKG_CONFIG_PATH}:${BWPY_DIR}/usr/share/pkgconfig"

These paths are treated as system paths for bwpy. Using CPATH and LIBRARY_PATH will ensure that these paths are searched after any -I and -L options for correctness. The CMake in bwpy also treats these paths as system paths for the same reason, and won't generate -I or -L flags for libraries in these paths. Thus, these environment variables must be set for bwpy's CMake to function correctly.

Known Limitations

  • Applications that use Tkinter, matplotlib's qt backend, or any other GUI application will require a connection to a properly configured X server.
  • MPI applications will not run on a login node, but must be ran in a job using aprun. This restriction exists even for runs with only one rank.
  • Using TensorFlow in bwpy 2.0.2 and higher requires
    1
    2
    3
    4
    
    module swap PrgEnv-cray PrgEnv-gnu/5.2.82-gcc.4.9.3
    module swap gcc gcc/5.3.0
    module load bwpy/2.0.2
    python -c 'import tensorflow; print(tensorflow.__version__)'
  • Using ipython in a virtualenv will result in a warning "UserWarning: Attempting to work in a virtualenv. If you encounter problems, please install IPython inside the virtualenv." and will escape the virtualenv. Please use "pip install ipython" to install a copy of ipython in the virtualenv.

  • Using OpenMM requires setting export OPENMM_PLUGIN_DIR=$BWPY_DIR/usr/lib/plugins otherwise the CUDA and CPU platform plugins are not found

  • bwpy's setup.py is affected by a setuptools bug that manifests in errors messages AttributeError: module 'setuptools.build_meta' has no attribute '__legacy__' which can be circumvented by adding / modifying the file pyproject.toml in the package source, then install using pip install $PWD after moving a possible .git directory out of the way:

    1
    2
    3
    
    [build-system]
    requires = [] # only needed if creating the file
    build-backend="setuptools.build_meta"
    

Resources

 

Environment modules used when compiling bwpy software

"1.2.4" "2.0.2"
PrgEnv-gnu/5.2.82-gcc.4.9.3 PrgEnv-gnu/5.2.82-gcc.4.9.3
alps/5.2.4-2.0502.9774.31.12.gem alps/5.2.4-2.0502.9774.31.12.gem
atp/2.0.4 atp/2.0.4
cmake/3.1.3  
cray-hdf5/1.10.0 cray-hdf5-parallel/1.10.0
cray-libsci/16.11.1 cray-libsci/16.11.1
cray-mpich/7.5.0 cray-mpich/7.5.0
cray-netcdf/4.4.1 cray-netcdf-hdf5parallel/4.4.1
cray-tpsl/16.07.1 cray-tpsl/16.07.1
craype-interlagos craype-interlagos
craype-network-gemini craype-network-gemini
craype/2.5.8 craype/2.5.8
cudatoolkit/7.5.18-1.0502.10743.2.1 cudatoolkit/9.1.85_3.10-1.0502.df1cc54.3.1
dmapp/7.0.1-1.0502.11080.8.74.gem dmapp/7.0.1-1.0502.11080.8.74.gem
dvs/2.5_0.9.0-1.0502.2188.1.113.gem dvs/2.5_0.9.0-1.0502.2188.1.113.gem
fftw/3.3.4.10 fftw/3.3.4.10
gcc/4.9.3 gcc/5.3.0
gni-headers/4.0-1.0502.10859.7.8.gem gni-headers/4.0-1.0502.10859.7.8.gem
java/jdk1.8.0_51 java/jdk1.8.0_51
moab/9.0.2.TAS7-1490665589_71674cf-sles11 moab/9.1.2-sles11
modules/3.2.10.4 modules/3.2.10.4
nodestat/2.2-1.0502.60539.1.31.gem nodestat/2.2-1.0502.60539.1.31.gem
pmi/5.0.10-1.0000.11050.179.3.gem pmi/5.0.14
rca/1.0.0-2.0502.60530.1.63.gem rca/1.0.0-2.0502.60530.1.63.gem
scripts scripts
sdb/1.1-1.0502.63652.4.27.gem sdb/1.1-1.0502.63652.4.27.gem
torque/6.0.4 torque/6.0.4
udreg/2.3.2-1.0502.10518.2.17.gem udreg/2.3.2-1.0502.10518.2.17.gem
ugni/6.0-1.0502.10863.8.28.gem ugni/6.0-1.0502.10863.8.28.gem
user-paths user-paths
xpmem/0.1-2.0502.64982.5.3.gem xpmem/0.1-2.0502.64982.5.3.gem

Table of available modules

module "1.2.4" "2.0.2"
absl-py N/A 0.2.2
alabaster 0.7.10 0.7.11
AlpsInfo N/A 1.0
ansi2html 1.4.2 1.4.2
apipkg 1.4 1.4
appdirs 1.4.3 1.4.3
apptools 4.4.0 4.4.0
argcomplete 1.9.4 1.9.4
asn1crypto 0.24.0 0.24.0
astroid 1.6.0 1.6.5
astropy 2.0.1 2.0.1
astropy-helpers 2.0.1 2.0.1
atom 0.4.1 0.4.1
attrs 17.4.0 18.1.0
Automat N/A 0.7.0
autopep8 1.3.3 1.3.5
Babel 2.5.3 2.6.0
backports 1 1.0
backports-abc 0.5 0.5
baselines N/A 0.1.5
basemap N/A 1.0.7
bcolz N/A 1.1.2
beautifulsoup4 4.6.0 4.6.0
biopandas 0.2.1 0.2.1
bitarray 0.8.1 0.8.3
bleach 2.1.3 2.1.3
blinker 1.4 1.4
blosc 1.5.1 1.5.1
bokeh 0.12.6 0.12.6
boto 2.48.0 2.48.0
Bottleneck 1.0.0 1.0.0
cairocffi 0.8.0 0.8.0
certifi 2018.4.16 2018.4.16
cffi 1.11.4 1.11.5
chaco #N/A 4.7.2
chardet 3.0.4 3.0.4
click 6.7 6.7
cloudpickle 0.3.1 0.3.1
cntk 2.3.1 2.5.1
colorama 0.3.9 0.3.9
configobj 5.0.6 5.0.6
constantly 15.1.0 15.1.0
cov-core 1.15.0 1.15.0
coverage 4.2 4.2
cryptography 2.1.4 2.1.4
cvxopt 1.1.9 1.1.9
cycler 0.10.0 0.10.0
Cython 0.28.2 0.28.4
cytoolz N/A 0.8.2
dask 0.15.1 0.18.2
decorator 4.2.1 4.3.0
defusedxml N/A 0.5.0
dill N/A 0.2.5
docutils 0.14 0.14
enable N/A 4.7.2
entrypoints 0.2.3 0.2.3
envisage 4.6.0 4.6.0
et-xmlfile 1.0.1 1.0.1
ete3 3.0.0b35 3.1.1
execnet 1.5.0 1.5.0
file-magic 0.3.0 0.3.0
filelock 2.0.6 2.0.6
flake8 3.5.0 3.5.0
funcsigs 1.0.2 1.0.2
future 0.16.0 0.16.0
GDAL 2.2.2 2.3.0
gdbus-codegen 2.52.3 2.52.3
gevent 1.2.2 1.2.2
globus-cli N/A 1.7.0
globus-sdk 1.7.0 1.7.0
gmpy2 2.0.8 2.0.8
google-api-python-client 1.6.5 1.6.5
greenlet 0.4.12 0.4.13
grpcio N/A 1.14.1
gsd 1.2.0 1.2.0
gym 0.2.11 0.2.11
h5py 2.7.1 2.8.0
hgdistver 0.25 0.25
horovod 0.12.1 0.12.1
html5lib 1.0.1 1.0.1
httplib2 0.10.3 0.11.3
hyperlink 17.3.1 18.0.0
idna 2.6 2.7
imagesize 0.7.1 1.0.0
incremental 17.5.0 17.5.0
ipykernel 4.6.1 4.8.2
ipyparallel 6.0.2 6.0.2
ipython 5.4.1 5.4.1
ipython-genutils 0.2.0 0.2.0
ipywidgets 7.0.0 7.0.0
isort 4.3.4 4.3.4
java-config N/A 2.2.0
jdcal 1.2 1.2
jedi 0.12.0 0.12.0
Jinja2 2.1 2.10
jmespath N/A 0.9.2
joblib 0.11 0.11
jplephem 2.6 2.6
jsonschema 2.6.0 2.6.0
jupyter-client 5.2.3 5.2.3
jupyter-console 5.1.0 5.1.0
jupyter-core 4.4.0 4.4.0
keyring 12.2.1 13.2.1
kiwisolver 1.0.1 1.0.1
Lasagne N/A 0.2.dev1
lazy-object-proxy 1.3.1 1.3.1
line-profiler 2.1.2 2.1.2
linecache2 1.0.0 1.0.0
llvmlite 0.23.0 0.24.0
locket 0.2.0 0.2.0
lxml 4.2.0 4.2.2
m2r N/A 0.1.14
Mako 1.0.6 1.0.7
MarkupSafe 1 1.0
matplotlib 2.2.2 2.2.2
mayavi 4.5.0 4.5.0
mccabe 0.6.1 0.6.1
MDP 3.5 3.5
memory-profiler 0.47 0.47
meson 0.46.1 0.47.0
metakernel 0.20.4 0.20.4
metakernel-bash 0.11.3 0.11.3
metakernel-python 0.11.3 0.11.3
mistune 0.7.4 0.7.4
mpi4py 3.0.0 3.0.0
mock 2.0.0 2.0.0
mpmath 1.0.0 1.0.0
natsort 4.0.4 4.0.4
nbconvert 5.2.1 5.2.1
nbformat 4.4.0 4.4.0
ndg-httpsclient 0.4.2 0.4.2
netCDF4 1.2.4 1.2.4
netifaces 0.10.6 0.10.6
networkx 1.11 1.11
nose 1.3.7 1.3.7
nose2 0.6.5 0.6.5
notebook 5.5.0 5.5.0
numba 0.37.0 0.37.0
numexpr 2.6.2 2.6.2
numpy 1.14.2 1.14.5
numpydoc 0.7.0 0.7.0
oauth2client 4.1.2 4.1.2
objgraph 3.1.0 3.1.0
olefile 0.44 0.44
opcodes N/A 0.3.14
OpenMM 7.0.1 7.0.1
openpyxl 2.3.3 2.3.3
packaging 16.8 17.1
pandas 0.23.0 0.23.0
pandocfilters 1.4.2 1.4.2
parso 0.1.1 0.1.1
partd 0.3.8 0.3.8
path.py 10.3.1 11.0.1
pathlib2 2.3.0 2.3.0
patsy 0.4.1 0.4.1
pbr 4.0.3 4.1.0
PeachPy N/A 0.2.0
pep8 1.7.0 1.7.0
pexpect 4.2.1 4.2.1
pickleshare 0.7.4 0.7.4
Pillow 4.3.0 5.2.0
pip 9.0.1 10.0.1
pkgconfig 1.2.2 1.2.2
plac 0.9.6 1.0.0
plotly 1.9.6 1.9.6
ply 3.11 3.11
progressbar N/A 2.3
prompt-toolkit 1.0.15 1.0.15
protobuf 3.1.0 3.6.0
psutil 5.4.3 5.4.6
ptyprocess 0.5.2 0.5.2
py 1.5.3 1.5.3
pyamg 3.2.1 3.2.1
pyasn1 0.4.2 0.4.2
pyasn1-modules 0.2.1 0.2.1
pycairo 1.16.3 1.17.0
pycodestyle 2.3.1 2.3.1
pycparser 2.18 2.18
pycuda 2017.1 2018.1
pycurl 7.43.0 7.43.0.2
pydot 1.2.3 1.2.3
pyelftools 0.24 0.24
pyephem 3.7.6.0 3.7.6.0
pyface 6.0.0 6.0.0
pyflakes 1.6.0 1.6.0
pygame N/A 1.9.3
pyglet 1.2.4 1.2.4
Pygments 2.2.0 2.2.0
pygpu 0.6.7 0.7.6
PyHamcrest N/A 1.9.0
PyJWT 1.7.1 1.7.1
pylibacl 0.5.0 0.5.0
pylint 1.8.2 1.8.4
pymongo 3.5.1 3.5.1
PyMySQL 0.8.0 0.8.1
pyopencl 2017.2 2017.2
PyOpenGL 3.1.0 3.1.0
pyOpenSSL 17.5.0 17.5.0
pyparsing 2.2.0 2.2.0
pysam 0.12.0.1 0.12.0.1
PySocks 1.6.7 1.6.8
pytest-cache 1 1.0
python-dateutil 2.7.2 2.7.2
pytools 2017.4 2017.4
pytz 2018.4 2018.4
PyWavelets 0.5.2 0.5.2
pyxattr 0.6.0 0.6.0
PyYAML 3.12 3.13
pyzmq 17.0.0 17.1.2
qtconsole 4.3.1 4.3.1
queuelib 1.1.1 1.1.1
redis 2.10.6 2.10.6
regex 2017.4.5 2017.4.5
reportlab 3.4.0 3.4.0
requests 2.18.4 2.19.1
rfc3987 1.3.7 1.3.7
rpy2 2.6.2 2.6.2
rsa 3.4.2 3.4.2
scandir 1.7 1.7
scikit-image 0.13.0 0.13.0
scikit-learn 0.19.0 0.19.1
scikit-sparse 0.3 0.3
scipy 1.0.0 1.1.0
scons N/A 3.0.1
seaborn 0.7.1 0.7.1
SecretStorage 2.3.1 2.3.1
Send2Trash 1.3.0 1.3.0
service-identity 17.0.0 17.0.0
setuptools 38.5.1 40.0.0
setuptools-scm 1.16.1 2.1.0
sh 1.12.9 1.12.9
Shapely 1.5.17 1.5.17
simplegeneric 0.8.1 0.8.1
simplejson 3.14.0 3.15.0
sip N/A 4.19.12
six 1.11.0 1.11.0
snakefood 1.4 1.4
snowballstemmer 1.2.1 1.2.1
Sphinx 1.6.7 1.7.5
sphinx-rtd-theme 0.2.4 0.2.4
sphinxcontrib-websupport 1.0.1 1.1.0
SQLAlchemy 1.2.7 1.2.9
sqlalchemy-migrate 0.11.0 0.11.0
sqlparse 0.2.4 0.2.4
statsmodels 0.8.0 0.8.0
stevedore 1.28.0 1.28.0
strict-rfc3339 0.7 0.7
sympy 1.1.1 1.1.1
tables 3.4.2 3.4.2
Tempita 0.5.3.dev0 0.5.3.dev0
tensorflow 1.4.1 1.10.0
terminado 0.8.1 0.8.1
testpath 0.1 0.1
Theano 0.9.0 1.0.2
toolz 0.9.0 0.9.0
torch 0.3.0 0.4.1
torchvision 0.2.1 0.2.1
tornado 4.5.1 5.1
tqdm N/A 4.28.1
traceback2 1.4.0 1.4.0
traitlets 4.3.2 4.3.2
traits 4.6.0 4.6.0
traitsui 6.0.0 6.0.0
trollius 2.1 2.1
Twisted N/A 18.7.0
txaio 2.9.0 2.9.0
typing 3.6.4 #N/A
ujson 1.35 1.35
uritemplate 3.0.0 3.0.0
urllib3 1.22 1.23
vcversioner 2.16.0.0 2.16.0.0
versioneer 0.16 0.16
virtualenv 15.1.0 16.0.0
virtualenv-clone 0.2.6 0.2.6
virtualenvwrapper 4.8.2 4.8.2
wcwidth 0.1.7 0.1.7
webcolors 1.5 1.5
webencodings 0.5.1 0.5.1
wheel 0.30.0 0.31.1
Whoosh 2.7.4 2.7.4
widgetsnbextension 3.0.0 3.0.0
Wraprun 0.2.1 0.2.1
wrapt 1.10.11 1.10.11
wslink 0.1.4 0.1.4
wstools N/A 0.4.5
wxPython 4.0.2 4.0.2
xarray 0.9.6 0.9.6
xcffib 0.6.0 0.6.0
xlrd 1.0.0 1.0.0
xlwt 1.2.0 1.2.0
yt 3.4.0 3.4.0
zope.interface 4.4.3 4.5.0