Running Snakemake with SLURM (using profile) - TGAC/knowledge_base GitHub Wiki
Running Snakemake with SLURM (using profile)
This guide explains how to set up and run Snakemake (tested version 8.14.0) on an SLURM-based cluster using the snakemake-executor-plugin-slurm.
This guide is based on my GitHub comment on the Snakemake repository.
Installation
Install Snakemake and the SLURM executor plugin via Conda:
conda install -y -c bioconda -c conda-forge snakemake=8.14.0 snakemake-executor-plugin-slurm
Test Directory Structure
Before running, your directory should look like this:
test_run/
βββ one.txt
βββ profiles/
β βββ work_profile/
β βββ config.v8+.yaml
βββ Snakefile
where the contents of files are:
profiles/work_profile/config.v8+.yaml
executor: slurm
default-resources:
slurm_account: "account_name"
slurm_partition: "queue_name"
runtime: 2h
mem_mb: 4096
slurm_extra: "'--mail-type=END [email protected] -o logs/smk.%N.%j.out -e logs/smk.%N.%j.err'"
printshellcmds: True
jobs: 100
restart-times: 3
latency-wait: 60
rerun-incomplete: True
use-conda: false
set-threads:
rule1: 1
rule2: 2
test: 4
set-resources:
test:
slurm_partition: "queue_name"
runtime: 4h
mem_mb: 4096
See Snakemake profiles documentation for more info.
Snakefile
rule all:
input:
"done.txt"
rule test:
input:
"one.txt"
output:
"done.txt"
log:
"test.log"
shell:
"""
echo "Processing data with {threads} threads" > {log}
cp {input} {output}
/usr/bin/time -v sleep 10
echo "Processing complete" >> {log}
"""
one.txt
Just a placeholder file:
empty file
Running the Workflow
Now we can execute snakemake on SLURM using the profiles/work_profile
.
From within the test_run/
directory:
$ cd test_run
$ snakemake --profile profiles/work_profile --snakefile Snakefile
Building DAG of jobs...
SLURM run ID: 952ada6a-70b3-44b8-b6d9-30c2ee2fc421
Using shell: /usr/bin/bash
Provided remote nodes: 100
Job stats:
job count
----- -------
all 1
test 1
total 2
Select jobs to execute...
Execute 1 jobs...
...
...
Finished job 0.
2 of 2 steps (100%) done
Complete log: .snakemake/log/2024-06-28T103831.904550.snakemake.log
After execution, your directory will look like:
test_run/
βββ one.txt
βββ profiles/
β βββ work_profile/
β βββ config.v8+.yaml
βββ Snakefile
βββ logs/
β βββ smk.e512n47.1118341.err
β βββ smk.e512n47.1118341.out
βββ test.log
βββ done.txt
Snakemake and plugin versions
snakemake==8.14.0
snakemake-executor-plugin-slurm==0.7.0
snakemake-executor-plugin-slurm-jobstep==0.2.1
snakemake-interface-common==1.17.2
snakemake-interface-executor-plugins==9.1.1
snakemake-interface-report-plugins==1.0.0
snakemake-interface-storage-plugins==3.2.2
Notes
In Snakemake (v8.14.0), SLURM jobs are named using UUIDs. To view the rule name/wildcards in your SLURM queue, Snakemake now adds that information to the --comments
section.
References:
Use the following squeue command to display comments:
We need to add %k
to the squeue
command to see the --comments
section
squeue -u $(whoami) -o "%.14i %.8u %.20k %.20j"
Thatβs it!
You now have a working Snakemake setup with SLURM executor integration.