How to run Enthought Canopy on maya

Introduction

On this page we’ll see how to use Enthought Canopy on the maya cluster. Before proceeding, make sure you’ve read the How To Run tutorial first. Enthought Canopy 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 maya. To enable the Enthought version, enter one of the following commands

[araim1@maya-usr1 ~]$ module load enthought
... OR ...
[araim1@maya-usr1 ~]$ module load enthought/canopy

The “enthought/canopy” module loads the latest installed version of Enthought. This must be done before running your Python code, either interactively or through the batch system. To verify that you are using the correct version of python enter the following command

[araim1@maya-usr1 ~]$ which python
/usr/cluster/Enthought/Canopy_64/User/bin/python

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 enthought
./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.


Download: ..code/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 enthought” command in your current shell session. We suggest these modifications to your batch script regardless, as a best practice.


Download: ..code/epd_hello/hello.py

Now we launch the job

[araim1@maya-usr1 epd_hello]$ module load enthought
[araim1@maya-usr1 epd_hello]$ sbatch run.slurm
sbatch: Submitted batch job 2618
[araim1@maya-usr1 epd_hello]$ ls
hello.py  run.slurm  slurm.err  slurm.out
[araim1@maya-usr1 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@maya-usr1 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 “python” command. Longer jobs should run on compute nodes, see Interacting with compute nodes.

[araim1@maya-usr1 epd_hello]$ module load enthought
[araim1@maya-usr1 epd_hello]$ python 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@maya-usr1 epd_hello]$ 

Running Python interactively

Python can also be used interatively on the user node, as in the following example

[araim1@maya-usr1 ~]$ module load enthought
[araim1@maya-usr1 ~]$ python
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@maya-usr1 ~]$