UMBC logo
UMBC High Performance Computing Facility
How to run Enthought Python on tara

Introduction

On this page we'll see how to use Enthought Python on the tara cluster. Before proceeding, make sure you've read the How To Run tutorial first. Enthought Python is a distribution of the Python scripting language intended for scientific computing. It can be used interactively or through scripting.

Loading the module

There are several versions of Python installed on tara. To enable the Enthought version, enter the following command

[araim1@tara-fe1 ~]$ module load epd
This must be done before running your Python code, either interactively or through the batch system. If you forget to load the module, your code will not run. Alternatively, you can load the module from within a shell script (e.g. from your submission script) as follows
#!/bin/bash -l
#SBATCH --job-name=hello_python
#SBATCH --output=slurm.out
#SBATCH --error=slurm.err
#SBATCH --partition=develop

module load epd
./myscript.py
Notice the "-l" argument on the first line, which is necessary. (This allows Bash to use the "module" alias).

Example batch script

We'll write a simple Python script that says "hello", and uses the SciPy and NumPy packages to do some simple linear algebra operations.
#!/bin/env python2.6

import numpy as np
from scipy import linalg

print "Hello world!"
A = np.mat('[1 3 5; 2 5 1; 2 3 8]')

print "\nA ="
print A

print "\ninv(A) ="
print linalg.inv(A)

print "\ndet(A) = ", linalg.det(A)

Download: ../code-2010/epd_hello/hello.py
We can launch it with a standard SLURM script. Again, we'll specify the "-l" option to Bash and load the module from within the batch script. The script will probably function correctly if you haven't made these additions, but have entered the "module load epd" command in your current shell session. We suggest these modifications to your batch script regardless, as a best practice.
#!/bin/bash -l
#SBATCH --job-name=hello_python
#SBATCH --output=slurm.out
#SBATCH --error=slurm.err
#SBATCH --partition=develop

module load epd
./hello.py

Download: ../code-2010/epd_hello/run.slurm
Now we launch the job
[araim1@tara-fe1 epd_hello]$ module load epd
[araim1@tara-fe1 epd_hello]$ sbatch run.slurm
sbatch: Submitted batch job 2618
[araim1@tara-fe1 epd_hello]$ ls
hello.py  run.slurm  slurm.err  slurm.out
[araim1@tara-fe1 epd_hello]$ cat slurm.out
Hello world!

A =
[[1 3 5]
 [2 5 1]
 [2 3 8]]

inv(A) =
[[-1.48  0.36  0.88]
 [ 0.56  0.08 -0.36]
 [ 0.16 -0.12  0.04]]

det(A) =  -25.0
[araim1@tara-fe1 epd_hello]$
Also note that hello.py can be run directly on the user node (which is okay here because it's a small job) using the "python2.6" command
[araim1@tara-fe1 epd_hello]$ module load epd
[araim1@tara-fe1 epd_hello]$ python2.6 hello.py
Hello world!

A =
[[1 3 5]
 [2 5 1]
 [2 3 8]]

inv(A) =
[[-1.48  0.36  0.88]
 [ 0.56  0.08 -0.36]
 [ 0.16 -0.12  0.04]]

det(A) =  -25.0
[araim1@tara-fe1 epd_hello]$ 

Running Python interactively

Python can also be used interatively on the user node, as in the following example
[araim1@tara-fe1 ~]$ module load epd
[araim1@tara-fe1 ~]$ python2.6
Enthought Python Distribution -- http://www.enthought.com
...
>>> import numpy as np
>>> from scipy import linalg
>>> print "Hello world!"
Hello world!
>>> A = np.mat('[1 3 5; 2 5 1; 2 3 8]')
>>> print A
[[1 3 5]
 [2 5 1]
 [2 3 8]]
>>> linalg.inv(A)
array([[-1.48,  0.36,  0.88],
       [ 0.56,  0.08, -0.36],
       [ 0.16, -0.12,  0.04]])
>>> linalg.det(A)
-25.000000000000004
>>> quit()
[araim1@tara-fe1 ~]$ 
As always, this should only be used for smaller computations. Intensive programs should be submitted to the compute nodes.