def load_IOTestsAcceptance(self): """load the models and exporters if necessary.""" if not hasattr(self, 'models') or \ not hasattr(self, 'fortran_models') or \ not hasattr(self, 'loop_exporters'): \ self.models = { \ 'loop_sm' : import_ufo.import_model('loop_sm') } self.fortran_models = { 'fortran_model' : helas_call_writers.FortranUFOHelasCallWriter(\ self.models['loop_sm']) } self.loop_exporters = { 'default' : loop_exporters.LoopProcessExporterFortranSA(\ _mgme_file_path, _proc_file_path, {'clean':False, 'complex_mass':False, 'export_format':'madloop','mp':True, 'loop_dir':_loop_file_path, 'cuttools_dir':_cuttools_file_path, 'fortran_compiler':'gfortran', 'output_dependencies':'external', 'SubProc_prefix': '', 'compute_color_flows': False}), 'optimized' : loop_exporters.\ LoopProcessOptimizedExporterFortranSA(\ _mgme_file_path, _proc_file_path, {'clean':False, 'complex_mass':False, 'export_format':'madloop','mp':True, 'loop_dir':_loop_file_path, 'cuttools_dir':_cuttools_file_path, 'fortran_compiler':'gfortran', 'output_dependencies':'external', 'SubProc_prefix': '', 'compute_color_flows': False}) } # d u~ > mu- vmx g self.addIOTestsForProcess(testName='dux_mumvmxg', testFolder='long_ML_SMQCD', particles_ids=[1, -2, 13, -14, 21], exporters=['default', 'optimized'], orders={ 'QCD': 1, 'QED': 2 }) # g g > w- t b~ Single top (long but really includes everything) self.addIOTestsForProcess(testName='gg_wmtbx', testFolder='long_ML_SMQCD', particles_ids=[21, 21, -24, 6, -5], exporters=['default', 'optimized'], orders={ 'QCD': 2, 'QED': 1 })
def load_IOTestsUnit(self): """load the models and exporters if necessary.""" if not hasattr(self, 'models') or \ not hasattr(self, 'fortran_models') or \ not hasattr(self, 'loop_exporters'):\ self.models = { \ 'loop_sm' : import_ufo.import_model('loop_sm') } self.fortran_models = { 'fortran_model' : helas_call_writers.FortranUFOHelasCallWriter(\ self.models['loop_sm']) } self.loop_exporters = { 'default' : loop_exporters.LoopProcessExporterFortranSA(\ _mgme_file_path, _proc_file_path, {'clean':False, 'complex_mass':False, 'export_format':'madloop','mp':True, 'loop_dir':_loop_file_path, 'cuttools_dir':_cuttools_file_path, 'fortran_compiler':'gfortran', 'output_dependencies':'external'}), 'optimized' : loop_exporters.\ LoopProcessOptimizedExporterFortranSA(\ _mgme_file_path, _proc_file_path, {'clean':False, 'complex_mass':False, 'export_format':'madloop','mp':True, 'loop_dir':_loop_file_path, 'cuttools_dir':_cuttools_file_path, 'fortran_compiler':'gfortran', 'output_dependencies':'external'}) } # g g > t t~ self.addIOTestsForProcess( testName = 'gg_ttx', testFolder = 'short_ML_SMQCD', particles_ids = [21,21,6,-6], exporters = self.loop_exporters, orders = {'QCD':2,'QED':0} ) # d d > t t~ (only the proc files for this one) self.addIOTestsForProcess( testName = 'ddx_ttx', testFolder = 'short_ML_SMQCD', particles_ids = [1,-1,6,-6], exporters = self.loop_exporters, orders = {'QCD':2,'QED':0}, files_to_check=IOTests.IOTest.proc_files) # And the loop induced g g > h h for good measure # Use only one exporter only here self.addIOTestsForProcess( testName = 'gg_hh', testFolder = 'short_ML_SMQCD_LoopInduced', particles_ids = [21,21,25,25], exporters = self.loop_exporters['default'], orders = {'QCD': 2, 'QED': 2} )
def test_UFO_fortran_helas_call_writer(self): """Test automatic generation of UFO helas calls in Fortran""" fortran_model = helas_call_writers.FortranUFOHelasCallWriter(\ self.mybasemodel) result = fortran_model.get_matrix_element_calls(self.mymatrixelement) solution = """CALL VXXXXX(P(0,1),ZERO,NHEL(1),-1*IC(1),W(1,1)) CALL VXXXXX(P(0,2),mdl_MW,NHEL(2),-1*IC(2),W(1,2)) CALL VXXXXX(P(0,3),ZERO,NHEL(3),+1*IC(3),W(1,3)) CALL VXXXXX(P(0,4),mdl_MW,NHEL(4),+1*IC(4),W(1,4)) CALL VXXXXX(P(0,5),mdl_MZ,NHEL(5),+1*IC(5),W(1,5)) CALL VVV1_3(W(1,1),W(1,2),-GC_3,DCMPLX(CMASS_mdl_MW),W(1,6)) CALL VVV1_2(W(1,3),W(1,4),-GC_3,DCMPLX(CMASS_mdl_MW),W(1,7)) # Amplitude(s) for diagram number 1 CALL VVV1_0(W(1,6),W(1,7),W(1,5),GC_53,AMP(1)) CALL VVV1_1(W(1,4),W(1,5),GC_53,DCMPLX(CMASS_mdl_MW),W(1,8)) # Amplitude(s) for diagram number 2 CALL VVV1_0(W(1,3),W(1,6),W(1,8),-GC_3,AMP(2)) # Amplitude(s) for diagram number 3 CALL VVVV5_0(W(1,3),W(1,6),W(1,4),W(1,5),GC_57,AMP(3)) CALL VVV1_2(W(1,1),W(1,4),-GC_3,DCMPLX(CMASS_mdl_MW),W(1,6)) CALL VVV1_3(W(1,3),W(1,2),-GC_3,DCMPLX(CMASS_mdl_MW),W(1,9)) # Amplitude(s) for diagram number 4 CALL VVV1_0(W(1,9),W(1,6),W(1,5),GC_53,AMP(4)) CALL VVV1_2(W(1,2),W(1,5),GC_53,DCMPLX(CMASS_mdl_MW),W(1,10)) # Amplitude(s) for diagram number 5 CALL VVV1_0(W(1,3),W(1,10),W(1,6),-GC_3,AMP(5)) # Amplitude(s) for diagram number 6 CALL VVVV5_0(W(1,3),W(1,2),W(1,6),W(1,5),GC_57,AMP(6)) # Amplitude(s) for diagram number 7 CALL VVV1_0(W(1,1),W(1,9),W(1,8),-GC_3,AMP(7)) # Amplitude(s) for diagram number 8 CALL VVV1_0(W(1,1),W(1,10),W(1,7),-GC_3,AMP(8)) CALL VVVV2_4(W(1,1),W(1,3),W(1,2),GC_5,DCMPLX(CMASS_mdl_MW),W(1,10)) # Amplitude(s) for diagram number 9 CALL VVV1_0(W(1,10),W(1,4),W(1,5),GC_53,AMP(9)) CALL VVVV5_3(W(1,1),W(1,2),W(1,5),GC_57,DCMPLX(CMASS_mdl_MW),W(1,10)) # Amplitude(s) for diagram number 10 CALL VVV1_0(W(1,3),W(1,10),W(1,4),-GC_3,AMP(10)) CALL VVVV2_3(W(1,1),W(1,3),W(1,4),GC_5,DCMPLX(CMASS_mdl_MW),W(1,10)) # Amplitude(s) for diagram number 11 CALL VVV1_0(W(1,2),W(1,10),W(1,5),GC_53,AMP(11)) CALL VVVV5_2(W(1,1),W(1,4),W(1,5),GC_57,DCMPLX(CMASS_mdl_MW),W(1,10)) # Amplitude(s) for diagram number 12 CALL VVV1_0(W(1,3),W(1,2),W(1,10),-GC_3,AMP(12))""" self.assertEqual(solution.split('\n'), result)
def load_IOTestsUnit(self): """load the models and exporters if necessary.""" if not hasattr(self, 'models') or \ not hasattr(self, 'fortran_models') or \ not hasattr(self, 'loop_exporters'): \ self.models = { \ 'loop_sm' : import_ufo.import_model('loop_sm') } self.fortran_models = { 'fortran_model' : helas_call_writers.FortranUFOHelasCallWriter(\ self.models['loop_sm']) } # g g > t t~ self.addIOTestsForProcess(testName='gg_ttx', testFolder='short_ML_SMQCD', particles_ids=[21, 21, 6, -6], exporters=['default', 'optimized'], orders={ 'QCD': 2, 'QED': 0 }) # d d > t t~ (only the proc files for this one) self.addIOTestsForProcess(testName='ddx_ttx', testFolder='short_ML_SMQCD', particles_ids=[1, -1, 6, -6], exporters=['default', 'optimized'], orders={ 'QCD': 2, 'QED': 0 }, files_to_check=IOTests.IOTest.proc_files) # And the loop induced g g > h h for good measure # Use only one exporter only here self.addIOTestsForProcess(testName='gg_hh', testFolder='short_ML_SMQCD_LoopInduced', particles_ids=[21, 21, 25, 25], exporters='default', orders={ 'QCD': 2, 'QED': 2 })
def test_UFO_fortran_helas_call_writer(self): """Test automatic generation of UFO helas calls in Fortran""" fortran_model = helas_call_writers.FortranUFOHelasCallWriter(\ self.mybasemodel) result = fortran_model.get_matrix_element_calls(self.mymatrixelement) solution =['CALL VXXXXX(P(0,1),zero,NHEL(1),-1*IC(1),W(1,1))', 'CALL VXXXXX(P(0,2),wmas,NHEL(2),-1*IC(2),W(1,2))', 'CALL VXXXXX(P(0,3),zero,NHEL(3),+1*IC(3),W(1,3))', 'CALL VXXXXX(P(0,4),wmas,NHEL(4),+1*IC(4),W(1,4))', 'CALL VXXXXX(P(0,5),zmas,NHEL(5),+1*IC(5),W(1,5))', 'CALL VVVV1_4(W(1,1),W(1,3),W(1,2),GC_51,wmas,wwid,W(1,6))', '# Amplitude(s) for diagram number 1', 'CALL VVV1_0(W(1,6),W(1,4),W(1,5),GC_12,AMP(1))', 'CALL VVVV1_3(W(1,1),W(1,3),W(1,4),GC_51,wmas,wwid,W(1,6))', '# Amplitude(s) for diagram number 2', 'CALL VVV1_0(W(1,2),W(1,6),W(1,5),GC_12,AMP(2))'] for i, line in enumerate(solution): self.assertEqual(line, result[i])
def export(self, nojpeg=False, main_file_name="", group_processes=False): """Export a generated amplitude to file""" self._curr_helas_model = helas_call_writers.FortranUFOHelasCallWriter( self._curr_model) def generate_matrix_elements(self, group=False): """Helper function to generate the matrix elements before exporting""" # Sort amplitudes according to number of diagrams, # to get most efficient multichannel output self._curr_amps.sort(key=lambda a: a.get_number_of_diagrams(), reverse=True) cpu_time1 = time.time() ndiags = 0 if not self._curr_matrix_elements.get_matrix_elements(): if group: raise MadGraph5Error("Cannot group subprocesses when "+\ "exporting to NLO") else: self._curr_matrix_elements = \ fks_helas.FKSHelasMultiProcess(\ self._fks_multi_proc, loop_optimized= self.options['loop_optimized_output']) if not self.options['low_mem_multicore_nlo_generation']: # generate the code the old way ndiags = sum([len(me.get('diagrams')) for \ me in self._curr_matrix_elements.\ get_matrix_elements()]) # assign a unique id number to all process and # generate a list of possible PDF combinations uid = 0 initial_states = [] for me in self._curr_matrix_elements.get_matrix_elements( ): uid += 1 # update the identification number me.get('processes')[0].set('uid', uid) try: initial_states.append(sorted(list(set((p.get_initial_pdg(1),p.get_initial_pdg(2)) for \ p in me.born_matrix_element.get('processes'))))) except IndexError: initial_states.append(sorted(list(set((p.get_initial_pdg(1)) for \ p in me.born_matrix_element.get('processes'))))) for fksreal in me.real_processes: # Pick out all initial state particles for the two beams try: initial_states.append(sorted(list(set((p.get_initial_pdg(1),p.get_initial_pdg(2)) for \ p in fksreal.matrix_element.get('processes'))))) except IndexError: initial_states.append(sorted(list(set((p.get_initial_pdg(1)) for \ p in fksreal.matrix_element.get('processes'))))) # remove doubles from the list checked = [] for e in initial_states: if e not in checked: checked.append(e) initial_states = checked self._curr_matrix_elements.set('initial_states', initial_states) else: #new NLO generation if self._curr_matrix_elements['has_loops']: self._curr_exporter.opt['mp'] = True self._curr_exporter.model = self._curr_model ndiags = 0 cpu_time2 = time.time() return ndiags, cpu_time2 - cpu_time1 # Start of the actual routine ndiags, cpu_time = generate_matrix_elements(self, group=group_processes) calls = 0 path = self._export_dir if self._export_format in ['NLO']: path = os.path.join(path, 'SubProcesses') #_curr_matrix_element is a FKSHelasMultiProcess Object self._fks_directories = [] proc_charac = self._curr_exporter.proc_characteristic for charac in ['has_isr', 'has_fsr', 'has_loops']: proc_charac[charac] = self._curr_matrix_elements[charac] # prepare for the generation # glob_directories_map is for the new NLO generation global glob_directories_map glob_directories_map = [] # Save processes instances generated self.born_processes_for_olp = [] self.born_processes = [] for ime, me in \ enumerate(self._curr_matrix_elements.get('matrix_elements')): if not self.options['low_mem_multicore_nlo_generation']: #me is a FKSHelasProcessFromReals calls = calls + \ self._curr_exporter.generate_directories_fks(me, self._curr_helas_model, ime, len(self._curr_matrix_elements.get('matrix_elements')), path,self.options['OLP']) self._fks_directories.extend(self._curr_exporter.fksdirs) self.born_processes_for_olp.append( me.born_matrix_element.get('processes')[0]) self.born_processes.append( me.born_matrix_element.get('processes')) else: glob_directories_map.append(\ [self._curr_exporter, me, self._curr_helas_model, ime, len(self._curr_matrix_elements.get('matrix_elements')), path, self.options['OLP']]) if self.options['low_mem_multicore_nlo_generation']: # start the pool instance with a signal instance to catch ctr+c logger.info('Writing directories...') original_sigint_handler = signal.signal( signal.SIGINT, signal.SIG_IGN) if self.ncores_for_proc_gen < 0: # use all cores pool = multiprocessing.Pool(maxtasksperchild=1) else: pool = multiprocessing.Pool( processes=self.ncores_for_proc_gen, maxtasksperchild=1) signal.signal(signal.SIGINT, original_sigint_handler) try: # the very large timeout passed to get is to be able to catch # KeyboardInterrupts diroutputmap = pool.map_async( generate_directories_fks_async, list(range(len(glob_directories_map)))).get(9999999) except KeyboardInterrupt: pool.terminate() raise KeyboardInterrupt pool.close() pool.join() #clean up tmp files containing final matrix elements for mefile in self._curr_matrix_elements.get( 'matrix_elements'): os.remove(mefile) for charac in ['nexternal', 'ninitial']: proc_charac[ charac] = self._curr_exporter.proc_characteristic[ charac] # ninitial and nexternal proc_charac['nexternal'] = max( [diroutput[4] for diroutput in diroutputmap]) ninitial_set = set( [diroutput[3] for diroutput in diroutputmap]) if len(ninitial_set) != 1: raise MadGraph5Error("Invalid ninitial values: %s" % ' ,'.join(list(ninitial_set))) proc_charac['ninitial'] = list(ninitial_set)[0] # max_n_matched_jets njet_set = set( [int(diroutput[6]) for diroutput in diroutputmap]) proc_charac['max_n_matched_jets'] = max(njet_set) self.born_processes = [] self.born_processes_for_olp = [] max_loop_vertex_ranks = [] for diroutput in diroutputmap: calls = calls + diroutput[0] self._fks_directories.extend(diroutput[1]) max_loop_vertex_ranks.append(diroutput[2]) if six.PY2: self.born_processes.extend(diroutput[5]) self.born_processes_for_olp.append(diroutput[5][0]) else: max_loop_vertex_ranks = [me.get_max_loop_vertex_rank() for \ me in self._curr_matrix_elements.get_virt_matrix_elements()] card_path = os.path.join(path, os.path.pardir, 'SubProcesses', \ 'procdef_mg5.dat') if self.options['loop_optimized_output'] and \ len(max_loop_vertex_ranks) > 0: self._curr_exporter.write_coef_specs_file( max_loop_vertex_ranks) if self._generate_info: self._curr_exporter.write_procdef_mg5( card_path, # self._curr_model['name'], self._generate_info) try: cmd.Cmd.onecmd(self, 'history .') except Exception: logger.debug('fail to run command \"history cmd\"') pass subproc_path = os.path.join(path, os.path.pardir, 'SubProcesses', \ 'initial_states_map.dat') self._curr_exporter.write_init_map( subproc_path, self._curr_matrix_elements.get('initial_states')) cpu_time1 = time.time()