【问题标题】:Snakemake hangs when cluster (slurm) cancelled a job当集群(slurm)取消作业时,Snakemake 挂起
【发布时间】:2023-04-23 12:01:01
【问题描述】:

也许对许多人来说答案是显而易见的,但我很惊讶我找不到关于这个主题的问题,这对我来说是一个主要问题。 非常感谢您的提示!

在 slurm 管理的集群上提交作业时,如果队列管理器取消作业(例如资源或时间不足),snakemake 似乎没有收到任何信号,并永远挂起。另一方面,当作业失败时,snakemake 也会失败,正如预期的那样。这种行为是正常的/想要的吗?当工作被取消时,我怎么能让蛇制作失败?我在snakemake 3.13.3 版本中遇到了这个问题,它一直在更新到5.3.0。

例如,在这种情况下,我启动了一个简单的管道,但规则 pluto 的资源不足:

$ snakemake -j1 -p --cluster 'sbatch --mem {resources.mem}' pluto.txt
Building DAG of jobs...
Using shell: /usr/bin/bash
Provided cluster nodes: 1
Unlimited resources: mem
Job counts:
    count   jobs
    1       pippo
    1       pluto
    2

[Tue Sep 25 16:04:21 2018]
rule pippo:
    output: pippo.txt
    jobid: 1
    resources: mem=1000

seq 1000000 | shuf > pippo.txt
Submitted job 1 with external jobid 'Submitted batch job 4776582'.
[Tue Sep 25 16:04:31 2018]
Finished job 1.
1 of 2 steps (50%) done

[Tue Sep 25 16:04:31 2018]
rule pluto:
    input: pippo.txt
    output: pluto.txt
    jobid: 0
    resources: mem=1

sort pippo.txt > pluto.txt
Submitted job 0 with external jobid 'Submitted batch job 4776583'.

挂在这里。以下是职位会计的内容:

$ sacct -S2018-09-25-16:04 -o jobid,JobName,state,ReqMem,MaxRSS,Start,End,Elapsed
       JobID    JobName      State     ReqMem     MaxRSS               Start                 End    Elapsed
------------ ---------- ---------- ---------- ---------- ------------------- ------------------- ----------
4776582      snakejob.+  COMPLETED     1000Mn            2018-09-25T16:04:22 2018-09-25T16:04:27   00:00:05
4776582.bat+      batch  COMPLETED     1000Mn      1156K 2018-09-25T16:04:22 2018-09-25T16:04:27   00:00:05
4776583      snakejob.+ CANCELLED+        1Mn            2018-09-25T16:04:32 2018-09-25T16:04:32   00:00:00
4776583.bat+      batch  CANCELLED        1Mn      1156K 2018-09-25T16:04:32 2018-09-25T16:04:32   00:00:00

【问题讨论】:

  • snakemake 版本是什么?我在 lsf 集群中遇到了v5.2.x 的问题,如果我杀死工作,snakemake 将无法识别;所以我回滚到v4.8.0
  • 我对 SGE 也有同样的问题。如果队列管理器出现问题,该作业可以永远停留在 Eqw 模式,而 snakemake 永远不会知道这一点并永远挂起。
  • @JeeYem 我编辑了包括版本信息,感谢您的支持!
  • it remained updating to 5.3.0 - 您是直接更新到v5.3.0 还是尝试了介于两者之间的某个版本?如果是前者,我建议尝试v4.6v4.8(我用过的只是几个版本)。

标签: jobs slurm cancellation snakemake


【解决方案1】:

Snakemake 无法识别 slurm(以及其他作业调度程序)中的各种作业状态。为了弥补这一差距,snakemake 提供了选项--cluster-status,其中可以提供自定义 python 脚本。根据snakemake's documentation

 --cluster-status

Status command for cluster execution. This is only considered in combination with the –cluster flag. 
If provided, Snakemake will use the status command to determine if a job has finished successfully or failed. 
For this it is necessary that the submit command provided to –cluster returns the cluster job id. 
Then, the status command will be invoked with the job id. 
Snakemake expects it to return ‘success’ if the job was successfull, ‘failed’ if the job failed and ‘running’ if the job still runs.

Example shown 在 snakemake 的文档中使用此功能:

#!/usr/bin/env python
import subprocess
import sys

jobid = sys.argv[1]

output = str(subprocess.check_output("sacct -j %s --format State --noheader | head -1 | awk '{print $1}'" % jobid, shell=True).strip())

running_status=["PENDING", "CONFIGURING", "COMPLETING", "RUNNING", "SUSPENDED"]
if "COMPLETED" in output:
  print("success")
elif any(r in output for r in running_status):
  print("running")
else:
  print("failed")

要使用这个脚本调用snakemake,类似于下面,status.py 是上面的脚本。

$ snakemake all --cluster "sbatch --cpus-per-task=1 --parsable" --cluster-status ./status.py

或者,您可以通过Snakemake-Profiles 为多个作业调度程序(slurm、lsf 等)使用预制的自定义脚本。这是用于 slurm 的那个 - slurm-status.py

【讨论】: