3  Create your Mamba environment and install software

Author

Gabriel Ortega-Solís

4 Note

This tutorial assumes that you successfully configured VSCode. If VSCode is properly working, you can just open a terminal manually and click on the run button in every code cell, and the code will be sent to your currently active terminal. If VSCode is not configured yet, you can copy and paste the code snippets in this tutorial into a terminal.

5 Goal

Create and manage a Mamba environment on the HPC cluster so your software is ready before submitting jobs.

6 Connect to the login node through SSH

Open a terminal on your personal computer and connect to the HPC cluster’s login node using SSH. For example:

Replace USERNAME with your actual username and skirit.metacentrum.cz with the appropriate login node for your cluster.

7 Request an interactive session

Run this command from a login node to request an interactive PBS session. After a short time, you will get a message that your interactive session started and your terminal will point to a compute node.

qsub -I \
  -N mamba_setup \
  -l select=1:ncpus=1:mem=16gb \
  -l walltime=02:00:00 \
  -j oe

8 Run environment setup inside the interactive session

After PBS allocates the node and you see the interactive shell prompt, run:

module add mambaforge
mamba create --prefix /storage/brno2/home/gortega/mamba/envs/geostats -c conda-forge "r-terra>=1.8"

The code above will install R as a “side effect” of installing version 1.8 or higher of the terra package. You can replace r-terra with any other package you want to install, and Mamba will automatically resolve and install the necessary dependencies. Alternatively, you could just create an empty environment running mamba create -n SOME_NAME and then install packages one by one or in groups as needed. The option -c conda-forge tells Mamba to look for packages in the conda-forge channel, which is a community-maintained repository of packages. You can specify other channels if you need software that is not available in conda-forge.

9 Activate the environment

Here we will activate the environment to check that it works.

mamba activate /storage/brno2/home/gortega/mamba/envs/geostats

10 Install more packages

You can install more packages in the same environment. For python , just replace the package name after conda-forge with the one you want to install. For R packages you have to write r-PACKAGE_NAME.

mamba install -c conda-forge geopandas r-sf

The most recommended way to install packages inside your environment is to use mamba install... because it will automatically resolve dependencies and propose a working configuration for all the packages in your environment. However, you can still install packages from other sources (e.g., using pip for Python or install.packages() for R) if you prefer, but be aware that this may lead to dependency conflicts or issues with reproducibility.

Example of installing an R package from GitHub using remotes:

Rscript -e "devtools::install_github('gortegasolis/geomattR', dependencies = FALSE, upgrade = 'never', force = TRUE)"

11 Deactivate the environment when you are done

mamba deactivate

12 Exit the interactive session

exit