[[PageOutline]] = Running Python on Cypress = == Python Modules == For python as well as all other computationally intensive workloads, you should always use a compute node, either interactively or in batch, rather than a login node. (See [[cypress/Python#RunningPythonInteractively|below]].) To query your working version of python, you can always use the command **python ----version** regardless of whether or not you use a module or a conda virtual environment (see [PytonInstallPackage here]). The default version of python on Cypress is Python 2.6.6 {{{ [tulaneID@cypress1 ~]$python --version Python 2.6.6 }}} Other versions of python are available on Cypress via modules with the following major names. (See [ModuleCommand Module command]). * python * anaconda * anaconda3 For example, the following is a query in short format for modules on Cypress using the search pattern **anaconda**. {{{ [tulaneID@cypress1 ~]$module avail -t anaconda /cm/local/modulefiles: /cm/shared/modulefiles: /share/apps/modulefiles: anaconda/2.1.0 anaconda/2.5.0 anaconda3/2018.12 anaconda3/2019.03 anaconda3/2020.07 anaconda3/4.0.0 anaconda3/5.1.0 /share/apps/centos7/modulefiles: anaconda3/2023.07 }}} In particular, for any module listed under /share/apps/centos7, you'll need to use a compute node in partition **centos7** (see [[cypress/using#Requestingpartitioncentos7withglibc2.17|here]]). === Anaconda === As the name implies, Anaconda and later Anaconda3 are larger versions of Python. In addition to Python 2.7.8 in Anaconda and Python 3.x in Anaconda3, over 300 of the most requested Python packages are also available. This includes * !NumPy * Pandas * !SciPy * Matplotlib * IPython. A complete list of packages available though Anaconda can be found [https://docs.anaconda.com/anaconda/packages/py3.7_linux-64 here]. ==== Install Packages to Anaconda Python ==== If you want to use some package but Anaconda on Cypress doesn't have it, you can install it on your home directory. See [[AnacondaInstallPackage|here]]. == 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 {{{#!python [tulaneID@cypress01-035 pp-1.6.4]$ ipython Python 2.7.11 |Anaconda 2.5.0 (64-bit)| (default, Dec 6 2015, 18:08:32) Type "copyright", "credits" or "license" for more information. IPython 4.1.2 -- An enhanced Interactive Python. ? -> Introduction and overview of IPython's features. %quickref -> Quick reference. help -> Python's own help system. object? -> Details about 'object', use 'object??' for extra details. In [1]: }}} == 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 }}} == Jupyter Notebook == The [http://jupyter.org/ Jupyter Notebook] is a web application that allows you to create and share documents that contain live code, equations, visualizations and explanatory text. [JupyterNode Here] show an example. == Installing Packages == See [PytonInstallPackage here].