Activate Conda in SLURM - JoshLoecker/MAPT GitHub Wiki

View the Simple SLURM Job for definitions on #SBATCH

In this job we are going to be activating a conda environment within SLURM.
When trying to activate Conda in SLURM results in Conda stating an error that it must first be ran with conda init. This is a problem, however, as the init command requires the shell to be closed, and re-opened. This is not possible with SLURM.
Instead, we must source our .bashrc profile, which should have conda initialized already. As a result, SLURM understands conda commands.

In this script, we are doing the following

  1. Sourcing our .bashrc
  2. Showing our currently activated conda environments (which should be none) a. Currently activated environments will be denoted with an asterisk (*)
  3. Activating the mapt_pipeline environment
  4. Show the activated conda environments; the mapt_pipeline will have an asterisk (*)
#!/bin/bash
#SBATCH --job-name="Activate Conda"
#SBATCH -p debug
#SBATCH -N 1
#SBATCH -n 1
#SBATCH -t 00:00:30
#SBATCH -o "activate_conda_output"
#SBATCH -e "activate_conda_output"

source ~/.bashrc
conda info --envs
conda activate /project/brookings_minion/conda-envs/mapt_pipeline
conda info --envs