Package madgraph :: Package interface :: Module launch_ext_program
[hide private]
[frames] | no frames]

Source Code for Module madgraph.interface.launch_ext_program

  1  ################################################################################ 
  2  # 
  3  # Copyright (c) 2009 The MadGraph5_aMC@NLO Development team and Contributors 
  4  # 
  5  # This file is a part of the MadGraph5_aMC@NLO project, an application which  
  6  # automatically generates Feynman diagrams and matrix elements for arbitrary 
  7  # high-energy processes in the Standard Model and beyond. 
  8  # 
  9  # It is subject to the MadGraph5_aMC@NLO license which should accompany this  
 10  # distribution. 
 11  # 
 12  # For more information, visit madgraph.phys.ucl.ac.be and amcatnlo.web.cern.ch 
 13  # 
 14  ################################################################################ 
 15   
 16   
 17  import logging 
 18  import os 
 19  import pydoc 
 20  import subprocess 
 21  import time 
 22  start=time.time() 
 23  import madgraph.iolibs.files as files 
 24  import madgraph.interface.madevent_interface as me_cmd 
 25  import madgraph.various.misc as misc 
 26  import madgraph.various.process_checks as process_checks 
 27  import madgraph.various.banner as banner_mod 
 28   
 29  #from madgraph import MG4DIR, MG5DIR, MadGraph5Error 
 30  #from madgraph.iolibs.files import cp 
 31  pjoin = os.path.join 
 32   
 33   
 34  logger = logging.getLogger('cmdprint.ext_program') 
 35   
 36   
 37   
38 -class ExtLauncher(object):
39 """ Generic Class for executing external program """ 40 41 program_dir = '' 42 executable = '' # path from program_dir 43 44 force = False 45
46 - def __init__(self, cmd, running_dir, card_dir='', **options):
47 """ initialize an object """ 48 49 self.running_dir = running_dir 50 self.card_dir = os.path.join(self.running_dir, card_dir) 51 self.cmd_int = cmd 52 #include/overwrite options 53 for key,value in options.items(): 54 setattr(self, key, value) 55 56 self.cards = [] # files can be modified (path from self.card_dir)
57
58 - def run(self):
59 """ execute the main code """ 60 61 self.prepare_run() 62 for card in self.cards: 63 self.treat_input_file(card, default = 'n') 64 65 self.launch_program()
66 67
68 - def prepare_run(self):
69 """ aditional way to prepare the run""" 70 pass
71
72 - def launch_program(self):
73 """launch the main program""" 74 subprocess.call([self.executable], cwd=self.running_dir)
75
76 - def edit_file(self, path):
77 """edit a file""" 78 79 path = os.path.realpath(path) 80 open_file(path)
81 82 83 # Treat Nicely the timeout
84 - def timeout_fct(self,timeout):
85 if timeout: 86 # avoid to always wait a given time for the next answer 87 self.force = True
88
89 - def ask(self, question, default, choices=[], path_msg=None):
90 """nice handling of question""" 91 92 if not self.force: 93 return self.cmd_int.ask(question, default, choices=choices, 94 path_msg=path_msg, fct_timeout=self.timeout_fct) 95 else: 96 return str(default)
97 98
99 - def treat_input_file(self, filename, default=None, msg=''):
100 """ask to edit a file""" 101 102 if msg == '' and filename == 'param_card.dat': 103 msg = \ 104 "WARNING: If you edit this file don\'t forget to consistently "+\ 105 "modify the different parameters,\n especially the width of all "+\ 106 "particles." 107 108 if not self.force: 109 if msg: print msg 110 question = 'Do you want to edit file: %(card)s?' % {'card':filename} 111 choices = ['y', 'n'] 112 path_info = 'path of the new %(card)s' % {'card':os.path.basename(filename)} 113 ans = self.ask(question, default, choices, path_info) 114 else: 115 ans = default 116 117 if ans == 'y': 118 path = os.path.join(self.card_dir, filename) 119 self.edit_file(path) 120 elif ans == 'n': 121 return 122 else: 123 path = os.path.join(self.card_dir, filename) 124 files.cp(ans, path)
125
126 -class MadLoopLauncher(ExtLauncher):
127 """ A class to launch a simple Standalone test """ 128
129 - def __init__(self, cmd_int, running_dir, **options):
130 """ initialize the StandAlone Version """ 131 132 ExtLauncher.__init__(self, cmd_int, running_dir, './Cards', **options) 133 self.cards = ['param_card.dat','MadLoopParams.dat']
134
135 - def prepare_run(self):
136 """ Possible preparatory actions to take.""" 137 pass
138
139 - def treat_input_file(self, filename, default=None, msg='', dir_path=None):
140 """ask to edit a file""" 141 142 if filename == 'PS.input': 143 if not self.force: 144 if msg!='': print msg 145 question = 'Do you want to specify the Phase-Space point: %(card)s?' % {'card':filename} 146 choices = ['y', 'n'] 147 path_info = 'path of the PS.input file' 148 ans = self.ask(question, default, choices, path_info) 149 else: 150 ans = default 151 if ans == 'y': 152 if not os.path.isfile(os.path.join(dir_path,'PS.input')): 153 PSfile = open(os.path.join(dir_path,'PS.input'), 'w') 154 if not os.path.isfile(os.path.join(dir_path,'result.dat')): 155 PSfile.write('\n'.join([' '.join(['%.16E'%0.0 for \ 156 pi in range(4)]) for pmom in range(1)])) 157 else: 158 default_ps = process_checks.LoopMatrixElementEvaluator.\ 159 parse_check_output(file(os.path.join(dir_path,\ 160 'result.dat')),format='dict')['res_p'] 161 PSfile.write('\n'.join([' '.join(['%.16E'%pi for pi \ 162 in pmom]) for pmom in default_ps])) 163 PSfile.write("\n\nEach line number 'i' like the above one sets"+\ 164 " the momentum of particle number i, \nordered like in"+\ 165 " the process definition. The format is (E,px,py,pz).") 166 PSfile.close() 167 self.edit_file(os.path.join(dir_path,'PS.input')) 168 else: 169 super(MadLoopLauncher,self).treat_input_file(filename,default,msg) 170 if filename == 'MadLoopParams.dat': 171 # Make sure to update the changes 172 MadLoopparam = banner_mod.MadLoopParam( 173 os.path.join(self.card_dir, 'MadLoopParams.dat')) 174 # Unless user asked for it, don't doublecheck the helicity filter. 175 MadLoopparam.set('DoubleCheckHelicityFilter', False, 176 changeifuserset=False) 177 MadLoopparam.write(os.path.join(self.card_dir,os.path.pardir, 178 'SubProcesses', 'MadLoopParams.dat'))
179
180 - def launch_program(self):
181 """launch the main program""" 182 evaluator = process_checks.LoopMatrixElementTimer 183 sub_path = os.path.join(self.running_dir, 'SubProcesses') 184 for path in os.listdir(sub_path): 185 if path.startswith('P') and \ 186 os.path.isdir(os.path.join(sub_path, path)): 187 shell_name = path.split('_')[1]+' > '+path.split('_')[2] 188 curr_path = os.path.join(sub_path, path) 189 infos = {} 190 logger.info("Initializing process %s."%shell_name) 191 nps = me_cmd.MadLoopInitializer.run_initialization( 192 curr_path, sub_path, infos, 193 req_files = ['HelFilter.dat','LoopFilter.dat']) 194 if nps == None: 195 raise MadGraph5Error,"MadLoop could not initialize the process %s"\ 196 %shell_name 197 logger.debug(("MadLoop initialization performed for %s"+\ 198 " using %d PS points (%s)")\ 199 %(shell_name,abs(nps),\ 200 'double precision' if nps>0 else 'quadruple precision')) 201 # Ask if the user wants to edit the PS point. 202 self.treat_input_file('PS.input', default='n', 203 msg='Phase-space point for process %s.'%shell_name,\ 204 dir_path=curr_path) 205 # We use mu_r=-1.0 to use the one defined by the user in the 206 # param_car.dat 207 me_cmd.MadLoopInitializer.fix_PSPoint_in_check(sub_path, 208 read_ps = os.path.isfile(os.path.join(curr_path, 'PS.input')), 209 npoints = 1, mu_r=-1.0) 210 # check 211 t1, t2, ram_usage = me_cmd.MadLoopInitializer.make_and_run(curr_path) 212 if t1==None or t2==None: 213 raise MadGraph5Error,"Error while running process %s."\ 214 %shell_name 215 try: 216 rFile=open(os.path.join(curr_path,'result.dat'), 'r') 217 except IOError: 218 raise MadGraph5Error,"Could not find result file %s."%\ 219 str(os.path.join(curr_path,'result.dat')) 220 # The result are returned as a dictionary. 221 result = evaluator.parse_check_output(rFile,format='dict') 222 for line in self.format_res_string(result, shell_name): 223 if isinstance(line, str): 224 logger.info(line) 225 elif isinstance(line,tuple): 226 logger.info(line[0],line[1])
227
228 - def format_res_string(self, res, shell_name):
229 """ Returns a good-looking string presenting the results. 230 The argument the tuple ((fin,born,spole,dpole,me_pow), p_out).""" 231 232 main_color='$MG:color:BLUE' 233 234 def special_float_format(float): 235 return '%s%.16e'%('' if float<0.0 else ' ',float)
236 237 so_order_names = res['Split_Orders_Names'] 238 239 def format_so_orders(so_orders): 240 return ' '.join(['%s=%d'%(so_order_names[i],so_orders[i]) for i in 241 range(len(so_orders))])
242 243 ASCII_bar = ('|'+''.join(['='*96]),main_color) 244 245 ret_code_h = res['return_code']//100 246 ret_code_t = (res['return_code']-100*ret_code_h)//10 247 ret_code_u = res['return_code']%10 248 StabilityOutput=[] 249 if ret_code_h==1: 250 if ret_code_t==3 or ret_code_t==4: 251 StabilityOutput.append('| Unknown numerical stability because '+\ 252 'MadLoop is in the initialization stage.') 253 else: 254 StabilityOutput.append('| Unknown numerical stability, check '+\ 255 'CTRunMode value in MadLoopParams.dat.') 256 elif ret_code_h==2: 257 StabilityOutput.append('| Stable kinematic configuration (SPS).') 258 elif ret_code_h==3: 259 StabilityOutput.append('| Unstable kinematic configuration (UPS).') 260 StabilityOutput.append('| Quadruple precision rescue successful.') 261 elif ret_code_h==4: 262 StabilityOutput.append('| Exceptional kinematic configuration (EPS).') 263 StabilityOutput.append('| Both double and quadruple precision'+\ 264 ' computations are unstable.') 265 266 if ret_code_t==2 or ret_code_t==4: 267 StabilityOutput.append('| Quadruple precision was used for this'+\ 268 'computation.') 269 if ret_code_h!=1: 270 if res['accuracy']>0.0: 271 StabilityOutput.append('| Estimated relative accuracy = %.1e'\ 272 %res['accuracy']) 273 elif res['accuracy']==0.0: 274 StabilityOutput.append('| Estimated relative accuracy = %.1e'\ 275 %res['accuracy']+' (i.e. beyond double precision)') 276 else: 277 StabilityOutput.append('| Estimated accuracy could not be '+\ 278 'computed for an unknown reason.') 279 280 PS_point_spec = ['|| Phase-Space point specification (E,px,py,pz)','|'] 281 PS_point_spec.append('\n'.join(['| '+' '.join(['%s'%\ 282 special_float_format(pi) for pi in pmom]) for pmom in res['res_p']])) 283 PS_point_spec.append('|') 284 285 str_lines=[] 286 287 notZeroBorn=True 288 if res['export_format']!='LoopInduced' and len(so_order_names) and \ 289 len([1 for k in res['Born_kept'] if k])==0: 290 notZeroBorn = False 291 str_lines.append( 292 ("| /!\\ There is no Born contribution for the squared orders specified in "+ 293 "the process definition/!\\",'$MG:color:RED')) 294 295 if res['export_format']=='Default' and notZeroBorn: 296 str_lines.extend(['\n',ASCII_bar, 297 ('|| Results for process %s'%shell_name,main_color), 298 ASCII_bar]+PS_point_spec+StabilityOutput+[ 299 '|', 300 ('|| Total(*) Born contribution (GeV^%d):'%res['gev_pow'],main_color), 301 ('| Born = %s'%special_float_format(res['born']),main_color), 302 ('|| Total(*) virtual contribution normalized with born*alpha_S/(2*pi):',main_color), 303 ('| Finite = %s'%special_float_format(res['finite']),main_color), 304 ('| Single pole = %s'%special_float_format(res['1eps']),main_color), 305 ('| Double pole = %s'%special_float_format(res['2eps']),main_color)]) 306 elif res['export_format']=='LoopInduced' and notZeroBorn: 307 str_lines.extend(['\n',ASCII_bar, 308 ('|| Results for process %s (Loop-induced)'%shell_name,main_color), 309 ASCII_bar]+PS_point_spec+StabilityOutput+[ 310 '|', 311 ('|| Loop amplitude squared, must be finite:',main_color), 312 ('| Finite = %s'%special_float_format(res['finite']),main_color), 313 '|(| Pole residues, indicated only for checking purposes: )', 314 '|( Single pole = %s )'%special_float_format(res['1eps']), 315 '|( Double pole = %s )'%special_float_format(res['2eps'])]) 316 317 if (len(res['Born_SO_Results'])+len(res['Born_SO_Results']))>0: 318 if notZeroBorn: 319 str_lines.append( 320 ("| (*) The results above sum all starred contributions below",main_color)) 321 322 str_lines.append('|') 323 if not notZeroBorn: 324 str_lines.append( 325 ("| The Born contributions below are computed but do not match these squared "+ 326 "orders constraints",main_color)) 327 328 if len(res['Born_SO_Results'])==1: 329 str_lines.append('|| All Born contributions are of split orders *(%s)'\ 330 %format_so_orders(res['Born_SO_Results'][0][0])) 331 elif len(res['Born_SO_Results'])>1: 332 for i, bso_contrib in enumerate(res['Born_SO_Results']): 333 str_lines.append('|| Born contribution of split orders %s(%s) = %s'\ 334 %('*' if res['Born_kept'][i] else ' ', 335 format_so_orders(bso_contrib[0]), 336 special_float_format(bso_contrib[1]['BORN']))) 337 338 if len(so_order_names): 339 str_lines.append('|') 340 341 if len(res['Loop_SO_Results'])==1: 342 str_lines.append('|| All virtual contributions are of split orders *(%s)'\ 343 %format_so_orders(res['Loop_SO_Results'][0][0])) 344 elif len(res['Loop_SO_Results'])>1: 345 if not notZeroBorn: 346 str_lines.append( 347 ("| The coupling order combinations matching the squared order"+ 348 " constraints are marked with a star",main_color)) 349 for i, lso_contrib in enumerate(res['Loop_SO_Results']): 350 str_lines.append('|| Virtual contribution of split orders %s(%s):'\ 351 %('*' if res['Loop_kept'][i] else ' ', 352 format_so_orders(lso_contrib[0]))) 353 str_lines.append('| Accuracy = %.1e'%\ 354 lso_contrib[1]['ACC']), 355 str_lines.append('| Finite = %s'%\ 356 special_float_format(lso_contrib[1]['FIN'])), 357 if res['export_format']=='LoopInduced': 358 str_lines.append('|( Single pole = %s )'%\ 359 special_float_format(lso_contrib[1]['1EPS'])) 360 str_lines.append('|( Double pole = %s )'%\ 361 special_float_format(lso_contrib[1]['2EPS'])) 362 else: 363 str_lines.append('| Single pole = %s'%\ 364 special_float_format(lso_contrib[1]['1EPS'])) 365 str_lines.append('| Double pole = %s'%\ 366 special_float_format(lso_contrib[1]['2EPS'])) 367 str_lines.extend([ASCII_bar,'\n']) 368 369 return str_lines 370
371 -class SALauncher(ExtLauncher):
372 """ A class to launch a simple Standalone test """ 373
374 - def __init__(self, cmd_int, running_dir, **options):
375 """ initialize the StandAlone Version""" 376 377 ExtLauncher.__init__(self, cmd_int, running_dir, './Cards', **options) 378 self.cards = ['param_card.dat']
379 380
381 - def launch_program(self):
382 """launch the main program""" 383 sub_path = os.path.join(self.running_dir, 'SubProcesses') 384 for path in os.listdir(sub_path): 385 if path.startswith('P') and \ 386 os.path.isdir(os.path.join(sub_path, path)): 387 cur_path = os.path.join(sub_path, path) 388 # make 389 misc.compile(cwd=cur_path, mode='unknown') 390 # check 391 subprocess.call(['./check'], cwd=cur_path)
392
393 -class MWLauncher(ExtLauncher):
394 """ A class to launch a simple Standalone test """ 395 396
397 - def __init__(self, cmd_int, running_dir, **options):
398 """ initialize the StandAlone Version""" 399 ExtLauncher.__init__(self, cmd_int, running_dir, './Cards', **options) 400 self.options = cmd_int.options
401
402 - def launch_program(self):
403 """launch the main program""" 404 405 import madgraph.interface.madweight_interface as MW 406 # Check for number of cores if multicore mode 407 mode = str(self.cluster) 408 nb_node = 1 409 if mode == "2": 410 import multiprocessing 411 max_node = multiprocessing.cpu_count() 412 if max_node == 1: 413 logger.warning('Only one core is detected on your computer! Pass in single machine') 414 self.cluster = 0 415 self.launch_program() 416 return 417 elif max_node == 2: 418 nb_node = 2 419 elif not self.force: 420 nb_node = self.ask('How many core do you want to use?', max_node, range(2,max_node+1)) 421 else: 422 nb_node=max_node 423 424 import madgraph.interface.madevent_interface as ME 425 426 stdout_level = self.cmd_int.options['stdout_level'] 427 if self.shell: 428 usecmd = MW.MadWeightCmdShell(me_dir=self.running_dir, options=self.options) 429 else: 430 usecmd = MW.MadWeightCmd(me_dir=self.running_dir, options=self.options) 431 usecmd.pass_in_web_mode() 432 #Check if some configuration were overwritten by a command. If so use it 433 set_cmd = [l for l in self.cmd_int.history if l.strip().startswith('set')] 434 for line in set_cmd: 435 try: 436 usecmd.do_set(line[3:], log=False) 437 except Exception: 438 pass 439 440 usecmd.do_set('stdout_level %s' % stdout_level,log=False) 441 #ensure that the logger level 442 launch = self.cmd_int.define_child_cmd_interface( 443 usecmd, interface=False) 444 445 command = 'launch' 446 if mode == "1": 447 command += " --cluster" 448 elif mode == "2": 449 command += " --nb_core=%s" % nb_node 450 451 if self.force: 452 command+= " -f" 453 if self.laststep: 454 command += ' --laststep=%s' % self.laststep 455 456 try: 457 os.remove('ME5_debug') 458 except: 459 pass 460 launch.run_cmd(command) 461 launch.run_cmd('quit') 462 463 if os.path.exists('ME5_debug'): 464 return True
465 466 467
468 -class aMCatNLOLauncher(ExtLauncher):
469 """A class to launch MadEvent run""" 470
471 - def __init__(self, running_dir, cmd_int, run_mode='', unit='pb', **option):
472 """ initialize the StandAlone Version""" 473 474 ExtLauncher.__init__(self, cmd_int, running_dir, './Cards', **option) 475 #self.executable = os.path.join('.', 'bin','generate_events') 476 477 self.options = option 478 assert hasattr(self, 'cluster') 479 assert hasattr(self, 'multicore') 480 assert hasattr(self, 'name') 481 assert hasattr(self, 'shell') 482 483 self.unit = unit 484 self.run_mode = run_mode 485 486 if self.cluster or option['cluster']: 487 self.cluster = 1 488 if self.multicore or option['multicore']: 489 self.cluster = 2 490 491 self.cards = [] 492 493 # Assign a valid run name if not put in options 494 if self.name == '': 495 self.name = me_cmd.MadEventCmd.find_available_run_name(self.running_dir)
496
497 - def launch_program(self):
498 """launch the main program""" 499 500 # Check for number of cores if multicore mode 501 mode = str(self.cluster) 502 nb_node = 1 503 if mode == "2": 504 import multiprocessing 505 max_node = multiprocessing.cpu_count() 506 if max_node == 1: 507 logger.warning('Only one core is detected on your computer! Pass in single machine') 508 self.cluster = 0 509 self.launch_program() 510 return 511 elif max_node == 2: 512 nb_node = 2 513 elif not self.force: 514 nb_node = self.ask('How many cores do you want to use?', max_node, range(2,max_node+1)) 515 else: 516 nb_node=max_node 517 518 import madgraph.interface.amcatnlo_run_interface as run_int 519 520 if hasattr(self, 'shell') and self.shell: 521 usecmd = run_int.aMCatNLOCmdShell(me_dir=self.running_dir, options = self.cmd_int.options) 522 else: 523 usecmd = run_int.aMCatNLOCmd(me_dir=self.running_dir, options = self.cmd_int.options) 524 525 #Check if some configuration were overwritten by a command. If so use it 526 set_cmd = [l for l in self.cmd_int.history if l.strip().startswith('set')] 527 all_options = usecmd.options_configuration.keys() + usecmd.options_madgraph.keys() + usecmd.options_madevent.keys() 528 for line in set_cmd: 529 arg = line.split() 530 if arg[1] not in all_options: 531 continue 532 try: 533 usecmd.exec_cmd(line) 534 except Exception, error: 535 misc.sprint('Command %s fails with msg: %s'%(str(line), \ 536 str(error))) 537 pass 538 launch = self.cmd_int.define_child_cmd_interface( 539 usecmd, interface=False) 540 #launch.me_dir = self.running_dir 541 option_line = ' '.join([' --%s' % opt for opt in self.options.keys() \ 542 if self.options[opt] and not opt in ['cluster', 'multicore', 'name', 'appl_start_grid','shell']]) 543 if self.options['name']: 544 option_line += ' --name %s' % self.options['name'] 545 if 'appl_start_grid' in self.options and self.options['appl_start_grid']: 546 option_line += ' --appl_start_grid %s' % self.options['appl_start_grid'] 547 command = 'launch ' + self.run_mode + ' ' + option_line 548 549 if mode == "1": 550 command += " -c" 551 elif mode == "2": 552 command += " -m" 553 usecmd.nb_core = int(nb_node) 554 try: 555 os.remove('ME5_debug') 556 except: 557 pass 558 launch.run_cmd(command) 559 launch.run_cmd('quit')
560 561 562 563 564
565 -class MELauncher(ExtLauncher):
566 """A class to launch MadEvent run""" 567
568 - def __init__(self, running_dir, cmd_int , unit='pb', **option):
569 """ initialize the StandAlone Version""" 570 571 ExtLauncher.__init__(self, cmd_int, running_dir, './Cards', **option) 572 #self.executable = os.path.join('.', 'bin','generate_events') 573 self.pythia = cmd_int.options['pythia-pgs_path'] 574 self.delphes = cmd_int.options['delphes_path'], 575 self.options = cmd_int.options 576 577 assert hasattr(self, 'cluster') 578 assert hasattr(self, 'multicore') 579 assert hasattr(self, 'name') 580 assert hasattr(self, 'shell') 581 582 self.unit = unit 583 584 if self.cluster: 585 self.cluster = 1 586 if self.multicore: 587 self.cluster = 2 588 589 self.cards = [] 590 591 # Assign a valid run name if not put in options 592 if self.name == '': 593 self.name = me_cmd.MadEventCmd.find_available_run_name(self.running_dir)
594
595 - def launch_program(self):
596 """launch the main program""" 597 598 # Check for number of cores if multicore mode 599 mode = str(self.cluster) 600 nb_node = 1 601 if mode == "2": 602 import multiprocessing 603 max_node = multiprocessing.cpu_count() 604 if max_node == 1: 605 logger.warning('Only one core is detected on your computer! Pass in single machine') 606 self.cluster = 0 607 self.launch_program() 608 return 609 elif max_node == 2: 610 nb_node = 2 611 elif not self.force: 612 nb_node = self.ask('How many cores do you want to use?', max_node, range(2,max_node+1)) 613 else: 614 nb_node=max_node 615 616 import madgraph.interface.madevent_interface as ME 617 618 stdout_level = self.cmd_int.options['stdout_level'] 619 if self.shell: 620 usecmd = ME.MadEventCmdShell(me_dir=self.running_dir, options=self.options) 621 else: 622 usecmd = ME.MadEventCmd(me_dir=self.running_dir, options=self.options) 623 usecmd.pass_in_web_mode() 624 #Check if some configuration were overwritten by a command. If so use it 625 set_cmd = [l for l in self.cmd_int.history if l.strip().startswith('set')] 626 all_options = usecmd.options_configuration.keys() + usecmd.options_madgraph.keys() + usecmd.options_madevent.keys() 627 for line in set_cmd: 628 arg = line.split() 629 if arg[1] not in all_options: 630 continue 631 try: 632 usecmd.do_set(line[3:], log=False) 633 except usecmd.InvalidCmd: 634 pass 635 usecmd.do_set('stdout_level %s' % stdout_level,log=False) 636 #ensure that the logger level 637 launch = self.cmd_int.define_child_cmd_interface( 638 usecmd, interface=False) 639 #launch.me_dir = self.running_dir 640 if self.unit == 'pb': 641 command = 'generate_events %s' % self.name 642 else: 643 warning_text = '''\ 644 Note that since 2.3. The launch for 1>N pass in event generation 645 For efficient width computation see arXiv:1402.1178.''' 646 logger.warning(warning_text) 647 command = 'generate_events %s' % self.name 648 if mode == "1": 649 command += " --cluster" 650 elif mode == "2": 651 command += " --nb_core=%s" % nb_node 652 653 if self.force: 654 command+= " -f" 655 656 if self.laststep: 657 command += ' --laststep=%s' % self.laststep 658 if self.reweight: 659 command += ' -R ' 660 if self.madspin: 661 command += ' -M ' 662 663 664 try: 665 os.remove('ME5_debug') 666 except: 667 pass 668 669 launch.run_cmd(command) 670 launch.run_cmd('quit') 671 672 if os.path.exists('ME5_debug'): 673 return True 674 675 # Display the cross-section to the screen 676 path = os.path.join(self.running_dir, 'SubProcesses', 'results.dat') 677 if not os.path.exists(path): 678 logger.error('Generation failed (no results.dat file found)') 679 return 680 fsock = open(path) 681 line = fsock.readline() 682 cross, error = line.split()[0:2] 683 684 logger.info('more information in %s' 685 % os.path.join(self.running_dir, 'index.html'))
686 687
688 -class Pythia8Launcher(ExtLauncher):
689 """A class to launch Pythia8 run""" 690
691 - def __init__(self, running_dir, cmd_int, **option):
692 """ initialize launching Pythia 8""" 693 694 running_dir = os.path.join(running_dir, 'examples') 695 ExtLauncher.__init__(self, cmd_int, running_dir, '.', **option) 696 self.cards = []
697
698 - def prepare_run(self):
699 """ ask for pythia-pgs/delphes run """ 700 701 # Find all main_model_process.cc files 702 date_file_list = [] 703 for file in misc.glob('main_*_*.cc', self.running_dir): 704 # retrieves the stats for the current file as a tuple 705 # (mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime) 706 # the tuple element mtime at index 8 is the last-modified-date 707 stats = os.stat(file) 708 # create tuple (year yyyy, month(1-12), day(1-31), hour(0-23), minute(0-59), second(0-59), 709 # weekday(0-6, 0 is monday), Julian day(1-366), daylight flag(-1,0 or 1)) from seconds since epoch 710 # note: this tuple can be sorted properly by date and time 711 lastmod_date = time.localtime(stats[8]) 712 date_file_list.append((lastmod_date, os.path.split(file)[-1])) 713 714 if not date_file_list: 715 raise MadGraph5Error, 'No Pythia output found' 716 # Sort files according to date with newest first 717 date_file_list.sort() 718 date_file_list.reverse() 719 files = [d[1] for d in date_file_list] 720 721 answer = '' 722 answer = self.ask('Select a main file to run:', files[0], files) 723 724 self.cards.append(answer) 725 726 self.executable = self.cards[-1].replace(".cc","") 727 728 # Assign a valid run name if not put in options 729 if self.name == '': 730 for i in range(1000): 731 path = os.path.join(self.running_dir, '', 732 '%s_%02i.log' % (self.executable, i)) 733 if not os.path.exists(path): 734 self.name = '%s_%02i.log' % (self.executable, i) 735 break 736 737 if self.name == '': 738 raise MadGraph5Error, 'too many runs in this directory' 739 740 # Find all exported models 741 models = misc.glob("Processes_*", pjoin(self.running_dir,os.path.pardir)) 742 models = [os.path.split(m)[-1].replace("Processes_","") for m in models] 743 # Extract model name from executable 744 models.sort(key=len) 745 models.reverse() 746 model_dir = "" 747 for model in models: 748 if self.executable.replace("main_", "").startswith(model): 749 model_dir = "Processes_%s" % model 750 break 751 if model_dir: 752 self.model = model 753 self.model_dir = os.path.realpath(os.path.join(self.running_dir, 754 os.path.pardir, 755 model_dir)) 756 self.cards.append(os.path.join(self.model_dir, 757 "param_card_%s.dat" % model))
758
759 - def launch_program(self):
760 """launch the main program""" 761 762 # Make pythia8 763 print "Running make for pythia8 directory" 764 if self.model_dir: 765 print "Running make in %s" % self.model_dir 766 misc.compile(cwd=self.model_dir, mode='cpp') 767 # Finally run make for executable 768 makefile = self.executable.replace("main_","Makefile_") 769 print "Running make with %s" % makefile 770 misc.compile(arg=['-f', makefile], cwd=self.running_dir, mode='cpp') 771 772 print "Running " + self.executable 773 774 output = open(os.path.join(self.running_dir, self.name), 'w') 775 if not self.executable.startswith('./'): 776 self.executable = os.path.join(".", self.executable) 777 subprocess.call([self.executable], stdout = output, stderr = output, 778 cwd=self.running_dir) 779 780 # Display the cross-section to the screen 781 path = os.path.join(self.running_dir, self.name) 782 pydoc.pager(open(path).read()) 783 784 print "Output of the run is found at " + \ 785 os.path.realpath(os.path.join(self.running_dir, self.name))
786 787 # old compatibility shortcut 788 open_file = misc.open_file 789