33energy calculations.
44
55Copyright 2021 (c) Sarath Menon^1, Yury Lysogorskiy^2, Ralf Drautz^2
6- ^1: Max Planck Institut für Eisenforschung, Dusseldorf, Germany
6+ ^1: Max Planck Institut für Eisenforschung, Dusseldorf, Germany
77^2: Ruhr-University Bochum, Bochum, Germany
88
9- calphy is published and distributed under the Academic Software License v1.0 (ASL).
10- calphy is distributed in the hope that it will be useful for non-commercial academic research,
11- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9+ calphy is published and distributed under the Academic Software License v1.0 (ASL).
10+ calphy is distributed in the hope that it will be useful for non-commercial academic research,
11+ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1212calphy API is published and distributed under the BSD 3-Clause "New" or "Revised" License
13- See the LICENSE FILE for more details.
13+ See the LICENSE FILE for more details.
1414
1515More information about the program can be found in:
1616Menon, Sarath, Yury Lysogorskiy, Jutta Rogal, and Ralf Drautz.
2525import os
2626import stat
2727
28+
2829class Local :
2930 """
3031 Local submission script
3132 """
33+
3234 def __init__ (self , options , cores = 1 , directory = os .getcwd ()):
33- self .queueoptions = {"scheduler" : "local" ,
34- "jobname" : "tis" ,
35- "queuename" : None ,
36- "memory" : None ,
37- "cores" : cores ,
38- "hint" : None ,
39- "directory" : directory ,
40- "options" : [],
41- "commands" : [],
42- "modules" : [],
43- "header" : "#!/bin/bash"
44-
45- }
46- for (key , val ) in options .items ():
35+ self .queueoptions = {
36+ "scheduler" : "local" ,
37+ "jobname" : "tis" ,
38+ "queuename" : None ,
39+ "memory" : None ,
40+ "cores" : cores ,
41+ "hint" : None ,
42+ "directory" : directory ,
43+ "options" : [],
44+ "commands" : [],
45+ "header" : "#!/bin/bash" ,
46+ }
47+ for key , val in options .items ():
4748 if key in self .queueoptions .keys ():
4849 if val is not None :
4950 self .queueoptions [key ] = val
@@ -60,14 +61,10 @@ def write_script(self, outfile):
6061 fout .write (self .queueoptions ["header" ])
6162 fout .write ("\n " )
6263
63- #now write modules
64- for module in self .queueoptions ["modules" ]:
65- fout .write ("module load %s\n " % module )
66-
67- #now finally commands
64+ # now finally commands
6865 for command in self .queueoptions ["commands" ]:
69- fout .write ("%s\n " % command )
70- fout .write ("%s > %s 2> %s\n " % (self .maincommand , jobout , joberr ))
66+ fout .write ("%s\n " % command )
67+ fout .write ("%s > %s 2> %s\n " % (self .maincommand , jobout , joberr ))
7168 self .script = outfile
7269
7370 def submit (self ):
@@ -77,41 +74,42 @@ def submit(self):
7774 st = os .stat (self .script )
7875 os .chmod (self .script , st .st_mode | stat .S_IEXEC )
7976 cmd = [self .script ]
80- proc = sub .Popen (cmd , stdin = sub .PIPE ,stdout = sub .PIPE ,stderr = sub .PIPE )
77+ proc = sub .Popen (cmd , stdin = sub .PIPE , stdout = sub .PIPE , stderr = sub .PIPE )
8178 return proc
8279
80+
8381class SLURM :
8482 """
8583 Slurm class for writing submission script
8684 """
85+
8786 def __init__ (self , options , cores = 1 , directory = os .getcwd ()):
8887 """
8988 Create class
9089 """
91- self .queueoptions = {"scheduler" : "slurm" ,
92- "jobname " : "tis " ,
93- "queuename " : None ,
94- "walltime " : "23:59:00" ,
95- "memory " : "3GB " ,
96- "cores " : cores ,
97- "hint " : "nomultithread" ,
98- "directory " : directory ,
99- "options " : [] ,
100- "commands " : [ "uss=$(whoami)" ,
101- "find /dev/shm/ -user $uss -type f -mmin +30 -delete" ,
102- ] ,
103- "modules" : [] ,
104- "header" : "#!/bin/bash"
105-
106- }
107- for ( key , val ) in options .items ():
90+ self .queueoptions = {
91+ "scheduler " : "slurm " ,
92+ "jobname " : "tis" ,
93+ "queuename " : None ,
94+ "walltime " : "23:59:00 " ,
95+ "memory " : "3GB" ,
96+ "cores " : cores ,
97+ "hint " : "nomultithread" ,
98+ "directory " : directory ,
99+ "options " : [] ,
100+ "commands" : [
101+ "uss=$(whoami)" ,
102+ "find /dev/shm/ -user $uss -type f -mmin +30 -delete" ,
103+ ],
104+ "header" : "#!/bin/bash" ,
105+ }
106+ for key , val in options .items ():
108107 if key in self .queueoptions .keys ():
109108 if val is not None :
110109 if val != "" :
111110 self .queueoptions [key ] = val
112111 self .maincommand = ""
113112
114-
115113 def write_script (self , outfile ):
116114 """
117115 Write the script file
@@ -123,69 +121,66 @@ def write_script(self, outfile):
123121 fout .write (self .queueoptions ["header" ])
124122 fout .write ("\n " )
125123
126- #write the main header options
127- fout .write ("#SBATCH --job-name=%s\n " % self .queueoptions ["jobname" ])
128- fout .write ("#SBATCH --time=%s\n " % self .queueoptions ["walltime" ])
124+ # write the main header options
125+ fout .write ("#SBATCH --job-name=%s\n " % self .queueoptions ["jobname" ])
126+ fout .write ("#SBATCH --time=%s\n " % self .queueoptions ["walltime" ])
129127 if self .queueoptions ["queuename" ] is not None :
130- fout .write ("#SBATCH --partition=%s\n " % self .queueoptions ["queuename" ])
131- fout .write ("#SBATCH --ntasks=%s\n " % str (self .queueoptions ["cores" ]))
132- fout .write ("#SBATCH --mem-per-cpu=%s\n " % self .queueoptions ["memory" ])
133- fout .write ("#SBATCH --hint=%s\n " % self .queueoptions ["hint" ])
134- fout .write ("#SBATCH --chdir=%s\n " % self .queueoptions ["directory" ])
128+ fout .write ("#SBATCH --partition=%s\n " % self .queueoptions ["queuename" ])
129+ fout .write ("#SBATCH --ntasks=%s\n " % str (self .queueoptions ["cores" ]))
130+ fout .write ("#SBATCH --mem-per-cpu=%s\n " % self .queueoptions ["memory" ])
131+ fout .write ("#SBATCH --hint=%s\n " % self .queueoptions ["hint" ])
132+ fout .write ("#SBATCH --chdir=%s\n " % self .queueoptions ["directory" ])
135133
136- #now write extra options
134+ # now write extra options
137135 for option in self .queueoptions ["options" ]:
138- fout .write ("#SBATCH %s\n " % option )
136+ fout .write ("#SBATCH %s\n " % option )
139137
140- #now write modules
141- for module in self .queueoptions ["modules" ]:
142- fout .write ("module load %s\n " % module )
143-
144- #now finally commands
138+ # now finally commands
145139 for command in self .queueoptions ["commands" ]:
146- fout .write ("%s\n " % command )
147- fout .write ("%s > %s 2> %s\n " % (self .maincommand , jobout , joberr ))
140+ fout .write ("%s\n " % command )
141+ fout .write ("%s > %s 2> %s\n " % (self .maincommand , jobout , joberr ))
148142
149143 self .script = outfile
150144
151145 def submit (self ):
152146 """
153147 Submit the job
154148 """
155- cmd = [' sbatch' , self .script ]
156- proc = sub .Popen (cmd , stdin = sub .PIPE ,stdout = sub .PIPE ,stderr = sub .PIPE )
149+ cmd = [" sbatch" , self .script ]
150+ proc = sub .Popen (cmd , stdin = sub .PIPE , stdout = sub .PIPE , stderr = sub .PIPE )
157151 print (f'submitting { self .queueoptions ["jobname" ]} ' )
158152 proc .communicate ()
159153 return proc
160154
161155
162-
163156class SGE :
164157 """
165158 Slurm class for writing submission script
166159 """
160+
167161 def __init__ (self , options , cores = 1 , directory = os .getcwd ()):
168162 """
169163 Create class
170164 """
171- self .queueoptions = {"scheduler" : "sge" ,
172- "jobname" : "tis" ,
173- "walltime" : "23:59:00" ,
174- "queuename" : None ,
175- "memory" : "3GB" ,
176- "system" : "smp" ,
177- "commands" : [],
178- "modules" : [],
179- "options" : ["-j y" ,
180- "-R y" ,
181- "-P ams.p" ,
182- ],
183- "cores" : cores ,
184- "hint" : None ,
185- "directory" : directory ,
186- "header" : "#!/bin/bash"
187- }
188- for (key , val ) in options .items ():
165+ self .queueoptions = {
166+ "scheduler" : "sge" ,
167+ "jobname" : "tis" ,
168+ "walltime" : "23:59:00" ,
169+ "queuename" : None ,
170+ "memory" : "3GB" ,
171+ "system" : "smp" ,
172+ "commands" : [],
173+ "options" : [
174+ "-j y" ,
175+ "-R y" ,
176+ "-P ams.p" ,
177+ ],
178+ "cores" : cores ,
179+ "hint" : None ,
180+ "directory" : directory ,
181+ "header" : "#!/bin/bash" ,
182+ }
183+ for key , val in options .items ():
189184 if key in self .queueoptions .keys ():
190185 if val is not None :
191186 self .queueoptions [key ] = val
@@ -195,40 +190,40 @@ def write_script(self, outfile):
195190 """
196191 Write the script file
197192 """
193+ jobout = "." .join ([outfile , "out" ])
194+ joberr = "." .join ([outfile , "err" ])
195+
198196 with open (outfile , "w" ) as fout :
199197 fout .write (self .queueoptions ["header" ])
200198 fout .write ("\n " )
201199
202- #write the main header options
203- fout .write ("#$ -N %s\n " % self .queueoptions ["jobname" ])
204- fout .write ("#$ -l h_rt=%s\n " % self .queueoptions ["walltime" ])
205- fout .write ("#$ -l qname=%s\n " % self .queueoptions ["queuename" ])
206- fout .write ("#$ -pe %s %s\n " % ( self .queueoptions ["system" ], str (self .queueoptions ["cores" ])))
207- fout .write ("#$ -l h_vmem=%s\n " % self .queueoptions ["memory" ])
208- fout .write ("#$ -cwd %s\n " % self .queueoptions ["directory" ])
209-
210- #now write extra options
200+ # write the main header options
201+ fout .write ("#$ -N %s\n " % self .queueoptions ["jobname" ])
202+ fout .write ("#$ -l h_rt=%s\n " % self .queueoptions ["walltime" ])
203+ fout .write ("#$ -l qname=%s\n " % self .queueoptions ["queuename" ])
204+ fout .write (
205+ "#$ -pe %s %s\n "
206+ % (self .queueoptions ["system" ], str (self .queueoptions ["cores" ]))
207+ )
208+ fout .write ("#$ -l h_vmem=%s\n " % self .queueoptions ["memory" ])
209+ fout .write ("#$ -cwd %s\n " % self .queueoptions ["directory" ])
210+
211+ # now write extra options
211212 for option in self .queueoptions ["options" ]:
212- fout .write ("#$ %s\n " % option )
213-
214- #now write modules
215- for module in self .queueoptions ["modules" ]:
216- fout .write ("module load %s\n " % module )
213+ fout .write ("#$ %s\n " % option )
217214
218- #now finally commands
215+ # now finally commands
219216 for command in self .queueoptions ["commands" ]:
220- fout .write ("%s\n " % command )
217+ fout .write ("%s\n " % command )
221218
222- fout .write ("%s > %s 2> %s\n " % (self .maincommand , jobout , joberr ))
223-
224- self .script = outfile
219+ fout .write ("%s > %s 2> %s\n " % (self .maincommand , jobout , joberr ))
225220
221+ self .script = outfile
226222
227223 def submit (self ):
228224 """
229225 Submit the job
230226 """
231- cmd = [' qsub' , self .script ]
232- proc = sub .Popen (cmd , stdin = sub .PIPE ,stdout = sub .PIPE ,stderr = sub .PIPE )
227+ cmd = [" qsub" , self .script ]
228+ proc = sub .Popen (cmd , stdin = sub .PIPE , stdout = sub .PIPE , stderr = sub .PIPE )
233229 return proc
234-
0 commit comments