Skip to content

Commit 5e41d05

Browse files
authored
fix: add --parsable to sbatch call for a more robust output parsing (#125)
Following discussion in #121 (comment) , this implementation seems more robust than match a word with only numbers (which could break in future versions of slurm, or if a cluster name is made of only numbers).
1 parent 03d474f commit 5e41d05

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

docs/further.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ You can use the following specifications:
119119
| `--ntasks` | `tasks` | number of concurrent tasks / ranks |
120120
| `--cpus-per-task` | `cpus_per_task` | number of cpus per task (in case of SMP, rather use `threads`) |
121121
| `--nodes` | `nodes` | number of nodes |
122-
| `--clusters` | `cluster` | comma separated string of clusters |
122+
| `--clusters` | `clusters` | comma separated string of clusters |
123123

124124
Each of these can be part of a rule, e.g.:
125125

snakemake_executor_plugin_slurm/__init__.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,11 @@ def run_job(self, job: JobExecutorInterface):
130130
else:
131131
comment_str = f"rule_{job.name}_wildcards_{wildcard_str}"
132132
call = (
133-
f"sbatch --job-name {self.run_uuid} --output {slurm_logfile} --export=ALL "
133+
f"sbatch "
134+
f"--parsable "
135+
f"--job-name {self.run_uuid} "
136+
f"--output {slurm_logfile} "
137+
f"--export=ALL "
134138
f"--comment {comment_str}"
135139
)
136140

@@ -205,10 +209,11 @@ def run_job(self, job: JobExecutorInterface):
205209
)
206210

207211
# multicluster submissions yield submission infos like
208-
# "Submitted batch job <id> on cluster <name>".
209-
# To extract the job id in this case we need to match any number
210-
# in between a string - which might change in future versions of SLURM.
211-
slurm_jobid = re.search(r"\d+", out).group()
212+
# "Submitted batch job <id> on cluster <name>" by default, but with the
213+
# --parsable option it simply yields "<id>;<name>".
214+
# To extract the job id we split by semicolon and take the first element
215+
# (this also works if no cluster name was provided)
216+
slurm_jobid = out.split(";")[0]
212217
slurm_logfile = slurm_logfile.replace("%j", slurm_jobid)
213218
self.logger.info(
214219
f"Job {job.jobid} has been submitted with SLURM jobid {slurm_jobid} "

0 commit comments

Comments
 (0)