Exemplo n.º 1
0
    def locate_external(self, name, language, output_dir=None):
        """search a valid external file and copy it to output_dir directory"""
        
        language_to_ext = {'Python': 'py',
                           'Fortran' : 'f',
                           'CPP': 'C'}
        ext = language_to_ext[language]
        paths = [os.path.join(self.model_pos, language), self.model_pos, 
                           os.path.join(root_path, 'aloha', 'template_files', )]

        ext_files  = []
        for path in paths:
            ext_files = glob.glob(os.path.join(path, '%s.%s' % (name, ext)))
            if ext_files:
                break
        else: 

            raise ALOHAERROR, 'No external routine \"%s.%s\" in directories\n %s' % \
                        (name, ext, '\n'.join(paths))
       
        if output_dir:
            for filepath in ext_files:
                
                files.cp(filepath, output_dir)
        return ext_files
Exemplo n.º 2
0
    def treat_input_file(self, filename, default=None, msg=''):
        """ask to edit a file"""

        if msg == '' and filename == 'param_card.dat':
            msg = \
            "WARNING: If you edit this file don\'t forget to consistently "+\
            "modify the different parameters,\n especially the width of all "+\
            "particles."

        if not self.force:
            if msg: print msg
            question = 'Do you want to edit file: %(card)s?' % {
                'card': filename
            }
            choices = ['y', 'n']
            path_info = 'path of the new %(card)s' % {
                'card': os.path.basename(filename)
            }
            ans = self.ask(question, default, choices, path_info)
        else:
            ans = default

        if ans == 'y':
            path = os.path.join(self.card_dir, filename)
            self.edit_file(path)
        elif ans == 'n':
            return
        else:
            path = os.path.join(self.card_dir, filename)
            files.cp(ans, path)
Exemplo n.º 3
0
    def copy_default_card(self, name):

        dico = {'dir': self.card_dir, 'name': name }

        if not os.path.exists('%(dir)s/%(name)s_card.dat' % dico):
            cp('%(dir)s/%(name)s_card_default.dat' % dico,
                '%(dir)s/%(name)s_card.dat' % dico)
Exemplo n.º 4
0
    def write_restrict_card(self, outputdir):
        """ propagate model restriction of the original model. """

        restrict_list = [
            l for l in os.listdir(self.modelpath) if l.startswith('restrict_')
        ]
        if not self.new_external:
            # no new entry in the card => just copy the restrict_card.dat
            for p in restrict_list:
                files.cp(pjoin(self.modelpath, p), outputdir)

        else:
            # need to add the parameter and ensure that they will not be restricted!
            for p in restrict_list:
                param_card = check_param_card.ParamCard(
                    pjoin(self.modelpath, p))
                for parameter in self.new_external:
                    block = parameter.lhablock
                    lhaid = parameter.lhacode
                    value = parameter.value
                    if value == 0:
                        value = 1e-99
                    elif value == 1:
                        value = 9.999999e-1
                    try:
                        param_card.add_param(block.lower(), lhaid, value,
                                             'from addon')
                    except check_param_card.InvalidParamCard:
                        logger.warning("%s will not acting for %s %s" %
                                       (p, block, lhaid))
                        param_card[block.lower()].get(lhaid).value = value
                # all added -> write it
                param_card.write(pjoin(outputdir, p), precision=7)
Exemplo n.º 5
0
    def test_madspin_gridpack(self):

        self.out_dir = self.run_dir
        self.generate('g g > t t~', 'sm')

        #put the MadSpin card
        ff = open(pjoin(self.out_dir, 'Cards/madspin_card.dat'), 'w')
        orig_card =  open(pjoin(self.out_dir, 'Cards/madspin_card_default.dat')).read()
        ff.write('set ms_dir %s' % pjoin(self.out_dir, 'MSDIR1'))
        ff.write(orig_card)
        ff.close()
        
        #reduce the number of events
        files.cp(pjoin(_file_path, 'input_files', 'run_card_matching.dat'),
                 pjoin(self.out_dir, 'Cards/run_card.dat'))

        #create the gridpack        
        self.do('launch -f')
        
        #move the MS gridpack
        self.assertTrue(os.path.exists(pjoin(self.out_dir, 'MSDIR1')))
        files.mv(pjoin(self.out_dir, 'MSDIR1'), pjoin(self.out_dir, 'MSDIR2'))
        
        #put the MadSpin card
        ff = open(pjoin(self.out_dir, 'Cards/madspin_card.dat'), 'w')
        ff.write('set ms_dir %s' % pjoin(self.out_dir, 'MSDIR2'))
        ff.write(orig_card)
        ff.close()
               
        #create the gridpack        
        self.do('launch -f')
        
        self.check_parton_output('run_02_decayed_1', 100)           
Exemplo n.º 6
0
    def setUp(self):
        """ Here we just copy the hidden restrict_card to a regular one.
        And we don't bother making it hidden again after the test."""
        model_path = os.path.join(_mg5_path, 'models', 'loop_qcd_qed_sm')
        if not os.path.exists(model_path):
            for tmp in os.environ['PYTHONPATH'].split(':'):
                model_path = os.path.join(tmp, 'loop_qcd_qed_sm')
                if os.path.exists(model_path):
                    break
        cp(os.path.join(model_path, '.restrict_parallel_test.dat'),
           os.path.join(model_path, 'restrict_parallel_test.dat'))
        cp(os.path.join(model_path, '.restrict_parallel_test_MB.dat'),
           os.path.join(model_path, 'restrict_parallel_test_MB.dat'))
        model_path = os.path.join(_mg5_path, 'models', 'loop_qcd_qed_sm_Gmu')
        if not os.path.exists(model_path):
            for tmp in os.environ['PYTHONPATH'].split(':'):
                model_path = os.path.join(tmp, 'loop_qcd_qed_sm_Gmu')
                if os.path.exists(model_path):
                    break

        cp(os.path.join(model_path, '.restrict_parallel_test_WW.dat'),
           os.path.join(model_path, 'restrict_parallel_test_WW.dat'))
        cp(os.path.join(model_path, '.restrict_parallel_test_ZZ.dat'),
           os.path.join(model_path, 'restrict_parallel_test_ZZ.dat'))
        cp(os.path.join(model_path, '.restrict_parallel_test_WZ.dat'),
           os.path.join(model_path, 'restrict_parallel_test_WZ.dat'))
Exemplo n.º 7
0
    def write_restrict_card(self, outputdir):
        """ propagate model restriction of the original model. """

        restrict_list = [l for l in os.listdir(self.modelpath) if l.startswith('restrict_')]
        if not self.new_external:
            # no new entry in the card => just copy the restrict_card.dat
            for p in restrict_list:
                files.cp(pjoin(self.modelpath, p), outputdir)
                
        else:
            # need to add the parameter and ensure that they will not be restricted!
            for p in restrict_list: 
                param_card = check_param_card.ParamCard(pjoin(self.modelpath, p))
                for parameter in self.new_external:
                    block = parameter.lhablock 
                    lhaid = parameter.lhacode
                    value = parameter.value
                    if value == 0:
                        value = 1e-99
                    elif value == 1:
                        value = 9.999999e-1
                    try:    
                        param_card.add_param(block.lower(), lhaid, value, 'from addon')
                    except check_param_card.InvalidParamCard:
                        logger.warning("%s will not acting for %s %s" % (p, block, lhaid))
                        param_card[block.lower()].get(lhaid).value = value
                # all added -> write it
                param_card.write(pjoin(outputdir, p))
Exemplo n.º 8
0
    def finalize(self, matrix_elements, history, mg5options, flaglist):
        """call the mother class, and do a couple of other things relevant 
        to OS subtraction
        """
        super(MadSTRExporter, self).finalize(matrix_elements, history, mg5options, flaglist)

        os_ids = self.get_os_ids_from_file(pjoin(self.dir_path, 'SubProcesses', 'os_ids.mg'))

        # add the widths corresponding to the os_ids to coupl.inc
        particle_dict = self.model.get('particle_dict') 
        # list(set( is needed for particle/antiparticle with the same width
        keep_widths = list(set([particle_dict[idd].get('width') for idd in os_ids]))
        self.update_couplinc(keep_widths,pjoin(self.dir_path, 'Source', 'coupl.inc'))

        # also, add a function that returns these widths to MODEL 
        filename=pjoin(self.dir_path, 'Source', 'MODEL', 'get_mass_width_fcts.f')
        width_particles = [particle_dict[idd] for idd in os_ids]
        self.update_get_mass_width(width_particles, filename)

        # replace the common_run_interface with the one from madstr_plugin
        internal = pjoin(self.dir_path, 'bin', 'internal')
        files.mv(pjoin(internal, 'common_run_interface.py'), \
                 pjoin(internal, 'common_run_interface_MG.py'))
        files.cp(pjoin(plugin_path, 'common_run_interface.py'), internal)

        # finally patch fks_singular so that it won't complain about negative 
        # weights for the real emission
        subprocess.call('patch -p3 < %s' % pjoin(self.template_path, 'fks_singular_patch.txt'), cwd=self.dir_path, shell=True)
Exemplo n.º 9
0
 def treat_input_file(self, filename, default=None, msg=''):
     """ask to edit a file"""
     
     if msg == '' and filename == 'param_card.dat':
         msg = \
         "WARNING: If you edit this file don\'t forget to consistently "+\
         "modify the different parameters,\n especially the width of all "+\
         "particles."
                                      
     if not self.force:
         if msg:  print msg
         question = 'Do you want to edit file: %(card)s?' % {'card':filename}
         choices = ['y', 'n']
         path_info = 'path of the new %(card)s' % {'card':os.path.basename(filename)}
         ans = self.ask(question, default, choices, path_info)
     else:
         ans = default
     
     if ans == 'y':
         path = os.path.join(self.card_dir, filename)
         self.edit_file(path)
     elif ans == 'n':
         return
     else:
         path = os.path.join(self.card_dir, filename)
         files.cp(ans, path)
Exemplo n.º 10
0
    def test_lhe_none_decay(self):
        """ """

        cwd = os.getcwd()

        files.cp(
            pjoin(MG5DIR, 'tests', 'input_files', 'test_spinmode_none.lhe.gz'),
            self.path)

        fsock = open(pjoin(self.path, 'test_hepmc'), 'w')
        text = """
        set spinmode none
        import ./test_spinmode_none.lhe.gz
        decay z > mu+ mu-
        launch
        """

        fsock.write(text)
        fsock.close()

        import subprocess
        if logging.getLogger('madgraph').level <= 20:
            stdout = None
            stderr = None
        else:
            devnull = open(os.devnull, 'w')
            stdout = devnull
            stderr = devnull

        subprocess.call([
            pjoin(MG5DIR, 'MadSpin', 'madspin'),
            pjoin(self.path, 'test_hepmc')
        ],
                        cwd=pjoin(self.path),
                        stdout=stdout,
                        stderr=stderr)

        self.assertTrue(
            os.path.exists(
                pjoin(self.path, 'test_spinmode_none_decayed.lhe.gz')))
        lhe = lhe_parser.EventFile(
            pjoin(self.path, 'test_spinmode_none_decayed.lhe.gz'))
        self.assertEqual(100, len(lhe))

        nb_dec = 0
        nb_muon = 0
        for event in lhe:
            muon_in = 0
            self.assertEqual(event.nexternal, len(event))
            for particle in event:
                if particle.pdg == 23:
                    self.assertEqual(particle.status, 2)
                    nb_dec += 1
                if particle.pdg == 13:
                    nb_muon += 1
                    muon_in += 1
            self.assertEqual(muon_in, 1)
        self.assertEqual(nb_dec, 189)
        self.assertEqual(nb_muon, 100)
Exemplo n.º 11
0
 def setUp(self):
     """ Here we just copy the hidden restrict_card to a regular one.
     And we don't bother making it hidden again after the test."""
     cp(os.path.join(_mg5_path,'models','loop_sm','.restrict_parallel_test.dat'),
        os.path.join(_mg5_path,'models','loop_sm','restrict_parallel_test.dat'))
     cp(os.path.join(_mg5_path,'models','loop_sm',
                                    '.restrict_parallel_test_c_massive.dat'),
        os.path.join(_mg5_path,'models','loop_sm',
                                     'restrict_parallel_test_c_massive.dat'))
Exemplo n.º 12
0
    def test_hepmc_decay(self):
        """ """

        cwd = os.getcwd()

        files.cp(pjoin(MG5DIR, 'tests', 'input_files', 'test.hepmc.gz'),
                 self.path)

        fsock = open(pjoin(self.path, 'test_hepmc'), 'w')
        text = """
        set spinmode none
        set cross_section {0:1.0}
        set new_wgt BR
        set input_format hepmc
        import ./test.hepmc.gz
        import model %s/tests/input_files/DM_pion %s/tests/input_files/DM_pion/param_pion.dat
        decay k0 > xr xr a
        launch
        """ % (MG5DIR, MG5DIR)

        fsock.write(text)
        fsock.close()

        import subprocess
        if logging.getLogger('madgraph').level <= 20:
            stdout = None
            stderr = None
        else:
            devnull = open(os.devnull, 'w')
            stdout = devnull
            stderr = devnull

        subprocess.call([
            pjoin(MG5DIR, 'MadSpin', 'madspin'),
            pjoin(self.path, 'test_hepmc')
        ],
                        cwd=pjoin(self.path),
                        stdout=stdout,
                        stderr=stdout)
        self.assertTrue(os.path.exists(pjoin(self.path,
                                             'test_decayed.lhe.gz')))
        lhe = lhe_parser.EventFile(pjoin(self.path, 'test_decayed.lhe.gz'))
        self.assertEqual(10, len(lhe))

        nb_dec = 0
        nb_photon = 0
        for event in lhe:
            self.assertEqual(event.nexternal, len(event))
            for particle in event:
                if particle.pdg == 130:
                    self.assertEqual(particle.status, 2)
                    nb_dec += 1
                if particle.pdg == 22:
                    nb_photon += 1

        self.assertEqual(nb_dec, 116)
        self.assertEqual(nb_photon, 116)
    def do_generate(self, line):
        """Generate an amplitude for a given process"""

        try:
            Switcher.do_generate(self, line)
        except:
            # put the stop logo on the web
            files.cp(self._export_dir+'/HTML/stop.jpg',self._export_dir+'/HTML/card.jpg')
            raise
Exemplo n.º 14
0
 def setUp(self):
     """ Here we just copy the hidden restrict_card to a regular one.
     And we don't bother making it hidden again after the test."""
     cp(os.path.join(_mg5_path,'models','loop_sm','.restrict_parallel_test.dat'),
        os.path.join(_mg5_path,'models','loop_sm','restrict_parallel_test.dat'))
     cp(os.path.join(_mg5_path,'models','loop_sm',
                                    '.restrict_parallel_test_c_massive.dat'),
        os.path.join(_mg5_path,'models','loop_sm',
                                     'restrict_parallel_test_c_massive.dat'))
Exemplo n.º 15
0
    def do_generate(self, line):
        """Generate an amplitude for a given process"""

        try:
            Switcher.do_generate(self, line)
        except:
            # put the stop logo on the web
            files.cp(self._export_dir+'/HTML/stop.jpg',self._export_dir+'/HTML/card.jpg')
            raise
Exemplo n.º 16
0
    def create_run_card(self, processes, history):
        """create the run_card for MadSTR, including the extra variables needed
        to control the OS subtraction also in banner.py"""
 
        run_card = banner_mod.RunCardNLO()
        
        run_card.create_default_for_process(self.proc_characteristic, 
                                            history,
                                            processes)
        
        run_card.write(pjoin(self.dir_path, 'Cards', 'run_card_default.dat'))

        # now edit the run_card with the extra variables
        os_text = \
"""#***********************************************************************
# Parameters relevant for the MasSTR plugin:                           *
# iSTR controls the strategy for the resonance treatment               *
#  istr = 1 -> DR without interferece                                  *
#  istr = 2 -> DR with interferece                                     *
#  istr = 3 -> DS with reshuffling on initial state, standard BW       *
#  istr = 4 -> DS with reshuffling on initial state, running BW        *
#  istr = 5 -> DS with reshuffling on all FS particles, standard BW    *
#  istr = 6 -> DS with reshuffling on all FS particles, running BW     *
#***********************************************************************
  2 = istr ! strategy to be used to remove resonances 
                         ! appearing in real emissions
 True = str_include_pdf ! compensate for PDFs when doing reshuffling
 True = str_include_flux ! compensate for flux when doing reshuffling"""

        run_card_lines = open(pjoin(self.dir_path, 'Cards', 'run_card_default.dat')).read().split('\n')
        # look for the line which contains 'store_rwgt_info', after which we will insert
        # the OS block
        for isplit, line in enumerate(run_card_lines):
            if 'store_rwgt_info' in line: break
        new_run_card_lines = run_card_lines[:isplit+1] + os_text.split('\n') + run_card_lines[isplit+1:]
        new_run_card = open(pjoin(self.dir_path, 'Cards', 'run_card_default.dat'), 'w')
        new_run_card.write('\n'.join(new_run_card_lines))
        new_run_card.close()

        # finally copy the run_card_default to run_card
        files.cp(pjoin(self.dir_path, 'Cards', 'run_card_default.dat'), \
                 pjoin(self.dir_path, 'Cards', 'run_card.dat'))

        # We also need to update banner.py
        banner_text = \
"""        self.add_param('istr', 2)
        self.add_param('str_include_pdf', True)
        self.add_param('str_include_flux', True)"""

        banner_lines = open(pjoin(self.dir_path, 'bin', 'internal', 'banner.py')).read().split('\n')
        for isplit, line in enumerate(banner_lines):
            if 'store_rwgt_info' in line: break
        new_banner_lines = banner_lines[:isplit+1] + banner_text.split('\n') + banner_lines[isplit+1:]
        new_banner = open(pjoin(self.dir_path, 'bin', 'internal', 'banner.py'), 'w')
        new_banner.write('\n'.join(new_banner_lines))
        new_banner.close()
Exemplo n.º 17
0
    def write_external_files(self, outputdir):
        """Copy/merge the routines written in Fortran/C++/pyhton"""

        #1. Special case for the formfactor written in Fortran
        re_fct = re.compile('''^\s{7,70}[\w\s]*function (\w*)\(''',
                            re.M + re.I)
        present_fct = set()
        for dirpath in self.all_path:
            if os.path.exists(pjoin(dirpath, 'Fortran', 'functions.f')):
                text = open(pjoin(dirpath, 'Fortran', 'functions.f')).read()
                new_fct = re_fct.findall(text)
                nb_old = len(present_fct)
                nb_added = len(new_fct)
                new_fct = set([f.lower() for f in new_fct])
                present_fct.update(new_fct)
                if len(present_fct) < nb_old + nb_added:
                    logger.critical(
                        '''Some Functions in functions.f are define in more than one model.
                    This require AT LEAST manual modification of the resulting file. But more likely the 
                    model need to be consider as un-physical! Use it very carefully.'''
                    )

                if not os.path.exists(pjoin(outputdir, 'Fortran')):
                    os.mkdir(pjoin(outputdir, 'Fortran'))
                fsock = open(pjoin(outputdir, 'Fortran', 'functions.f'), 'a')
                fsock.write(text)
                fsock.close()

        #2. Ohter files present in Fortran/Cpp/Python directory
        #   ASk user to handle it if any!
        for dirpath in self.all_path:
            for subdir in ['Fortran', 'CPP', 'Python']:
                if os.path.exists(pjoin(dirpath, subdir)):
                    for filepath in os.listdir(pjoin(dirpath, subdir)):
                        if filepath == 'functions.f':
                            continue
                        if '.' not in filepath:
                            continue
                        logger.warning(
                            'Manual HELAS routine associated to the model. Those are not modified automaticaly!! So you need to manually checked them'
                        )
                        nb = 0
                        name, extension = filepath.rsplit('.', 1)

                        while 1:
                            filename = '%s%s%s' % (name, '.moved' * nb,
                                                   extension)
                            if os.path.exists(
                                    pjoin(outputdir, subdir, filename)):
                                nb += 1
                            else:
                                break
                        if not os.path.exists(pjoin(outputdir, subdir)):
                            os.mkdir(pjoin(outputdir, subdir))
                        files.cp(pjoin(dirpath, subdir, filepath),
                                 pjoin(outputdir, subdir, filename))
Exemplo n.º 18
0
 def copy_model_resources(self):
     """Make the copy/symbolic links"""
     model_path = pjoin(self.export_dir, 'Source', 'MODEL')
     if os.path.exists(pjoin(model_path, 'ident_card.dat')):
         mv(pjoin(model_path, 'ident_card.dat'),
            pjoin(self.export_dir, 'Cards'))
     cp(pjoin(model_path, 'param_card.dat'), pjoin(self.export_dir,
                                                   'Cards'))
     mv(pjoin(model_path, 'param_card.dat'),
        pjoin(self.export_dir, 'Cards', 'param_card_default.dat'))
Exemplo n.º 19
0
 def do_add(self, line):
     """Generate an amplitude for a given process and add to
     existing amplitudes
     syntax:
     """
     try:
        Switcher.do_add(self, line)
     except:
         # put the stop logo on the web
         files.cp(self._export_dir+'/HTML/stop.jpg',self._export_dir+'/HTML/card.jpg')
         raise
 def do_add(self, line):
     """Generate an amplitude for a given process and add to
     existing amplitudes
     syntax:
     """
     try:
        Switcher.do_add(self, line)
     except:
         # put the stop logo on the web
         files.cp(self._export_dir+'/HTML/stop.jpg',self._export_dir+'/HTML/card.jpg')
         raise
Exemplo n.º 21
0
def PLUGIN_cp(path1, path2, log=True, error=False):
    """ simple cp taking linux or mix entry"""
    from madgraph.iolibs.files import format_path
    path1 = format_path(path1)
    path2 = format_path(path2)
    try:
        import shutil
        ###shutil.copy(path1, path2)
        shutil.copy(path1, path2, follow_symlinks=False) # AV
    except:
        from madgraph.iolibs.files import cp
        cp(path1, path2, log=log, error=error)
Exemplo n.º 22
0
 def check_3body(self, part, multi1='all', multi2='all', multi3='all', log=None,
                 raiseerror=False):
     """checking the 3body between the decay module and standard MG5"""
     try:
         pid = self.particles_id[part]
     except:
         return 'True'
     if log:
         log = open(log,'w')
     
     to_avoid, twobody_decay = self.get_2body(part)
     to_avoid.update(['a','g', part])#, 'u','u~', 'd', 'd~','c', 'c~','s', 's~'])
     
     # Generate the MG comparison point:
     start= time.time()
     dir_name = 'TEST_DECAY3_%s_%s' % (self.model,part)
     os.system('rm -rf %s >/dev/null' % dir_name)
     os.system('rm -rf %s_dec >/dev/null' % dir_name)
     self.cmd.run_cmd('set automatic_html_opening False --no-save')
     self.cmd.exec_cmd('generate %s > %s %s %s $ all $$ %s --optimize' % 
                       (part, multi1, multi2, multi3, ' '.join(to_avoid)))
     print 'generate %s > %s %s %s $ all $$ %s --optimize' % \
                       (part, multi1, multi2, multi3, ' '.join(to_avoid))
     self.cmd.exec_cmd('history hist.cmd')
     if self.cmd._curr_amps:
         print dir_name  
         self.cmd.exec_cmd('output %s -f' % dir_name)
         #files.cp(pjoin(_file_path, 'input_files/run_card_decay.dat'),
         #             '%s/Cards/run_card.dat' % dir_name, log=True)
             
         self.cmd.exec_cmd('launch -f')
     stop_mg5 = time.time()
     print 'MG5 Running time: %s s ' % (stop_mg5 -start)
             
     #
     # Run MG Decay module
     #
     start4= time.time()
     self.cmd.do_compute_widths('%s --body_decay=3' % part, do2body=True)
     if self.cmd._curr_amps:  
         self.cmd.exec_cmd('output %s_dec -f' % dir_name)
         files.cp(pjoin(_file_path, 'input_files/run_card_decay.dat'),
                  '%s_dec/Cards/run_card.dat' % dir_name, log=True)
         self.cmd.exec_cmd('launch -f')
     stop_mg5 = time.time()
     print 'DECAY Running time: %s s ' % (stop_mg5 -start4)
     
     pid = self.particles_id[part]
     return self.compare3(
                      pjoin(dir_name,'Events','run_01','param_card.dat'), 
                      pjoin('%s_dec' % dir_name, 'Events','run_01','param_card.dat'), 
                      pid, 'MG5', 'DECAY', twobody_decay, log, raiseerror=raiseerror) 
Exemplo n.º 23
0
 def check_3body(self, part, multi1='all', multi2='all', multi3='all', log=None,
                 raiseerror=False):
     """checking the 3body between the decay module and standard MG5"""
     try:
         pid = self.particles_id[part]
     except:
         return 'True'
     if log:
         log = open(log,'w')
     
     to_avoid, twobody_decay = self.get_2body(part)
     to_avoid.update(['a','g', part])#, 'u','u~', 'd', 'd~','c', 'c~','s', 's~'])
     
     # Generate the MG comparison point:
     start= time.time()
     dir_name = 'TEST_DECAY3_%s_%s' % (self.model,part)
     os.system('rm -rf %s >/dev/null' % dir_name)
     os.system('rm -rf %s_dec >/dev/null' % dir_name)
     self.cmd.run_cmd('set automatic_html_opening False --no-save')
     self.cmd.exec_cmd('generate %s > %s %s %s $ all $$ %s --optimize' % 
                       (part, multi1, multi2, multi3, ' '.join(to_avoid)))
     print('generate %s > %s %s %s $ all $$ %s --optimize' % \
                       (part, multi1, multi2, multi3, ' '.join(to_avoid)))
     self.cmd.exec_cmd('history hist.cmd')
     if self.cmd._curr_amps:
         print(dir_name)  
         self.cmd.exec_cmd('output %s -f' % dir_name)
         #files.cp(pjoin(_file_path, 'input_files/run_card_decay.dat'),
         #             '%s/Cards/run_card.dat' % dir_name, log=True)
             
         self.cmd.exec_cmd('launch -f')
     stop_mg5 = time.time()
     print('MG5 Running time: %s s ' % (stop_mg5 -start))
             
     #
     # Run MG Decay module
     #
     start4= time.time()
     self.cmd.do_compute_widths('%s --body_decay=3' % part, do2body=True)
     if self.cmd._curr_amps:  
         self.cmd.exec_cmd('output %s_dec -f' % dir_name)
         files.cp(pjoin(_file_path, 'input_files/run_card_decay.dat'),
                  '%s_dec/Cards/run_card.dat' % dir_name, log=True)
         self.cmd.exec_cmd('launch -f')
     stop_mg5 = time.time()
     print('DECAY Running time: %s s ' % (stop_mg5 -start4))
     
     pid = self.particles_id[part]
     return self.compare3(
                      pjoin(dir_name,'Events','run_01','param_card.dat'), 
                      pjoin('%s_dec' % dir_name, 'Events','run_01','param_card.dat'), 
                      pid, 'MG5', 'DECAY', twobody_decay, log, raiseerror=raiseerror) 
Exemplo n.º 24
0
    def test_madspin_gridpack(self):

        self.out_dir = self.run_dir
        self.generate('g g > t t~', 'sm')

        #put the MadSpin card
        ff = open(pjoin(self.out_dir, 'Cards/madspin_card.dat'), 'w')
        orig_card = open(pjoin(self.out_dir,
                               'Cards/madspin_card_default.dat')).read()
        ff.write('set ms_dir %s' % pjoin(self.out_dir, 'MSDIR1'))
        ff.write(orig_card)
        ff.close()

        run_card = banner.RunCardLO(
            pjoin(self.run_dir, 'Cards', 'run_card.dat'))
        self.assertFalse('ptj' in run_card.user_set)
        self.assertFalse('drjj' in run_card.user_set)
        self.assertFalse('ptj2min' in run_card.user_set)
        self.assertFalse('ptj3min' in run_card.user_set)
        self.assertFalse('mmjj' in run_card.user_set)
        self.assertTrue('ptheavy' in run_card.user_set)
        self.assertFalse('el' in run_card.user_set)
        self.assertFalse('ej' in run_card.user_set)
        self.assertFalse('polbeam1' in run_card.user_set)
        self.assertFalse('ptl' in run_card.user_set)

        #reduce the number of events
        files.cp(pjoin(_file_path, 'input_files', 'run_card_matching.dat'),
                 pjoin(self.out_dir, 'Cards/run_card.dat'))

        #create the gridpack
        self.do('launch -f')
        self.check_parton_output('run_01', 100)
        self.check_parton_output('run_01_decayed_1', 100)
        #move the MS gridpack
        self.assertTrue(os.path.exists(pjoin(self.out_dir, 'MSDIR1')))
        files.mv(pjoin(self.out_dir, 'MSDIR1'), pjoin(self.out_dir, 'MSDIR2'))

        #put the MadSpin card
        ff = open(pjoin(self.out_dir, 'Cards/madspin_card.dat'), 'w')
        ff.write('set ms_dir %s' % pjoin(self.out_dir, 'MSDIR2'))
        ff.write(orig_card)
        ff.close()

        #create the gridpack
        self.do('launch -f')

        self.check_parton_output('run_02_decayed_1', 100)

        self.assertEqual(self.debugging, False)
Exemplo n.º 25
0
    def __init__(self):
        """ launch all the compilation """

        self.make_UFO_pkl()
        self.make_v4_pkl()
        self.make_stdHep()
        self.make_CutTools()
        self.make_IREGI()

        #important for UCL cluster
        files.cp(pjoin(MG5DIR, 'input', '.mg5_configuration_default.txt'),
                 pjoin(MG5DIR, 'input', 'mg5_configuration.txt'))
        self.cmd = interface.MasterCmd()
        self.install_package()
Exemplo n.º 26
0
    def __init__(self):
        """ launch all the compilation """
        
        self.make_UFO_pkl()
        self.make_v4_pkl()
        self.make_stdHep()
        self.make_CutTools()
        self.make_IREGI()

        #important for UCL cluster
        files.cp(pjoin(MG5DIR,'input','.mg5_configuration_default.txt'),
                 pjoin(MG5DIR,'input','mg5_configuration.txt'))
        self.cmd = interface.MasterCmd()        
        self.install_package()
Exemplo n.º 27
0
    def do_save(self, line, check=True, **opt):
        """Save information to file"""

        if check:
            self.check_save([])
            raise  #useless but full security

        args = self.split_arg(line)
        if args[0] != 'options':
            Switcher.do_save(self, line, check, opt)
        else:
            # put default options since
            # in the web the local file is not used
            # in download the default file is more usefull
            files.cp(pjoin(MG5DIR, 'input', 'mg5_configuration.txt'), args[1])
 def do_save(self, line, check=True, **opt):
     """Save information to file"""
     
     if check:
         self.check_save([])
         raise #useless but full security
     
     args = self.split_arg(line)
     if args[0] != 'options':
         Switcher.do_save(self, line,check, opt)
     else:
         # put default options since 
         # in the web the local file is not used
         # in download the default file is more usefull
         files.cp(pjoin(MG5DIR,'input','mg5_configuration.txt'), args[1])
Exemplo n.º 29
0
    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')
Exemplo n.º 30
0
    def write_external_files(self, outputdir):
        """Copy/merge the routines written in Fortran/C++/pyhton"""
        
        #1. Special case for the formfactor written in Fortran
        re_fct = re.compile('''^\s{7,70}[\w\s]*function (\w*)\(''',re.M+re.I)
        present_fct = set()
        for dirpath in self.all_path:
            if os.path.exists(pjoin(dirpath, 'Fortran', 'functions.f')):
                text = open(pjoin(dirpath, 'Fortran', 'functions.f')).read()
                new_fct = re_fct.findall(text)
                nb_old = len(present_fct)
                nb_added = len(new_fct)
                new_fct = set([f.lower() for f in new_fct])
                present_fct.update(new_fct)
                if len(present_fct) < nb_old + nb_added:
                    logger.critical('''Some Functions in functions.f are define in more than one model.
                    This require AT LEAST manual modification of the resulting file. But more likely the 
                    model need to be consider as un-physical! Use it very carefully.''')
                
                if not os.path.exists(pjoin(outputdir, 'Fortran')):
                    os.mkdir(pjoin(outputdir, 'Fortran'))
                fsock = open(pjoin(outputdir, 'Fortran','functions.f'),'a')
                fsock.write(text)
                fsock.close()
                
        #2. Ohter files present in Fortran/Cpp/Python directory
        #   ASk user to handle it if any!
        for dirpath in self.all_path:
            for subdir in ['Fortran', 'CPP', 'Python']:
                if os.path.exists(pjoin(dirpath, subdir)):
                    for filepath in os.listdir(pjoin(dirpath, subdir)):
                        if filepath == 'functions.f':
                            continue
                        if '.' not in filepath:
                            continue
                        logger.warning('Manual HELAS routine associated to the model. Those are not modified automaticaly!! So you need to manually checked them')
                        nb = 0
                        name, extension = filepath.rsplit('.', 1) 

                        while 1:
                            filename = '%s%s%s' %(name, '.moved' * nb, extension)
                            if os.path.exists(pjoin(outputdir, subdir, filename)):
                                nb+=1
                            else:
                                break
                        if not os.path.exists(pjoin(outputdir, subdir)):
                            os.mkdir(pjoin(outputdir, subdir))
                        files.cp(pjoin(dirpath, subdir, filepath), pjoin(outputdir, subdir, filename))
Exemplo n.º 31
0
    def __init__(self, ext_programs):
        """ launch all the compilation """

        # important to uclclus
        if self.overwrite_configuration:
            files.cp(pjoin(MG5DIR,'input','.mg5_configuration_default.txt'),
                     pjoin(MG5DIR,'input','mg5_configuration.txt'))
            
        self.cmd = interface.MasterCmd()                

        if self.autorun:
            self.make_UFO_pkl()
            self.make_v4_pkl()
            self.make_stdHep()
            self.make_CutTools()
            self.make_IREGI()
            self.install_package(ext_programs)
            self.test_output_LO()
            self.test_output_NLO()
            self.precompilation(debug=True)
            self.precompilation(debug=False)
Exemplo n.º 32
0
    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')
Exemplo n.º 33
0
 def do_check_events(self, line):
     """MadWeight Function: check that the events are valid
     and write the events to MG mapping"""
     self.configure()
     evt_file = pjoin(self.me_dir,'Events','input.lhco')
     if not os.path.exists(evt_file):
         question = 'Which LHCO file do you want to use?'
         default = ''            
         if os.path.exists('%s.gz' % evt_file):
             input_file =  '%s.gz' % evt_file
         else:
             input_file = self.ask(question, default, path_msg='valid path')
         
         if not input_file:
             raise self.InvalidCmd('Please specify a valid LHCO File')
         
         if input_file.endswith('.gz'):
             misc.gunzip(input_file, keep=True, stdout=evt_file)
         else:
             files.cp(input_file, evt_file)
         
     verif_event.verif_event(self.MWparam)
Exemplo n.º 34
0
    def do_check_events(self, line):
        """MadWeight Function: check that the events are valid
        and write the events to MG mapping"""
        self.configure()
        evt_file = pjoin(self.me_dir, 'Events', 'input.lhco')
        if not os.path.exists(evt_file):
            question = 'Which LHCO file do you want to use?'
            default = ''
            if os.path.exists('%s.gz' % evt_file):
                input_file = '%s.gz' % evt_file
            else:
                input_file = self.ask(question, default, path_msg='valid path')

            if not input_file:
                raise self.InvalidCmd('Please specify a valid LHCO File')

            if input_file.endswith('.gz'):
                misc.gunzip(input_file, keep=True, stdout=evt_file)
            else:
                files.cp(input_file, evt_file)

        verif_event.verif_event(self.MWparam)
Exemplo n.º 35
0
    def locate_external(self, name, language, output_dir=None):
        """search a valid external file and copy it to output_dir directory"""
        
        language_to_ext = {'Python': 'py',
                           'Fortran' : 'f',
                           'CPP': 'C'}
        ext = language_to_ext[language]
         
        if os.path.exists(os.path.join(self.model_pos, '%s.%s' % (name, ext))):
            filepos = '%s/%s.%s' % (self.model_pos, name, ext)

        elif os.path.exists(os.path.join(root_path, 'aloha', 'template_files', 
                                                       '%s.%s' %(name, ext))):
            filepos = '%s/aloha/template_files/%s.%s' % (root_path, name, ext)
        else:
            path1 = self.model_pos
            path2 = os.path.join(root_path, 'aloha', 'template_files', )
            raise ALOHAERROR, 'No external routine \"%s.%s\" in directories\n %s\n %s' % \
                        (name, ext, path1, path2)
        
        if output_dir:
            files.cp(filepos, output_dir)
        return filepos
Exemplo n.º 36
0
    def write(self, outputdir):
        """ """
        if not os.path.exists(outputdir):
            os.mkdir(outputdir)
        files.cp(os.path.join(self.modelpath, '__init__.py'), outputdir)
        files.cp(os.path.join(self.modelpath, 'object_library.py'), outputdir)
        files.cp(os.path.join(self.modelpath, 'write_param_card.py'), outputdir)

        self.write_particles(outputdir)
        self.write_vertices(outputdir)
        self.write_couplings(outputdir)
        self.write_lorentz(outputdir)
        self.write_parameters(outputdir)
        self.write_orders(outputdir)
        self.write_functions(outputdir)
        self.write_propagators(outputdir)
        self.write_ctvertices(outputdir)
        
        self.write_external_files(outputdir)
        self.write_restrict_card(outputdir)
Exemplo n.º 37
0
    def write(self, outputdir):
        """ """
        if not os.path.exists(outputdir):
            os.mkdir(outputdir)
        files.cp(os.path.join(self.modelpath, '__init__.py'), outputdir)
        files.cp(os.path.join(self.modelpath, 'object_library.py'), outputdir)
        files.cp(os.path.join(self.modelpath, 'write_param_card.py'), outputdir)

        self.write_particles(outputdir)
        self.write_vertices(outputdir)
        self.write_couplings(outputdir)
        self.write_lorentz(outputdir)
        self.write_parameters(outputdir)
        self.write_orders(outputdir)
        self.write_functions(outputdir)
        self.write_propagators(outputdir)
        self.write_ctvertices(outputdir)
        
        self.write_external_files(outputdir)
        self.write_restrict_card(outputdir)
Exemplo n.º 38
0
    def copy_template(self, model):
        out = super(ISR_Exporter, self).copy_template(model)
        cp(pjoin(rootdir, 'genps.f'), pjoin(self.dir_path, 'SubProcesses'))
        cp(pjoin(rootdir, 'pdg2pdf.f'), pjoin(self.dir_path, 'Source', 'PDF'))
        cp(pjoin(rootdir, 'reweight.f'), pjoin(self.dir_path, 'SubProcesses'))

        filename = pjoin(self.dir_path, 'Cards', 'me5_configuration.txt')
        self.cmd.do_save('options %s' % filename.replace(' ', '\ '),
                         check=False,
                         to_keep={'mg5_path': MG5DIR})

        #filename = pjoin(self.dir_path,'Cards', 'proc_card_mg5.dat')
        #self.cmd.do_history(filename)
        if self.cmd._generate_info:
            # Write the procdef_mg5.dat file with process info
            card_path = pjoin(self.dir_path ,'SubProcesses', \
                                     'procdef_mg5.dat')
            self.write_procdef_mg5(card_path, self.cmd._curr_model['name'],
                                   self.cmd._generate_info)
        return

        return out
Exemplo n.º 39
0
 def has_same_decay(self, particle, run_fr=True):
     """create mg5 directory and then use fr to compare. Returns the ratio of
     the decay or None if this ratio is not constant for all channel.
     Check only 2 body.
     """
     enter_time = time.time()
     
     dir_name = 'TEST_DECAY_%s_%s' % (self.model,particle)       
     pid = self.particles_id[particle]
     
     # clean previous run
     os.system('rm -rf %s >/dev/null' % dir_name)
     os.system('rm -rf %s_dec >/dev/null' % dir_name)        
     #
     # RUN MG5
     #
     start1= time.time()
     self.cmd.run_cmd("set automatic_html_opening False --no-save")
     try:
         self.cmd.exec_cmd('generate %s > all all --optimize' % particle)
     except InvalidCmd:
         return 'True'
     if self.cmd._curr_amps: 
         self.cmd.exec_cmd('output %s -f' % dir_name)
         
         
         files.cp(pjoin(_file_path, 'input_files/run_card_decay.dat'),
                  '%s/Cards/run_card.dat' % dir_name, log=True)
         self.cmd.exec_cmd("set automatic_html_opening False --no-save")
         self.cmd.exec_cmd('launch -f')
     stop_mg5 = time.time()
     print 'MG5 Running time: %s s ' % (stop_mg5 -start1)
             
     #
     # Run MG Decay module
     #
     start4= time.time()
     self.cmd.run_cmd("set automatic_html_opening False --no-save")
     self.cmd.exec_cmd('calculate_width %s 2' % particle)
     if self.cmd._curr_amps:  
         self.cmd.exec_cmd('output %s_dec -f' % dir_name)
         files.cp(pjoin(_file_path, 'input_files/run_card_decay.dat'),
                  '%s_dec/Cards/run_card.dat' % dir_name, log=True)
         print "279 launch"
         self.cmd.exec_cmd('launch -f')
     stop_mg5 = time.time()
     print 'DECAY Running time: %s s ' % (stop_mg5 -start4)
     
     #
     # RUN FR DECAY
     #
     if run_fr:    
         me_cmd = me_interface.MadEventCmd(dir_name)
         self.cmd.define_child_cmd_interface(me_cmd, False)
         start3 = time.time()
         me_cmd.model_name = self.model
         me_cmd.run_cmd("set automatic_html_opening False --no-save")
         me_cmd.do_compute_widths(' %s -f --body_decay=2' % particle)
         stop_fr = time.time()
         print 'FR Running time: %s s ' % (stop_fr -start3)
         out1 = self.compare(pjoin(dir_name, 'Cards', 'param_card.dat'),
                      pjoin(dir_name,'Events','run_01','param_card.dat'), 
                      pid, 'FR', 'MG5')         
         out2 = self.compare(pjoin(dir_name, 'Cards', 'param_card.dat'),
                      pjoin('%s_dec' % dir_name, 'Events','run_01','param_card.dat'), 
                      pid, 'FR', 'DECAY')
         me_cmd.do_quit('')
 
         if out1 == out2 == 'True':
             os.system('rm -rf %s >/dev/null' % dir_name)
             os.system('rm -rf %s_dec >/dev/null' % dir_name)
             
             return 'True'
         else:
             return out1 + out2
     else:
         return self.compare(
                      pjoin(dir_name,'Events','run_01','param_card.dat'), 
                      pjoin('%s_dec' % dir_name, 'Events','run_01','param_card.dat'), 
                      pid, 'MG5', 'DECAY') 
Exemplo n.º 40
0
    def setUp(self):
        """ """
    
        if os.path.exists('/tmp/edit_card'):
            os.system('rm -rf /tmp/edit_card')
        os.system('mkdir /tmp/edit_card;mkdir /tmp/edit_card/Cards;')
        template_path = pjoin(root_path, '..', 'Template')
        card= 'param_card'
        files.cp(pjoin(root_path, 'input_files/restrict_sm.dat'), '/tmp/edit_card/Cards/%s.dat' % card)
        files.cp(pjoin(root_path, 'input_files/restrict_sm.dat'), '/tmp/edit_card/Cards/%s_default.dat' % card)
                
        card = 'run_card'
        import madgraph.various.banner as banner_mod
        card = banner_mod.RunCardLO()
        card.write('/tmp/edit_card/Cards/run_card.dat')
        card.write('/tmp/edit_card/Cards/run_card_default.dat')


        card = 'MadWeight_card'
        files.cp(pjoin(template_path, 'MadWeight/Cards/%s.dat' % card), '/tmp/edit_card/Cards')
        files.cp(pjoin(template_path, 'MadWeight/Cards/%s.dat' % card), '/tmp/edit_card/Cards/%s_default.dat' % card)
        card = 'shower_card'
        files.cp(pjoin(template_path, 'NLO/Cards/%s.dat' % card), '/tmp/edit_card/Cards')
        files.cp(pjoin(template_path, 'NLO/Cards/%s.dat' % card), '/tmp/edit_card/Cards/%s_default.dat' % card)
        
        #MadLoop Card
        files.cp(pjoin(template_path, 'loop_material/StandAlone/Cards/MadLoopParams.dat'), '/tmp/edit_card/Cards')
        
        #Pythia8 
        files.cp(pjoin(template_path, 'LO/Cards/pythia8_card_default.dat'), '/tmp/edit_card/Cards/pythia8_card_default.dat')
        files.cp(pjoin(template_path, 'LO/Cards/pythia8_card_default.dat'), '/tmp/edit_card/Cards/pythia8_card.dat')
        
        fakemother = FakeInterface('/tmp/edit_card/')
        self.cmd = runcmd.AskforEditCard('', cards=['run_card.dat', 'param_card.dat', 'madweight_card.dat', 'shower_card.dat',
                                                    'pythia8_card.dat'],
                                        mode='auto', mother_interface=fakemother)
Exemplo n.º 41
0
    def runIOTests(self, update = False, force = 0, verbose=False, \
                                                       testKeys='instanceList'):
        """ Run the IOTests for this instance (defined in self.instance_tests)
            and compare the files of the chosen tests against the hardcoded ones
            stored in tests/input_files/IOTestsComparison. If you see
            an error in the comparison and you are sure that the newest output
            is correct (i.e. you understand that this modification is meant to
            be so). Then feel free to automatically regenerate this file with
            the newest version by doing 
            
              ./test_manager -i U folderName/testName/fileName
                
            If update is True (meant to be used by __main__ only) then
            it will create/update/remove the files instead of testing them.
            The argument tests can be a list of tuple-keys describing the tests
            to cover. Otherwise it is the instance_test list.
            The force argument must be 10 if you do not want to monitor the 
            modifications on the updated files. If it is 0 you will monitor
            all modified file and if 1 you will monitor each modified file of
            a given name only once.
        """
        # First make sure that the tarball need not be untarred
        # Extract the tarball for hardcoded in all cases to make sure the
        # IOTestComparison folder is synchronized with it.
        if IOTestManager._compress_ref_fodler:
            if path.isdir(_hc_comparison_files):
                try:
                    shutil.rmtree(_hc_comparison_files)
                except IOError:
                    pass
            if path.isfile(_hc_comparison_tarball):
                tar = tarfile.open(_hc_comparison_tarball, mode='r:bz2')
                tar.extractall(path.dirname(_hc_comparison_files))
                tar.close()
            else:
                raise MadGraph5Error(
                    "Could not find the comparison tarball %s." %
                    _hc_comparison_tarball)
        else:
            if not path.isdir(_hc_comparison_files):
                raise MadGraph5Error(
                    "Could not find the comparison tarball %s." %
                    _hc_comparison_tarball)

        # In update = True mode, we keep track of the modification to
        # provide summary information
        modifications = {
            'updated': [],
            'created': [],
            'removed': [],
            'missing': []
        }

        # List all the names of the files for which modifications have been
        # reviewed at least once.The approach taken here is different than
        # with the list refusedFolder and refusedTest.
        # The key of the dictionary are the filenames and the value are string
        # determining the user answer for that file.
        reviewed_file_names = {}

        # Chose what test to cover
        if testKeys == 'instanceList':
            testKeys = self.instance_tests

        if verbose:            print("\n== "+colored%(32,"Operational mode")+\
    " : file %s ==\n"%(colored%(34,('UPDATE' if update else 'TESTING'))))
        for (folder_name, test_name) in testKeys:
            try:
                (iotest, iotestManager) = self.all_tests[(folder_name,
                                                          test_name)]
            except KeyError:
                raise MadGraph5Error('Test (%s,%s) could not be found.'\
                                                       %(folder_name, test_name))
            if verbose:
                print("Processing %s in %s" %
                      (colored % (32, test_name), colored % (34, folder_name)))

            files_path = iotest.run(iotestManager)
            try:
                pass
#                files_path = iotest.run(iotestManager)
            except Exception as e:
                iotest.clean_output()
                if not verbose:
                    raise e
                else:
                    print(colored%(31,"  Test %s "%test_name+\
                              "crashed with the following error:\n  %s."%str(e)))
                    continue

            # First create the list of files to check as the user might be using
            # regular expressions.
            filesToCheck = []
            # Store here the files reckognized as veto rules (with filename
            # starting with '-')
            veto_rules = []
            for fname in iotest.testedFiles:
                # Disregard the veto rules
                regexp_finder = re.compile(
                    r'^(?P<veto>-)?(?P<root_folder>.*)(\/)?\[(?P<regexp>.*)\]$'
                )
                found = regexp_finder.search(fname)
                if not found is None:
                    # folder without the final /
                    base_path = pjoin(files_path, found.group('root_folder'))
                    regexp = re.compile(found.group('regexp'))
                    # In filesToCheck, we must remove the files_path/ prepended
                    for root, dirnames, filenames in os.walk(base_path):
                        for file in filenames:
                            if not regexp.search(str(os.path.relpath(
                                    pjoin(root,file),base_path))) is None and \
                                              not path.islink(pjoin(root,file)):
                                new_target = os.path.relpath(
                                    pjoin(root, file), files_path)
                                if found.group('veto') == '-':
                                    veto_rules.append(new_target)
                                else:
                                    filesToCheck.append(new_target)
                else:
                    fn = fname[1:] if fname.startswith('-') else fname
                    if (not path.exists(pjoin(files_path, fn))) or path.islink(
                            pjoin(files_path, fn)):
                        if force in [0, 1]:
                            answer = Cmd.timed_input(question=
                                                     """The IOTest %s does not create file '%s'. Fix it! [type 'enter'] >"""\
                                    %(test_name,fn),default="y")
                        modifications['missing'].append(
                            "%s/%s/%s" %
                            (folder_name, test_name, path.basename(fname)))
                        if verbose:                            print("    > [ %s ] "%(colored%(31,"MISSING"))+\
                  "%s/%s/%s"%(folder_name,test_name,path.basename(fname)))
                    else:
                        if fname.startswith('-'):
                            veto_rules.append(fn)
                        else:
                            filesToCheck.append(fn)

            # Apply the trimming of the veto rules
            filesToCheck = [f for f in filesToCheck if f not in veto_rules]

            if update:
                # Remove files which are no longer used for comparison
                activeFiles = [self.toFileName(f) for f in filesToCheck]
                for file in glob.glob(pjoin(_hc_comparison_files,folder_name,\
                                                                test_name,'*')):
                    # Ignore the .BackUp files and directories. Also ignore
                    # a file which was previously flagged missing because it
                    # was explicitly specified in the list of files that the
                    # test *must* provide.
                    if path.basename(file).endswith('.BackUp') or \
                       path.isdir(file) or \
                       pjoin(folder_name,test_name,path.basename(file)) in \
                                                       modifications['missing']:
                        continue
                    if path.basename(file) not in activeFiles:
                        if force==0 or (force==1 and \
                         path.basename(file) not in list(reviewed_file_names.keys())):
                            answer = Cmd.timed_input(question=
                                                     """Obsolete ref. file %s in %s/%s detected, delete it? [y/n] >"""\
                                    %(path.basename(file),folder_name,test_name)
                                                                   ,default="y")
                            reviewed_file_names[path.basename(file)] = answer
                        elif (force==1 and \
                             path.basename(file) in list(reviewed_file_names.keys())):
                            answer = reviewed_file_names[path.basename(file)]
                        else:
                            answer = 'Y'

                        if answer not in ['Y', 'y', '']:
                            if verbose:
                                print("    > [ %s ] "%(colored%(31,"IGNORED"))+\
                          "file deletion %s/%s/%s"%(folder_name,test_name,
                                                            path.basename(file)))
                            continue

                        os.remove(file)
                        if verbose:                            print("    > [ %s ] "%(colored%(31,"REMOVED"))+\
                  "%s/%s/%s"%(folder_name,test_name,path.basename(file)))
                        modifications['removed'].append('/'.join(
                            str(file).split('/')[-3:]))

            # Make sure it is not filtered out by the user-filter
            if self.filesChecked_filter != ['ALL']:
                new_filesToCheck = []
                for file in filesToCheck:
                    # Try if it matches any filter
                    for filter in self.filesChecked_filter:
                        # A regular expression
                        if filter.endswith(']'):
                            split = filter[:-1].split('[')
                            # folder without the final /
                            folder = split[0][:-1]
                            if folder != path.dirname(pjoin(file)):
                                continue
                            search = re.compile('['.join(split[1:]))
                            if not search.match(path.basename(file)) is None:
                                new_filesToCheck.append(file)
                                break
                        # Just the exact filename
                        elif filter == file:
                            new_filesToCheck.append(file)
                            break
                filesToCheck = new_filesToCheck

            # Now we can scan them and process them one at a time
            # Keep track of the folders and testNames the user did not want to
            # create
            refused_Folders = []
            refused_testNames = []
            for fname in filesToCheck:
                file_path = path.abspath(pjoin(files_path, fname))
                self.assertTrue(path.isfile(file_path),
                                'File %s not found.' % str(file_path))
                comparison_path = pjoin(_hc_comparison_files,\
                                    folder_name,test_name,self.toFileName(fname))
                if not update:
                    if not os.path.isfile(comparison_path):
                        iotest.clean_output()
                        if not verbose:
                            raise MadGraph5Error("Missing ref. files for test %s\n"%test_name+\
                                "Create them with './test_manager.py -U %s'"%test_name)
                            continue
                        else:
                            print(colored % (31, 'The ref. file %s' % str(
                                '/'.join(comparison_path.split('/')[-3:])) +
                                             ' does not exist.'))
                            print(colored %
                                  (34, 'Consider creating it with ' +
                                   './test_manager.py -U %s' % test_name))
                            exit(0)
                    goal = open(comparison_path).read() % misc.get_pkg_info()
                    if not verbose:
                        self.assertFileContains(open(file_path), goal)
                    else:
                        try:
                            self.assertFileContains(open(file_path), goal)
                        except AssertionError:
                            if verbose:
                                print("    > %s differs from the reference." %
                                      fname)

                else:
                    if not path.isdir(pjoin(_hc_comparison_files,
                                            folder_name)):
                        if force == 0:
                            if folder_name in refused_Folders:
                                continue
                            answer = Cmd.timed_input(
                                question=
                                """New folder %s detected, create it? [y/n] >"""
                                % folder_name,
                                default="y")
                            if answer not in ['Y', 'y', '']:
                                refused_Folders.append(folder_name)
                                if verbose:                                    print("    > [ %s ] folder %s"\
                                   %(colored%(31,"IGNORED"),folder_name))
                                continue
                        if verbose:                            print("    > [ %s ] folder %s"%\
                                    (colored%(32,"CREATED"),folder_name))
                        os.makedirs(pjoin(_hc_comparison_files, folder_name))
                    if not path.isdir(
                            pjoin(_hc_comparison_files, folder_name,
                                  test_name)):
                        if force == 0:
                            if (folder_name, test_name) in refused_testNames:
                                continue
                            answer = Cmd.timed_input(
                                question=
                                """New test %s/%s detected, create it? [y/n] >"""
                                % (folder_name, test_name),
                                default="y")
                            if answer not in ['Y', 'y', '']:
                                refused_testNames.append(
                                    (folder_name, test_name))
                                if verbose:                                    print("    > [ %s ] test %s/%s"\
                         %(colored%(31,"IGNORED"),folder_name,test_name))
                                continue
                        if verbose:                            print("    > [ %s ] test %s/%s"\
                         %(colored%(32,"CREATED"),folder_name,test_name))
                        os.makedirs(
                            pjoin(_hc_comparison_files, folder_name,
                                  test_name))
                    # Transform the package information to make it a template
                    file = open(file_path, 'r')
                    target = file.read()
                    # So that if % appear, we cast them to %% which are not formatted.
                    target = target.replace('%', '%%')
                    # So that the version and date is automatically updated
                    target = target.replace('MadGraph5_aMC@NLO v. %(version)s, %(date)s'\
                                                           %misc.get_pkg_info(),
                                          'MadGraph5_aMC@NLO v. %(version)s, %(date)s')
                    target = target.replace('v%(version)s (%(date)s)'\
                                                           %misc.get_pkg_info(),
                                                      'v%(version)s (%(date)s)')
                    file.close()
                    if os.path.isfile(comparison_path):
                        file = open(comparison_path, 'r')
                        existing = file.read()
                        file.close()
                        if existing == target:
                            continue
                        else:
                            # Copying the existing reference as a backup
                            tmp_path = pjoin(_hc_comparison_files,folder_name,\
                                        test_name,self.toFileName(fname)+'.BackUp')
                            if os.path.isfile(tmp_path):
                                os.remove(tmp_path)
                            file = open(tmp_path, 'w')
                            file.write(target)
                            file.close()
                            if force==0 or (force==1 and path.basename(\
                            comparison_path) not in list(reviewed_file_names.keys())):
                                text = \
"""File %s in test %s/%s differs by the following (reference file first):
"""%(fname,folder_name,test_name)
                                text += misc.Popen(['diff',str(comparison_path),
                                  str(tmp_path)],stdout=subprocess.PIPE).\
                                                                communicate()[0].decode('utf-8')
                                # Remove the last newline
                                if text[-1] == '\n':
                                    text = text[:-1]
                                if (len(text.split('\n')) < 15):
                                    print(text)
                                else:
                                    pydoc.pager(text)
                                    print("Difference displayed in editor.")
                                answer = ''
                                while answer not in ['y', 'n']:
                                    answer = Cmd.timed_input(
                                        question=
                                        """Ref. file %s differs from the new one (see diff. before), update it? [y/n/h/r] >"""
                                        % fname,
                                        default="y")
                                    if answer not in ['y', 'n']:
                                        if answer == 'r':
                                            pydoc.pager(text)
                                        else:
                                            print("reference path: %s" %
                                                  comparison_path)
                                            print("code returns: %s" %
                                                  tmp_path)

                                os.remove(tmp_path)
                                reviewed_file_names[path.basename(\
                                                      comparison_path)] = answer
                            elif (force==1 and path.basename(\
                                comparison_path) in list(reviewed_file_names.keys())):
                                answer = reviewed_file_names[path.basename(\
                                                               comparison_path)]
                            else:
                                answer = 'Y'
                            if answer not in ['Y', 'y', '']:
                                if verbose:                                    print("    > [ %s ] %s"%\
                                          (colored%(31,"IGNORED"),fname))
                                continue

                            # Copying the existing reference as a backup
                            back_up_path = pjoin(_hc_comparison_files,folder_name,\
                                         test_name,self.toFileName(fname)+'.BackUp')
                            if os.path.isfile(back_up_path):
                                os.remove(back_up_path)
                            cp(comparison_path, back_up_path)
                            if verbose:                                print("    > [ %s ] %s"\
                                         %(colored%(32,"UPDATED"),fname))
                            modifications['updated'].append('/'.join(
                                comparison_path.split('/')[-3:]))
                    else:
                        if force==0 or (force==1 and path.basename(\
                            comparison_path) not in list(reviewed_file_names.keys())):
                            answer = Cmd.timed_input(
                                question=
                                """New file %s detected, create it? [y/n] >"""
                                % fname,
                                default="y")
                            reviewed_file_names[path.basename(\
                                                      comparison_path)] = answer
                        elif (force==1 and path.basename(\
                                comparison_path) in list(reviewed_file_names.keys())):
                            answer = reviewed_file_names[\
                                                 path.basename(comparison_path)]
                        else:
                            answer = 'Y'
                        if answer not in ['Y', 'y', '']:
                            if verbose:                                print("    > [ %s ] %s"%\
                                          (colored%(31,"IGNORED"),fname))
                            continue
                        if verbose:                            print("    > [ %s ] %s"%\
                                          (colored%(32,"CREATED"),fname))
                        modifications['created'].append('/'.join(
                            comparison_path.split('/')[-3:]))
                    file = open(comparison_path, 'w')
                    file.write(target)
                    file.close()

            # Clean the iotest output
            iotest.clean_output()

        # Monitor the modifications when in creation files mode by returning the
        # modifications dictionary.
        if update:
            return modifications
        else:
            return 'test_over'
Exemplo n.º 42
0
    def do_launch(self, line):
        """end of the configuration launched the code"""
        
        if self.options["spinmode"] in ["none"]:
            return self.run_bridge(line)
        elif self.options["spinmode"] == "bridge":
            raise Exception, "Bridge mode not yet available due to lack of validation."
        
        if self.options['ms_dir'] and os.path.exists(pjoin(self.options['ms_dir'], 'madspin.pkl')):
            return self.run_from_pickle()
        
    
        args = self.split_arg(line)
        self.check_launch(args)
        for part in self.list_branches.keys():
            if part in self.mg5cmd._multiparticles:
                if any(pid in self.final_state for pid in self.mg5cmd._multiparticles[part]):
                    break
            pid = self.mg5cmd._curr_model.get('name2pdg')[part]
            if pid in self.final_state:
                break
#        else:
#            logger.info("Nothing to decay ...")
#            return
        

        model_line = self.banner.get('proc_card', 'full_model_line')

        if not self.seed:
            self.seed = random.randint(0, int(30081*30081))
            self.do_set('seed %s' % self.seed)
            logger.info('Will use seed %s' % self.seed)
            self.history.insert(0, 'set seed %s' % self.seed)

        if self.seed > 30081*30081: # can't use too big random number
            msg = 'Random seed too large ' + str(self.seed) + ' > 30081*30081'
            raise Exception, msg

        self.options['seed'] = self.seed
        text = '%s\n' % '\n'.join([ line for line in self.history if line])
        self.banner.add_text('madspin' , text)
        
        
        self.update_status('generating Madspin matrix element')
        generate_all = madspin.decay_all_events(self, self.banner, self.events_file, 
                                                    self.options)
        
        self.update_status('running MadSpin')
        generate_all.run()
                        
        self.branching_ratio = generate_all.branching_ratio
        try:
            self.err_branching_ratio = generate_all.err_branching_ratio
        except Exception:
            self.err_branching_ratio = 0
            
        evt_path = self.events_file.name
        try:
            self.events_file.close()
        except:
            pass
        misc.gzip(evt_path)
        decayed_evt_file=evt_path.replace('.lhe', '_decayed.lhe')
        misc.gzip(pjoin(self.options['curr_dir'],'decayed_events.lhe'),
                  stdout=decayed_evt_file)
        if not self.mother:
            logger.info("Decayed events have been written in %s.gz" % decayed_evt_file)

        # Now arxiv the shower card used if RunMaterial is present
        ms_card_path = pjoin(self.options['curr_dir'],'Cards','madspin_card.dat')
        run_dir = os.path.realpath(os.path.dirname(decayed_evt_file))
        if os.path.exists(ms_card_path):
            if os.path.exists(pjoin(run_dir,'RunMaterial.tar.gz')):
                misc.call(['tar','-xzpf','RunMaterial.tar.gz'], cwd=run_dir)
                base_path = pjoin(run_dir,'RunMaterial')
            else:
                base_path = pjoin(run_dir)

            evt_name = os.path.basename(decayed_evt_file).replace('.lhe', '')
            ms_card_to_copy = pjoin(base_path,'madspin_card_for_%s.dat'%evt_name)
            count = 0    
            while os.path.exists(ms_card_to_copy):
                count += 1
                ms_card_to_copy = pjoin(base_path,'madspin_card_for_%s_%d.dat'%\
                                                               (evt_name,count))
            files.cp(str(ms_card_path),str(ms_card_to_copy))
            
            if os.path.exists(pjoin(run_dir,'RunMaterial.tar.gz')):
                misc.call(['tar','-czpf','RunMaterial.tar.gz','RunMaterial'], 
                                                                    cwd=run_dir)
                shutil.rmtree(pjoin(run_dir,'RunMaterial'))
Exemplo n.º 43
0
    def setUp(self):
        """ """
    
        if os.path.exists('/tmp/edit_card'):
            os.system('rm -rf /tmp/edit_card')
        os.system('mkdir /tmp/edit_card;mkdir /tmp/edit_card/Cards;')
        template_path = pjoin(root_path, '..', 'Template')
        card= 'param_card'
        files.cp(pjoin(root_path, 'input_files/restrict_sm.dat'), '/tmp/edit_card/Cards/%s.dat' % card)
        files.cp(pjoin(root_path, 'input_files/restrict_sm.dat'), '/tmp/edit_card/Cards/%s_default.dat' % card)
                
        card = 'run_card'
        import madgraph.various.banner as banner_mod
        card = banner_mod.RunCardLO()
        card.write('/tmp/edit_card/Cards/run_card.dat')
        card.write('/tmp/edit_card/Cards/run_card_default.dat')


        card = 'MadWeight_card'
        files.cp(pjoin(template_path, 'MadWeight/Cards/%s.dat' % card), '/tmp/edit_card/Cards')
        files.cp(pjoin(template_path, 'MadWeight/Cards/%s.dat' % card), '/tmp/edit_card/Cards/%s_default.dat' % card)
        card = 'shower_card'
        files.cp(pjoin(template_path, 'NLO/Cards/%s.dat' % card), '/tmp/edit_card/Cards')
        files.cp(pjoin(template_path, 'NLO/Cards/%s.dat' % card), '/tmp/edit_card/Cards/%s_default.dat' % card)
        
        #MadLoop Card
        files.cp(pjoin(template_path, 'loop_material/StandAlone/Cards/MadLoopParams.dat'), '/tmp/edit_card/Cards')
        
        fakemother = FakeInterface('/tmp/edit_card/')
        self.cmd = runcmd.AskforEditCard('', cards=['run_card.dat', 'param_card.dat', 'madweight_card.dat', 'shower_card.dat'],
                                        mode='auto', mother_interface=fakemother)
    def check_compilation(self):
        """check that the model compile return correct output"""
        #Check the cleaning
        join = lambda p: os.path.join(self.output_path, p)
        self.assertFalse(os.path.exists(self.give_pos('testprog')))
        try:
            os.remove(join('../param_card.inc'))
        except:
            pass
        # prepare for a local compilation

        subprocess.call(['python', 'write_param_card.py'],
                        cwd=os.path.join(MG5DIR, 'models', 'sm'),
                        stdout=subprocess.PIPE)
        files.cp(os.path.join(MG5DIR, 'models', 'sm', 'param_card.dat'),
                 join('param_card.dat'))

        text = file(join('makefile')).read().replace(
            '../../Cards/param_card.dat', 'param_card.dat')
        open(join('makefile'), 'w').write(text)
        #make ../param_card.inc
        param_card = check_param_card.ParamCard(join('param_card.dat'))
        param_card.write_inc_file(join('../param_card.inc'),
                                  join('ident_card.dat'),
                                  join('param_card.dat'))

        subprocess.call(['make', 'testprog'],
                        cwd=self.output_path,
                        stdout=subprocess.PIPE,
                        stderr=subprocess.PIPE)
        self.assertTrue(os.path.exists(self.give_pos('testprog')))

        os.chmod(os.path.join(self.output_path, 'testprog'), 0777)
        testprog = subprocess.Popen("./testprog",
                                    stdout=subprocess.PIPE,
                                    cwd=self.output_path,
                                    stderr=subprocess.STDOUT,
                                    shell=True)

        solutions = {
            'ymtau ': [1.7769999504089355],
            'I4x33 ': [0.024123685681481218, 0.0],
            'MTA ': [1.7769999504089355],
            'GC_81 ': [0.0, 67.544],
            'GC_5 ': [0.0, 0.094836],
            'MZ ': [91.18800354003906],
            'GC_27 ': [0.94484, 0.0],
            'I1x33 ': [0.024123685681481218, 0.0],
            'I3x33 ': [0.9448443987662922, 0.0],
            'GC_95 ': [0.66811, 0.0],
            'GC_60 ': [-0.37035, 0.0],
            'ee__exp__2 ': [0.09483552005165403],
            'aEWM1 ': [132.5070037841797],
            'ytau ': [0.01020661671581679],
            'GC_69 ': [-0.0, -190.38],
            'GC_35 ': [-0.0, -0.42671],
            'cw__exp__2 ': [0.7777535472599892],
            'Gf ': [1.16639e-05],
            'GC_59 ': [0.0, 0.08231],
            'GC_21 ': [-0.94484, -0.0],
            'ee ': [0.307953762847045],
            'WZ ': [2.441404104232788],
            'sw2 ': [0.22224645274001076],
            'WT ': [1.5083359479904175],
            'GC_80 ': [-0.0, -33.772],
            'GC_57 ': [-0.0, -0.35482],
            'sqrt__sw2 ': [0.4714302204356555],
            'GC_67 ': [13.239, 0.0],
            'GC_76 ': [-29.784, 0.0],
            'GC_36 ': [0.0, 0.33188],
            'GC_68 ': [-0.0, -63.46],
            'GC_56 ': [0.10058, 0.0],
            'sw__exp__2 ': [0.22224645274001076],
            'GC_3 ': [-0.0, -0.30795],
            'GC_54 ': [-0.10058, 0.0],
            'WW ': [2.047600030899048],
            'GC_70 ': [-26.266, 0.0],
            'GC_66 ': [-13.239, 0.0],
            'GC_38 ': [-0.0, -0.32662],
            'GC_83 ': [-0.0, -0.017058],
            'GC_77 ': [-16.545, 0.0],
            'gw ': [0.653232969584471],
            'MH ': [125.0],
            'ymb ': [4.199999809265137],
            'complexi ': [0.0, 1.0],
            'GC_37 ': [-0.32662, 0.0],
            'conjg__CKM1x1 ': [1.0],
            'GC_2 ': [0.0, 0.2053],
            'GC_51 ': [0.0, 0.28804],
            'GC_71 ': [-0.0, -26.266],
            'GC_39 ': [0.0, 0.32662],
            'GC_82 ': [-0.017058, 0.0],
            'GC_55 ': [-0.0, -0.10058],
            'GC_78 ': [16.545, 0.0],
            'GC_98 ': [-0.0072172, 0.0],
            'GC_30 ': [-0.024124, -0.0],
            'GC_15 ': [0.024124, 0.0],
            'cw ': [0.881903366168873],
            'yt ': [0.9448443987662922],
            'sqrt__aEW ': [0.08687215260631942],
            'vev ': [246.2184581018163],
            'GC_79 ': [29.784, 0.0],
            'GC_72 ': [0.0, 52.532],
            'GC_1 ': [-0.0, -0.10265],
            'conjg__CKM3x3 ': [1.0],
            'GC_52 ': [-0.0, -0.57609],
            'GC_100 ': [0.0, 0.46191],
            'GC_65 ': [0.0, 0.27432],
            'GC_12 ': [0.0, 1.4828],
            'I2x33 ': [0.9448443987662922, 0.0],
            'GC_94 ': [-0.0, -0.66811],
            'sqrt__aS ': [0.3435112817874484],
            'GC_31 ': [-0.0, -0.25774],
            'aS ': [0.11800000071525575],
            'MW__exp__2 ': [6467.21673128622],
            'MZ__exp__4 ': [69143415.65084904],
            'yb ': [0.024123685681481218],
            'GC_99 ': [-0.0, -0.0072172],
            'WH ': [0.006382339168339968],
            'GC_96 ': [-0.010207, 0.0],
            'MH__exp__2 ': [15625.0],
            'GC_63 ': [0.0, 0.12671],
            'GC_53 ': [0.0, 0.57609],
            'GC_73 ': [26.266, 0.0],
            'GC_64 ': [0.0, 0.084653],
            'sw ': [0.4714302204356555],
            'GC_9 ': [0.053768, 0.0],
            'GC_32 ': [-0.0, -0.51548],
            'muH ': [88.38834764831844],
            'GC_7 ': [-0.053768, 0.0],
            'aEW ': [0.0075467708984556505],
            'vev__exp__2 ': [60623.52911003587],
            'MZ__exp__2 ': [8315.251989618177],
            'GC_97 ': [0.010207, 0.0],
            'GC_62 ': [0.0, 0.37035],
            'GC_74 ': [-24.765, 0.0],
            'g1 ': [0.34919218438279087],
            'GC_10 ': [-1.2177, 0.0],
            'GC_8 ': [0.0, 0.053768],
            'CKM3x3 ': [1.0],
            'MW ': [80.41900727617956],
            'MT ': [172.0],
            'GC_33 ': [-0.0, -0.77321],
            'GC_6 ': [0.0, 0.18967],
            'GC_4 ': [0.0, 0.30795],
            'MB ': [4.699999809265137],
            'GC_61 ': [0.0, -0.20573],
            'ymt ': [164.5],
            'GC_75 ': [24.765, 0.0],
            'G__exp__2 ': [1.4828317414825511],
            'lam ': [0.1288691060169027],
            'GC_50 ': [-0.0, -0.28804],
            'GC_34 ': [0.0, 0.21336],
            'GC_11 ': [0.0, 1.2177],
            'sqrt__2 ': [1.4142135623730951],
            'GC_58 ': [-0.0, -0.027437]
        }
        #solutions = {'GC_5 ': [0.0, 0.094836], 'mdl_MW ': [80.41900727617956], 'mdl_yb ': [0.024123685681481218], 'mdl_sw__exp__2 ': [0.22224645274001076], 'mdl_conjg__CKM3x3 ': [1.0], 'GC_56 ': [0.10058, 0.0], 'mdl_MH ': [125.0], 'GC_95 ': [0.66811, 0.0], 'mdl_I4x33 ': [0.024123685681481218, 0.0], 'mdl_complexi ': [0.0, 1.0], 'aEWM1 ': [132.5070037841797], 'GC_69 ': [-0.0, -190.38], 'GC_35 ': [-0.0, -0.42671], 'mdl_Gf ': [1.16639e-05], 'mdl_gw ': [0.653232969584471], 'mdl_conjg__CKM1x1 ': [1.0], 'mdl_sqrt__aEW ': [0.08687215260631942], 'GC_59 ': [0.0, 0.08231], 'GC_21 ': [-0.94484, -0.0], 'GC_4 ': [0.0, 0.30795], 'mdl_cw ': [0.881903366168873], 'GC_80 ': [-0.0, -33.772], 'GC_64 ': [0.0, 0.084653], 'GC_57 ': [-0.0, -0.35482], 'GC_76 ': [-29.784, 0.0], 'GC_67 ': [13.239, 0.0], 'mdl_vev__exp__2 ': [60623.52911003587], 'mdl_I3x33 ': [0.9448443987662922, 0.0], 'GC_36 ': [0.0, 0.33188], 'mdl_I1x33 ': [0.024123685681481218, 0.0], 'GC_81 ': [0.0, 67.544], 'mdl_sw2 ': [0.22224645274001076], 'GC_68 ': [-0.0, -63.46], 'mdl_ytau ': [0.01020661671581679], 'GC_100 ': [0.0, 0.46191], 'GC_3 ': [-0.0, -0.30795], 'GC_54 ': [-0.10058, 0.0], 'GC_70 ': [-26.266, 0.0], 'GC_66 ': [-13.239, 0.0], 'GC_38 ': [-0.0, -0.32662], 'GC_83 ': [-0.0, -0.017058], 'GC_77 ': [-16.545, 0.0], 'GC_27 ': [0.94484, 0.0], 'GC_10 ': [-1.2177, 0.0], 'GC_37 ': [-0.32662, 0.0], 'GC_60 ': [-0.37035, 0.0], 'GC_2 ': [0.0, 0.2053], 'mdl_muH ': [88.38834764831844], 'mdl_MT ': [172.0], 'mdl_WH ': [0.006382339168339968], 'GC_51 ': [0.0, 0.28804], 'GC_71 ': [-0.0, -26.266], 'GC_39 ': [0.0, 0.32662], 'GC_82 ': [-0.017058, 0.0], 'mdl_sw ': [0.4714302204356555], 'GC_55 ': [-0.0, -0.10058], 'GC_61 ': [0.0, -0.20573], 'mdl_cw__exp__2 ': [0.7777535472599892], 'mdl_ymt ': [164.5], 'GC_78 ': [16.545, 0.0], 'mdl_CKM3x3 ': [1.0], 'GC_30 ': [-0.024124, -0.0], 'GC_15 ': [0.024124, 0.0], 'mdl_aEW ': [0.0075467708984556505], 'mdl_sqrt__sw2 ': [0.4714302204356555], 'mdl_I2x33 ': [0.9448443987662922, 0.0], 'GC_72 ': [0.0, 52.532], 'GC_1 ': [-0.0, -0.10265], 'GC_52 ': [-0.0, -0.57609], 'GC_65 ': [0.0, 0.27432], 'GC_12 ': [0.0, 1.4828], 'mdl_ymb ': [4.199999809265137], 'mdl_ee ': [0.307953762847045], 'GC_79 ': [29.784, 0.0], 'mdl_sqrt__2 ': [1.4142135623730951], 'GC_31 ': [-0.0, -0.25774], 'aS ': [0.11800000071525575], 'GC_99 ': [-0.0, -0.0072172], 'mdl_vev ': [246.2184581018163], 'GC_96 ': [-0.010207, 0.0], 'GC_63 ': [0.0, 0.12671], 'GC_53 ': [0.0, 0.57609], 'GC_73 ': [26.266, 0.0], 'mdl_MZ__exp__2 ': [8315.251989618177], 'mdl_WZ ': [2.441404104232788], 'GC_9 ': [0.053768, 0.0], 'mdl_g1 ': [0.34919218438279087], 'GC_32 ': [-0.0, -0.51548], 'mdl_G ': [1.2177157884673053], 'mdl_WT ': [1.5083359479904175], 'GC_7 ': [-0.053768, 0.0], 'mdl_G__exp__2 ': [1.4828317414825511], 'GC_97 ': [0.010207, 0.0], 'GC_62 ': [0.0, 0.37035], 'GC_74 ': [-24.765, 0.0], 'mdl_MZ ': [91.18800354003906], 'mdl_MZ__exp__4 ': [69143415.65084904], 'GC_8 ': [0.0, 0.053768], 'mdl_yt ': [0.9448443987662922], 'GC_98 ': [-0.0072172, 0.0], 'mdl_ee__exp__2 ': [0.09483552005165403], 'mdl_MB ': [4.699999809265137], 'GC_33 ': [-0.0, -0.77321], 'mdl_ymtau ': [1.7769999504089355], 'mdl_WW ': [2.047600030899048], 'GC_6 ': [0.0, 0.18967], 'mdl_MTA ': [1.7769999504089355], 'GC_75 ': [24.765, 0.0], 'GC_94 ': [-0.0, -0.66811], 'mdl_MW__exp__2 ': [6467.21673128622], 'mdl_MH__exp__2 ': [15625.0], 'GC_50 ': [-0.0, -0.28804], 'GC_34 ': [0.0, 0.21336], 'GC_11 ': [0.0, 1.2177], 'mdl_sqrt__aS ': [0.3435112817874484], 'GC_58 ': [-0.0, -0.027437], 'mdl_lam ': [0.1288691060169027]}
        nb_value = 0
        for line in testprog.stdout:
            self.assertTrue('Warning' not in line)
            if '=' not in line:
                continue
            split = line.split('=')
            variable = split[0].lstrip()
            if variable.startswith('mdl_'):
                variable = variable[4:]

            if ',' in line:
                value = eval(split[1])
            else:
                value = [float(numb) for numb in split[1].split()]
            nb_value += 1

            for i, singlevalue in enumerate(value):
                #try:
                self.assertAlmostEqual(singlevalue,
                                       solutions[variable][i],
                                       places=6,
                    msg='fail to be equal for param %s : %s != %s' % \
                        (variable, singlevalue, solutions[variable][i]))
            #except Exception as error:
            #    print variable
            #    if i == 0:
            #        solutions[variable] = [singlevalue]
            #    else:
            #        solutions[variable].append(singlevalue)

        self.assertEqual(nb_value, 116)
Exemplo n.º 45
0
    def has_same_decay(self, particle):
        """create mg5 directory and then use fr to compare. Returns the ratio of
        the decay or None if this ratio is not constant for all channel.
        """
        enter_time = time.time()
        def error_text(mg5_info, fr_info, pid):
            """get error text"""
            text = "MG5 INFORMATION:\n"
            text += 'total: %s ' % mg5_info['decay'].get((pid,)).value 
            if mg5_info['decay'].decay_table.has_key(pid):
                text += str(mg5_info['decay'].decay_table[pid])+'\n'
            text += "FR INFORMATION\n"
            text += 'total: %s ' % fr_info['decay'].get((pid,)).value 
            if fr_info['decay'].decay_table.has_key(pid):
                text += str(fr_info['decay'].decay_table[pid])+'\n'
            print text
            return text
        
        dir_name = 'TEST_DECAY_%s_%s' % (self.model,particle)       
        pid = self.particles_id[particle]
        
        # clean previous run
        os.system('rm -rf %s >/dev/null' % dir_name)
        
        #
        # RUN MG5
        #
        start1= time.time()
        self.cmd.exec_cmd('set automatic_html_opening False')
        self.cmd.exec_cmd('generate %s > all all' % particle)

        self.cmd.exec_cmd('output %s -f' % dir_name)
        
        
        files.cp(pjoin(_file_path, 'input_files/run_card_decay.dat'),
                 '%s/Cards/run_card.dat' % dir_name, log=True)
        
        self.cmd.exec_cmd('launch -f')
        stop_mg5 = time.time()
        print 'MG5 Running time: %s s ' % (stop_mg5 -start1)
        mg5_info = card_reader.ParamCard(pjoin(dir_name,'Events','run_01','param_card.dat'))
        
        #
        # RUN FR DECAY
        #
                
        me_cmd = me_interface.MadEventCmd(dir_name)
        start3 = time.time()
        me_cmd.exec_cmd('compute_widths %s -f' % particle)
        stop_fr = time.time()
        fr_info = card_reader.ParamCard(pjoin(dir_name, 'Cards', 'param_card.dat'))
        print 'FR Running time: %s s ' % (stop_fr -start3)
        
        
        # check the total width
        mg5_width = mg5_info['decay'].get((pid,)).value
        fr_width = fr_info['decay'].get((pid,)).value
        print mg5_width, fr_width
        
        if mg5_width == fr_width == 0:
            return 'True'
        elif (mg5_width - fr_width) / (mg5_width + fr_width) > 1e-4:
            text = error_text(mg5_info, fr_info, pid)
            return text + '\n%s has not the same total width: ratio of %s' % \
                (particle, (mg5_width - fr_width) / (mg5_width + fr_width))
        
        mg5_info_partial = {}
        for partial_width in mg5_info['decay'].decay_table[pid]:
            lha_code = list(partial_width.lhacode)
            lha_code.sort()
            lha_code = tuple(lha_code)
            mg5_info_partial[lha_code] = partial_width.value
            
        for partial_width in fr_info['decay'].decay_table[pid]:
            lha_code = list(partial_width.lhacode)
            lha_code.sort()
            lha_code = tuple(lha_code)
            mg5_value = mg5_info_partial[lha_code]
            fr_value = partial_width.value
            if mg5_value == fr_value == 0:
                continue
            elif (mg5_value - fr_value) / (mg5_value + fr_value) > 1e-3 and \
                mg5_value / mg5_width > 1e-5:
                text = error_text(mg5_info, fr_info, pid)
                return text + '\n%s has not the same partial width for %s: ratio of %s' % \
                (particle, lha_code, (mg5_value - fr_value) / (mg5_value + fr_value))
                return False            
            
        os.system('rm -rf %s >/dev/null' % dir_name)
        return 'True'
Exemplo n.º 46
0
logging.info("Branching " + MG5DIR + "/aloha to directory " + filepath)
status = subprocess.call(['bzr', 'branch', MG5DIR, filepath])
if status:
    logging.error("bzr branch failed. Script stopped")
    exit()

# 2. Copy MG5 files needed by ALOHA + remove pointless direcoty
devnull = os.open(os.devnull, os.O_RDWR)
logging.info("copying files")
requested_files = [
    'madgraph/iolibs/files.py', 'madgraph/iolibs/file_writers.py'
]

for fname in requested_files:
    files_routines.cp(MG5DIR + '/' + fname, filepath + '/aloha')

for fname in os.listdir(filepath):
    if fname in ['aloha', 'VERSION']:
        continue
    os.system('rm -rf %s ' % os.path.join(filepath, fname))

os.mkdir(filepath + '/vendor')
shutil.copytree(os.path.join(MG5DIR, 'vendor', 'ply'),
                filepath + '/vendor/ply')
files_routines.cp(MG5DIR + '/vendor/__init__.py',
                  filepath + '/vendor/__init__.py')

# 4. Create the automatic documentation in the apidoc directory

try:
    logging.info("Removing existing directory " + filepath)
    shutil.rmtree(filepath)

logging.info("Branching " + MG5DIR + "/aloha to directory " + filepath)
status = subprocess.call(['bzr', 'branch', MG5DIR, filepath])
if status:
    logging.error("bzr branch failed. Script stopped")
    exit()

# 2. Copy MG5 files needed by ALOHA + remove pointless direcoty
devnull = os.open(os.devnull, os.O_RDWR)
logging.info("copying files")
requested_files=['madgraph/iolibs/files.py','madgraph/iolibs/file_writers.py']

for fname in requested_files:
    files_routines.cp(MG5DIR +'/'+ fname, filepath+'/aloha')

for fname in os.listdir(filepath):
    if fname in ['aloha','VERSION']:
        continue
    os.system('rm -rf %s ' % os.path.join(filepath,fname))

os.mkdir(filepath+'/vendor')
shutil.copytree(os.path.join(MG5DIR,'vendor','ply'),filepath+'/vendor/ply')
files_routines.cp(MG5DIR +'/vendor/__init__.py', filepath+'/vendor/__init__.py')


# 4. Create the automatic documentation in the apidoc directory

try:
    status1 = subprocess.call(['epydoc', '--html', '-o', 'apidoc', 'aloha'], cwd = filepath)
Exemplo n.º 48
0
    def has_same_decay(self, particle, run_fr=True):
        """create mg5 directory and then use fr to compare. Returns the ratio of
        the decay or None if this ratio is not constant for all channel.
        Check only 2 body.
        """
        enter_time = time.time()

        dir_name = 'TEST_DECAY_%s_%s' % (self.model, particle)
        pid = self.particles_id[particle]

        # clean previous run
        os.system('rm -rf %s >/dev/null' % dir_name)
        os.system('rm -rf %s_dec >/dev/null' % dir_name)
        #
        # RUN MG5
        #
        start1 = time.time()
        self.cmd.run_cmd("set automatic_html_opening False --no-save")
        try:
            self.cmd.exec_cmd('generate %s > all all --optimize' % particle)
        except InvalidCmd:
            return 'True'
        if self.cmd._curr_amps:
            self.cmd.exec_cmd('output %s -f' % dir_name)

            files.cp(pjoin(_file_path, 'input_files/run_card_decay.dat'),
                     '%s/Cards/run_card.dat' % dir_name,
                     log=True)
            self.cmd.exec_cmd("set automatic_html_opening False --no-save")
            self.cmd.exec_cmd('launch -f')
        stop_mg5 = time.time()
        print 'MG5 Running time: %s s ' % (stop_mg5 - start1)

        #
        # Run MG Decay module
        #
        start4 = time.time()
        self.cmd.run_cmd("set automatic_html_opening False --no-save")
        self.cmd.exec_cmd('calculate_width %s 2' % particle)
        if self.cmd._curr_amps:
            self.cmd.exec_cmd('output %s_dec -f' % dir_name)
            files.cp(pjoin(_file_path, 'input_files/run_card_decay.dat'),
                     '%s_dec/Cards/run_card.dat' % dir_name,
                     log=True)
            print "279 launch"
            self.cmd.exec_cmd('launch -f')
        stop_mg5 = time.time()
        print 'DECAY Running time: %s s ' % (stop_mg5 - start4)

        #
        # RUN FR DECAY
        #
        if run_fr:
            me_cmd = me_interface.MadEventCmd(dir_name)
            self.cmd.define_child_cmd_interface(me_cmd, False)
            start3 = time.time()
            me_cmd.model_name = self.model
            me_cmd.run_cmd("set automatic_html_opening False --no-save")
            me_cmd.do_compute_widths(' %s -f --body_decay=2' % particle)
            stop_fr = time.time()
            print 'FR Running time: %s s ' % (stop_fr - start3)
            out1 = self.compare(
                pjoin(dir_name, 'Cards', 'param_card.dat'),
                pjoin(dir_name, 'Events', 'run_01', 'param_card.dat'), pid,
                'FR', 'MG5')
            out2 = self.compare(
                pjoin(dir_name, 'Cards', 'param_card.dat'),
                pjoin('%s_dec' % dir_name, 'Events', 'run_01',
                      'param_card.dat'), pid, 'FR', 'DECAY')
            me_cmd.do_quit('')

            if out1 == out2 == 'True':
                os.system('rm -rf %s >/dev/null' % dir_name)
                os.system('rm -rf %s_dec >/dev/null' % dir_name)

                return 'True'
            else:
                return out1 + out2
        else:
            return self.compare(
                pjoin(dir_name, 'Events', 'run_01', 'param_card.dat'),
                pjoin('%s_dec' % dir_name, 'Events', 'run_01',
                      'param_card.dat'), pid, 'MG5', 'DECAY')
Exemplo n.º 49
0
    def do_launch(self, line):
        """end of the configuration launched the code"""

        if self.options['ms_dir'] and os.path.exists(
                pjoin(self.options['ms_dir'], 'madspin.pkl')):
            return self.run_from_pickle()

        args = self.split_arg(line)
        self.check_launch(args)
        for part in self.list_branches.keys():
            if part in self.mg5cmd._multiparticles:
                if any(pid in self.final_state
                       for pid in self.mg5cmd._multiparticles[part]):
                    break
            pid = self.mg5cmd._curr_model.get('name2pdg')[part]
            if pid in self.final_state:
                break
        else:
            logger.info("Nothing to decay ...")
            return

        model_line = self.banner.get('proc_card', 'full_model_line')

        if not self.seed:
            import random
            self.seed = random.randint(0, int(30081 * 30081))
            self.do_set('seed %s' % self.seed)
            logger.info('Will use seed %s' % self.seed)
            self.history.insert(0, 'set seed %s' % self.seed)

        if self.seed > 30081 * 30081:  # can't use too big random number
            msg = 'Random seed too large ' + str(self.seed) + ' > 30081*30081'
            raise Exception, msg

        self.options['seed'] = self.seed
        text = '%s\n' % '\n'.join([line for line in self.history if line])
        self.banner.add_text('madspin', text)

        self.update_status('generating Madspin matrix element')
        generate_all = madspin.decay_all_events(self, self.banner,
                                                self.events_file, self.options)

        self.update_status('running MadSpin')
        generate_all.run()

        self.branching_ratio = generate_all.branching_ratio
        evt_path = self.events_file.name
        try:
            self.events_file.close()
        except:
            pass
        misc.call(['gzip -f %s' % evt_path], shell=True)
        decayed_evt_file = evt_path.replace('.lhe', '_decayed.lhe')
        shutil.move(pjoin(self.options['curr_dir'], 'decayed_events.lhe'),
                    decayed_evt_file)
        misc.call(['gzip -f %s' % decayed_evt_file], shell=True)
        if not self.mother:
            logger.info("Decayed events have been written in %s.gz" %
                        decayed_evt_file)

        # Now arxiv the shower card used if RunMaterial is present
        ms_card_path = pjoin(self.options['curr_dir'], 'Cards',
                             'madspin_card.dat')
        run_dir = os.path.realpath(os.path.dirname(decayed_evt_file))
        if os.path.exists(ms_card_path):
            if os.path.exists(pjoin(run_dir, 'RunMaterial.tar.gz')):
                misc.call(['tar', '-xzpf', 'RunMaterial.tar.gz'], cwd=run_dir)
                base_path = pjoin(run_dir, 'RunMaterial')
            else:
                base_path = pjoin(run_dir)

            evt_name = os.path.basename(decayed_evt_file).replace('.lhe', '')
            ms_card_to_copy = pjoin(base_path,
                                    'madspin_card_for_%s.dat' % evt_name)
            count = 0
            while os.path.exists(ms_card_to_copy):
                count += 1
                ms_card_to_copy = pjoin(base_path,'madspin_card_for_%s_%d.dat'%\
                                                               (evt_name,count))
            files.cp(str(ms_card_path), str(ms_card_to_copy))

            if os.path.exists(pjoin(run_dir, 'RunMaterial.tar.gz')):
                misc.call(
                    ['tar', '-czpf', 'RunMaterial.tar.gz', 'RunMaterial'],
                    cwd=run_dir)
                shutil.rmtree(pjoin(run_dir, 'RunMaterial'))
Exemplo n.º 50
0
    def check_compilation(self):
        """check that the model compile return correct output"""
        #Check the cleaning
        join = lambda p: os.path.join(self.output_path, p)
        self.assertFalse(os.path.exists(self.give_pos('testprog')))
        try:
            os.remove(join('../param_card.inc'))
        except:
            pass
        # prepare for a local compilation
        
        subprocess.call(['python','write_param_card.py'], cwd=os.path.join(MG5DIR,'models','sm'),
                        stdout=subprocess.PIPE)
        files.cp(os.path.join(MG5DIR,'models','sm','param_card.dat'),
                 join('param_card.dat'))
        
        text = file(join('makefile')).read().replace('../../Cards/param_card.dat','param_card.dat')
        open(join('makefile'),'w').write(text)
        #make ../param_card.inc 
        param_card = check_param_card.ParamCard(join('param_card.dat'))
        param_card.write_inc_file(join('../param_card.inc'), join('ident_card.dat'),
                                   join('param_card.dat'))
        
        subprocess.call(['make', 'testprog'], cwd=self.output_path,
                        stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        self.assertTrue(os.path.exists(self.give_pos('testprog')))
        
        os.chmod(os.path.join(self.output_path, 'testprog'), 0777)
        testprog = subprocess.Popen("./testprog", stdout=subprocess.PIPE,
                            cwd=self.output_path,
                            stderr=subprocess.STDOUT, shell=True)

        solutions = {'ymtau ': [1.7769999504089355], 'I4x33 ': [0.024123685681481218, 0.0], 'MTA ': [1.7769999504089355], 'GC_81 ': [0.0, 67.544], 'GC_5 ': [0.0, 0.094836], 'MZ ': [91.18800354003906], 'GC_27 ': [0.94484, 0.0], 'I1x33 ': [0.024123685681481218, 0.0], 'I3x33 ': [0.9448443987662922, 0.0], 'GC_95 ': [0.66811, 0.0], 'GC_60 ': [-0.37035, 0.0], 'ee__exp__2 ': [0.09483552005165403], 'aEWM1 ': [132.5070037841797], 'ytau ': [0.01020661671581679], 'GC_69 ': [-0.0, -175.45], 'GC_35 ': [-0.0, -0.42671], 'cw__exp__2 ': [0.7777535472599892], 'Gf ': [1.16639e-05], 'GC_59 ': [0.0, 0.08231], 'GC_21 ': [-0.94484, -0.0], 'ee ': [0.307953762847045], 'WZ ': [2.441404104232788], 'sw2 ': [0.22224645274001076], 'WT ': [1.5083359479904175], 'GC_80 ': [-0.0, -33.772], 'GC_57 ': [-0.0, -0.35482], 'sqrt__sw2 ': [0.4714302204356555], 'GC_67 ': [13.239, 0.0], 'GC_76 ': [-29.784, 0.0], 'GC_36 ': [0.0, 0.33188], 'GC_68 ': [-0.0, -58.485], 'GC_56 ': [0.10058, 0.0], 'sw__exp__2 ': [0.22224645274001076], 'GC_3 ': [-0.0, -0.30795], 'GC_54 ': [-0.10058, 0.0], 'WW ': [2.047600030899048], 'GC_70 ': [-26.266, 0.0], 'GC_66 ': [-13.239, 0.0], 'GC_38 ': [-0.0, -0.32662], 'GC_83 ': [-0.0, -0.017058], 'GC_77 ': [-16.545, 0.0], 'gw ': [0.653232969584471], 'MH ': [120.0], 'ymb ': [4.199999809265137], 'complexi ': [0.0, 1.0], 'GC_37 ': [-0.32662, 0.0], 'conjg__CKM1x1 ': [1.0], 'GC_2 ': [0.0, 0.2053], 'GC_51 ': [0.0, 0.28804], 'GC_71 ': [-0.0, -26.266], 'GC_39 ': [0.0, 0.32662], 'GC_82 ': [-0.017058, 0.0], 'GC_55 ': [-0.0, -0.10058], 'GC_78 ': [16.545, 0.0], 'GC_98 ': [-0.0072172, 0.0], 'GC_30 ': [-0.024124, -0.0], 'GC_15 ': [0.024124, 0.0], 'cw ': [0.881903366168873], 'yt ': [0.9448443987662922], 'sqrt__aEW ': [0.08687215260631942], 'vev ': [246.2184581018163], 'GC_79 ': [29.784, 0.0], 'GC_72 ': [0.0, 52.532], 'GC_1 ': [-0.0, -0.10265], 'conjg__CKM3x3 ': [1.0], 'GC_52 ': [-0.0, -0.57609], 'GC_100 ': [0.0, 0.46191], 'GC_65 ': [0.0, 0.27432], 'GC_12 ': [0.0, 1.4828], 'I2x33 ': [0.9448443987662922, 0.0], 'GC_94 ': [-0.0, -0.66811], 'sqrt__aS ': [0.3435112817874484], 'GC_31 ': [-0.0, -0.23753], 'aS ': [0.11800000071525575], 'MW__exp__2 ': [6467.21673128622], 'MZ__exp__4 ': [69143415.65084904], 'yb ': [0.024123685681481218], 'GC_99 ': [-0.0, -0.0072172], 'WH ': [0.0057530878111720085], 'GC_96 ': [-0.010207, 0.0], 'MH__exp__2 ': [14400.0], 'GC_63 ': [0.0, 0.12671], 'GC_53 ': [0.0, 0.57609], 'GC_73 ': [26.266, 0.0], 'GC_64 ': [0.0, 0.084653], 'sw ': [0.4714302204356555], 'GC_9 ': [0.053768, 0.0], 'GC_32 ': [-0.0, -0.47506], 'muH ': [84.8528137423857], 'GC_7 ': [-0.053768, 0.0], 'aEW ': [0.0075467708984556505], 'vev__exp__2 ': [60623.52911003587], 'MZ__exp__2 ': [8315.251989618177], 'GC_97 ': [0.010207, 0.0], 'GC_62 ': [0.0, 0.37035], 'GC_74 ': [-24.765, 0.0], 'g1 ': [0.34919218438279087], 'GC_10 ': [-1.2177, 0.0], 'GC_8 ': [0.0, 0.053768], 'CKM3x3 ': [1.0], 'MW ': [80.41900727617956], 'MT ': [172.0], 'GC_33 ': [-0.0, -0.71259], 'GC_6 ': [0.0, 0.18967], 'GC_4 ': [0.0, 0.30795], 'MB ': [4.699999809265137], 'GC_61 ': [0.0, -0.20573], 'ymt ': [164.5], 'GC_75 ': [24.765, 0.0], 'G__exp__2 ': [1.4828317414825511], 'lam ': [0.11876576810517753], 'GC_50 ': [-0.0, -0.28804], 'GC_34 ': [0.0, 0.21336], 'GC_11 ': [0.0, 1.2177], 'sqrt__2 ': [1.4142135623730951], 'GC_58 ': [-0.0, -0.027437]}
        nb_value = 0
        #solutions = {}
        for line in testprog.stdout:
            self.assertTrue('Warning' not in line)
            if '=' not in line:
                continue
            split = line.split('=')
            variable = split[0].lstrip()
            if ',' in line:
                value = eval(split[1])
            else:
                value=[float(numb) for numb in split[1].split()]
            nb_value +=1

            for i, singlevalue in enumerate(value):
                #try:
                    self.assertAlmostEqual(singlevalue,
                                           solutions[variable][i],
                                           places=7,
                        msg='fail to be equal for param %s : %s != %s' % \
                            (variable, singlevalue, solutions[variable][i]))
                #except Exception as error:
                #    print variable
                #    if i == 0:
                #        solutions[variable] = [singlevalue]
                #    else:
                #        solutions[variable].append(singlevalue)
        
        #print solutions
        self.assertEqual(nb_value, 116)
Exemplo n.º 51
0
    def runIOTests(self, update = False, force = 0, verbose=False, \
                                                       testKeys='instanceList'):
        """ Run the IOTests for this instance (defined in self.instance_tests)
            and compare the files of the chosen tests against the hardcoded ones
            stored in tests/input_files/IOTestsComparison. If you see
            an error in the comparison and you are sure that the newest output
            is correct (i.e. you understand that this modification is meant to
            be so). Then feel free to automatically regenerate this file with
            the newest version by doing 
            
              ./test_manager -i U folderName/testName/fileName
                
            If update is True (meant to be used by __main__ only) then
            it will create/update/remove the files instead of testing them.
            The argument tests can be a list of tuple-keys describing the tests
            to cover. Otherwise it is the instance_test list.
            The force argument must be 10 if you do not want to monitor the 
            modifications on the updated files. If it is 0 you will monitor
            all modified file and if 1 you will monitor each modified file of
            a given name only once.
        """
        # First make sure that the tarball need not be untarred
        # Extract the tarball for hardcoded in all cases to make sure the 
        # IOTestComparison folder is synchronized with it.
        if IOTestManager._compress_ref_fodler:
            if path.isdir(_hc_comparison_files):
                try:
                    shutil.rmtree(_hc_comparison_files)
                except IOError:
                    pass
            if path.isfile(_hc_comparison_tarball):
                tar = tarfile.open(_hc_comparison_tarball,mode='r:bz2')
                tar.extractall(path.dirname(_hc_comparison_files))
                tar.close()
            else:
                raise MadGraph5Error, \
              "Could not find the comparison tarball %s."%_hc_comparison_tarball
        else:
            if not path.isdir(_hc_comparison_files):
                raise MadGraph5Error, \
              "Could not find the comparison tarball %s."%_hc_comparison_tarball

        # In update = True mode, we keep track of the modification to 
        # provide summary information
        modifications={'updated':[],'created':[], 'removed':[], 'missing':[]}
        
        # List all the names of the files for which modifications have been
        # reviewed at least once.The approach taken here is different than
        # with the list refusedFolder and refusedTest.
        # The key of the dictionary are the filenames and the value are string
        # determining the user answer for that file.
        reviewed_file_names = {}
        
        # Chose what test to cover
        if testKeys == 'instanceList':
            testKeys = self.instance_tests
        
        if verbose: print "\n== "+colored%(32,"Operational mode")+\
            " : file %s ==\n"%(colored%(34,('UPDATE' if update else 'TESTING')))
        for (folder_name, test_name) in testKeys:
            try:
                (iotest, iotestManager) = self.all_tests[(folder_name, test_name)]
            except KeyError:
                raise MadGraph5Error, 'Test (%s,%s) could not be found.'\
                                                       %(folder_name, test_name)
            if verbose: print "Processing %s in %s"%(
                                colored%(32,test_name),colored%(34,folder_name))
            
            files_path = iotest.run(iotestManager)
            try:
                pass
#                files_path = iotest.run(iotestManager)
            except Exception as e: 
                iotest.clean_output()
                if not verbose:
                    raise e
                else:
                    print colored%(31,"  Test %s "%test_name+\
                              "crashed with the following error:\n  %s."%str(e))
                    continue

            # First create the list of files to check as the user might be using
            # regular expressions.
            filesToCheck=[]
            # Store here the files reckognized as veto rules (with filename
            # starting with '-')
            veto_rules = []
            for fname in iotest.testedFiles:
                # Disregard the veto rules
                regexp_finder = re.compile(
                r'^(?P<veto>-)?(?P<root_folder>.*)(\/)?\[(?P<regexp>.*)\]$')
                found = regexp_finder.search(fname)
                if not found is None:
                    # folder without the final /
                    base_path = pjoin(files_path,found.group('root_folder'))
                    regexp = re.compile(found.group('regexp'))
                    # In filesToCheck, we must remove the files_path/ prepended
                    for root, dirnames, filenames in os.walk(base_path):
                        for file in filenames:
                            if not regexp.search(str(os.path.relpath(
                                    pjoin(root,file),base_path))) is None and \
                                              not path.islink(pjoin(root,file)):
                                new_target = os.path.relpath(
                                                   pjoin(root,file),files_path)
                                if found.group('veto')=='-':
                                    veto_rules.append(new_target)
                                else:
                                    filesToCheck.append(new_target)
                else:
                    fn = fname[1:] if fname.startswith('-') else fname
                    if (not path.exists(pjoin(files_path,fn))) or path.islink(pjoin(files_path,fn)):
                        if force in [0,1]:
                            answer = Cmd.timed_input(question=
"""The IOTest %s does not create file '%s'. Fix it! [type 'enter'] >"""\
                                    %(test_name,fn),default="y")
                        modifications['missing'].append(
                        "%s/%s/%s"%(folder_name,test_name,path.basename(fname)))
                        if verbose: print "    > [ %s ] "%(colored%(31,"MISSING"))+\
                          "%s/%s/%s"%(folder_name,test_name,path.basename(fname))
                    else:
                        if fname.startswith('-'):
                            veto_rules.append(fn)
                        else:
                            filesToCheck.append(fn)

            # Apply the trimming of the veto rules
            filesToCheck = [f for f in filesToCheck if f not in veto_rules]

            if update:
                # Remove files which are no longer used for comparison
                activeFiles = [self.toFileName(f) for f in filesToCheck]
                for file in glob.glob(pjoin(_hc_comparison_files,folder_name,\
                                                                test_name,'*')):
                    # Ignore the .BackUp files and directories. Also ignore
                    # a file which was previously flagged missing because it
                    # was explicitly specified in the list of files that the
                    # test *must* provide.
                    if path.basename(file).endswith('.BackUp') or \
                       path.isdir(file) or \
                       pjoin(folder_name,test_name,path.basename(file)) in \
                                                       modifications['missing']:
                        continue
                    if path.basename(file) not in activeFiles:
                        if force==0 or (force==1 and \
                         path.basename(file) not in reviewed_file_names.keys()):
                            answer = Cmd.timed_input(question=
"""Obsolete ref. file %s in %s/%s detected, delete it? [y/n] >"""\
                                    %(path.basename(file),folder_name,test_name)
                                                                   ,default="y")
                            reviewed_file_names[path.basename(file)] = answer
                        elif (force==1 and \
                             path.basename(file) in reviewed_file_names.keys()):
                            answer = reviewed_file_names[path.basename(file)]
                        else:
                            answer = 'Y'
                            
                        if answer not in ['Y','y','']:
                            if verbose: 
                                print "    > [ %s ] "%(colored%(31,"IGNORED"))+\
                          "file deletion %s/%s/%s"%(folder_name,test_name,
                                                            path.basename(file))
                            continue

                        os.remove(file)
                        if verbose: print "    > [ %s ] "%(colored%(31,"REMOVED"))+\
                          "%s/%s/%s"%(folder_name,test_name,path.basename(file))
                        modifications['removed'].append(
                                            '/'.join(str(file).split('/')[-3:]))

                    
            # Make sure it is not filtered out by the user-filter
            if self.filesChecked_filter!=['ALL']:
                new_filesToCheck = []
                for file in filesToCheck:
                    # Try if it matches any filter
                    for filter in self.filesChecked_filter:
                        # A regular expression
                        if filter.endswith(']'):
                            split=filter[:-1].split('[')
                            # folder without the final /
                            folder=split[0][:-1]
                            if folder!=path.dirname(pjoin(file)):
                                continue
                            search = re.compile('['.join(split[1:]))
                            if not search.match(path.basename(file)) is None:
                                new_filesToCheck.append(file)
                                break    
                        # Just the exact filename
                        elif filter==file:
                            new_filesToCheck.append(file)
                            break
                filesToCheck = new_filesToCheck
            
            # Now we can scan them and process them one at a time
            # Keep track of the folders and testNames the user did not want to
            # create
            refused_Folders = []
            refused_testNames = []
            for fname in filesToCheck:
                file_path = path.abspath(pjoin(files_path,fname))
                self.assertTrue(path.isfile(file_path),
                                            'File %s not found.'%str(file_path))
                comparison_path = pjoin(_hc_comparison_files,\
                                    folder_name,test_name,self.toFileName(fname))
                if not update:
                    if not os.path.isfile(comparison_path):
                        iotest.clean_output()
                        if not verbose:
                            raise MadGraph5Error,\
                                "Missing ref. files for test %s\n"%test_name+\
                                "Create them with './test_manager.py -U %s'"%test_name
                            continue
                        else:
                            print colored%(31,'The ref. file %s'
                            %str('/'.join(comparison_path.split('/')[-3:]))+' does not exist.')
                            print colored%(34,'Consider creating it with '+
                                            './test_manager.py -U %s'%test_name)
                            exit(0)
                    goal = open(comparison_path).read()%misc.get_pkg_info()
                    if not verbose:
                        self.assertFileContains(open(file_path), goal)
                    else:
                        try:
                            self.assertFileContains(open(file_path), goal)
                        except AssertionError:
                            if verbose: 
                                print "    > %s differs from the reference."%fname
                            
                else:                        
                    if not path.isdir(pjoin(_hc_comparison_files,folder_name)):
                        if force==0:
                            if folder_name in refused_Folders:
                                continue
                            answer = Cmd.timed_input(question=
"""New folder %s detected, create it? [y/n] >"""%folder_name
                                                                   ,default="y")
                            if answer not in ['Y','y','']:
                                refused_Folders.append(folder_name)
                                if verbose: print "    > [ %s ] folder %s"\
                                           %(colored%(31,"IGNORED"),folder_name)
                                continue
                        if verbose: print "    > [ %s ] folder %s"%\
                                            (colored%(32,"CREATED"),folder_name)                        
                        os.makedirs(pjoin(_hc_comparison_files,folder_name))
                    if not path.isdir(pjoin(_hc_comparison_files,folder_name,
                                                                    test_name)):
                        if force==0:
                            if (folder_name,test_name) in refused_testNames:
                                continue
                            answer = Cmd.timed_input(question=
"""New test %s/%s detected, create it? [y/n] >"""%(folder_name,test_name)
                                                                   ,default="y")
                            if answer not in ['Y','y','']:
                                refused_testNames.append((folder_name,test_name))
                                if verbose: print "    > [ %s ] test %s/%s"\
                                 %(colored%(31,"IGNORED"),folder_name,test_name)
                                continue
                        if verbose: print "    > [ %s ] test %s/%s"\
                                 %(colored%(32,"CREATED"),folder_name,test_name)
                        os.makedirs(pjoin(_hc_comparison_files,folder_name,
                                                                    test_name))
                    # Transform the package information to make it a template
                    file = open(file_path,'r')
                    target=file.read()
                    # So that if % appear, we cast them to %% which are not formatted.
                    target = target.replace('%','%%')
                    # So that the version and date is automatically updated
                    target = target.replace('MadGraph5_aMC@NLO v. %(version)s, %(date)s'\
                                                           %misc.get_pkg_info(),
                                          'MadGraph5_aMC@NLO v. %(version)s, %(date)s')
                    target = target.replace('v%(version)s (%(date)s)'\
                                                           %misc.get_pkg_info(),
                                                      'v%(version)s (%(date)s)')
                    file.close()
                    if os.path.isfile(comparison_path):
                        file = open(comparison_path,'r')
                        existing = file.read()
                        file.close()
                        if existing == target:
                            continue
                        else:
                            # Copying the existing reference as a backup
                            tmp_path = pjoin(_hc_comparison_files,folder_name,\
                                        test_name,self.toFileName(fname)+'.BackUp')
                            if os.path.isfile(tmp_path):
                                os.remove(tmp_path)
                            file = open(tmp_path,'w')
                            file.write(target)
                            file.close()
                            if force==0 or (force==1 and path.basename(\
                            comparison_path) not in reviewed_file_names.keys()):
                                text = \
"""File %s in test %s/%s differs by the following (reference file first):
"""%(fname,folder_name,test_name)
                                text += misc.Popen(['diff',str(comparison_path),
                                  str(tmp_path)],stdout=subprocess.PIPE).\
                                                                communicate()[0]
                                # Remove the last newline
                                if text[-1]=='\n':
                                    text=text[:-1]
                                if (len(text.split('\n'))<15):
                                    print text
                                else:
                                    pydoc.pager(text)
                                    print "Difference displayed in editor."
                                answer = ''
                                while answer not in ['y', 'n']:
                                    answer = Cmd.timed_input(question=
"""Ref. file %s differs from the new one (see diff. before), update it? [y/n/h/r] >"""%fname
                                                                   ,default="y")
                                    if answer not in ['y','n']:
                                        if answer == 'r':
                                            pydoc.pager(text)
                                        else:
                                            print "reference path: %s" % comparison_path
                                            print "code returns: %s" % tmp_path
                                
                                
                                os.remove(tmp_path)
                                reviewed_file_names[path.basename(\
                                                      comparison_path)] = answer        
                            elif (force==1 and path.basename(\
                                comparison_path) in reviewed_file_names.keys()):
                                answer = reviewed_file_names[path.basename(\
                                                               comparison_path)]
                            else:
                                answer = 'Y'
                            if answer not in ['Y','y','']:
                                if verbose: print "    > [ %s ] %s"%\
                                                  (colored%(31,"IGNORED"),fname)
                                continue
                            
                            # Copying the existing reference as a backup
                            back_up_path = pjoin(_hc_comparison_files,folder_name,\
                                         test_name,self.toFileName(fname)+'.BackUp')
                            if os.path.isfile(back_up_path):
                                os.remove(back_up_path)
                            cp(comparison_path,back_up_path)
                            if verbose: print "    > [ %s ] %s"\
                                                 %(colored%(32,"UPDATED"),fname)
                            modifications['updated'].append(
                                      '/'.join(comparison_path.split('/')[-3:]))
                    else:
                        if force==0 or (force==1 and path.basename(\
                            comparison_path) not in reviewed_file_names.keys()):
                            answer = Cmd.timed_input(question=
"""New file %s detected, create it? [y/n] >"""%fname
                                                                   ,default="y")
                            reviewed_file_names[path.basename(\
                                                      comparison_path)] = answer
                        elif (force==1 and path.basename(\
                                comparison_path) in reviewed_file_names.keys()):
                            answer = reviewed_file_names[\
                                                 path.basename(comparison_path)]
                        else:
                            answer = 'Y'
                        if answer not in ['Y','y','']:
                            if verbose: print "    > [ %s ] %s"%\
                                                  (colored%(31,"IGNORED"),fname)
                            continue
                        if verbose: print "    > [ %s ] %s"%\
                                                  (colored%(32,"CREATED"),fname)
                        modifications['created'].append(
                                      '/'.join(comparison_path.split('/')[-3:]))
                    file = open(comparison_path,'w')
                    file.write(target)
                    file.close()

            # Clean the iotest output
            iotest.clean_output()

        # Monitor the modifications when in creation files mode by returning the
        # modifications dictionary.
        if update:
            return modifications
        else:
            return 'test_over'
Exemplo n.º 52
0
    def setUp(self):
        """ """

        if os.path.exists("/tmp/edit_card"):
            os.system("rm -rf /tmp/edit_card")
        os.system("mkdir /tmp/edit_card;mkdir /tmp/edit_card/Cards;")
        template_path = pjoin(root_path, "..", "Template")
        card = "param_card"
        files.cp(pjoin(root_path, "input_files/restrict_sm.dat"), "/tmp/edit_card/Cards/%s.dat" % card)
        files.cp(pjoin(root_path, "input_files/restrict_sm.dat"), "/tmp/edit_card/Cards/%s_default.dat" % card)

        card = "run_card"
        files.cp(pjoin(template_path, "LO/Cards/%s.dat" % card), "/tmp/edit_card/Cards")
        files.cp(pjoin(template_path, "LO/Cards/%s.dat" % card), "/tmp/edit_card/Cards/%s_default.dat" % card)
        card = "MadWeight_card"
        files.cp(pjoin(template_path, "MadWeight/Cards/%s.dat" % card), "/tmp/edit_card/Cards")
        files.cp(pjoin(template_path, "MadWeight/Cards/%s.dat" % card), "/tmp/edit_card/Cards/%s_default.dat" % card)

        fakemother = FakeInterface("/tmp/edit_card/")
        self.cmd = runcmd.AskforEditCard(
            "", cards=["run_card.dat", "param_card.dat", "madweight_card.dat"], mode="auto", mother_interface=fakemother
        )