-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CLI for slurm configuration (#70)
- Loading branch information
1 parent
f4b476a
commit d855db2
Showing
9 changed files
with
141 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
export MODULEPATH=/groups/esm/modules:$MODULEPATH | ||
module purge | ||
module load climacommon/2024_03_18 | ||
|
||
source slurm/parse_commandline.sh | ||
if [ ! -d $output ] ; then | ||
mkdir -p $output | ||
fi | ||
|
||
# Initialize the project and setup calibration | ||
init_id=$(sbatch --parsable \ | ||
--output=$logfile \ | ||
--partition=$partition \ | ||
slurm/initialize.sbatch $experiment_id) | ||
echo -e "Initialization job_id: $init_id\n" | ||
|
||
# Loop over iterations | ||
dependency="afterok:$init_id" | ||
for i in $(seq 0 $((n_iterations - 1))) | ||
do | ||
echo "Scheduling iteration $i" | ||
format_i=$(printf "iteration_%03d" "$i") | ||
|
||
ensemble_array_id=$( | ||
sbatch --dependency=$dependency --kill-on-invalid-dep=yes --parsable \ | ||
--job=model-$i \ | ||
--output=/dev/null \ | ||
--array=1-$ensemble_size \ | ||
--time=$slurm_time \ | ||
--ntasks=$slurm_ntasks \ | ||
--partition=$partition \ | ||
--cpus-per-task=$slurm_cpus_per_task \ | ||
--gpus-per-task=$slurm_gpus_per_task \ | ||
slurm/model_run.sbatch $experiment_id $i) | ||
|
||
dependency=afterany:$ensemble_array_id | ||
echo "Iteration $i job id: $ensemble_array_id" | ||
|
||
update_id=$( | ||
sbatch --dependency=$dependency --kill-on-invalid-dep=yes --parsable \ | ||
--job=update-$i \ | ||
--output=$logfile \ | ||
--open-mode=append \ | ||
--partition=$partition \ | ||
slurm/update.sbatch $experiment_id $i) | ||
|
||
dependency=afterany:$update_id | ||
echo -e "Update $i job id: $update_id\n" | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# Default arguments | ||
slurm_time="2:00:00" | ||
slurm_ntasks="1" | ||
slurm_cpus_per_task="1" | ||
slurm_gpus_per_task="0" | ||
|
||
help_message="Usage: | ||
./pipeline.sh [options] experiment_id | ||
Options: | ||
-t, --time=HH:MM:SS: Set max wallclock time (default: 2:00:00). | ||
-n, --ntasks: Set number of tasks to launch (default: 1). | ||
-c, --cpus_per_task: Set CPU cores per task (mutually exclusive with -g, default: 8). | ||
-g, --gpus_per_task: Set GPUs per task (mutually exclusive with -c, default: 0). | ||
-h, --help: Display this help message. | ||
Arguments: | ||
experiment_id: A unique identifier for your experiment (required)." | ||
|
||
# Parse arguments using getopt | ||
VALID_ARGS=$(getopt -o h,t:,n:,c:,g: --long help,time:,ntasks:,cpus_per_task:,gpus_per_task: -- "$@") | ||
if [[ $? -ne 0 ]]; then | ||
exit 1; | ||
fi | ||
|
||
eval set -- "$VALID_ARGS" | ||
|
||
# Process arguments | ||
while [ : ]; do | ||
case "$1" in | ||
-t | --time) | ||
slurm_time="$2" | ||
shift 2 | ||
;; | ||
-n | --ntasks) | ||
slurm_ntasks="$2" | ||
shift 2 | ||
;; | ||
-c | --cpus_per_task) | ||
slurm_cpus_per_task="$2" | ||
shift 2 | ||
;; | ||
-g | --gpus_per_task) | ||
slurm_gpus_per_task="$2" | ||
shift 2 | ||
;; | ||
-h | --help) | ||
printf "%s\n" "$help_message" | ||
exit 0 | ||
;; | ||
--) shift; break ;; # End of options | ||
esac | ||
done | ||
|
||
experiment_id="$1" | ||
if [ -z $experiment_id ] ; then | ||
echo "Error: No experiment ID provided." | ||
exit 1 | ||
fi | ||
|
||
# Get values from EKP config file | ||
ensemble_size=$(grep "ensemble_size:" experiments/$experiment_id/ekp_config.yml | awk '{print $2}') | ||
n_iterations=$(grep "n_iterations:" experiments/$experiment_id/ekp_config.yml | awk '{print $2}') | ||
output=$(grep "output_dir:" experiments/$experiment_id/ekp_config.yml | awk '{print $2}') | ||
logfile=$output/experiment_log.out | ||
|
||
# Set partition | ||
if [[ $slurm_gpus_per_task -gt 0 ]]; then | ||
partition=gpu | ||
else | ||
partition=expansion | ||
fi | ||
|
||
# Output slurm configuration | ||
echo "Running experiment: $experiment_id" | ||
indent=" └ " | ||
printf "Slurm configuration (per ensemble member):\n" | ||
printf "%sTime limit: %s\n" "$indent" "$slurm_time" | ||
printf "%sTasks: %s\n" "$indent" "$slurm_ntasks" | ||
printf "%sCPUs per task: %s\n" "$indent" "$slurm_cpus_per_task" | ||
printf "%sGPUs per task: %s\n" "$indent" "$slurm_gpus_per_task" | ||
echo "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters