我正在努力理解 Snakemake 如何向 slurm 提交作业。
当我有一个基本的 slurm sbatch 脚本时,我通常会添加一行,例如
#SBATCH --mem=5G
现在,我将snakemake与slurm一起使用
snakemake --configfile config.yaml --snakefile test.smk --profile simple/.
配置文件如下所示:
cluster:
mkdir -p logs &&
sbatch
--partition={resources.partition}
--cpus-per-task={threads}
--gpus={resources.gpus}
--mem={resources.mem_mb}
--time={resources.runtime}
--job-name={rule}
--output=logs/{rule}.out
--error=logs/{rule}.err
--parsable
default-resources:
- partition=batch
- runtime=10
- nodes=1
slurm: True
现在,大多数时候我没有在我的snakemake规则中定义资源,所以它只是使用默认值(无论那些是什么?)。但是,我注意到,当 Snakemake 规则的输入文件相当大(或者我一次输入多个较大的文件)时,我经常在启动时收到类似于 slurm 提交失败,无法满足内存规范 的错误,并且 Snakemake 在之前停止它可以开始了。然后我需要按照此规则手动指定内存:
for plevel in plevels:
# PURPOSE: Link the previously generated ec.bin files to speed up hic runs.
rule:
name: f"run_link_bin_{plevel}"
input:
hifiasm_bin=expand("{output_directory}/hifi/hifiasm/{species_lower}.ec.bin", output_directory=config["output_directory"], species_lower=config["species_lower"]),
hifiasm_bin_reverse=expand("{output_directory}/hifi/hifiasm/{species_lower}.ovlp.reverse.bin", output_directory=config["output_directory"], species_lower=config["species_lower"]),
hifiasm_bin_source=expand("{output_directory}/hifi/hifiasm/{species_lower}.ovlp.source.bin", output_directory=config["output_directory"], species_lower=config["species_lower"]),
output:
ln_hifiasm_bin=expand("{output_directory}/hic/hifiasm/purge_level_{plevel}/{species_lower}.ec.bin", output_directory=config["output_directory"], species_lower=config["species_lower"], plevel=plevel),
ln_hifiasm_bin_reverse=expand("{output_directory}/hic/hifiasm/purge_level_{plevel}/{species_lower}.ovlp.reverse.bin", output_directory=config["output_directory"], species_lower=config["species_lower"], plevel=plevel),
ln_hifiasm_bin_source=expand("{output_directory}/hic/hifiasm/purge_level_{plevel}/{species_lower}.ovlp.source.bin", output_directory=config["output_directory"], species_lower=config["species_lower"], plevel=plevel),
message: "Message: Link the previously generated ec.bin files to sped up re-run."
resources:
slurm_partition=bigmem,
mem_mb=1000000, # pointless here, but snakemake sees the large input size and wants more memory
shell:
"""
ln -s {input.hifiasm_bin} {output.ln_hifiasm_bin}
ln -s {input.hifiasm_bin_reverse} {output.ln_hifiasm_bin_reverse}
ln -s {input.hifiasm_bin_source} {output.ln_hifiasm_bin_source}
"""
我确信,您注意到在这种情况下分配这么多内存绝对没有意义,因为该规则只是软链接一些(尽管相当大)文件。但是,如果我不这样做,snakmake 就无法开始运行此规则。 所以我想我的问题是,如果规则中未设置
mem_mb
参数,snakmake 在 slurm 作业中会自动请求多少内存?这似乎取决于输入文件的大小?在这种情况下,最佳做法是什么?
所以我想我的问题是,如果规则中未设置 mem_mb 参数,snakmake 在 slurm 作业中会自动请求多少内存?
我不认为snakemake会自动分配任何资源。如果规则的
mem_mb
中不存在 resources.mem_mb
,则 Snakemake 将使用默认资源中的任何内容,并且如果默认资源中没有 mem_mb
条目,则将在没有 --mem
的情况下提交 sbatch 作业选项,您将获得集群管理员默认设置的任何内容。
我并不认为这是一个“最佳实践”,只是一个建议:
将默认资源中的