BinAC/Software/Conda

From bwHPC Wiki
Jump to navigation Jump to search
Caution
The licensing situation with Anaconda is currently unclear. To be on the safe side, make sure to not use the defaults channel


Use Conda Environments on BinAC

Conda can be used to easily install software (usually Python packages) in dedicated environments in your own workspace.

On BinAC, you can simply load the Miniforge module and start creating environments.

Use the centrally installed Miniforge Module

The module `devel/miniforge` provides a central conda installation on BinAC.

module load devel/miniforge

The old module environment on BinAC is not able to init everything for your current shell, you have to do it by hand. Also add this to your jobscripts.

source ${MINIFORGE_HOME}/.bashrc

You can now use the `conda` command:

$ which conda
/opt/bwhpc/common/devel/miniforge/24.9.0/condabin/conda

Controle environment location

New conda environments are created in your home directory by default. As there is a quota on your home directory you may want to store them in a workspace:

# Create workspace:
ws_allocate conda <days>   # e.g. 100

The last step defines the newly created workspace as the download and installation path for your environments:

conda config --prepend envs_dirs $( ws_find conda )/conda/envs
conda config --prepend pkgs_dirs $( ws_find conda )/conda/pkgs
conda config --show envs_dirs
conda config --show pkgs_dirs

If you don't specify a new envs_dir Conda will use ~/.conda/envs in your home directory as the default installation path (same applies to pkgs_dirs).

Install Packages into Environments

You can create environments and install packages into these environments or create them during install.

conda create -n scipy_env
conda activate scipy_env

Create a new environment and install packages into it with a single command:

conda create -n scipy_env scipy
conda activate scipy_env

Search for an exact version:

conda search scipy==1.7.3

It is also not a problem to install older Python versions:

conda create -n scipy-py27 scipy python=2.7
conda activate scipy-py27

Activating Environments

To use the software in an environment, you must first activate it:

conda activate scipy

Disable the environment to load a different environment:

conda deactivate

List packages and Environments

List packages of current environment:

conda list

List packages in given environment:

conda list -n scipy

List environments:

conda env list

Configure Channels

Add channels to get more software. We suggest to try the following channels:

conda-forge
bioconda
Caution
The licensing situation with Anaconda is currently unclear. To be on the safe side, make sure to not use the defaults channel

You can add channel to your configuration, but than you'll search and install automatically from this channel:

conda config --add channels bioconda
conda config --show channels
conda config --remove channels bioconda   # remove channel again

Deleting environments

Example:

conda env remove -n scipy-1.7.3 --all

Create Reproducible Conda Environments

This section is intended for advanced users who want to secure environments and create reproducible environments.

For a more detailed environments documentation refer to the conda documentation.

Create an environment file for re-creation:

conda env export -n scipy-1.7.3 -f scipy-1.7.3.yml

Re-create saved environment:

conda env create -f scipy-1.7.3.yml

Create a file with full URL for re-installation of packages:

conda list --explicit -n scipy-1.7.3 >scipy-1.7.3.txt

Install requirements file into environment:

conda create --name scipy-1.7.3 --file scipy-1.7.3.txt

The first backup option is from the conda-env command and tries to reproduce the environment by name and version. The second option comes from the conda command itself and specifies the location of the file, as well. You can install the identical packages into a newly created environment. Please verify the architecture first.

To clone an existing environment:

conda create --name scipy-1.7.3-clone --clone scipy-1.7.3

Versioning

Please keep in mind that modifying, updating and installing new packages into existing environments can modify the outcome of your results. We strongly encourage researchers to creating new environments (or cloning) before installing or updating packages. Consider using meaningful names for your environments using version numbers and dependencies.

Constraint Specification
exact version scipy==1.7.3
fuzzy version scipy=1.7
greater equal "scipy>=1.7"

For more information see cheat sheet below.

Example:

conda create -c intel -n scipy-1.7.3 scipy==1.7.3=py39h5c0f66f_1

Cheat Sheet

Conda official cheat sheet