使用 Python 提交 Slurm 作业

Submit Slurm Jobs using Python

我有foo.sh如下

#!/bin/bash
#SBATCH -A research
#SBATCH -p long
#SBATCH --mem-per-cpu=1024
#SBATCH -N 1
#SBATCH -n 24
#SBATCH -t 2-00:00:00
#SBATCH --mail-type=END
#SBATCH --exclude=node37

module load Gaussian/09revC

export GAUSS_SCRDIR=/scratch/$USER.$SLURM_JOBID
/bin/mkdir -p $GAUSS_SCRDIR

g09 

/bin/rm -rf $GAUSS_SCRDIR

然后我从另一个名为 submit.sh

的 bash 文件调用 foo.sh
#!/bin/bash
sbatch foo.sh 00_molecule_name_some_method.com
sbatch foo.sh 01_molecule_name_some_method.com
sbatch foo.sh 02_molecule_name_some_method.com

这会提交多个作业。

我想将 submit.sh 更改为 Python 文件,它将调用 foo.sh 并为其提供参数,该参数将转到 foo.sh 中的 </code>,Python 不应等待作业完成。</p> <p>另外 <code>molecule_namesome_method 是我将在 for 循环中提供的变量

模板Python脚本submit.py

for molecule_name in molecules:
    for some_method in methods:
        foo.sh molecule_name some_method

我收到这个错误:

/bin/mkdir: cannot create directory ‘/scratch’: Permission denied
PGFIO/stdio: No such file or directory
PGFIO-F-/OPEN/unit=11/error code returned by host stdio - 2.
File name = /scratch/USERNAME./Gau-41212.inp
In source file ml0.f, at line number 181
PGFIO/stdio: No such file or directory
PGFIO-F-/OPEN/unit=11/error code returned by host stdio - 2.
File name = /scratch/USERNAME./Gau-41213.inp
In source file ml0.f, at line number 181

使用Subprocess

import subprocess
for molecule_name in molecules:
    for some_method in methods:
        command1 = subprocess.Popen(['foo.sh', molecule_name, some_method])