使用python向作业调度程序提交多个作业的逻辑

时间:2015-08-11 16:10:30

标签: python

我正在编写一些代码来将多个作业提交给作业调度程序。

代码:

def submit_copasi_job_SGE(self,run_script_name,copasi_file,new_report_name):
    CT=Cluster_Tools() #initialize a custom class
    CT.change_scan_report_name(copasi_file,new_report_name) # use a custom function
    with open(run_script_name+'.sh','w') as f: #write a .sh script for submission to the job scheduler
        f.write('#!/bin/bash\n#$ -V -cwd\nmodule add apps/COPASI\nCopasiSE {}'.format(copasi_file))
    os.system('qsub {}'.format(run_script_name)) # submit to the job scheduler
    os.remove(run_script_name) # remove the run script

def submit_multi_copasi_job_SGE(self,run_script_name,copasi_file,new_report_name,n):
    CT=Cluster_Tools() #initialize custom class
    run_script_vec=[]  #create a numbered list of run script names
    for i in range(n): 
        run_script_vec.append(run_script_name+'_'+str(i))
    print run_script_vec
    for i in run_script_vec: #iterate over the run scripts with the previously defined function 
        CT.submit_copasi_job_SGE(i,copasi_file,new_report_name+str(i))

第一部分将向作业调度程序提交作业。这是经过测试的,并且有效。现在我正在尝试编写一个函数迭代第一个函数以多次提交相同的作业(使用不同的输出文件名,因此第一个函数的'change_scan_report_name'位)。

我得到的错误如下:

  File "/home/b3053674/Models/Retinoic_Acid/Fit5/Copasi_Tools.py", line 307, in submit_copasi_job_SGE
    os.remove(run_script_name)
OSError: [Errno 2] No such file or directory: '/home/b3053674/Models/Retinoic_Acid/Fit5/run_0.sh'

我怀疑这是一个逻辑问题,但我感到困惑,认为这应该有效。任何人都可以发现这个错误吗?

1 个答案:

答案 0 :(得分:1)

您将脚本定义为with open(run_script_name+'.sh','w') 然后您尝试删除run_script_name,但该文件名为run_script_name+".sh"

所以,固定版本应为:

def submit_copasi_job_SGE(self,run_script_name,copasi_file,new_report_name):
    CT=Cluster_Tools() #initialize a custom class
    CT.change_scan_report_name(copasi_file,new_report_name) # use a custom function
    with open(run_script_name+'.sh','w') as f: #write a .sh script for submission to the job scheduler
        f.write('#!/bin/bash\n#$ -V -cwd\nmodule add apps/COPASI\nCopasiSE {}'.format(copasi_file))
    os.system('qsub {}'.format(run_script_name)) # submit to the job scheduler
    os.remove(run_script_name+'.sh') # remove the run script

def submit_multi_copasi_job_SGE(self,run_script_name,copasi_file,new_report_name,n):
    CT=Cluster_Tools() #initialize custom class
    run_script_vec=[]  #create a numbered list of run script names
    for i in range(n): 
        run_script_vec.append(run_script_name+'_'+str(i))
    print run_script_vec
    for i in run_script_vec: #iterate over the run scripts with the previously defined function 
        CT.submit_copasi_job_SGE(i,copasi_file,new_report_name+str(i))