Add SLURM batch script

This commit is contained in:
Benoît Seignovert 2024-03-08 17:16:30 +01:00
parent 825c9ea2c3
commit e7ab73de0b
Signed by: Benoît Seignovert
GPG key ID: F5D8895227D18A0B
2 changed files with 92 additions and 3 deletions

View file

@ -13,6 +13,65 @@ from .progress import ElapseTime, get_progress
class GlicidSpawner(SlurmSpawner):
"""Glicid SLURM Spawner."""
batch_script = Unicode(
"""#!/bin/bash
#SBATCH --job-name={{job_name}}
#SBATCH --output={{homedir}}/.{{job_name}}.log
#SBATCH --chdir={{workdir}}
#SBATCH --export={{keepvars}}
{% if cluster -%}#SBATCH --cluster={{cluster}}{%- endif %}
{% if partition -%}#SBATCH --partition={{partition}}{%- endif %}
{% if node -%}#SBATCH --nodelist={{node}}{%- endif %}
{% if qos -%}#SBATCH --qos={{qos}}{%- endif %}
{% if runtime -%}#SBATCH --time={{runtime}}{%- endif %}
{% if nprocs -%}#SBATCH --cpus-per-task={{nprocs}}{%- endif %}
{% if memory -%}#SBATCH --mem={{memory}}{%- endif %}
{% if gres -%}#SBATCH --gres={{gres}}{%- endif %}
# Redirect logs
export JUPYTER_LOG_DIR="{{homedir}}/.jupyter/spawner/logs"
mkdir -p ${JUPYTER_LOG_DIR}
echo "The {{job_name}} logs are located in: ${JUPYTER_LOG_DIR}"
export JUPYTER_JOB_LOG=${JUPYTER_LOG_DIR}/$(date "+%Y-%m-%d")_{{job_name}}_${SLURM_JOB_ID}.log
{ PS4='[$(date "+%Y-%m-%d %T")]\011 ';
set -xeo pipefail;
trap 'echo SIGTERM received' TERM;
{# SLURM config #}
scontrol write batch_script ${SLURM_JOB_ID} -;
{# Micromamba config #}
export MAMBA_ROOT_PREFIX=/micromamba/operator;
export MAMBA_EXE=$MAMBA_ROOT_PREFIX/bin/micromamba;
source $MAMBA_ROOT_PREFIX/etc/profile.d/micromamba.sh;
{# Activate micromamba env requested by the user #}
micromamba activate {{ pyenv }};
export JUPYTER_PATH={{ pyenv }}/share/jupyter;
{# Prologue #}
{%- if prologue -%}
{{prologue}};
{%- endif -%}
{# Start Jupyter single-user command #}
{{cmd}};
{# Epilogue #}
{%- if epilogue -%}
{{epilogue}};
{%- endif -%}
} > ${JUPYTER_JOB_LOG} 2>&1
""",
help='Template for SLURM job submission batch script.',
).tag(config=True)
disable_user_config = Bool(
True,
help='Disable per-user configuration of single-user servers.',