如何确保slurm中的python提交脚本位于发出sbatch命令的位置? [英] How does one make sure that the python submission script in slurm is in the location from where the sbatch command was given?

查看:120
本文介绍了如何确保slurm中的python提交脚本位于发出sbatch命令的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个python提交脚本,该脚本使用 slurm sbatch 一起运行:

I have a python submission script that I run with sbatch using slurm:

sbatch batch.py

当我这样做时,由于我假设 batch.py​​ 进程未继承正确的环境变量,因此这些操作无法正常工作.因此,它不是从 sbatch 命令执行的地方运行 batch.py​​ ,而是从其他地方运行(我相信是/).我设法通过用bash脚本包装python脚本来解决此问题:

when I do this things do not work properly because I assume, the batch.py process does not inherit the right environment variables. Thus instead of running batch.py from where the sbatch command was done, its ran from somewhere else (/ I believe). I have managed to fix this by doing wrapping the python script with a bash script:

#!/usr/bin/env bash
cd path/to/scripts
python script.py

这种临时性的破解工作似乎可以避免所有问题,而不是解决所有问题.有人知道如何更好地解决此问题吗?

this temporary hack sort of works it seems though it seems that it avoids the question all together rather than addressing it. Does someone know how to fix this in a better way?

例如,我知道在docker中存在 -w -WORKDIR ,以便docker容器知道其假设位置.我想知道是否存在类似的东西.

I know for example, that in docker the -w or -WORKDIR exists so that the docker container knows where its suppose to be at. I was wondering if something like that existed for slurm.

推荐答案

Slurm旨在在提交时将用户的环境推送到作业,但用户或系统管理员明确禁用的变量除外.

Slurm is designed to push the user's environment at submit time to the job, except for variables explicitly disabled by the user or the system administrator.

但是脚本的运行方式如下:将脚本复制到Slurm特定目录中分配的主节点上,然后从此处运行,并将 $ PWD 设置为该目录 sbatch 命令的运行位置.

But the way the script is run is as follows: the script is copied on the master node of the allocation in a Slurm specific directory and run from there, with the $PWD set to the directory where the sbatch command was run.

您可以通过一个简单的脚本看到这一点:

You can see that with a simple script like this one:

$ cat t.sh
#!/bin/bash
#
#SBATCH --job-name=test_ms
#SBATCH --output=res_ms.txt

echo $PWD
dirname $(readlink -f "$0")

$ sbatch t.sh
Submitted batch job 1109631
$ cat res_ms.txt
/home/damienfrancois/
/var/spool/slurm/job1109631

一个结果是,在当前目录中导入模块的Python脚本无法这样做.然后,解决方法是在失败的导入之前显式添加 sys.path.append(os.getcwd()).

One consequence is that Python scripts that import modules in the current directory fail to do so. The workaround is then to explicitly add sys.path.append(os.getcwd()) before the failing imports.

这篇关于如何确保slurm中的python提交脚本位于发出sbatch命令的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆