def compare_processes(self, my_proc_list = [], model = 'loop_sm-parallel_test', pickle_file = "", energy = 2000, tolerance = 1e-06, filename = "", chosen_runner = "ML5_opt"): """ 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) # 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() # Always put the saved run first if you use it, so that the corresponding PS # points will be used. if pickle_file != "": my_comp.set_me_runners(stored_runner,ML5_opt,ML5_default) else: my_comp.set_me_runners(ML5_opt,ML5_default) # 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 create_pickle(my_proc_list, pickle_file, runner, ref_runner=None, model = 'loop_sm-parallel_test', energy = 2000): """ Create a pickle with name 'pickle_file' on the specified processes and also possibly using the PS points provided by the reference runner """ my_comp = loop_me_comparator.LoopMEComparator() if not ref_runner is None: my_comp.set_me_runners(ref_runner,runner) else: my_comp.set_me_runners(runner) my_comp.run_comparison(my_proc_list,model=model,energy=energy) loop_me_comparator.LoopPickleRunner.store_comparison( os.path.join(_pickle_path,pickle_file), [runner.proc_list,runner.res_list], runner.model,runner.name,energy=runner.energy)
# GoSam.setup('/Users/valentin/Documents/HEP_softs/GoSam/gosam-2.0.beta') # Create a MERunner object for MadLoop 5 optimized ML5_opt = loop_me_comparator.LoopMG5Runner() ML5_opt.setup(mg5_path, optimized_output=True) # Create a MERunner object for MadLoop 5 default ML5_default = loop_me_comparator.LoopMG5Runner() ML5_default.setup(mg5_path, optimized_output=False) # Create a MERunner object for UFO-ALOHA-MG5 # my_mg5_ufo = me_comparator.MG5_UFO_Runner() # my_mg5_ufo.setup(mg5_path, mg4_path) # Create and setup a comparator my_comp = loop_me_comparator.LoopMEComparator() # Always put the saved run first if you use it, so that the corresponding PS # points will be used #my_comp.set_me_runners(ML5_opt,GoSam) my_comp.set_me_runners(HCRvalue, ML5_opt) # Run the actual comparison # energy=1000 energy = HCRvalue.energy my_comp.run_comparison(my_proc_list, model=model, energy=energy) # Save the result of a runner #SaveRunner('trial.pkl',ML5_opt) # Do some cleanup #my_comp.cleanup()
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_induce=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 file = open( os.path.join(_mg5_path, 'Template', 'loop_material', 'StandAlone', 'Cards', 'MadLoopParams.dat'), 'r') # 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()) MLParams = file.read() MLred = re.search(r'#MLReductionLib\n', MLParams) MLredstr = MLParams[MLred.end():MLred.end() + 1] if loop_induce and MLredstr != "1": return # Create a MERunner object for MadLoop 5 optimized # Open Loops is not avaiable for loop induced processes if not loop_induce: 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_induce: my_comp.set_me_runners(stored_runner, ML5_opt, ML5_default) elif pickle_file != "" and loop_induce: my_comp.set_me_runners(stored_runner, ML5_default) elif pickle_file == "" and not loop_induce: 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()