This lesson is in the early stages of development (Alpha version)

Accessing software via Modules

Overview

Teaching: 30 min
Exercises: 15 min
Questions
  • How do we load and unload software packages?

Objectives
  • Load and use a software package.

  • Explain how the shell environment changes when the module mechanism loads or unloads packages.

On a high-performance computing system, it is seldom the case that the software we want to use is available when we log in. It is installed, but we will need to “load” it before it can run.

Before we start using individual software packages, however, we should understand the reasoning behind this approach. The three biggest factors are:

Software incompatibility is a major headache for programmers. Sometimes the presence (or absence) of a software package will break others that depend on it. Two well known examples are Python and C compiler versions. Python 3 famously provides a python command that conflicts with that provided by Python 2. Software compiled against a newer version of the C libraries and then run on a machine that has older C libraries installed will result in a nasty 'GLIBCXX_3.4.20' not found error.

Software versioning is another common issue. A team might depend on a certain package version for their research project - if the software version was to change (for instance, if a package was updated), it might affect their results. Having access to multiple software versions allows a set of researchers to prevent software versioning issues from affecting their results.

Dependencies are where a particular software package (or even a particular version) depends on having access to another software package (or even a particular version of another software package). For example, the VASP materials science software may depend on having a particular version of the FFTW (Fastest Fourier Transform in the West) software library available for it to work.

Environment Modules

Environment modules are the solution to these problems. A module is a self-contained description of a software package – it contains the settings required to run a software package and, usually, encodes required dependencies on other software packages.

There are a number of different environment module implementations commonly used on HPC systems: the two most common are TCL modules and Lmod. Both of these use similar syntax and the concepts are the same so learning to use one will allow you to use whichever is installed on the system you are using. In both implementations the module command is used to interact with environment modules. An additional subcommand is usually added to the command to specify what you want to do. For a list of subcommands you can use module -h or module help. As for all commands, you can access the full help on the man pages with man module.

On login you may start out with a default set of modules loaded or you may start out with an empty environment; this depends on the setup of the system you are using.

Listing Available Modules

To see available software modules, use module avail:

[netid@dev-amd20 ~]$ module avail
------------ /opt/modules/MPI/GCC/6.4.0-2.28/OpenMPI/2.1.2 ------------
   ABySS/2.0.2
   ABySS/2.1.1
   ABySS/2.1.5                                (D)
   ANTs/2.3.2
   ATK/2.28.1
   Armadillo/8.400.0
   BBMap/37.93
   BCFtools/1.9
   BLAST+/2.7.1                               (D)
   BUSCO/3.1.0-Python-3.6.4
   BWA/0.7.17
   BamTools/2.5.1
   BioPerl/1.7.2-Perl-5.26.1
   Boost.Python/1.66.0-Python-3.6.4

[removed most of the output here for clarity]

  Where:
   L:        Module is loaded
   Aliases:  Aliases exist: foo/1.2.3 (1.2) means that "module load foo/1.2"
             will load foo/1.2.3
   D:        Default Module

Use "module spider" to find all possible modules and extensions.
Use "module keyword key1 key2 ..." to search for all possible modules matching
any of the "keys".

Listing Currently Loaded Modules

You can use the module list command to see which modules you currently have loaded in your environment. If you have no modules loaded, you will see a message telling you so

[netid@dev-amd20 ~]$ module list
Currently Loaded Modules:
  1) GCCcore/6.4.0    6) OpenMPI/2.1.2    11) ScaLAPACK/2.0.2-OpenBLAS-0.2.20  16) ncurses/6.0      21) libffi/3.2.1
  2) binutils/2.28    7) tbb/2018_U3      12) bzip2/1.0.6                      17) libreadline/7.0  22) Python/3.6.4
  3) GNU/6.4.0-2.28   8) imkl/2018.1.163  13) zlib/1.2.11                      18) Tcl/8.6.8        23) Java/1.8.0_152
  4) numactl/2.0.11   9) OpenBLAS/0.2.20  14) Boost/1.67.0                     19) SQLite/3.21.0    24) MATLAB/2018a
  5) hwloc/1.11.8    10) FFTW/3.3.7       15) CMake/3.11.1                     20) GMP/6.1.2        25) powertools/1.2

You should generally find and select modules based on your needs rather than using the defaults. We alway recommend clearing out all modules before you try loading new ones to help avoid conflicts. To do this, use the module purge command:

[netid@dev-amd20 ~]$ module purge
[netid@dev-amd20 ~]$ module list
No modules loaded

Loading and Unloading Software

To load a software module, use module load. In this example we will use Python 3.

Initially, there is only one version of Python 3 that is available. We can test this by using the which command. which looks for programs the same way that Bash does, so we can use it to tell us where a particular piece of software is stored.

[netid@dev-amd20 ~]$ which python3

If python3 did not exist we would see output like

which: no python3 in (
/opt/software/core/lua/lua/bin:/usr/lib64/qt-3.3/bin:/usr/local/bin:
/usr/bin:/usr/local/sbin:/usr/sbin:/usr/local/hpcc/bin:/usr/lpp/mmfs/bin:
/opt/ibutils/bin:/opt/puppetlabs/bin:/opt/dell/srvadmin/bin)

However, in our case we do have an existing python3 available so we see

/usr/bin/python3

We need a different Python than the system provided one though, so let us load a module to access it.

We can load the python3 command with module load:

[netid@dev-amd20 ~]$ module load GCC/10.2.0 OpenMPI/4.0.5 Python/3.8.6
[netid@dev-amd20 ~]$ which python3
/opt/software/Python/3.8.6-GCCcore-10.2.0-new/bin/python3

So, what just happened?

To understand the output, first we need to understand the nature of the $PATH environment variable. $PATH is a special environment variable that controls where a UNIX system looks for software. Specifically $PATH is a list of directories (separated by :) that the OS searches through for a command before giving up and telling us it can’t find it. As with all environment variables we can print it out using echo.

[netid@dev-amd20 ~]$ echo $PATH
/opt/software/Python/3.8.6-GCCcore-10.2.0-new/bin:/opt/software/SQLite/3.33.0-GCCcore-10.2.0/bin:/opt/software/Tcl/8.6.10-GCCcore-10.2.0/bin:/opt/software/ncurses/6.2-GCCcore-10.2.0/bin:/opt/software/bzip2/1.0.8-GCCcore-10.2.0/bin:/opt/software/OpenMPI/4.0.5-GCC-10.2.0/bin:/opt/software/libfabric/1.11.0-GCCcore-10.2.0/bin:/opt/software/UCX/1.9.0-GCCcore-10.2.0/bin:/opt/software/hwloc/2.2.0-GCCcore-10.2.0/sbin:/opt/software/hwloc/2.2.0-GCCcore-10.2.0/bin:/opt/software/libxml2/2.9.10-GCCcore-10.2.0/bin:/opt/software/XZ/5.2.5-GCCcore-10.2.0/bin:/opt/software/numactl/2.0.13-GCCcore-10.2.0/bin:/opt/software/binutils/2.35-GCCcore-10.2.0/bin:/opt/software/GCCcore/10.2.0/bin:/opt/software/powertools/bin:/opt/software/core/lua/lua/bin:/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/usr/local/hpcc/bin:/usr/lpp/mmfs/bin:/opt/ibutils/bin:/opt/puppetlabs/bin:/opt/dell/srvadmin/bin

You’ll notice a similarity to the output of the which command. In this case, there’s only one difference: the different directory at the beginning. When we ran the module load command, it added a directory to the beginning of our $PATH. Let’s examine what’s there:

[netid@dev-amd20 ~]$ ls /opt/software/Python/3.8.6-GCCcore-10.2.0-new/bin
2to3              netaddr        pytest                 rst2s5.py
2to3-3.8          nosetests      py.test                rst2xetex.py
chardetect        nosetests-3.8  python                 rst2xml.py
cygdb             pasteurize     python3                rstpep2html.py
cython            pbr            python3.8              runxlrd.py
cythonize         pip            python3.8-config       sphinx-apidoc
doesitcache       pip3           python3-config         sphinx-autogen
easy_install      pip3.8         rst2html4.py           sphinx-build
easy_install-3.8  pkginfo        rst2html5.py           sphinx-quickstart
flit              poetry         rst2html.py            tabulate
futurize          pybabel        rst2latex.py           virtualenv
idle3             __pycache__    rst2man.py             wheel
idle3.8           pydoc3         rst2odt_prepstyles.py
jsonschema        pydoc3.8       rst2odt.py
keyring           pygmentize     rst2pseudoxml.py

Taking this to its conclusion, module load will add software to your $PATH. It “loads” software. A special note on this - depending on which version of the module program that is installed at your site, module load will also load required software dependencies.

To demonstrate, let’s use module list. module list shows all loaded software modules.

[netid@dev-amd20 ~]$ module list
Currently Loaded Modules:
  1) powertools/1.2   8) libxml2/2.9.10     15) ncurses/6.2
  2) GCCcore/10.2.0   9) libpciaccess/0.16  16) libreadline/8.0
  3) zlib/1.2.11     10) hwloc/2.2.0        17) Tcl/8.6.10
  4) binutils/2.35   11) UCX/1.9.0          18) SQLite/3.33.0
  5) GCC/10.2.0      12) libfabric/1.11.0   19) GMP/6.2.0
  6) numactl/2.0.13  13) OpenMPI/4.0.5      20) libffi/3.3
  7) XZ/5.2.5        14) bzip2/1.0.8        21) Python/3.8.6
[netid@dev-amd20 ~]$ module load GROMACS
[netid@dev-amd20 ~]$ module list
Currently Loaded Modules:
Currently Loaded Modules:
  1) powertools/1.2     11) UCX/1.9.0         21) Python/3.8.6
  2) GCCcore/10.2.0     12) libfabric/1.11.0  22) OpenBLAS/0.3.13
  3) zlib/1.2.11        13) OpenMPI/4.0.5     23) FFTW/3.3.8
  4) binutils/2.35      14) bzip2/1.0.8       24) ScaLAPACK/2.1.0
  5) GCC/10.2.0         15) ncurses/6.2       25) pybind11/2.6.0
  6) numactl/2.0.13     16) libreadline/8.0   26) SciPy-bundle/2020.11
  7) XZ/5.2.5           17) Tcl/8.6.10        27) networkx/2.5
  8) libxml2/2.9.10     18) SQLite/3.33.0     28) GROMACS/2021
  9) libpciaccess/0.16  19) GMP/6.2.0
 10) hwloc/2.2.0        20) libffi/3.3

So in this case, loading the GROMACS module (a bioinformatics software package), also loaded GMP/6.2.0 and SciPy-bundle/2020.11 as well. Let’s try unloading the GROMACS package.

[netid@dev-amd20 ~]$ module unload GROMACS
[netid@dev-amd20 ~]$ module list
Currently Loaded Modules:
  1) powertools/1.2   8) libxml2/2.9.10     15) ncurses/6.2
  2) GCCcore/10.2.0   9) libpciaccess/0.16  16) libreadline/8.0
  3) zlib/1.2.11     10) hwloc/2.2.0        17) Tcl/8.6.10
  4) binutils/2.35   11) UCX/1.9.0          18) SQLite/3.33.0
  5) GCC/10.2.0      12) libfabric/1.11.0   19) GMP/6.2.0
  6) numactl/2.0.13  13) OpenMPI/4.0.5      20) libffi/3.3
  7) XZ/5.2.5        14) bzip2/1.0.8        21) Python/3.8.6

So using module unload “un-loads” a module, and depending on how a site is configured it may also unload all of the dependencies (in our case it does). If we wanted to unload everything at once, we could run module purge (unloads everything).

[netid@dev-amd20 ~]$ module purge
[netid@dev-amd20 ~]$ module list
No modules loaded

Note that module purge is informative. It will also let us know if a default set of “sticky” packages cannot be unloaded (and how to actually unload these if we truly so desired).

Note that this module loading process happens principally through the manipulation of environment variables like $PATH. There is usually little or no data transfer involved.

The module loading process manipulates other special environment variables as well, including variables that influence where the system looks for software libraries, and sometimes variables which tell commercial software packages where to find license servers.

The module command also restores these shell environment variables to their previous state when a module is unloaded.

Using Software Modules in Scripts

Create a job that is able to run python3 --version. Remember, no software is loaded by default! Running a job is just like logging on to the system (you should not assume a module loaded on the login node is loaded on a compute node).

Solution

[netid@dev-amd20 ~]$ nano python-module.sh
[netid@dev-amd20 ~]$ cat python-module.sh
#!/usr/bin/env bash
#SBATCH #SBATCH -t 00:00:30

module purge
module load GCC/10.2.0 OpenMPI/4.0.5 Python/3.8.6

python3 --version
[netid@dev-amd20 ~]$ sbatch python-module.sh

Software Versioning

So far, we’ve learned how to load and unload software packages. This is very useful. However, we have not yet addressed the issue of software versioning. At some point or other, you will run into issues where only one particular version of some software will be suitable. Perhaps a key bugfix only happened in a certain version, or version X broke compatibility with a file format you use. In either of these example cases, it helps to be very specific about what software is loaded.

Let’s use Python 3 as an example and try to load another version. We can see what versions are available using the module spider command:

[netid@dev-amd20 ~]$ module spider Python
----------------------------------------------------------------------------
  Python:
----------------------------------------------------------------------------
    Description:
      Python is a programming language that lets you work more quickly and
      integrate your systems more effectively.

     Versions:
        Python/2.7.9
        Python/2.7.10
        Python/2.7.11
...skipping...
        Python/3.10.8-bare
        Python/3.10.8
        Python/3.11.3
     Other possible modules matches:
        Biopython  Boost.Python  GitPython  IPython  ScientificPython  ...

----------------------------------------------------------------------------
  To find other possible module matches execute:

      $ module -r spider '.*Python.*'

----------------------------------------------------------------------------
  For detailed information about a specific "Python" package (including how to load the modules) use the module's full name.
  Note that names that have a trailing (E) are extensions provided by other modules.
  For example:

     $ module spider Python/3.11.3
----------------------------------------------------------------------------

To find out what command to use to load a specific version, we can use module spider with that version:

 module spider Python/3.11.3
----------------------------------------------------------------------------
  Python: Python/3.11.3
----------------------------------------------------------------------------
    Description:
      Python is a programming language that lets you work more quickly and
      integrate your systems more effectively.


    You will need to load all module(s) on any one of the lines below before the "Python/3.11.3" module is available to load.

      GCCcore/12.3.0
 
    Help:
      Description
      ===========
      Python is a programming language that lets you work more quickly and integrate your systems
       more effectively.
      
      
      More information
      ================
       - Homepage: https://python.org/
      
      
      Included extensions
      ===================
      flit_core-3.9.0, pip-23.1.2, setuptools-67.7.2, wheel-0.40.0

In this case, we need to load the GCCcore/12.3.0 module first first, since Python/3.11.3 needs it to be able to run

[netid@dev-amd20 ~]$ module load GCCcore/12.3.0 Python/3.11.3

Dependency consistency

If you need to load multiple pieces of software at the same time, you need to make sure they use the same versions of any common dependencies. There is unfortunately not a good solution to this yet! The best way is to use module spider on different versions to try to find a match.

Key Points

  • Load software with module load softwareName.

  • Unload software with module unload

  • Clean out all loaded modules with module purge to avoid conflicts

  • Multiple pieces of software need to use compatible dependencies