Python is a widespread programming language used in many domains. The availability of many libraries (Python modules, not to be mixed up with environment modules system) make it feasible for scientific computing.
Note: the Python version 2 and version 3 are mainly incompatible. The Python-2 has reached EOL as of 2020-01-01 and is deprecated. Migrate your application to Python-3.
Note : The Python-3 binaries typically are called 'python3', 'pip3' and so on; there are also 'python2' and 'pip2' (and so on) binaries available for Python-2 version, making essentially two versions versions of Python available at the same time with 'python' being python2 or python3 - environment-dependent, today linked typically to version 2 of python due to historical reasons. This may be subject of change. It is highly reccomendable to use 'python2' / 'python3' instead of 'python' even if 'python' links to the right version in actual environment as it would enshure the right version of Python interpreter being ised.
There are many roots of Python software in the HPC Cluster:
- 1. Python brought along by the OS distribution (Linux)
- 2. Python from the module system
- 3. Intel Python
- 4. Own version in your $HOME
- 5. Installing of additional Python packages
- 6. Known issues
In Linux, there is a version of Python boxed in the distribution, delivered as RPM. This Python and some Py-modules (NumPy, SciPy, Matplotlib, ...) are available by default. If you miss a Py-module let us know - maybe there is a suitable RPM available. Not all RPMs will be installed (i.e. we cannot install RPMs whose depend on OS-distributed MPI packages as these MPI RPMs are incompatible to the batch system).
The RPMs installed in exactly that versions which are available by OS, also typically older versions. The RPMs are updated accordingly to the OS distribution update rules. We do not offer any other versions/updates/fixes besides the distribution RPMs. Users cannot modify this installation. You can add further Py-Modules (or newer versions of preinstalled ones) in your $HOME as desctibed below.
If you need yet another version of Python as the one available by default in Linux environment, take a look at the output of 'module avail python' command. It lists a number of Python installations available in the HPC Cluster. E.g. type 'module load python/3.9.1' for loading of the the appropriate version of Python3.
- Note: the name of the Python binary version 3 is 'python3' and not just 'python'! The name 'python' will still be resolved as the Linux's one Python-2 interpreter.
- You can add Py-Modules and packages in your $HOME as described below.
- some Py-Modules (NumPy, SciPy, ...) are bundled in these installations, are build in optimised form using Intel MKL, offereng up to 2x speedup in comparison to vanilla installations using (parallel!) OpenBLAS, and likely tremendous speedup if compared to some unoptimised serial implementations (danger of those in unoptimised 'Conda' installations). (Note: in older versions of modules the NumPy/SciPy and friends are made available by PYTHONPATH environment variable set by loading the python environment module. Whenever modifying this environment variable, you will likely wish to enhance the value instead to overwrite it, e.g. 'export PYTHONPATH=$HOME/my/newpatho/added:$PYTHONPATH' - remember that this would disarm your likely newer versions of any package installed locally in $HOME/.local adding a mess into your environment...)
- install updated versions of preinstalled modules if needed locally as described below by using 'pip3 install --upgrade ..' and friends.
The users are welcome to add needed Py-modules in their $HOME directory, e.g. by 'pip3'. Python software often rely on GCC compilers and often do not work [out of the box] with Intel compilers; thus type 'module switch intel gcc' before adding any Py-Modules. You can install Python module in your $HOME in many ways:
- Install the modules in an arbitrary directory in $HOME (or $WORK or..) and propagate it by the PYTHONPATH environment variable (ultimate flexibility, need to take care about environment), or
- Install in standard-$HOME installation $HOME/.local e. g. by 'pip3 install --user ...' (easy-to-use as not needed to set up the PYTHONPATH environment variable, less flexible, danger of side effects when using multiple Python versions and/or very compilicated toolchains like tensorflow and other AI toolhains).
- Use Virtual Environment (like Conda). TBD.
$ module switch intel gcc
$ module switch intel gcc
TBD: Conda/Anaconda/VirtialEnvironment Example.
Use 'pip3 -vvv list' to see the list of available Python modules in the active environment. Newer versions of 'pip' list also location of that module giving hint which version is used: one boxed with python installation, one of 'pip3 install --user ...' installation to default $HOME (recognizable on $HOME/.local/lib/.... in path), or one of $PYTHONPATH to some location.
For more insight in python search paths (SYS.PATH) see
- https://www.devdungeon.com/content/python-import-syspath-and-pythonpath-tutorial or
- https://datacadamia.com/lang/python/engine/searchpath and
$ python3 -c 'import sys; print(sys.path)'
If a module is available in more that one locations (in different versions?) the first one found in paths will be used. This can be useful if installing an update to already-availble python module by
'pip3 install --user --upgrade ...', but can also be a pitfail: PYTHONPATH superseeds local path $HOME/.local/... - if in PYTHONPATH is an older version of a python module, your installtion using 'pip install --user FooBar' will succeed but wil not be used!
- See Tensorflow
It is possible to use Python with MPI (Message Passing Interface). One widely used interface is 'mpi4py'. You must install this package into your $HOME using command 'pip2' or 'pip3' (depending on Python version used):
|$ pip2 install --user mpi4py|
$ pip3 install --user mpi4py
Note that this will install a version pf mpi4py adopted to combination of Python (version), MPI library (vendor and version), compiler (vendor and version). In case of any change in vendor, and also highly likely in case of any change of version of any those component, you must reinstall 'mpi4py'. Backup and/or cleanup content of your $HOME/.local prior that step!
NumPy and SciPy are two wide-used scientific/numerical Python packages. They rely on a fast (and parallelised with threads) BLAS/LAPACK implementation. Intel MKL is the recommended implementation in Intel CPUs and is proven to be up to 2x faster that OpenBLAS (which is not bad, too!). When using NumPy/SciPy linked to Intel MKL (or OpenBLAS) you can use up all cores of todays multicore computer with significant (or even nearly-linear) speedp. Set up the number of threads by using the OMP_NUM_THREADS envvar (or sumbit a shared memory parallelised batch job). The most disadvantageous implementation of BLAS/LAPACK would be the native/naive implementation from netlib, which is not parallelised at all and stays single-core and thus pretty slow. You can see the configuration of NumPy and SciPy in your environment bythose command:
$ python3 -c "import numpy as np; print(np.version.version); np.show_config()"
When installing an updated version of NumPy/SciPy - wittingly or not wittingly but as a side effect of installing a package by 'pip3 --user --upgrade something' - you can advise to use Intel MKL, as described here https://software.intel.com/content/www/us/en/develop/articles/build-numpy-with-mkl-and-icc.html by creating a '.numpy-site.cfg' file in your $HOME directory. Note that the 'pip3' may ignore this file by default and install a BLOB wheel, so force it by '--no-binary' flag:
$ cat $HOME/.numpy-site.cfg
After (re)installation of your NumPy and when interested you can try to benchmark NumPy/SciPy and compare your results to
The 3.6.8.sysdef is the vanilla Python version from Linux; the version python/3.7.3 use OpenBLAS and python/3.7.9 use Intel MKL.
- When using mpi4py and Intel MPI 2018, the MPI process will stuck forever when startet across multiple nodes. Workarounds:
- configure your job to stay single-node
- use intelmpi/2019
- switch to Open MPI (you have to reinstall mpi4py from scratch!)
- Do you see an error of type 'ImportError: No module named FooBar'?
- a python module named FooBar is missing. Solution in most cases would be to install it using 'pip3 install --user FooBar' - for example see above section '5. Installing of additional Python packages.'.
- Do you see an error of type 'ImportError: /home/ab123456/.local/lib/python3.?/site-packages/............86_64-linux-gnu.so: undefined symbol: __intel_sse2_strlen'?
- a python module containig a library was built using Intel compilers and miss some libraries. Easiest solution: reinstall (everything) from scrath using GCC compilers:
- $ module switch intel gcc
- (backup ~/.local)
- mv ~/.local/lib/python3.? ~/.local/lib/__RM_ME__python3.?
- pip3 install --user --no-cache-dir someUsefulPythonSoftware
- if any strange behaviour keeps also after a re-insatllation of software from scratch, use ' --no-cache-dir ' to disable the pip's cache (maybe containing malformed packeges).