def do_define_transfer_fct(self, line): """MadWeight Function:Define the current transfer function""" with misc.chdir(self.me_dir): self.configure() args = self.split_arg(line) path = pjoin(self.me_dir, 'Source', 'MadWeight', 'transfer_function', 'data') listdir=os.listdir(path) question = 'Please choose your transfer_function between\n' possibilities = [content[3:-4] for content in listdir \ if (content.startswith('TF') and content.endswith('dat'))] for i, tfname in enumerate(possibilities): question += ' %s / %s\n' % (i, tfname) possibilities += range(len(possibilities)) if args and args[0] in possibilities: tfname = args[0] else: tfname = self.ask(question, 'dbl_gauss_pt_jet', possibilities) if tfname.isdigit(): tfname = possibilities[int(tfname)] P_dir, MW_dir = MW_info.detect_SubProcess(P_mode=1) os.chdir('./Source/MadWeight/transfer_function') change_tf.create_TF_main(tfname,0, MW_dir)
def test_run_fromP(self): """ """ cmd = os.getcwd() self.generate('p p > e+ e-', 'sm') self.assertEqual(cmd, os.getcwd()) shutil.copy( os.path.join(_file_path, 'input_files', 'run_card_matching.dat'), '/tmp/MGPROCESS/Cards/run_card.dat') with misc.chdir('/tmp/MGPROCESS/'): ff = open('cmd.cmd', 'w') ff.write('set automatic_html_opening False --nosave\n') ff.write('set notification_center False --nosave\n') ff.write('display options\n') ff.write('display variable allow_notification_center\n') ff.write('generate_events -f \n') ff.close() if logger.getEffectiveLevel() > 20: output = open(os.devnull, 'w') else: output = None id = subprocess.call(['./bin/madevent', 'cmd.cmd'], stdout=output, stderr=output) self.assertEqual(id, 0) self.check_parton_output(cross=947.9)
def do_define_transfer_fct(self, line): """MadWeight Function:Define the current transfer function""" with misc.chdir(self.me_dir): self.configure() args = self.split_arg(line) path = pjoin(self.me_dir, 'Source', 'MadWeight', 'transfer_function', 'data') listdir = os.listdir(path) question = 'Please choose your transfer_function between\n' possibilities = [content[3:-4] for content in listdir \ if (content.startswith('TF') and content.endswith('dat'))] for i, tfname in enumerate(possibilities): question += ' %s / %s\n' % (i, tfname) possibilities += range(len(possibilities)) if args and args[0] in possibilities: tfname = args[0] else: tfname = self.ask(question, 'dbl_gauss_pt_jet', possibilities) if tfname.isdigit(): tfname = possibilities[int(tfname)] P_dir, MW_dir = MW_info.detect_SubProcess(P_mode=1) os.chdir('./Source/MadWeight/transfer_function') change_tf.create_TF_main(tfname, 0, MW_dir)
def check_html_page(cls, link): """return True if all link in the html page are existing on disk. otherwise raise an assertion error""" text = open(link).read() pattern = re.compile(r'href=[\"\']?(.*?)?[\"\'\s\#]', re.DOTALL) cwd = os.path.dirname(link) with misc.chdir(cwd): for path in pattern.findall(text): if not path: continue # means is just a linke starting with # cls.assertTrue(os.path.exists(path), '%s/%s' % (cwd, path)) return True
def do_launch(self, line): """MadWeight Function:run the full suite of commands""" args = self.split_arg(line) #if not os.path.exists(pjoin(self.me_dir, 'Cards','transfer_card.dat')): # self.exec_cmd('define_transfer_fct') cards = [ 'param_card.dat', 'run_card.dat', 'madweight_card.dat', 'transfer_card.dat', 'input.lhco' ] if not self.force: self.ask_edit_cards(cards, mode='fixed', plot=False) else: self.configured = 0 self.configure() with misc.chdir(self.me_dir): if not os.path.exists( pjoin(self.me_dir, self.MWparam['mw_run']['inputfile'])): raise self.InvalidCmd('Please specify a valid LHCO File') if pjoin(self.me_dir, self.MWparam['mw_run']['inputfile']) not in \ [pjoin(self.me_dir, 'Events', 'input.lhco'), pjoin(self.me_dir, 'Events', 'input.lhco.gz')]: zipped = self.MWparam['mw_run']['inputfile'].endswith('.gz') if zipped: files.cp( pjoin(self.me_dir, self.MWparam['mw_run']['inputfile']), pjoin(self.me_dir, 'Events', 'input.lhco.gz')) if os.path.exists( pjoin(self.me_dir, 'Events', 'input.lhco')): os.remove(pjoin(self.me_dir, 'Events', 'input.lhco')) else: files.cp( pjoin(self.me_dir, self.MWparam['mw_run']['inputfile']), pjoin(self.me_dir, 'Events', 'input.lhco')) if not (os.path.exists(pjoin(self.me_dir, 'Events', 'input.lhco')) or \ os.path.exists(pjoin(self.me_dir, 'Events', 'input.lhco.gz'))): raise self.InvalidCmd('Please specify a valid LHCO File') self.exec_cmd('treatcards') self.exec_cmd('get_integration_channel') self.exec_cmd('compile') self.exec_cmd('check_events') self.exec_cmd('submit_jobs') self.exec_cmd('collect')
def copy_template(self, model): misc.sprint( 'Entering PLUGIN_ProcessExporter.copy_template (initialise the directory)' ) try: os.mkdir(self.dir_path) except os.error as error: logger.warning(error.strerror + ' ' + self.dir_path) with misc.chdir(self.dir_path): logger.info('Creating subdirectories in directory %s' % self.dir_path) for d in ['src', 'Cards', 'SubProcesses', 'CMake']: # AV - added CMake, removed lib try: os.mkdir(d) except os.error as error: logger.warning(error.strerror + ' ' + os.path.join(self.dir_path, d)) # Write param_card open(os.path.join('Cards', 'param_card.dat'), 'w').write(model.write_param_card()) # Copy files in various subdirectories for key in self.from_template: for f in self.from_template[key]: PLUGIN_export_cpp.cp( f, key) # NB this assumes directory key exists... # Copy src makefile if self.template_src_make: makefile_src = self.read_template_file( self.template_src_make) % { 'model': self.get_model_name(model.get('name')) } open(os.path.join('src', 'cudacpp_src.mk'), 'w').write(makefile_src) # Copy SubProcesses makefile if self.template_Sub_make: makefile = self.read_template_file(self.template_Sub_make) % { 'model': self.get_model_name(model.get('name')) } open(os.path.join('SubProcesses', 'cudacpp.mk'), 'w').write(makefile)
def do_launch(self, line): """MadWeight Function:run the full suite of commands""" args = self.split_arg(line) #if not os.path.exists(pjoin(self.me_dir, 'Cards','transfer_card.dat')): # self.exec_cmd('define_transfer_fct') cards = ['param_card.dat', 'run_card.dat', 'madweight_card.dat', 'transfer_card.dat', 'input.lhco'] if not self.force: self.ask_edit_cards(cards, mode='fixed', plot=False) else: self.configured = 0 self.configure() with misc.chdir(self.me_dir): if not os.path.exists(pjoin(self.me_dir, self.MWparam['mw_run']['inputfile'])): raise self.InvalidCmd('Please specify a valid LHCO File') if pjoin(self.me_dir, self.MWparam['mw_run']['inputfile']) not in \ [pjoin(self.me_dir, 'Events', 'input.lhco'), pjoin(self.me_dir, 'Events', 'input.lhco.gz')]: zipped = self.MWparam['mw_run']['inputfile'].endswith('.gz') if zipped: files.cp(pjoin(self.me_dir, self.MWparam['mw_run']['inputfile']), pjoin(self.me_dir, 'Events', 'input.lhco.gz')) if os.path.exists(pjoin(self.me_dir, 'Events', 'input.lhco')): os.remove(pjoin(self.me_dir, 'Events', 'input.lhco')) else: files.cp(pjoin(self.me_dir, self.MWparam['mw_run']['inputfile']), pjoin(self.me_dir, 'Events', 'input.lhco')) if not (os.path.exists(pjoin(self.me_dir, 'Events', 'input.lhco')) or \ os.path.exists(pjoin(self.me_dir, 'Events', 'input.lhco.gz'))): raise self.InvalidCmd('Please specify a valid LHCO File') self.exec_cmd('treatcards') self.exec_cmd('get_integration_channel') self.exec_cmd('compile') self.exec_cmd('check_events') self.exec_cmd('submit_jobs') self.exec_cmd('collect')
def test_run_fromP(self): """ """ cmd = os.getcwd() self.generate('p p > e+ e-', 'sm') self.assertEqual(cmd, os.getcwd()) shutil.copy(os.path.join(_file_path, 'input_files', 'run_card_matching.dat'), '/tmp/MGPROCESS/Cards/run_card.dat') with misc.chdir('/tmp/MGPROCESS/'): ff = open('cmd.cmd','w') ff.write('set automatic_html_opening False --nosave\n') ff.write('set notification_center False --nosave\n') ff.write('display options\n') ff.write('display variable allow_notification_center\n') ff.write('generate_events -f \n') ff.close() if logger.getEffectiveLevel() > 20: output = open(os.devnull,'w') else: output = None id = subprocess.call(['./bin/madevent','cmd.cmd'], stdout=output, stderr=output) self.assertEqual(id, 0) self.check_parton_output(cross=947.9)
def test_nlo_reweighting(self): """check that nlo reweighting is working. The main point is to check the recombination of the weights Since the rest should be either checked by the lhe_parser classs or by the various check of the standalone checks """ # create a reweight directory interface = MGCmd.MasterCmd() interface.exec_cmd("import model loop_sm", errorhandling=False) interface.exec_cmd("set group_subprocesses False") interface.exec_cmd("generate u d~ > e+ ve [virt=QCD]", precmd=True, errorhandling=False) interface.exec_cmd('output standalone_rw %s/rw_mevirt -f' % self.path) # update the makefile: # update make_opts m_opts = {} if interface.options['lhapdf']: #lhapdfversion = subprocess.Popen([mgcmd.options['lhapdf'], '--version'], # stdout = subprocess.PIPE).stdout.read().strip()[0] m_opts['lhapdf'] = True m_opts['lhapdfversion'] = 5 # 6 always fail on my computer since 5 is compatible but slower always use 5 m_opts['llhapdf'] = subprocess.Popen([interface.options['lhapdf'], '--libs'], stdout = subprocess.PIPE).stdout.read().strip().split()[0] m_opts['f2pymode'] = True else: raise Exception, "need LHAPDF" lhapdf = False lhapdfversion = 0 path = pjoin(self.path,'rw_mevirt', 'Source', 'make_opts') commonCmd.CommonRunCmd.update_make_opts_full(path, m_opts) # Now compile the Source directory misc.compile(cwd=pjoin(self.path, 'rw_mevirt', 'Source')) #link it with misc.chdir(pjoin(self.path)): if self.path not in sys.path: sys.path.insert(0, self.path) mymod = __import__('rw_mevirt.Source.rwgt2py', globals(), locals(), [],-1) mymod = mymod.Source.rwgt2py #mymod.initialise([1,1], 244600) scales2 = [[1283.6655, 1283.6655], [1283.6655, 1283.6655], [1283.6655, 1283.6655]] pdg = [[21, 21], [2, 2]] bjx = [[0.00036333765, 0.00036942677], [0.5007504, 0.51807252]] wgt = [[-1.0551457726, 0.890469566701], [0.0, 0.0], [0.0, 0.0]] gs = [1.3206738, 1.3206738] qcdpower = [2, 2] orig_wgt = -0.28722482722716736 ref_wgts = [-1.8403634002861815, 1.5531385730590141] #value = mymod.test_pdf() #self.assertAlmostEqual(value, 1.0) out, partial = mymod.get_wgt(scales2, pdg, bjx, wgt, gs, qcdpower, 1., 1.) #print ref_wgts, partial, [partial[i]/ref_wgts[i] for i in range(2)] #print out, orig_wgt, out/orig_wgt self.assertAlmostEqual(partial[0], ref_wgts[0], places=2) self.assertAlmostEqual(partial[1], ref_wgts[1], places=2) self.assertAlmostEqual(out, orig_wgt, places=2)
def testIO_Loop_sqso_uux_ddx(self): """ target: [loop_matrix(.*)\.f] [write_mp_compute_loop_coefs(.*)\.f] [mp_helas_calls(.*)\.f] [helas_calls(.*)\.f] [loop_CT_calls(.*)\.f] """ myleglist = base_objects.LegList() myleglist.append(base_objects.Leg({'id':2,'state':False})) myleglist.append(base_objects.Leg({'id':-2,'state':False})) myleglist.append(base_objects.Leg({'id':1,'state':True})) myleglist.append(base_objects.Leg({'id':-1,'state':True})) fortran_model=\ helas_call_writers.FortranUFOHelasCallWriterOptimized(self.model,False) SO_tests = [({},['QCD','QED'],{},{},['QCD','QED'],'QCDQEDpert_default') ,({},['QCD'],{},{},['QCD'],'QCDpert_default') ,({},['QED'],{},{},['QED'],'QEDpert_default') ,({},['QCD','QED'],{'QCD':4},{'QCD':'=='},['QCD','QED'], 'QCDQEDpert_QCDsq_eq_4') ,({},['QCD','QED'],{'QED':4},{'QCD':'<='},['QCD','QED'], 'QCDQEDpert_QEDsq_le_4') ,({},['QCD','QED'],{'QCD':4},{'QCD':'>'},['QCD','QED'], 'QCDQEDpert_QCDsq_gt_4') ,({'QED':2},['QCD','QED'],{'QCD':0,'QED':2}, {'QCD':'>','QED':'>'},['QCD','QED'], 'QCDQEDpert_QCDsq_gt_0_QEDAmpAndQEDsq_gt_2') ,({'QED':2},['QCD','QED'],{'WEIGHTED':10,'QED':2}, {'WEIGHTED':'<=','QED':'>'},['WEIGHTED','QCD','QED'], 'QCDQEDpert_WGTsq_le_10_QEDAmpAndQEDsq_gt_2')] for orders, pert_orders, sq_orders , sq_orders_type, split_orders, name \ in SO_tests: myproc = base_objects.Process({'legs':myleglist, 'model':self.model, 'orders': orders, 'squared_orders': sq_orders, 'perturbation_couplings':pert_orders, 'sqorders_types':sq_orders_type, 'split_orders':split_orders}) myloopamp = loop_diagram_generation.LoopAmplitude(myproc) matrix_element=loop_helas_objects.LoopHelasMatrixElement(\ myloopamp,optimized_output=True) # It is enough here to generate and check the filer loop_matrix.f # only here. For that we must initialize the general replacement # dictionary first (The four functions below are normally directly # called from the write_matrix_element function in the exporter # [but we don't call it here because we only want the file # loop_matrix.f]). matrix_element.rep_dict = self.exporter.\ generate_general_replace_dict(matrix_element) # and for the same reason also force the computation of the analytical # information in the Helas loop diagrams. matrix_element.compute_all_analytic_information( self.exporter.get_aloha_model(self.model)) # Finally the entries specific to the optimized output self.exporter.set_optimized_output_specific_replace_dict_entries(\ matrix_element) # We can then finally write out 'loop_matrix.f' with misc.chdir(self.IOpath): writer = writers.FortranWriter(\ pjoin(self.IOpath,'loop_matrix_%s.f'%name)) self.exporter.write_loopmatrix(writer,matrix_element, fortran_model, write_auxiliary_files=False) writer = writers.FortranWriter(\ pjoin(self.IOpath,'write_mp_compute_loop_coefs_%s.f'%name)) self.exporter.write_mp_compute_loop_coefs(writer, matrix_element, fortran_model) for file in glob.glob(pjoin(self.IOpath,'mp_helas_calls_*.f'))+\ glob.glob(pjoin(self.IOpath,'helas_calls_*.f'))+\ glob.glob(pjoin(self.IOpath,'loop_CT_calls*.f')): base_name = '.'.join(file.split('.')[:-1])+'_%s.'+file.split('.')[-1] shutil.move(file,base_name%name)