61
61
import madgraph.various.gen_crossxhtml as gen_crossxhtml
62
62
import madgraph.various.sum_html as sum_html
63
63
import madgraph.various.misc as misc
64
import madgraph.various.combine_runs as combine_runs
65
66
import models.check_param_card as check_param_card
66
67
from madgraph import InvalidCmd, MadGraph5Error
79
80
import internal.cluster as cluster
80
81
import internal.check_param_card as check_param_card
81
82
import internal.sum_html as sum_html
83
import internal.combine_runs as combine_runs
84
86
class MadEventError(Exception):
338
340
logger.info(" timeout VALUE")
339
341
logger.info(" (default 20) Seconds allowed to answer questions.")
340
342
logger.info(" Note that pressing tab always stops the timer.")
343
logger.info(" cluster_temp_path PATH")
344
logger.info(" (default None) Allow to perform the run in PATH directory")
345
logger.info(" This allow to not run on the central disk. This is not used")
346
logger.info(" by condor cluster (since condor has it's own way to prevent it).")
342
349
def run_options_help(self, data):
344
351
logger.info('-- local options:')
1539
1546
options_madevent = {'automatic_html_opening':True,
1541
1548
'cluster_queue':'madgraph',
1550
'cluster_temp_path':None}
1545
1553
############################################################################
1645
1653
args.remove(arg)
1655
if args and args[0] in ["run_mode", "cluster_mode", "cluster_queue",
1656
"cluster_temp_path", "nb_core"]:
1647
1659
if self.cluster_mode == 2 and not self.nb_core:
1648
1660
import multiprocessing
1649
1661
self.nb_core = multiprocessing.cpu_count()
1651
1663
if self.cluster_mode == 1 and not hasattr(self, 'cluster'):
1652
cluster_name = self.options['cluster_type']
1653
self.cluster = cluster.from_name[cluster_name](self.options['cluster_queue'])
1665
cluster_name = opt['cluster_type']
1666
self.cluster = cluster.from_name[cluster_name](opt['cluster_queue'],
1667
opt['cluster_temp_path'])
1656
1670
############################################################################
1951
1965
raise self.InvalidCmd, 'run_mode should be 0, 1 or 2.'
1952
1966
self.cluster_mode = int(args[1])
1953
1967
self.options['run_mode'] = self.cluster_mode
1954
elif args[0] == 'cluster_type':
1955
self.options['cluster_type'] = args[1]
1956
self.cluster = cluster.from_name[args[1]](self.options['cluster_queue'])
1968
elif args[0] in ['cluster_type', 'cluster_queue', 'cluster_temp_path']:
1969
self.options[args[0]] = args[1]
1971
self.cluster = cluster.from_name[opt['cluster_type']](\
1972
opt['cluster_queue'], opt['cluster_temp_path'])
1957
1973
elif args[0] == 'nb_core':
1958
1974
if args[1] == 'None':
1959
1975
import multiprocessing
2373
2389
# clean previous run
2374
2390
for match in glob.glob(pjoin(Pdir, '*ajob*')):
2375
2391
if os.path.basename(match)[:4] in ['ajob', 'wait', 'run.', 'done']:
2376
os.remove(pjoin(Pdir, match))
2393
for match in glob.glob(pjoin(Pdir, 'G*')):
2394
if os.path.exists(pjoin(match,'results.dat')):
2395
os.remove(pjoin(match, 'results.dat'))
2378
2397
#compile gensym
2379
2398
misc.compile(['gensym'], cwd=Pdir)
2401
2420
self.total_jobs += len(alljobs)
2402
2421
for i, job in enumerate(alljobs):
2403
2422
job = os.path.basename(job)
2404
self.launch_job('./%s' % job, cwd=Pdir, remaining=(len(alljobs)-i-1),
2423
self.launch_job('%s' % job, cwd=Pdir, remaining=(len(alljobs)-i-1),
2405
2424
run_type='survey on %s (%s/%s)' % (subdir,nb_proc+1,len(subproc)))
2406
2425
if os.path.exists(pjoin(self.me_dir,'error')):
2407
2426
self.monitor(html=True)
2453
2472
# clean previous run
2454
2473
for match in glob.glob(pjoin(Pdir, '*ajob*')):
2455
2474
if os.path.basename(match)[:4] in ['ajob', 'wait', 'run.', 'done']:
2456
os.remove(pjoin(Pdir, match))
2458
2477
proc = misc.Popen([pjoin(bindir, 'gen_ximprove')],
2459
2478
stdout=devnull,
2464
2483
if os.path.exists(pjoin(Pdir, 'ajob1')):
2465
2484
misc.compile(['madevent'], cwd=Pdir)
2467
2485
alljobs = glob.glob(pjoin(Pdir,'ajob*'))
2487
#remove associated results.dat (ensure to not mix with all data)
2488
Gre = re.compile("\s*j=(G[\d\.\w]+)")
2490
Gdirs = Gre.findall(open(job).read())
2492
if os.path.exists(pjoin(Pdir, Gdir, 'results.dat')):
2493
os.remove(pjoin(Pdir, Gdir,'results.dat'))
2468
2495
nb_tot = len(alljobs)
2469
2496
self.total_jobs += nb_tot
2470
2497
for i, job in enumerate(alljobs):
2471
2498
job = os.path.basename(job)
2472
self.launch_job('./%s' % job, cwd=Pdir, remaining=(nb_tot-i-1),
2499
self.launch_job('%s' % job, cwd=Pdir, remaining=(nb_tot-i-1),
2473
2500
run_type='Refine number %s on %s (%s/%s)' %
2474
2501
(self.nb_refine, subdir, nb_proc+1, len(subproc)))
2475
2502
self.monitor(run_type='All job submitted for refine number %s' % self.nb_refine,
2484
2511
bindir = pjoin(os.path.relpath(self.dirbin, pjoin(self.me_dir,'SubProcesses')))
2485
misc.call([pjoin(bindir, 'combine_runs')],
2486
cwd=pjoin(self.me_dir,'SubProcesses'),
2513
combine_runs.CombineRuns(self.me_dir)
2489
2515
cross, error = sum_html.make_all_html_results(self)
2490
2516
self.results.add_detail('cross', cross)
2513
2539
out = misc.call(['../bin/internal/run_combine'],
2514
2540
cwd=pjoin(self.me_dir,'SubProcesses'),
2515
2541
stdout=open(pjoin(self.me_dir,'SubProcesses','combine.log'),'w'))
2517
output = open(pjoin(self.me_dir,'SubProcesses','combine.log')).read()
2544
output = misc.mult_try_open(pjoin(self.me_dir,'SubProcesses','combine.log')).read()
2518
2545
# Store the number of unweighted events for the results object
2519
2546
pat = re.compile(r'''\s*Unweighting selected\s*(\d+)\s*events''',re.MULTILINE)
2520
if self.cluster_mode == 1 and not output:
2522
output = open(pjoin(self.me_dir,'SubProcesses','combine.log')).read()
2525
nb_event = pat.search(output).groups()[0]
2526
self.results.add_detail('nb_event', nb_event)
2548
nb_event = pat.search(output).groups()[0]
2549
self.results.add_detail('nb_event', nb_event)
2530
2552
# Define The Banner
2531
2553
tag = self.run_card['run_tag']
3374
3396
elif mode == 1:
3375
self.cluster.submit(exe, stdout=stdout, cwd=cwd)
3397
# For condor cluster, create the input/output files
3399
input_files = ['madevent','input_app.txt','symfact.dat','iproc.dat',
3400
pjoin(self.me_dir, 'SubProcesses','randinit')]
3403
#Find the correct PDF input file
3405
input_files.append(self.pdffile)
3407
for line in open(pjoin(self.me_dir,'Source','PDF','pdf_list.txt')):
3411
if data[0].lower() == self.run_card['pdlabel'].lower():
3412
self.pdffile = pjoin(self.me_dir, 'lib', 'Pdfdata', data[2])
3413
input_files.append(self.pdffile)
3416
# possible when using lhapdf
3417
self.pdffile = pjoin(self.me_dir, 'lib', 'PDFsets')
3418
input_files.append(self.pdffile)
3421
#Find the correct ajob
3422
Gre = re.compile("\s*j=(G[\d\.\w]+)")
3427
fsock = open(pjoin(cwd,exe))
3429
output_files = Gre.findall(text)
3430
if not output_files:
3431
Ire = re.compile("for i in ([\d\s]*) ; do")
3432
data = Ire.findall(text)
3433
data = ' '.join(data).split()
3435
output_files.append('G%s' % nb)
3437
for G in output_files:
3438
if os.path.isdir(pjoin(cwd,G)):
3439
input_files.append(G)
3442
self.cluster.submit2(exe, stdout=stdout, cwd=cwd,
3443
input_files=input_files, output_files=output_files)
3446
self.cluster.submit(exe, stdout=stdout, cwd=cwd)
3377
3448
elif mode == 2:
3490
3561
time_mod = max([os.path.getctime(pjoin(self.me_dir,'Cards','run_card.dat')),
3491
3562
os.path.getctime(pjoin(self.me_dir,'Cards','param_card.dat'))])
3493
if self.configured > time_mod:
3564
if self.configured > time_mod and hasattr(self, 'random'):
3496
3567
self.configured = time.time()
3548
3620
for name in ['../bin/internal/gen_ximprove', 'all',
3549
'../bin/internal/combine_events',
3550
'../bin/internal/combine_runs']:
3621
'../bin/internal/combine_events']:
3551
3622
misc.compile(arg=[name], cwd=os.path.join(self.me_dir, 'Source'))
4510
4581
self.total_jobs += nb_tot
4511
4582
for i, job in enumerate(alljobs):
4512
4583
job = os.path.basename(job)
4513
self.launch_job('./%s' % job, cwd=Pdir, remaining=(nb_tot-i-1),
4584
self.launch_job('%s' % job, cwd=Pdir, remaining=(nb_tot-i-1),
4514
4585
run_type='Refine number %s on %s (%s/%s)' %
4515
4586
(self.nb_refine, subdir, nb_proc+1, len(subproc)))
4516
4587
if os.path.exists(pjoin(self.me_dir,'error')):