[[PageOutline]] = Running Python on Cypress = == Python Modules == As of August 18th, 2015 there are three (3) versions of Python available on Cypress * Python 2.6.6 is loaded by default for al users * Python 2.7.8 is available as part of the Anaconda module * Python 2.7.10 is available as a stand alone module We currently do not have Python 3 installed on Cypress as we have had no requests for Python 3. === Anaconda === As the name implies, Anaconda is a larger version of Python. In addition to Python 2.7.8, Anaconda includes over 300 of the most requested Python packages. This includes * !NumPy * Pandas * !SciPy * Matplotlib * IPython. A complete list of packages available though Anaconda can be found [http://docs.continuum.io/anaconda/pkg-docs here]. ==== Install Packages to Anaconda Python ==== 'conda' is the command to add packages to Anaconda python distribution. However, since you don't have a permission in /share/apps/anaconda, it won't work. There is a workaround. Here, for example, we want to add 'vtk' python wrapper library. {{{ conda install vtk }}} But you will see an error message with an instruction for the workaround. First clone the python environment into your home directory by {{{ conda create -n my_root --clone=/share/apps/anaconda/2/2.5.0 }}} then, {{{ source activate my_root }}} Finally, you can install the package, {{{ conda install vtk }}} In case you encounter "Error: 'conda' can only be installed into the root environment", try {{{ conda remove conda-build conda remoce conda-env conda update -all conda install vtk }}} From next time, to use Anaconda python, {{{ module load anaconda source activate my_root }}} == Installing Packages == One of the best things about Python is the number of packages provided by the user community. On a personal machine, the most popular method today for managing these packages is the use of a package manager, like pip. Unfortunately, these require root access and are not a viable solution on Cypress. There is an easy solution. Any well written Python package will allow the user to perform a "user only installation." This typically only requires the addition of a single flag when installing the package. As an example, let's install the package Parallel Python (pp). If you wish to follow along, the package can be downloaded [http://www.parallelpython.com/content/view/18/32/ here]. When you have the packages tar file in the desired directory, you can unpack it with the '''tar''' command {{{ [tulaneID@cypress1 ~]$ tar -xvf pp-1.6.4.tar.gz pp-1.6.4/ pp-1.6.4/doc/ pp-1.6.4/doc/ppserver.1 pp-1.6.4/doc/example.config pp-1.6.4/doc/ppdoc.html pp-1.6.4/pp.py pp-1.6.4/README pp-1.6.4/pptransport.py pp-1.6.4/PKG-INFO pp-1.6.4/ppcommon.py pp-1.6.4/ppserver.py pp-1.6.4/ppworker.py pp-1.6.4/CHANGELOG pp-1.6.4/MANIFEST.in pp-1.6.4/AUTHORS pp-1.6.4/ppauto.py pp-1.6.4/setup.py pp-1.6.4/examples/ pp-1.6.4/examples/reverse_md5.py pp-1.6.4/examples/sum_primes_functor.py pp-1.6.4/examples/auto_diff.py pp-1.6.4/examples/callback.py pp-1.6.4/examples/quicksort.py pp-1.6.4/examples/dynamic_ncpus.py pp-1.6.4/examples/sum_primes.py pp-1.6.4/COPYING [tulaneID@cypress1 ~]$ }}} Now move into the package directory and examine the README file {{{ [tulaneID@cypress1 ~]$ cd pp-1.6.4 [tulaneID@cypress1 pp-1.6.4]$ ls AUTHORS COPYING examples PKG-INFO ppcommon.py ppserver.py ppworker.py setup.py CHANGELOG doc MANIFEST.in ppauto.py pp.py pptransport.py README [tulaneID@cypress1 pp-1.6.4]$ cat README Visit http://www.parallelpython.com for up-to-date documentation, examples and support forums INSTALATION: python setup.py install LOCAL DOCUMENTATION: pydoc.html }}} After using idev to launch and interactive session,let's try their instructions {{{ [tulaneID@cypress01-035 pp-1.6.4]$ python setup.py install running install running build running build_py creating build creating build/lib copying pp.py -> build/lib copying ppauto.py -> build/lib copying ppcommon.py -> build/lib copying pptransport.py -> build/lib copying ppworker.py -> build/lib running build_scripts creating build/scripts-2.7 copying and adjusting ppserver.py -> build/scripts-2.7 changing mode of build/scripts-2.7/ppserver.py from 644 to 755 running install_lib copying build/lib/pptransport.py -> /share/apps/anaconda/2.1.0/lib/python2.7/site-packages error: [Errno 13] Permission denied: '/share/apps/anaconda/2.1.0/lib/python2.7/site-packages/pptransport.py' [tulaneID@cypress01-035 pp-1.6.4]$ }}} Our installation failed because we lack the permissions to add files to the system wide Python installation. But that's not what we want anyway, we just want to install the package for our personal use. We need to add the flag '''- -prefix=$HOME''' to tell the installer where to place the package. {{{ [tulaneID@cypress01-035 pp-1.6.4]$ python setup.py install --prefix=$HOME running install running build running build_py running build_scripts running install_lib creating /home/tulaneID/lib creating /home/tulaneID/lib/python2.7 creating /home/tulaneID/lib/python2.7/site-packages copying build/lib/pptransport.py -> /home/tulaneID/lib/python2.7/site-packages copying build/lib/pp.py -> /home/tulaneID/lib/python2.7/site-packages copying build/lib/ppworker.py -> /home/tulaneID/lib/python2.7/site-packages copying build/lib/ppcommon.py -> /home/tulaneID/lib/python2.7/site-packages copying build/lib/ppauto.py -> /home/tulaneID/lib/python2.7/site-packages byte-compiling /home/tulaneID/lib/python2.7/site-packages/pptransport.py to pptransport.pyc byte-compiling /home/tulaneID/lib/python2.7/site-packages/pp.py to pp.pyc byte-compiling /home/tulaneID/lib/python2.7/site-packages/ppworker.py to ppworker.pyc byte-compiling /home/tulaneID/lib/python2.7/site-packages/ppcommon.py to ppcommon.pyc byte-compiling /home/tulaneID/lib/python2.7/site-packages/ppauto.py to ppauto.pyc running install_scripts copying build/scripts-2.7/ppserver.py -> /home/tulaneID/bin changing mode of /home/tulaneID/bin/ppserver.py to 755 running install_egg_info Writing /home/tulaneID/lib/python2.7/site-packages/pp-1.6.4-py2.7.egg-info }}} We now have our own personal build of parallel python. {{{ [tulaneID@cypress01-035 pp-1.6.4]$ python Python 2.7.8 |Anaconda 2.1.0 (64-bit)| (default, Aug 21 2014, 18:22:21) [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2 Type "help", "copyright", "credits" or "license" for more information. Anaconda is brought to you by Continuum Analytics. Please check out: http://continuum.io/thanks and https://binstar.org >>> import pp >>> pp.version '1.6.4' >>> }}} == Running Python Interactively == Start an interactive session using idev {{{ [tulaneID@cypress1 pp-1.6.4]$ idev Requesting 1 node(s) task(s) to normal queue of defq partition 1 task(s)/node, 20 cpu(s)/task, 2 MIC device(s)/node Time: 0 (hr) 60 (min). Submitted batch job 52311 Seems your requst is pending. JOBID=52311 begin on cypress01-035 --> Creating interactive terminal session (login) on node cypress01-035. --> You have 0 (hr) 60 (min). [tulaneID@cypress01-035 pp-1.6.4]$ }}} Load the desired Python module {{{ [tulaneID@cypress01-035 pp-1.6.4]$ module load anaconda [tulaneID@cypress01-035 pp-1.6.4]$ module list Currently Loaded Modulefiles: 1) git/2.4.1 3) idev 5) anaconda/2.1.0 2) slurm/14.03.0 4) bbcp/amd64_rhel60 }}} Run Python in the command line window {{{ [tulaneID@cypress01-035 pp-1.6.4]$ python Python 2.7.8 |Anaconda 2.1.0 (64-bit)| (default, Aug 21 2014, 18:22:21) [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2 Type "help", "copyright", "credits" or "license" for more information. Anaconda is brought to you by Continuum Analytics. Please check out: http://continuum.io/thanks and https://binstar.org >>> }}} == Running a Python script in Batch mode == You can also submit your Python job to the batch nodes (compute nodes) on Cypress. Inside your SLURM script, include a command to load the desired Python module. Then invoke '''python''' on your python script. {{{#!bash #!/bin/bash #SBATCH --qos=normal # Quality of Service #SBATCH --job-name=python # Job Name #SBATCH --time=00:01:00 # WallTime #SBATCH --nodes=1 # Number of Nodes #SBATCH --ntasks-per-node=1 # Number of tasks (MPI processes) #SBATCH --cpus-per-task=1 # Number of threads per task (OMP threads) module load anaconda python mypythonscript.py }}} == Running a Parallel Python Job == The exact configuration of you parallel job script will depend on the flavor of parallelism that you choose for you Python script. As an example we will use the Parallel Python (pp) package that we installed above. Parallel Python used the shared memory model of parallelism (analogous to to OpenMP). Let's run the [http://www.parallelpython.com/content/view/17/31/ sum of primes] example from the Parallel Python website. We need to communicate the number of cores we wish to use to our script. The syntax here is {{{ python sum_primes.py [ncpus] }}} We can communicate the SLURM parameters to the script using the appropriate SLURM environment variable. {{{#!bash #!/bin/bash #SBATCH --qos=normal # Quality of Service #SBATCH --job-name=python # Job Name #SBATCH --time=00:01:00 # WallTime #SBATCH --nodes=1 # Number of Nodes #SBATCH --ntasks-per-node=1 # Number of tasks (MPI processes) #SBATCH --cpus-per-task=15 # Number of threads per task (OMP threads) module load anaconda python sum_primes.py $SLURM_CPUS_PER_TASK }}}