-
Notifications
You must be signed in to change notification settings - Fork 16
/
generateJobs_local.py
executable file
·180 lines (154 loc) · 5.7 KB
/
generateJobs_local.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#! /usr/bin/env python
"""
This script duplicates the EBE-Node folder and generate a collection of pbs
files to be batch-submitted. For efficiency all codes inside EBE-Node should
be compiled.
"""
from sys import argv, exit
from os import makedirs, path, unlink
from shutil import copytree, copy, rmtree
from subprocess import call
from check_prerequisites import checkEnvironment, checkExecutables, greetings
# check argv
try:
# set parameters
numberOfJobs = int(argv[1])
numberOfEventsPerJob = int(argv[2])
# set optional parameters
argId = 2
argId += 1
if len(argv)>=argId+1: # set working folder
workingFolder = path.abspath(argv[argId])
else:
workingFolder = path.abspath("./PlayGround")
argId += 1
if len(argv)>=argId+1: # folder to store results
resultsFolder = path.abspath(argv[argId])
else:
resultsFolder = path.abspath("./RESULTS")
argId += 1
if len(argv)>=argId+1: # set wall time
walltime = argv[argId]
else:
walltime = "%d:00:00" % (3*numberOfEventsPerJob) # 3 hours per job
argId += 1
if len(argv)>=argId+1: # whether to compress final results folder
compressResultsFolderAnswer = argv[argId]
else:
compressResultsFolderAnswer = "yes"
except:
print('Usage: generateJobs.py number_of_jobs number_of_events_per_job [working_folder="./PlayGround"] [results_folder="./RESULTS"] [walltime="03:00:00" (per event)] [compress_results_folder="yes"]')
exit()
# save config files
open("saved_configs.py", "w").writelines("""
iEbeConfigs = {
"number_of_jobs" : %d,
"number_of_events_per_job" : %d,
"working_folder" : "%s",
"results_folder" : "%s",
"walltime" : "%s",
"compress_results_folder" : "%s",
}
""" % (numberOfJobs, numberOfEventsPerJob, workingFolder, resultsFolder, walltime, compressResultsFolderAnswer)
)
# define colors
purple = "\033[95m"
green = "\033[92m"
blue = "\033[94m"
yellow = "\033[93m"
red = "\033[91m"
normal = "\033[0m"
# print welcome message
print(yellow)
greetings(3)
print(purple + "\n" + "-"*80 + "\n>>>>> Welcome to the event generator! <<<<<\n" + "-"*80 + normal)
# check prerequisites
print(green + "\n>>>>> Checking for required libraries <<<<<\n" + normal)
if not checkEnvironment():
print("Prerequisites not met. Install the required library first please. Aborting.")
exit()
# check existence of executables
print(green + "\n>>>>> Checking for existence of executables <<<<<\n" + normal)
if not checkExecutables():
print("Not all executables can be generated. Aborting.")
exit()
# clean up check_prerequisites.pyc
if path.exists("check_prerequisites.pyc"): unlink("check_prerequisites.pyc")
# generate events
print(green + "\n>>>>> Generating events <<<<<\n" + normal)
# prepare directories
if not path.exists(resultsFolder): makedirs(resultsFolder)
if path.exists(workingFolder): rmtree(workingFolder)
makedirs(workingFolder)
ebeNodeFolder = "EBE-Node"
crankFolderName = "crank"
crankFolder = path.join(ebeNodeFolder, crankFolderName)
# copy parameter file into the crank folder
copy("ParameterDict.py", crankFolder)
# backup parameter files to the result folder
copy(path.join(crankFolder, "SequentialEventDriver.py"), resultsFolder)
copy(path.join(crankFolder, "ParameterDict.py"), resultsFolder)
# duplicate EBE-Node folder to working directory, write .pbs file
for i in range(1, numberOfJobs+1):
targetWorkingFolder = path.join(workingFolder, "job-%d" % i)
# copy folder
copytree(ebeNodeFolder, targetWorkingFolder)
open(path.join(targetWorkingFolder, "job-%d.pbs" % i), "w").write(
"""
#!/usr/bin/env bash
#PBS -N iEBE-%d
#PBS -l walltime=%s
#PBS -j oe
#PBS -S /bin/bash
cd %s
(cd %s
ulimit -n 1000
python ./SequentialEventDriver_shell.py %d 1> RunRecord.txt 2> ErrorRecord.txt
cp RunRecord.txt ErrorRecord.txt ../finalResults/
)
mv ./finalResults %s/job-%d
""" % (i, walltime, targetWorkingFolder, crankFolderName, numberOfEventsPerJob, resultsFolder, i)
)
if compressResultsFolderAnswer == "yes":
open(path.join(targetWorkingFolder, "job-%d.pbs" % i), "a").write(
"""
(cd %s
zip -r -m -q job-%d.zip job-%d
)
""" % (resultsFolder, i, i)
)
# add a data collector watcher
if compressResultsFolderAnswer == "yes":
EbeCollectorFolder = "EbeCollector"
utilitiesFolder = "utilities"
watcherDirectory = path.join(workingFolder, "watcher")
makedirs(path.join(watcherDirectory, ebeNodeFolder))
copytree(path.join(ebeNodeFolder, EbeCollectorFolder), path.join(watcherDirectory, ebeNodeFolder, EbeCollectorFolder))
copytree(utilitiesFolder, path.join(watcherDirectory, utilitiesFolder))
open(path.join(watcherDirectory, "watcher.pbs"), "w").write(
"""
#!/usr/bin/env bash
#PBS -N watcher
#PBS -l walltime=%s
#PBS -j oe
#PBS -S /bin/bash
cd %s
(cd %s
python autoZippedResultsCombiner.py %s %d "job-(\d*).zip" 60 1> WatcherReport.txt
mv WatcherReport.txt %s
)
""" % (walltime, watcherDirectory, utilitiesFolder, resultsFolder, numberOfJobs, resultsFolder)
)
import ParameterDict
initial_condition_type = (
ParameterDict.initial_condition_control['initial_condition_type'])
if initial_condition_type == 'pre-generated':
initial_file_path = (ParameterDict.initial_condition_control[
'pre-generated_initial_file_path'])
call("./copy_pre_generated_initial_conditions.sh %d %d %s %s"
% (numberOfJobs, numberOfEventsPerJob, initial_file_path,
workingFolder), shell=True)
print("Jobs generated. Submit them using submitJobs scripts.")
###########################################################################
# 05-23-2013:
# Bugfix: "cd %s" added to the pbs files.