# Conda

Another example of **conda** environment setup.

##### Login on the submit node

Login on the cluster submission node, check the page *[How to Access](https://wiki.incd.pt/books/how-to-access)* for more information:

    $ ssh -l <username> cirrus.ncg.ingrid.pt
    [username@cirrus ~]$ _

##### Prepare a conda virtual environment

The default **python** version for *CentOS 7.x* is ***2.7.5*** which is not suitable for many applications. So, we will create a **python** virtual environment:

	[username@cirrus ~]$ conda create -n myconda python=3.6
    [username@cirrus ~]$ conda activate myconda
    
On the first command, where we create the **conda** virtual environment, you can include a list of applications to include on your environmnet, for example:

	[username@cirrus ~]$ conda create -n myconda python=3.6 ipython-notebook numpy=1.6

##### Manage the conda virtual environment

It is possible to include additional packages to your **conda** environment, for example:

	[username@cirrus ~]$ conda activate myconda
    [username@cirrus ~]$ conda install numpy

You can update your software bandle on the **conda** virtual environment with the command:

	[username@cirrus ~]$ conda update [scipy ...]

or remove a specific application:

	[username@cirrus ~]$ conda uninstall tensorflow-gpu

Check the **conda** help for more information:

	[username@cirrus ~]$ conda help
    [username@cirrus ~]$ conda install --help

##### Manage the conda packages list with pip

It is possible to complemment the **conda** virtual environment packages list with **pip**. For example:

	[username@cirrus ~]$ conda activate myconda
    [username@cirrus ~]$ pip install --upgrade pip
    [username@cirrus ~]$ pip install --upgrade setuptools
    [username@cirrus ~]$ pip install tensorflow-gpu
    [username@cirrus ~]$ pip install keras

##### Manage packages versions

If the applications available on **conda** virtual environment do not match your version requirements you may need to use packages from **pip** repostory; check the availability of ***conda search*** and ***pip search*** command line interfaces.

As an example we have the **tensorflow-gpu** package, when used with **keras**, the **conda** repository downgrades ***tensorflow-gpu** to version *1.15*, but you most likely will prefer version *2.0*. The **pip** repository has the right combination of **tensorflow-gpu** and **keras** packages.

***We advise the user to install a package from only one repository in order to guarantee perfect behaviour.***

##### Load conda environment on a batch job

Create a submit script:

	[username@cirrus ~]$ cat submit.sh 
	
	#!/bin/bash
	
	#SBATCH --job-name=MyFirstSlurmJob
	#SBATCH --time=0:10:0
	#SBATCH --nodes=1
	#SBATCH --ntasks-per-node=16

	# Be sure to request the correct partition to avoid the job to be held in the queue, furthermore
	#	on CIRRUS-B (Minho)  choose for example HPC_4_Days
	#	on CIRRUS-A (Lisbon) choose for example hpc
	#SBATCH --partition=HPC_4_Days

    # check python version
    python --version
    
	# Load conda environment
	conda activate myconda

    # recheck python version
    python --version

	# your job payload
    #....

Submit:

	[username@cirrus ~]$ sbatch submit.sh
    Your job 2037792 ("submit.sh") has been submitted

After completion:

	[username@hpc7 ~]$ ls -l
    -rwxr-----+ 1 username hpc    668 Jan  7 12:19 submit.sh
	-rw-r-----+ 1 username hpc     44 Jan  7 12:18 submit.sh.e2037792
	-rw-r-----+ 1 username hpc      0 Jan  7 12:18 submit.sh.o2037792
    
    [username@cirrus ~]$ cat submit.sh.e2037792
    Python 2.7.5
	Python 3.6.9 :: Anaconda, Inc.

##### Some References

* [GitHub OS-agnostic](https://github.com/conda/conda)
* [Anaconda Documentation](https://docs.anaconda.com/anaconda)
* [Conda Documentation](https://docs.conda.io/en/latest)