Conda

Conda is an open-source package management system and environment management system that runs on Windows, macOS, and Linux. Conda quickly installs, runs, and updates packages and their dependencies. Conda as a package manager helps you find and install packages.

For more information see conda documentation

How to Install Conda?

You can use the SStack tool to install Conda to manage software on discovery.

For example, to install Conda stack named 2024A in your home directory, run command:

sstack install -t conda -n 2024A

This creates a module file that you can load in your environment to be able to use the stack to manage software, as shown in the following:

module use "/home/tahat/sstack/modules"
module load conda/2024A

To check if conda is loaded and what version is it, run the following command:

conda --version

Output

conda 4.13.0

How to Use Conda to Manage Software?

You can use conda to install packages in your environment. For example, to install matplotlib, run command:

conda install matplotlib

Once the installation is completed successfully, you can check if the package is available. To check if matplotlib is available, run command:

conda list matplotlib

Output

# packages in environment at /home/tahat/sstack/stacks/conda/2024A:
#
# Name                    Version                   Build  Channel
matplotlib                3.5.2           py310hff52083_0    conda-forge
matplotlib-base           3.5.2           py310h5701ce4_0    conda-forge
matplotlib-inline         0.1.3              pyhd8ed1ab_0    conda-forge

Create a Virtual Environmnet

Conda allows you to create a new conda environment. The simplest way you can create a new conda environment is like so:

conda create -n <env-name>

For example, to create a new environment named myproject, run command:

conda create -n myproject

To check all environmnets, run command:

conda env list

Output

# conda environments:
#
base                  *  /home/tahat/sstack/stacks/conda/2022A
myproject                /home/tahat/sstack/stacks/conda/2022A/envs/myproject

The output shows that the created environmnet is available and you can use it. It also that you are in the base environmnet.

Create a Module for Virtual Environment

Once you create a conda environmnet, you can create a module file for it. This will add the environment to the module system where you can load it in your enviroument. A module named base was created when the conda stack was installed. To see if the base module is available, run command:

module avail base

-------------------------------------------------------- /home/tahat/sstack/stacks/conda/2024A/modules ---------------------------------------------------------
   base

Use "module spider" to find all possible modules and extensions.
Use "module keyword key1 key2 ..." to search for all possible modules matching any of the "keys".

You need to create module file having the same name of your created environmnet in the same path of base module file (base.lua). To find where to add the module file and what contents you need to add to it, run command:

module --raw show base

Output

------------------------------------------------------------------------------------------------------------------------------------------------------------
   /home/tahat/sstack/stacks/conda/2024A/modules/base.lua:
------------------------------------------------------------------------------------------------------------------------------------------------------------
help([[For help contact hpc-team@nmsu.edu]])
whatis([[Name : conda Base Env]])
whatis([[Version: Latest]])
whatis([[Target: x86_64]])
whatis([[Short description :  This is a redundant module to load the base conda environment as an example.]])

family("conda_env")

-- Modify String In Quotes To Match Desired Environment Name or Path
local env_name = "base"
-- Don't forget to update line 2/3 aswell to update the Module Name/Version

execute{cmd="conda activate " .. env_name,modeA={"load"}}
execute{cmd="conda deactivate",modeA={"unload"}}

The above output shows that base.lua is in /home/tahat/sstack/stacks/conda/2024A/modules. You need to create a module file myproject.lua in the same path, as follows:

touch /home/tahat/sstack/stacks/conda/2024A/modules/myproject.lua

Now, you need to copy the content of the base.lua file into myproject.lua.

cp /home/tahat/sstack/stacks/conda/2024A/modules/base.lua /home/tahat/sstack/stacks/conda/2024A/modules/myproject.lua

Now you need to update myproject.lua to have the correct environment name env_name as commented in line 9 in the file.

vim /home/tahat/sstack/stacks/conda/2024A/modules/myproject.lua

Update line 2 and 10, with the correct env-name.

help([[For help contact hpc-team@nmsu.edu]])
whatis([[Name : conda myproject Env]])
whatis([[Version: Latest]])
whatis([[Target: x86_64]])
whatis([[Short description :  This is a redundant module to load the base conda environment as an example.]])

family("conda_env")

-- Modify String In Quotes To Match Desired Environment Name or Path
local env_name = "myproject"
-- Don't forget to update line 2/3 aswell to update the Module Name/Version

execute{cmd="conda activate " .. env_name,modeA={"load"}}
execute{cmd="conda deactivate",modeA={"unload"}}

Check if the created module is available:

module avail myproject

Output

-------------------------------------------------------- /home/tahat/sstack/stacks/conda/2024A/modules ---------------------------------------------------------
   myproject

Use "module spider" to find all possible modules and extensions.
Use "module keyword key1 key2 ..." to search for all possible modules matching any of the "keys".

For more information see conda documentation