Automatic loading of Spack modules when the Conda environment is loaded.
Spack and Conda can influence each other with side effects. Therefore I do not activate them by default. The following functions allow you to activate Conda and Spack by bash command.
# for example, add to .bashrc
enabled_spack=0
enable_spack(){
if [[ enabled_spack -eq 0 ]]; then
. /opt/spack/share/spack/setup-env.sh
enabled_spack=1
fi
}
enabled_conda=0
enable_conda(){
if [[ enabled_conda -eq 0 ]]; then
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/opt/miniconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/opt/miniconda3/etc/profile.d/conda.sh" ]; then
. "/opt/miniconda3/etc/profile.d/conda.sh"
else
export PATH="/opt/sehrig/miniconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda initialize <<<
enable_conda=1
fi
}
# wrapper command to automatically activate Spack when a specific Spack module is required
alias singularity=my_singularity
loaded_spack=0
my_singularity(){
if [[ loaded_spack -eq 0 ]]; then
if [[ enabled_spack -eq 0 ]]; then
enable_spack
fi
spack load [email protected]
loaded_spack=1
fi
command singularity $@
}
Create conda environment
conda create -n test-env
Create activate and deactivate scripts
mkdir -p /opt/miniconda3/envs/test-env/etc/conda/activate.d
mkdir -p /opt/miniconda3/envs/test-env/etc/conda/deactivate.d
nano /opt/miniconda3/envs/test-env/etc/conda/activate.d/spack_load.sh
nano /opt/miniconda3/envs/test-env/etc/conda/activate.d/spack_unload.sh
spack_load.sh
#!/bin/bash
if [[ enabled_spack -eq 0 ]]; then
enable_spack
fi
spack load [email protected]
spack load [email protected]
spack_unload.sh
#!/bin/bash
spack unload [email protected]
spack unload [email protected]
Since this PR, spack does not set the
LD_LIBRARY_PATH
automatically anymore. This solves and causes problems. A valid solution is, that spack generates aSPACK_LD_LIBRARY_PATH
variable and the conda init script copies the required paths to theLD_LIBRARY_PATH
variable.Following commands needs to run one time, that spack creates the
SPACK_LD_LIBRARY_PATH
variable:The following conda init script set the path to the CUDA
lib64
folder:deinit script: