HPC Slurm Workflow
Use this skill when the task involves HPC jobs, Slurm scripts, failed jobs, job arrays, memory/time/resource estimates, logs, scratch/work storage, or micromamba environments.
Code Deliverable Format
- Slurm job-submission, launcher, and worker scripts are allowed because they
are execution artifacts required by the cluster workflow.
- For new analysis code that is not itself an HPC execution artifact, default
to R Markdown (
.Rmd) for R-first work or Jupyter (.ipynb) for
Python-first or mixed-language work.
- Create other standalone scripts only when the user explicitly asks for them.
- Preserve native source formats when explicitly modifying existing code.
Rules
- Start with read-only diagnostics.
- Check
squeue -u "$USER" for active jobs.
- Use
sacct for completed jobs.
- Inspect stdout and stderr before changing code.
- Do not delete files unless explicitly asked.
- Do not use sudo.
- Estimate resources before submitting jobs.
- Use
set -euo pipefail in Bash scripts.
- Activate micromamba or conda environments explicitly.
- Write Slurm logs under
slurm_logs/ unless the project already uses a different log directory.
- Write all generated HPC outputs under a single project directory in scratch unless the user specifies another location.
Containerized HPC Execution
Use this section when the task involves Docker, Apptainer, Singularity, containerized Slurm jobs, or moving a local/container workflow to HPC.
Rules:
- Prefer Apptainer/Singularity for HPC execution.
- Do not use Docker directly on HPC unless the cluster explicitly supports it.
- Do not use sudo.
- Do not copy raw data, processed data, model files, large results, credentials, secrets, tokens, or private keys into container images.
- Use bind mounts for project directories, scratch directories, data directories, result directories, logs, and MLflow run directories.
- Prefer explicit bind mounts over relying on implicit host paths.
- Print the container image path, bind mounts, working directory, config path, output directory, Git commit if available, and random seed if relevant before long jobs.
- Keep Slurm logs under the projects log convention. If none exists, use
slurm_logs/.
- Test the container with a small smoke command before submitting a full Slurm job.
- Do not submit full Slurm jobs until a small local, interactive, or dry-run test has passed unless the user explicitly overrides.
Expected Apptainer pattern:
apptainer exec \
--bind /scratch/$USER/project:/work \
image.sif \
python /work/scripts/run.py --config /work/configs/small.yaml
Expected Example Slurm pattern:
#!/usr/bin/env bash
#SBATCH -A one_sc_default
#SBATCH --job-name=project_test
#SBATCH --cpus-per-task=1
#SBATCH --mem=4G
#SBATCH --time=00:10:00
#SBATCH --output=slurm_logs/%x_%j.out
#SBATCH --error=slurm_logs/%x_%j.err
set -euo pipefail
echo "Job ID: ${SLURM_JOB_ID:-NA}"
echo "Host: $(hostname)"
echo "Working directory: $(pwd)"
echo "Image: /path/to/image.sif"
echo "Started: $(date)"
apptainer exec \
--bind /scratch/$USER/project:/work \
/path/to/image.sif \
python /work/scripts/run.py --config /work/configs/small.yaml
echo "Finished: $(date)"
When debugging a containerized Slurm job, inspect in this order:
- Slurm stdout and stderr.
sacct resource usage.
- Whether the image path exists.
- Whether bind-mounted host paths exist.
- Whether paths inside the container match the script.
- Whether the expected conda/micromamba/container environment is actually active.
- Whether the failure is a path issue, dependency issue, permission issue, resource issue, or scientific-code issue.
Expected output
When debugging, provide:
- Likely failure mode.
- Commands to confirm it.
- Minimal fix.
- Exact command to rerun.
- Ask follow up question to ensure direction and goal is correct.
1---2name: hpc-slurm-workflow3description: Use for Slurm, sbatch, squeue, sacct, logs, quotas, scratch/work storage, micromamba, and HPC job debugging.4---56# HPC Slurm Workflow78Use this skill when the task involves HPC jobs, Slurm scripts, failed jobs, job arrays, memory/time/resource estimates, logs, scratch/work storage, or micromamba environments.910## Code Deliverable Format1112- Slurm job-submission, launcher, and worker scripts are allowed because they13 are execution artifacts required by the cluster workflow.14- For new analysis code that is not itself an HPC execution artifact, default15 to R Markdown (`.Rmd`) for R-first work or Jupyter (`.ipynb`) for16 Python-first or mixed-language work.17- Create other standalone scripts only when the user explicitly asks for them.18- Preserve native source formats when explicitly modifying existing code.1920## Rules2122- Start with read-only diagnostics.23- Check `squeue -u "$USER"` for active jobs.24- Use `sacct` for completed jobs.25- Inspect stdout and stderr before changing code.26- Do not delete files unless explicitly asked.27- Do not use sudo.28- Estimate resources before submitting jobs.29- Use `set -euo pipefail` in Bash scripts.30- Activate micromamba or conda environments explicitly.31- Write Slurm logs under `slurm_logs/` unless the project already uses a different log directory.32- Write all generated HPC outputs under a single project directory in scratch unless the user specifies another location.3334## Containerized HPC Execution3536Use this section when the task involves Docker, Apptainer, Singularity, containerized Slurm jobs, or moving a local/container workflow to HPC.3738Rules:3940- Prefer Apptainer/Singularity for HPC execution.41- Do not use Docker directly on HPC unless the cluster explicitly supports it.42- Do not use sudo.43- Do not copy raw data, processed data, model files, large results, credentials, secrets, tokens, or private keys into container images.44- Use bind mounts for project directories, scratch directories, data directories, result directories, logs, and MLflow run directories.45- Prefer explicit bind mounts over relying on implicit host paths.46- Print the container image path, bind mounts, working directory, config path, output directory, Git commit if available, and random seed if relevant before long jobs.47- Keep Slurm logs under the projects log convention. If none exists, use `slurm_logs/`.48- Test the container with a small smoke command before submitting a full Slurm job.49- Do not submit full Slurm jobs until a small local, interactive, or dry-run test has passed unless the user explicitly overrides.5051Expected Apptainer pattern:5253 apptainer exec \54 --bind /scratch/$USER/project:/work \55 image.sif \56 python /work/scripts/run.py --config /work/configs/small.yaml5758Expected Example Slurm pattern:5960 #!/usr/bin/env bash61 #SBATCH -A one_sc_default62 #SBATCH --job-name=project_test63 #SBATCH --cpus-per-task=164 #SBATCH --mem=4G65 #SBATCH --time=00:10:0066 #SBATCH --output=slurm_logs/%x_%j.out67 #SBATCH --error=slurm_logs/%x_%j.err6869 set -euo pipefail7071 echo "Job ID: ${SLURM_JOB_ID:-NA}"72 echo "Host: $(hostname)"73 echo "Working directory: $(pwd)"74 echo "Image: /path/to/image.sif"75 echo "Started: $(date)"7677 apptainer exec \78 --bind /scratch/$USER/project:/work \79 /path/to/image.sif \80 python /work/scripts/run.py --config /work/configs/small.yaml8182 echo "Finished: $(date)"8384When debugging a containerized Slurm job, inspect in this order:85861. Slurm stdout and stderr.872. `sacct` resource usage.883. Whether the image path exists.894. Whether bind-mounted host paths exist.905. Whether paths inside the container match the script.916. Whether the expected conda/micromamba/container environment is actually active.927. Whether the failure is a path issue, dependency issue, permission issue, resource issue, or scientific-code issue.9394## Expected output9596When debugging, provide:97981. Likely failure mode.992. Commands to confirm it.1003. Minimal fix.1014. Exact command to rerun.1025. Ask follow up question to ensure direction and goal is correct.