def treat_input_file(self, filename, default=None, msg='', dir_path=None): """ask to edit a file""" if filename == 'PS.input': if not self.force: if msg != '': print msg question = 'Do you want to specify the Phase-Space point: %(card)s?' % { 'card': filename } choices = ['y', 'n'] path_info = 'path of the PS.input file' ans = self.ask(question, default, choices, path_info) else: ans = default if ans == 'y': if not os.path.isfile(os.path.join(dir_path, 'PS.input')): PSfile = open(os.path.join(dir_path, 'PS.input'), 'w') if not os.path.isfile(os.path.join(dir_path, 'result.dat')): PSfile.write('\n'.join([' '.join(['%.16E'%0.0 for \ pi in range(4)]) for pmom in range(1)])) else: default_ps = process_checks.LoopMatrixElementEvaluator.\ parse_check_output(file(os.path.join(dir_path,\ 'result.dat')),format='dict')['res_p'] PSfile.write('\n'.join([' '.join(['%.16E'%pi for pi \ in pmom]) for pmom in default_ps])) PSfile.write("\n\nEach line number 'i' like the above one sets"+\ " the momentum of particle number i, \nordered like in"+\ " the process definition. The format is (E,px,py,pz).") PSfile.close() self.edit_file(os.path.join(dir_path, 'PS.input')) else: super(MadLoopLauncher, self).treat_input_file(filename, default, msg) if filename == 'MadLoopParams.dat': # Make sure to update the changes MadLoopparam = banner_mod.MadLoopParam( os.path.join(self.card_dir, 'MadLoopParams.dat')) # Unless user asked for it, don't doublecheck the helicity filter. MadLoopparam.set('DoubleCheckHelicityFilter', False, ifnotdefault=False) MadLoopparam.write( os.path.join(self.card_dir, os.path.pardir, 'SubProcesses', 'MadLoopParams.dat'))
def compare_processes(self, my_proc_list=[], model='loop_sm-parallel_test', pickle_file="", energy=2000, tolerance=3e-06, filename="", chosen_runner="ML5_opt", compare_with=['ML5_opt', 'ML5_def']): """ A helper function to compare processes. Note that the chosen_runner is what runner should to create the reference pickle if missing""" # Print out progress if it is a run for an individual process if len(my_proc_list) == 1: print "\n== %s ==" % my_proc_list[0][0] else: print "\n== %s ==" % filename # Check if pickle exists, if not create it if pickle_file != "" and not os.path.isfile( os.path.join(_pickle_path, pickle_file)): print " => Computing reference evaluation with %s" % chosen_runner self.create_loop_pickle(my_proc_list, model, pickle_file, energy, chosen_runner) print "\n => Done with %s evaluation" % chosen_runner # Load the stored runner if pickle_file != "": stored_runner = me_comparator.PickleRunner.find_comparisons( os.path.join(_pickle_path, pickle_file))[0] # Create a MERunner object for MadLoop 5 optimized ML5_opt = loop_me_comparator.LoopMG5Runner() ML5_opt.setup(_mg5_path, optimized_output=True, temp_dir=filename) MLCard = banner_mod.MadLoopParam( os.path.join(_mg5_path, 'Template', 'loop_material', 'StandAlone', 'Cards', 'MadLoopParams.dat')) MLredstr = MLCard['MLReductionLib'][0:1] if MLredstr == "1": # Create a MERunner object for MadLoop 5 default ML5_default = loop_me_comparator.LoopMG5Runner() ML5_default.setup(_mg5_path, optimized_output=False, temp_dir=filename) # Create and setup a comparator my_comp = loop_me_comparator.LoopMEComparator() # Remove the default ML5 comparator if using TIR to_compare_with = copy.copy(compare_with) if MLredstr != '1': try: to_compare_with.pop(to_compare_with.index('ML5_def')) except ValueError: pass runners_available = { 'ML5_opt': ML5_opt, 'ML5_def': ML5_opt, 'Stored': stored_runner } # Always put the saved run first if you use it, so that the corresponding PS # points will be used. runners_to_compare = [] if pickle_file != "": runners_to_compare.append(stored_runner) runners_to_compare.extend([runners_available[runner] for runner in \ to_compare_with]) if len(runners_to_compare) <= 1: raise MadGraph5Error,\ """ Only one runner to compute the result with, so there is no possible comparison. This is most likely due to the fact that you are running a TIR only comparison and the reference pickle cannot be found.""" # Set the runners to include my_comp.set_me_runners(*runners_to_compare) # Run the actual comparison my_comp.run_comparison(my_proc_list, model=model, energy=energy) # Print the output my_comp.output_result(filename=os.path.join(_mg5_path, filename + '.log')) # Assert that all process comparisons passed the tolerance cut my_comp.assert_processes(self, tolerance) # Do some cleanup my_comp.cleanup()
def compare_processes(testInstance, my_proc_list=[], model='loop_qcd_qed_sm-parallel_test', pickle_file="", energy=2000, tolerance=3e-06, filename="", chosen_runner="ML5_opt", loop_induced=False, mu_r=0.0): """ A helper function to compare processes. Note that the chosen_runner is what runner should to create the reference pickle if missing""" # Print out progress if it is a run for an individual process if len(my_proc_list) == 1: print("\n== %s %s ==" % (my_proc_list[0][0], my_proc_list[0][2])) else: print("\n== %s ==" % filename) # Check if pickle exists, if not create it if pickle_file != "" and not os.path.isfile( os.path.join(_pickle_path, pickle_file)): print(" => Computing reference evaluation with %s" % chosen_runner) create_loop_pickle(my_proc_list, model, pickle_file, energy, chosen_runner) print("\n => Done with %s evaluation" % chosen_runner) # Load the stored runner if pickle_file != "": stored_runner = me_comparator.PickleRunner.find_comparisons( os.path.join(_pickle_path, pickle_file))[0] energy = stored_runner.energy # Check if the process has squared order constraints has_sqso = any('^2' in key for proc in my_proc_list for key in \ proc[3].keys()) MLCard = banner_mod.MadLoopParam( os.path.join(_mg5_path, 'Template', 'loop_material', 'StandAlone', 'Cards', 'MadLoopParams.dat')) MLredstr = MLCard['MLReductionLib'][0:1] # Create a MERunner object for MadLoop 5 optimized ML5_opt = loop_me_comparator.LoopMG5Runner() ML5_opt.setup(_mg5_path, optimized_output=True, temp_dir=filename,\ mu_r=mu_r) if MLredstr == "1" and not has_sqso: # Create a MERunner object for MadLoop 5 default ML5_default = loop_me_comparator.LoopMG5Runner() ML5_default.setup(_mg5_path, optimized_output=False, temp_dir=filename,\ mu_r=mu_r) # Create and setup a comparator my_comp = loop_me_comparator.LoopMEComparator() if MLredstr == "1" and not has_sqso: # Always put the saved run first if you use it, so that the corresponding PS # points will be used. if pickle_file != "" and not loop_induced: my_comp.set_me_runners(stored_runner, ML5_opt, ML5_default) elif pickle_file != "" and loop_induced: my_comp.set_me_runners(stored_runner, ML5_default) elif pickle_file == "" and not loop_induced: my_comp.set_me_runners(ML5_opt, ML5_default) else: raise MadGraph5Error( 'Cannot find pickle_file for loop induced process.') else: if pickle_file != "": my_comp.set_me_runners(stored_runner, ML5_opt) else: raise MadGraph5Error("CANNOT find the stored result with TIR") # Run the actual comparison my_comp.run_comparison(my_proc_list, model=model, energy=energy) # Print the output my_comp.output_result(filename=os.path.join(_mg5_path,filename+'.log'),\ tolerance = tolerance) # Assert that all process comparisons passed the tolerance cut my_comp.assert_processes(testInstance, tolerance) # Do some cleanup my_comp.cleanup()