-
Notifications
You must be signed in to change notification settings - Fork 0
/
runner.pbs
executable file
·112 lines (96 loc) · 3.24 KB
/
runner.pbs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/bin/bash -l
#PBS -l walltime=0:10:00
#PBS -l mem=5gb
# In the comments above, we request 10 minutes of wallclock time and 5GB RAM.
# This should be enough to debug, install environments and launch jobs.
# author: Benjamin Rombaut
# contact: benjamin.rombaut[at]ugent.be
# last update: 2024-02-18
# Using -v, we can pass arguments that will be filled in in the variables in the
# script. For example:
#
# $ qsub runner.pbs -v CLUSTER=donphan
#
# will make sure the variable $CLUSTER contains the value "donphan" within the script.
# echo $PBS_O_WORKDIR
# if [ -d $PBS_O_WORKDIR ]; then
# # navigate to the folder where the script is located
# cd $PBS_O_WORKDIR
# fi
echo "Working dir: $PWD"
# Navigate to the folder "venvs" in the VSC_DATA directory
ROOT_VENVS=$VSC_DATA/venvs/
# pip respects the TMPDIR environment variable
# otherwise ~/.cache/pip will soon take all available VSC_HOME space
# no TMPDIR is set by default, so we set it to a temporary
export TMPDIR=${TMPDIR:-$VSC_DATA/tmp}
if [ ! -d $ROOT_VENVS ]; then
mkdir $ROOT_VENVS
fi
# If the CLUSTER argument is empty, throw an error
if [ -z $CLUSTER ]; then
# detect cluster from loaded cluster module
CLUSTER=$(module list 2>&1 | grep -oP '(?<=cluster/)[^/ ]+')
# CLUSTER=$SLURM_CLUSTERS
echo "No CLUSTER argument provided, detected cluster '$CLUSTER'"
fi
if [[ -z $INSTALL && -z $ACTIVATE && -z $CONDA ]]; then
echo "Provide an INSTALL or ACTIVATE argument: INSTALL=folder/with/requirements.txt_and_modules.sh qsub runner.pbs" 1>&2
exit 1
fi
if [[ -z $PIP_ARGS ]]; then
PIP_ARGS="$INSTALL"
fi
if [ ! -z $INSTALL ]; then
# install a new virtual environment
NAME=`basename $(readlink -f $INSTALL)`
# This is the name of the virtual environment we will construct.
# The name depends on the chosen cluster.
VENV_NAME=venv_${NAME}_${CLUSTER}
VENV_PATH="${ROOT_VENVS}/${VENV_NAME}/"
# Load the modules
source $INSTALL/modules.sh
# Create the virtual environment and install packages
# If this virtual environment already exists, delete it.
if [ -d $VENV_PATH ]; then
rm -r $VENV_PATH
fi
python -m venv $VENV_PATH
source $VENV_PATH/bin/activate
if [ ! -z "$PIP_ARGS" ]; then
python -m pip install $PIP_ARGS
fi
echo "Virtual environment $VENV_PATH installed."
# TODO: add `pip install -e .` for local packages
elif [ ! -z $ACTIVATE ]; then
NAME=`basename $(readlink -f $ACTIVATE)`
# This is the name of the virtual environment we will construct.
# The name depends on the chosen cluster.
VENV_NAME=venv_${NAME}_${CLUSTER}
VENV_PATH="${ROOT_VENVS}/${VENV_NAME}/"
# Load the modules
# cd $ACTIVATE
source $ACTIVATE/modules.sh
# Activate the virtual environment
if [ -f $VENV_PATH/bin/activate ]; then
source $VENV_PATH/bin/activate
fi
echo "Virtual environment $VENV_PATH activated."
elif [ ! -z $CONDA ]; then
# activate a conda environment
source ~/.bashrc
conda activate $CONDA
echo "Virtual environment $CONDA activated."
fi
if [ ! -z "$SCRIPT" ]; then
# Navigate to the script folder
# if script ends with .py, use python
# if [[ "$SCRIPT" == *.py ]]; then
# SCRIPT="python $SCRIPT"
# elif [[ "$SCRIPT" == *.sh ]]; then
# # just use bash
# SCRIPT="bash $SCRIPT"
# fi
# Run the script (or an absolute script path) with the arguments
$SCRIPT $@
fi