Skip to content

Instantly share code, notes, and snippets.

@fmaussion
Created January 23, 2019 21:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fmaussion/c5bead87d1fd79b98006b139891b499a to your computer and use it in GitHub Desktop.
Save fmaussion/c5bead87d1fd79b98006b139891b499a to your computer and use it in GitHub Desktop.
Cluster script with singularity
#!/bin/bash
#
#SBATCH --job-name=prepro_levels
#SBATCH --ntasks=1
#SBATCH --exclusive
#SBATCH --partition=low
#SBATCH --time=48:00:00
#SBATCH --mail-user=fabien.maussion@uibk.ac.at
#SBATCH --mail-type=ALL
# Abort whenever a single step fails. Without this, bash will just continue on errors.
set -e
# Current RGI region
OGGM_RGI_REG=`printf "%02d" $SLURM_ARRAY_TASK_ID`
export OGGM_RGI_REG
# On every node, when slurm starts a job, it will make sure the directory
# /work/username exists and is writable by the jobs user.
# We create a sub-directory there for this job to store its runtime data at.
OGGM_WORKDIR="/work/$SLURM_JOB_USER/$SLURM_JOB_ID/rgi_reg_$RGI_REG"
mkdir -p "$OGGM_WORKDIR"
echo "RGI Region: $OGGM_RGI_REG"
echo "Workdir for this run: $OGGM_WORKDIR"
# Export the WORKDIR as environment variable so our script can use it to find its working directory.
export OGGM_WORKDIR
# Use the local data download cache
export OGGM_DOWNLOAD_CACHE=/home/data/download
export OGGM_DOWNLOAD_CACHE_RO=1
export OGGM_EXTRACT_DIR="/work/$SLURM_JOB_USER/$SLURM_JOB_ID/oggm_tmp"
# All commands in the EOF block run inside of the container
# Adjust container version to your needs, they are guaranteed to never change after their respective day has passed.
srun -n 1 -c "${SLURM_JOB_CPUS_PER_NODE}" singularity exec docker://oggm/oggm:20181123 bash -s <<EOF
set -e
# Setup a fake home dir inside of our workdir, so we don't clutter the actual shared homedir with potentially incompatible stuff.
export HOME="$OGGM_WORKDIR/fake_home"
mkdir "\$HOME"
# Create a venv that _does_ use system-site-packages, since everything is already installed on the container.
# We cannot work on the container itself, as the base system is immutable.
python3 -m venv --system-site-packages "$OGGM_WORKDIR/oggm_env"
source "$OGGM_WORKDIR/oggm_env/bin/activate"
# Make sure latest pip is installed
pip install --upgrade pip setuptools
# Install a fixed OGGM version (20 Jan 2019)
pip install --upgrade "git+https://github.com/OGGM/oggm.git@c0c81cb612d6c020647ca7262705349a097b606f"
# Finally, the runs
oggm_prepro --map-border 10
oggm_prepro --map-border 80
oggm_prepro --map-border 160
oggm_prepro --map-border 250
EOF
# Print a final message so you can actually see it being done in the output log.
echo "SLURM DONE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment