15 import Alignment.MillePedeAlignmentAlgorithm.mpslib.Mpslibclass
as mpslib
16 import Alignment.MillePedeAlignmentAlgorithm.mpslib.tools
as mps_tools
27 """Forward proxy to location visible from the batch system. 30 - `rundir`: directory for storing the forwarded proxy 33 if not mps_tools.check_proxy():
34 print "Please create proxy via 'voms-proxy-init -voms cms -rfc'." 37 local_proxy = subprocess.check_output([
"voms-proxy-info",
"--path"]).
strip()
38 shutil.copyfile(local_proxy, os.path.join(rundir,
".user_proxy"))
42 """Writes 'job.submit' file in `path`. 45 - `path`: job directory 46 - `script`: script to be executed 48 - `lib`: MPS lib object 51 resources = lib.get_class(
"pede").
split(
"_")[1:]
52 job_flavour = resources[-1]
54 job_submit_template=
"""\ 56 executable = {script:s} 57 output = {jobm:s}/STDOUT 58 error = {jobm:s}/STDOUT 61 transfer_output_files = "" 62 request_memory = {pedeMem:d}M 64 # adapted to space used on eos for binaries: 65 request_disk = {disk:d} 67 # adapted to threads parameter in pede options and number of available cores 68 request_cpus = {cpus:d} 70 +JobFlavour = "{flavour:s}" 72 if "bigmem" in resources:
73 job_submit_template +=
"""\ 75 +AccountingGroup = "group_u_CMS.e_cms_caf_bigmem" 77 # automatically remove the job if the submitter has no permissions to run a BigMemJob 78 periodic_remove = !regexp("group_u_CMS.e_cms_caf_bigmem", AccountingGroup) && BigMemJob =?= True 80 job_submit_template +=
"\nqueue\n" 82 print "Determine number of pede threads..." 83 cms_process = mps_tools.get_process_object(os.path.join(Path, mergeCfg))
84 pede_options = cms_process.AlignmentProducer.algoConfig.pedeSteerer.options.value()
86 for option
in pede_options:
87 if "threads" in option:
88 n_threads = option.replace(
"threads",
"").
strip()
89 n_threads =
max(
map(
lambda x:
int(x), n_threads.split()))
91 if n_threads > 16: n_threads = 16
95 print "Determine required disk space on remote host..." 98 spco = subprocess.check_output
100 cmd = [
"du",
"--apparent-size"]
101 disk_usage = [
int(item.split()[0])
102 for directory
in (
"binaries",
"monitors",
"tree_files")
105 glob.glob(opj(lib.mssDir, directory,
"*"))).splitlines()]
106 disk_usage = sum(disk_usage)
109 job_submit_file = os.path.join(Path,
"job.submit")
110 with open(job_submit_file,
"w")
as f:
111 f.write(job_submit_template.format(script = os.path.abspath(script),
112 jobm = os.path.abspath(path),
113 pedeMem = lib.pedeMem,
114 disk =
int(disk_usage),
116 flavour = job_flavour))
118 return job_submit_file
124 description=
"Submit jobs that are setup in local mps database to batch system.",
126 parser.add_argument(
"maxJobs", type=int, nargs=
'?', default=1,
127 help=
"number of Mille jobs to be submitted (default: %(default)d)")
128 parser.add_argument(
"-j",
"--job-id", dest =
"job_id", nargs =
"*",
129 help = (
"job IDs to be submitted; " 130 "use either 'job<ID>' or directly '<ID>'"))
131 parser.add_argument(
"-a",
"--all", dest=
"allMille", default=
False,
133 help = (
"submit all setup Mille jobs; " 134 "maxJobs and --job-id are ignored"))
135 parser.add_argument(
"-m",
"--merge", dest=
"fireMerge", default=
False,
137 help = (
"submit all setup Pede jobs; " 138 "maxJobs is ignored, but --job-id is respected"))
139 parser.add_argument(
"-f",
"--force-merge", dest=
"forceMerge", default=
False,
141 help=(
"force the submission of the Pede job in case some "+
142 "Mille jobs are not in the OK state"))
143 parser.add_argument(
"-p",
"--forward-proxy", dest=
"forwardProxy", default=
False,
145 help=
"forward VOMS proxy to batch system")
146 args = parser.parse_args(sys.argv[1:])
149 lib = mpslib.jobdatabase()
154 args.maxJobs = lib.nJobs
157 if args.job_id
is None:
158 job_mask = lib.JOBDIR
161 for job_id
in args.job_id:
163 if job_id.startswith(
"job"): job_mask.append(job_id)
164 elif job_id.startswith(
"m"): job_mask.append(
"job"+job_id)
167 job_mask.append(lib.JOBDIR[
int(job_id)-1])
171 print "ID provided to '-j/--job-id' is out of range:", job_id
174 if invalid_id
or job_mask[-1]
not in lib.JOBDIR:
175 print "ID provided to '-j/--job-id' is invalid:", job_id
176 print "'-j/--job-id' requires the IDs to exist and to be of either",
177 print "of the following formats:" 185 theJobData = os.path.join(os.getcwd(),
"jobData")
188 theJobName =
'mpalign' 189 if lib.addFiles !=
'':
190 theJobName = lib.addFiles
192 fire_htcondor =
False 195 if not args.fireMerge:
197 resources = lib.get_class(
'mille')
200 if 'cmscafspec' in resources:
201 print '\nWARNING:\n Running mille jobs on cmscafspec, intended for pede only!\n\n' 202 resources =
'-q cmscafalcamille' 204 elif 'cmscaf' in resources:
206 resources =
'-q'+resources+
' -m g_cmscaf' 207 elif "htcondor" in resources:
210 resources =
'-q '+resources
213 for i
in xrange(lib.nJobs):
214 if lib.JOBDIR[i]
not in job_mask:
continue 215 if lib.JOBSTATUS[i] ==
'SETUP':
216 if nSub < args.maxJobs:
217 if args.forwardProxy:
222 submission =
'bsub -J %s %s %s/%s/theScript.sh' % \
223 (theJobName, resources, theJobData, lib.JOBDIR[i])
226 result = subprocess.check_output(submission,
227 stderr=subprocess.STDOUT,
229 except subprocess.CalledProcessError
as e:
232 result = result.strip()
235 match = re.search(
'Job <(\d+)> is submitted', result)
238 lib.JOBSTATUS[i] =
'SUBTD' 239 lib.JOBID[i] = match.group(1)
241 print 'Submission of %03d seems to have failed: %s' % (lib.JOBNUMBER[i],result),
248 resources = lib.get_class(
'pede')
249 if 'cmscafspec' in resources:
250 resources =
'-q cmscafalcamille' 251 elif "htcondor" in resources:
254 resources =
'-q '+resources
256 if not fire_htcondor:
258 resources = resources+
' -R \"rusage[mem="%s"]\"' %
str(lib.pedeMem)
262 for i
in xrange(lib.nJobs):
263 if lib.JOBSTATUS[i] !=
'OK':
264 if 'DISABLED' not in lib.JOBSTATUS[i]:
270 while i<len(lib.JOBDIR):
272 if lib.JOBDIR[i]
not in job_mask:
277 if lib.JOBSTATUS[i] !=
'SETUP':
278 print 'Merge job %d status %s not submitted.' % \
279 (jobNumFrom1, lib.JOBSTATUS[i])
280 elif not (mergeOK
or args.forceMerge):
281 print 'Merge job',jobNumFrom1,
'not submitted since Mille jobs error/unfinished (Use -m -f to force).' 284 Path = os.path.join(theJobData,lib.JOBDIR[i])
285 backupScriptPath = os.path.join(Path,
"theScript.sh.bak")
286 scriptPath = os.path.join(Path,
"theScript.sh")
292 if not os.path.isfile(backupScriptPath):
293 os.system(
'cp -p '+scriptPath+
' '+backupScriptPath)
296 command =
'cat '+backupScriptPath+
' | grep CONFIG_FILE | head -1 | awk -F"/" \'{print $NF}\'' 297 mergeCfg = subprocess.check_output(command, stderr=subprocess.STDOUT, shell=
True)
298 mergeCfg = mergeCfg.strip()
304 backupCfgPath = os.path.join(Path, mergeCfg+
".bak")
305 cfgPath = os.path.join(Path, mergeCfg)
306 if not os.path.isfile(backupCfgPath):
307 os.system(
'cp -p '+cfgPath+
' '+backupCfgPath)
310 with open(os.path.join(Path,
".weights.pkl"),
"rb")
as f:
311 weight_conf = cPickle.load(f)
314 mps_tools.run_checked([
"mps_weight.pl",
"-c"])
317 for name,weight
in weight_conf:
318 print " ".
join([
"mps_weight.pl",
"-N", name, weight])
319 mps_tools.run_checked([
"mps_weight.pl",
"-N", name, weight])
322 inCfgPath = theJobData+
'/'+lib.JOBDIR[0]+
'/the.py' 323 command =
'mps_merge.py -w -c '+inCfgPath+
' '+Path+
'/'+mergeCfg+
' '+Path+
' '+
str(lib.nJobs)
327 command =
'mps_scriptm.pl -c '+lib.mergeScript+
' '+scriptPath+
' '+Path+
' '+mergeCfg+
' '+
str(lib.nJobs)+
' '+lib.mssDir+
' '+lib.mssDirPool
332 if os.path.isfile(backupScriptPath):
333 os.system(
'cp -pf '+backupScriptPath+
' '+scriptPath)
336 command =
"cat "+scriptPath+
" | grep '^\s*CONFIG_FILE' | awk -F'=' '{print $2}'" 337 mergeCfg = subprocess.check_output(command, stderr=subprocess.STDOUT, shell=
True)
338 command =
'basename '+mergeCfg
339 mergeCfg = subprocess.check_output(command, stderr=subprocess.STDOUT, shell=
True)
340 mergeCfg = mergeCfg.replace(
'\n',
'')
346 backupCfgPath = Path+
'/%s.bak' % mergeCfg
347 cfgPath = Path+
'/%s' % mergeCfg
348 if os.path.isfile(backupCfgPath):
349 os.system(
'cp -pf '+backupCfgPath+
' '+cfgPath)
355 curJobName =
'm'+
str(nMerge)+
'_'+theJobName
358 submission = [
"condor_submit",
359 "-batch-name", curJobName,
362 submission = [
"bsub",
"-J", curJobName, resources, scriptPath]
365 result = subprocess.check_output(submission, stderr=subprocess.STDOUT)
367 except subprocess.CalledProcessError
as e:
371 result = result.strip()
375 match = re.search(
r"1 job\(s\) submitted to cluster (\d+)\.", result)
377 match = re.search(
'Job <(\d+)> is submitted', result)
379 lib.JOBSTATUS[i] =
'SUBTD' 380 lib.JOBID[i] = match.group(1)
382 if fire_htcondor: lib.JOBID[i] +=
".0" 383 print "jobid is", lib.JOBID[i]
385 print 'Submission of merge job seems to have failed:',result,
def forward_proxy(rundir)
def write_HTCondor_submit_file(path, script, config, lib)
static std::string join(char **cmd)