Compute2: Using Anaconda3 through Lmod

You can use our service desk portal for getting RIS support. RIS also offers 15 min. virtual office hours session Mon-Thru..

Compute2: Using Anaconda3 through Lmod

Overview

This page provides the basics of how to use Anaconda3 on the Compute2 platform through command line.

Load Modules

  • Load the RIS THPC module environment first.

    $ module load ris
  • Load the Anaconda3 module.

    $ module load anaconda3

Activating the base environment

  • The (base) environment needs to be activated before using other conda commands

    $ source activate
  • Once conda has been activated, users will need to start a job as work should not be run on the login nodes.

    (base) $ srun -A compute2-account -p general-interactive --pty /bin/bash

Setting Up a Conda Directory

  • By default, conda will use $HOME/.conda directory as the source for installing. Given that $HOME directories are limited in space, it is highly recommended to use a Storage Platform for packages.

  • The following conda variables can be set either before or while running an interactive job.

    (base) $ export CONDA_ENVS_PATH="/storageN/fs1/allocation_name/Active/conda/envs" (base) $ export CONDA_PKGS_DIRS="/storageN/fs1/allocation_name/Active/conda/pkgs"
  • Once these are set, conda will use those directories as a source for environments and packages.

  • These variables can also be set in the .bashrc file so that they are set upon login.

Please DO NOT COPY the above code. Replace above path with accurate storage allocation/folder paths.

Creating a Conda Environment

  • Make sure to be working in an interactive job and not on the login clients.

    (base) $ srun -A compute2-account -p general-interactive --pty /bin/bash
  • While not a requirement, it is recommended that a .yml file is used when creating an environment.

  • Create the .yml file. An example is below.

    name: example channels: - conda-forge - bioconda dependencies: - python=3.12 - pip
  • Create the environment using the .yml file.

    (base) $ conda env create -f environment.yml

Activate the Environment

  • Once the environment has been created, it can now be activated and used.

    (base) $ conda activate example

Deactivate the Environment

  • Once work has been completed you can deactivate the environment if needed.

    (example) $ conda deactivate
  • This should put you back in the (base) environment. You can deactivate this one as well.

    (base) $ conda deactivate

Using a Conda Environment in Jobs

  • Users will need to make sure the ris and anaconda3 modules are loaded as part of the job.

  • Users will need to make sure the Conda environment variables are set either in their .bashrc or as part of running a job.

  • Users will need to make sure to activate the Conda environment as part of the job.

Interactive Job (srun)

$ module load ris $ srun -A compute2-groupname -p general-interactive --pty /bin/bash $ module load anaconda3 $ source activate $ export CONDA_ENVS_DIRS="/storageN/fs1/allocation_name/Active/conda/envs" $ export CONDA_PKGS_DIRS="/storageN/fs1/allocation_name/Active/conda/pkgs" $ conda activate example $ python helloworld.py

Lines 5 and 6 are not required if you have these variables in your .bashrc file.

Batch Job

  • In addition to the above, for a batch job, users will need to source the .bashrc file.

  • Example job file: example.slurm.

    #!/bin/bash #SBATCH -A compute2-account #SBATCH -p general-cpu #SBATCH --output=example.log export CONDA_ENVS_DIRS="/storageN/fs1/allocation_name/Active/conda/envs" export CONDA_PKGS_DIRS="/storageN/fs1/allocation_name/Active/conda/pkgs" module load ris shared module load anaconda3 source activate conda activate example conda info python helloworld.py

Lines 7 and 8 are not required if you have these variables in your .bashrc file or have otherwise defined them in a .condarc.

  • Example job submission

    sbatch example.slurm