forked from lkwagner/autogenv2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
QWalkRunner.py
146 lines (130 loc) · 4.51 KB
/
QWalkRunner.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
from __future__ import print_function
import os
import numpy as np
import subprocess as sub
import shutil
import submitter
from submitter import LocalSubmitter
####################################################
class LocalQWalkRunner(LocalSubmitter):
""" Runs a crystal job defined by CrystalWriter. """
_name_='LocalCrystalRunner'
def __init__(self, BIN='~/bin/'):
self.BIN=BIN
self.np=1
self.nn=1
self.jobname='ag_qwalk'
self._queueid=None
#-------------------------------------------------
def check_status(self):
# This is only for a queue, so just never return 'running'.
return 'ok'
#-------------------------------------------------
def run(self,qwinpfns,qwoutfns):
""" Submits executibles using _qsub. """
for qwinpfn,qwoutfn in zip(qwinpfns,qwoutfns):
exe = self.BIN+"qwalk %s"%qwinpfn
prep_commands=[]
final_commands = []
loc = os.getcwd()
qids=self._qsub(exe,prep_commands,final_commands,self.jobname,qwoutfn,loc)
self._queueid=qids
####################################################
class QWalkRunnerPBS:
_name_='QWalkRunnerPBS'
def __init__(self,exe='~/bin/qwalk',
queue='batch',
walltime='12:00:00',
jobname=os.getcwd().split('/')[-1]+'_qwalk',
prefix="",#for example, load modules
postfix="",#for any clean-up.
np=1,nn=1
):
self.exe=exe
self.np=np
self.nn=nn
self.jobname=jobname
self.queue=queue
self.walltime=walltime
self.prefix=prefix
self.postfix=postfix
self.queueid=[]
#-------------------------------------
def check_status(self):
return submitter.check_PBS_stati(self.queueid)
#-------------------------------------
def run(self,qwinps,qwouts,jobname=None):
if jobname is None:
jobname=self.jobname
#Just supporting one run for the moment
qwinp=qwinps[0]
qwout=qwouts[0]
for qwinp,qwout in zip(qwinps,qwouts):
jobout=qwinp+".jobout"
np_tot=self.np*self.nn
qsub="#PBS -q %s \n"%self.queue +\
"#PBS -l nodes=%i:ppn=%i\n"%(self.nn,self.np) +\
"#PBS -l walltime=%s\n"%self.walltime +\
"#PBS -j oe \n" +\
"#PBS -N %s \n"%jobname +\
"#PBS -o %s \n"%jobout +\
self.prefix+"\n" +\
"cd ${PBS_O_WORKDIR}\n" +\
"mpirun -np %i %s %s > %s \n"%(np_tot,self.exe,qwinp,qwinp+'.out') +\
self.postfix
qsubfile=qwinp+".qsub"
with open(qsubfile,'w') as f:
f.write(qsub)
result = sub.check_output("qsub %s"%(qsubfile),shell=True)
self.queueid.append(result.decode().split()[0].split('.')[0])
print("Submitted as %s"%self.queueid)
####################################################
class QWalkRunnerTaub:
_name_='QWalkRunnerPBS'
def __init__(self,exe='~/bin/qwalk',
queue='batch',
walltime='12:00:00',
jobname=os.getcwd().split('/')[-1]+'_qwalk',
prefix="",#for example, load modules
postfix="",#for any clean-up.
np=1,nn=1
):
self.exe=exe
self.np=np
self.nn=nn
self.jobname=jobname
self.queue=queue
self.walltime=walltime
self.prefix=prefix
self.postfix=postfix
self.queueid=[]
#-------------------------------------
def check_status(self):
return submitter.check_PBS_stati(self.queueid)
#-------------------------------------
def run(self,qwinps,qwouts,jobname=None):
if jobname is None:
jobname=self.jobname
#Just supporting one run for the moment
qwinp=qwinps[0]
qwout=qwouts[0]
for qwinp,qwout in zip(qwinps,qwouts):
jobout=qwinp+".jobout"
np_tot=self.np*self.nn
qsub="#PBS -q %s \n"%self.queue +\
"#PBS -l nodes=%i:ppn=%i\n"%(self.nn,self.np) +\
"#PBS -l walltime=%s\n"%self.walltime +\
"#PBS -j oe \n" +\
"#PBS -N %s \n"%jobname +\
"#PBS -o %s \n"%jobout +\
self.prefix+"\n" +\
"cd ${PBS_O_WORKDIR}\n" +\
"module load openmpi/1.4-gcc+ifort\n" +\
"mpirun -np %i %s %s > %s \n"%(np_tot,self.exe,qwinp,qwinp+'.out') +\
self.postfix
qsubfile=qwinp+".qsub"
with open(qsubfile,'w') as f:
f.write(qsub)
result = sub.check_output("qsub %s"%(qsubfile),shell=True)
self.queueid.append(result.decode().split()[0].split('.')[0])
print("Submitted as %s"%self.queueid)