Beispiel #1
0
    def dump_ME7(self, all_MEAccessors, all_integrands):
        """ Dumps all necessary information in order to bootstrap the ME7 interface.
        It is mostly all contained in all_MEAccessors and all_integrands."""

        # Simply retrieve this information from one process of the first contribution.
        n_initial = self.contributions[0].get_processes_map().values(
        )[0][0].get_ninitial()

        # For now the db is a rude pickle file, but we might improve this to an actual DB eventually
        integrand_dumps = [
            integrand.generate_dump() for integrand in all_integrands
        ]
        import madgraph
        for itg_dump in integrand_dumps:
            itg_dump[
                'class'] = 'madgraph.integrator.ME7Integrands.ME7_integrands.ME7CythonIntegrand_B'
        ME7_dump = {
            'all_MEAccessors':
            all_MEAccessors.generate_dump(),
            'all_integrands':
            [integrand.generate_dump() for integrand in all_integrands],
            #            'all_integrands'  : integrand_dumps,
            'model_name':
            'ME7_UFO_model_%s' % self.model.get('name'),
            'model_with_CMS':
            self.options['complex_mass_scheme'],
            'n_initial':
            n_initial,
            'subtraction_scheme':
            self.options['subtraction_scheme']
        }

        save_load_object.save_to_file(pjoin(self.export_dir, 'MadEvent7.db'),
                                      ME7_dump)
Beispiel #2
0
    def store_comparison(pickle_path, proc_list, model, name,
                         orders={}, energy=1000):
        """Store a comparison corresponding to the parameters given."""

        new_runner = PickleRunner()
        new_runner.proc_list = proc_list[0]
        new_runner.res_list = proc_list[1]
        new_runner.model = model
        new_runner.name = "Stored " + name
        new_runner.orders = orders
        new_runner.energy = energy

        save_load_object.save_to_file(pickle_path, new_runner)

        logging.info("Stored comparison object in %s" % pickle_path)
    def store_comparison(pickle_path, proc_list, model, name,
                         orders={}, energy=1000):
        """Store a comparison corresponding to the parameters given."""

        new_runner = PickleRunner()
        new_runner.proc_list = proc_list[0]
        new_runner.res_list = proc_list[1]
        new_runner.model = model
        new_runner.name = "Stored " + name
        new_runner.orders = orders
        new_runner.energy = energy

        save_load_object.save_to_file(pickle_path, new_runner)

        logging.info("Stored comparison object in %s" % pickle_path)
Beispiel #4
0
def import_model(model_path, mgme_dir=MG4DIR, absolute=True):
    """create a model from a MG4 model directory."""

    # Check for a valid directory
    model_path_old = model_path
    model_path = find_model_path(model_path, mgme_dir, absolute)

    files_list = [os.path.join(model_path, 'particles.dat'),\
                  os.path.join(model_path, 'interactions.dat')]

    for filepath in files_list:
        if not os.path.isfile(filepath):
            if not absolute:
                raise InvalidCmd,  "%s directory is not a valid v4 model" % \
                                                                    (model_path)
            else:
                return import_model(model_path_old, mgme_dir, False)

    # use pickle files if defined
    if files.is_uptodate(os.path.join(model_path, 'model.pkl'), files_list):
        model = save_load_object.load_from_file( \
                                          os.path.join(model_path, 'model.pkl'))
        if model.has_key('version_tag') and model.get(
                'version_tag') == os.path.realpath(model_path) + str(
                    misc.get_pkg_info()):
            return model, model_path

    model = base_objects.Model()
    model.set('particles',files.read_from_file( \
                                  os.path.join(model_path, 'particles.dat'),
                                  read_particles_v4))

    model.set('interactions',files.read_from_file( \
                                  os.path.join(model_path, 'interactions.dat'),
                                  read_interactions_v4,
                                  model['particles']))

    model.set('name', os.path.split(model_path)[-1])

    # save in a pickle files to fasten future usage
    if ReadWrite:
        try:
            save_load_object.save_to_file(
                os.path.join(model_path, 'model.pkl'), model)
        except Exception:
            logger.warning("fail to write %s. This is perfectly fine will just prevent speed boost in future load of this model" %\
                           os.path.join(model_path, 'model.pkl'))
    return model, model_path
def import_model(model_path, mgme_dir = MG4DIR, absolute=True):
    """create a model from a MG4 model directory."""

    # Check for a valid directory
    model_path_old = model_path
    model_path = find_model_path(model_path, mgme_dir, absolute)

    files_list = [os.path.join(model_path, 'particles.dat'),\
                  os.path.join(model_path, 'interactions.dat')]
    
    for filepath in files_list:
        if not os.path.isfile(filepath):
            if not absolute:
                raise InvalidCmd,  "%s directory is not a valid v4 model" % \
                                                                    (model_path)
            else:
                return import_model(model_path_old, mgme_dir, False)
                                                                
    # use pickle files if defined
    if files.is_uptodate(os.path.join(model_path, 'model.pkl'), files_list):
        model = save_load_object.load_from_file( \
                                          os.path.join(model_path, 'model.pkl'))
        if model.has_key('version_tag') and model.get('version_tag') == os.path.realpath(model_path) + str(misc.get_pkg_info()):
            return model, model_path

    model = base_objects.Model()    
    model.set('particles',files.read_from_file( \
                                  os.path.join(model_path, 'particles.dat'),
                                  read_particles_v4))
    
    model.set('interactions',files.read_from_file( \
                                  os.path.join(model_path, 'interactions.dat'),
                                  read_interactions_v4,
                                  model['particles']))
    
    model.set('name', os.path.split(model_path)[-1])  

    # save in a pickle files to fasten future usage
    if ReadWrite:
        try:
            save_load_object.save_to_file(os.path.join(model_path, 'model.pkl'), model)
        except Exception:
            logger.warning("fail to write %s. This is perfectly fine will just prevent speed boost in future load of this model" %\
                           os.path.join(model_path, 'model.pkl'))
    return model, model_path  
Beispiel #6
0
def import_model(model_path, mgme_dir = MG4DIR):
    """create a model from a MG4 model directory."""

    # Check for a valid directory
    model_path = find_model_path(model_path, mgme_dir)

    files_list = [os.path.join(model_path, 'particles.dat'),\
                  os.path.join(model_path, 'interactions.dat')]
    
    for filepath in files_list:
        if not os.path.isfile(filepath):
            raise InvalidCmd,  "%s directory is not a valid v4 model" % \
                                                                    (model_path)
                                                                
    # use pickle files if defined
    if files.is_uptodate(os.path.join(model_path, 'model.pkl'), files_list):
        model = save_load_object.load_from_file( \
                                          os.path.join(model_path, 'model.pkl'))
        if model.has_key('version_tag') and model.get('version_tag') == os.path.realpath(model_path) + str(misc.get_pkg_info()):
            return model, model_path

    model = base_objects.Model()    
    model.set('particles',files.read_from_file( \
                                  os.path.join(model_path, 'particles.dat'),
                                  read_particles_v4))
    
    model.set('interactions',files.read_from_file( \
                                  os.path.join(model_path, 'interactions.dat'),
                                  read_interactions_v4,
                                  model['particles']))
    
    model.set('name', os.path.split(model_path)[-1])  

    # save in a pickle files to fasten future usage
    save_load_object.save_to_file(os.path.join(model_path, 'model.pkl'), model)
    
    return model, model_path  
Beispiel #7
0
    ufo_model = ufomodels.load_model(model_path)
    ufo2mg5_converter = UFOMG5Converter(ufo_model)
    model = ufo2mg5_converter.load_model()
    
    if model_path[-1] == '/': model_path = model_path[:-1] #avoid empty name
    model.set('name', os.path.split(model_path)[-1])
    model.set('version_tag', os.path.realpath(model_path) + str(misc.get_pkg_info()))

    # Load the Parameter/Coupling in a convinient format.
    parameters, couplings = OrganizeModelExpression(ufo_model).main()
    model.set('parameters', parameters)
    model.set('couplings', couplings)
    model.set('functions', ufo_model.all_functions)
    
    # save in a pickle files to fasten future usage
    save_load_object.save_to_file(os.path.join(model_path, 'model.pkl'), model) 
 
    #if default and os.path.exists(os.path.join(model_path, 'restrict_default.dat')):
    #    restrict_file = os.path.join(model_path, 'restrict_default.dat') 
    #    model = import_ufo.RestrictModel(model)
    #    model.restrict_model(restrict_file)
    return model
    

class UFOMG5Converter(object):
    """Convert a UFO model to the MG5 format"""

    use_lower_part_names = False

    def __init__(self, model, auto=False):
        """ initialize empty list for particles/interactions """
Beispiel #8
0
    model = base_objects.Model()
    model.set('particles',files.read_from_file( \
                                  os.path.join(model_path, 'particles.dat'),
                                  read_particles_v4))

    model.set('interactions',files.read_from_file( \
                                  os.path.join(model_path, 'interactions.dat'),
                                  read_interactions_v4,
                                  model['particles']))

    model.set('name', os.path.split(model_path)[-1])

    # save in a pickle files to fasten future usage
    if ReadWrite:
        try:
            save_load_object.save_to_file(
                os.path.join(model_path, 'model.pkl'), model)
        except Exception:
            logger.warning("fail to write %s. This is perfectly fine will just prevent speed boost in future load of this model" %\
                           os.path.join(model_path, 'model.pkl'))
    return model, model_path


def find_model_path(model_path, mgme_dir, absolute=True):
    """Find the path to the model, starting with path model_path."""

    # treat simple case (model_path is a valid path/ mgme_dir doesn't exist)
    if os.path.isdir(model_path) and absolute:
        return model_path
    elif mgme_dir and os.path.isdir(
            os.path.join(mgme_dir, 'models', model_path + "_v4")):
        model_path = os.path.join(mgme_dir, 'models', model_path + "_v4")