def test_mssm_equivalence(self): """Test the UFO and MG4 MSSM model correspond to the same model """ # import UFO model sm_path = import_ufo.find_ufo_path('mssm') ufo_model = import_ufo.import_model(sm_path) #converter = import_ufo.UFOMG5Converter(model) #ufo_model = converter.load_model() ufo_model.pass_particles_name_in_mg_default() # import MG4 model model = base_objects.Model() if not MG4DIR: raise MadGraph5Error, "Please provide a valid MG/ME path with -d" v4_path = os.path.join(MG4DIR, 'models', 'mssm_v4') if not os.path.isdir(v4_path): v4_path = os.path.join(MG4DIR, 'Models', 'mssm') if not os.path.isdir(v4_path): raise MadGraph5Error, \ "Please provide a valid MG/ME path with -d" model.set('particles', files.read_from_file( os.path.join(v4_path,'particles.dat'), import_v4.read_particles_v4)) model.set('interactions', files.read_from_file( os.path.join(v4_path,'interactions.dat'), import_v4.read_interactions_v4, model['particles'])) model.pass_particles_name_in_mg_default() # Checking the particles for particle in model['particles']: ufo_particle = ufo_model.get("particle_dict")[particle['pdg_code']] self.check_particles(particle, ufo_particle) # Skip test below until equivalence has been created by Benj and Claude return # Checking the interactions nb_vertex = 0 ufo_vertices = [] for ufo_vertex in ufo_model['interactions']: pdg_code_ufo = [abs(part['pdg_code']) for part in ufo_vertex['particles']] int_name = [part['name'] for part in ufo_vertex['particles']] rep = (pdg_code_ufo, int_name) pdg_code_ufo.sort() ufo_vertices.append(pdg_code_ufo) mg4_vertices = [] for vertex in model['interactions']: pdg_code_mg4 = [abs(part['pdg_code']) for part in vertex['particles']] pdg_code_mg4.sort() try: ufo_vertices.remove(pdg_code_mg4) except ValueError: mg4_vertices.append(pdg_code_mg4) self.assertEqual(ufo_vertices, []) self.assertEqual(mg4_vertices, [])
def test_mssm_equivalence(self): """Test the UFO and MG4 MSSM model correspond to the same model """ # import UFO model mssm_path = import_ufo.find_ufo_path('MSSM_SLHA2') ufo_model = import_ufo.import_model(mssm_path) #converter = import_ufo.UFOMG5Converter(model) #ufo_model = converter.load_model() ufo_model.pass_particles_name_in_mg_default() # import MG4 model model = base_objects.Model() if not MG4DIR: raise MadGraph5Error("Please provide a valid MG/ME path with -d") v4_path = os.path.join(MG4DIR, 'models', 'mssm_v4') if not os.path.isdir(v4_path): import_ufo.import_model_from_db('mssm_v4', local_dir=True) model.set('particles', files.read_from_file( os.path.join(v4_path,'particles.dat'), import_v4.read_particles_v4)) model.set('interactions', files.read_from_file( os.path.join(v4_path,'interactions.dat'), import_v4.read_interactions_v4, model['particles'])) #model.pass_particles_name_in_mg_default() # Checking the particles for particle in model['particles']: ufo_particle = ufo_model.get("particle_dict")[particle['pdg_code']] self.check_particles(particle, ufo_particle) # Skip test below until equivalence has been created by Benj and Claude return # Checking the interactions nb_vertex = 0 ufo_vertices = [] for ufo_vertex in ufo_model['interactions']: pdg_code_ufo = [abs(part['pdg_code']) for part in ufo_vertex['particles']] int_name = [part['name'] for part in ufo_vertex['particles']] rep = (pdg_code_ufo, int_name) pdg_code_ufo.sort() ufo_vertices.append(pdg_code_ufo) mg4_vertices = [] for vertex in model['interactions']: pdg_code_mg4 = [abs(part['pdg_code']) for part in vertex['particles']] pdg_code_mg4.sort() try: ufo_vertices.remove(pdg_code_mg4) except ValueError: mg4_vertices.append(pdg_code_mg4) self.assertEqual(ufo_vertices, []) self.assertEqual(mg4_vertices, [])
def test_sm_equivalence(self): """Test the UFO and MG4 SM model correspond to the same model """ # import UFO model sm_path = import_ufo.find_ufo_path('sm') ufo_model = import_ufo.import_model(sm_path) ufo_model.pass_particles_name_in_mg_default() # import MG4 model model = base_objects.Model() v4_path = os.path.join(MG4DIR, 'models', 'sm_v4') if not os.path.isdir(v4_path): v4_path = os.path.join(MG4DIR, 'Models', 'sm') if not os.path.isdir(v4_path): raise MadGraph5Error, \ "Please provide a valid MG/ME path with -d" model.set( 'particles', files.read_from_file(os.path.join(v4_path, 'particles.dat'), import_v4.read_particles_v4)) model.set( 'interactions', files.read_from_file(os.path.join(v4_path, 'interactions.dat'), import_v4.read_interactions_v4, model['particles'])) model.pass_particles_name_in_mg_default() # Checking the particles for particle in model['particles']: ufo_particle = ufo_model.get("particle_dict")[particle['pdg_code']] self.check_particles(particle, ufo_particle) # Checking the interactions nb_vertex = 0 ufo_vertices = [] for ufo_vertex in ufo_model['interactions']: pdg_code_ufo = [ abs(part['pdg_code']) for part in ufo_vertex['particles'] ] int_name = [part['name'] for part in ufo_vertex['particles']] rep = (pdg_code_ufo, int_name) pdg_code_ufo.sort() ufo_vertices.append(pdg_code_ufo) mg4_vertices = [] for vertex in model['interactions']: pdg_code_mg4 = [ abs(part['pdg_code']) for part in vertex['particles'] ] pdg_code_mg4.sort() try: ufo_vertices.remove(pdg_code_mg4) except ValueError: mg4_vertices.append(pdg_code_mg4) self.assertEqual(ufo_vertices, [[25, 25, 25, 25]]) self.assertEqual(mg4_vertices, [])
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 load_from_file(filename): """Save any Python object to file filename""" if not isinstance(filename, str): raise SaveObjectError, "filename must be a string" return files.read_from_file(filename, unpickle_object)
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 setUp(self): """ open the proc_card and initialize the object""" v4proccard_file = open(os.path.join(_file_path, os.path.pardir, 'input_files', \ 'v4_proc_card.dat')) self.proccard = import_v4.ProcCardv4Reader(v4proccard_file) # First define a valid model for Standard Model model = base_objects.Model() # Import Particles information input_path = os.path.join(_file_path, '../input_files/v4_sm_particles.dat') model.set('particles', files.read_from_file(input_path, import_v4.read_particles_v4)) # Import Interaction information input_path = os.path.join(_file_path , '../input_files/v4_sm_interactions.dat') model.set('interactions', files.read_from_file(input_path, \ import_v4.read_interactions_v4, \ model.get('particles'))) self.model = model
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
def get_pkg_info(info_str=None): """Returns the current version information of the MadGraph package, as written in the VERSION text file. If the file cannot be found, a dictionary with empty values is returned. As an option, an info string can be passed to be read instead of the file content. """ if info_str is None: info_dict = files.read_from_file(os.path.join(madgraph.__path__[0], "VERSION"), parse_info_str) else: info_dict = parse_info_str(StringIO.StringIO(info_str)) return info_dict
def get_pkg_info(info_str=None): """Returns the current version information of the MadGraph5_aMC@NLO package, as written in the VERSION text file. If the file cannot be found, a dictionary with empty values is returned. As an option, an info string can be passed to be read instead of the file content. """ if info_str is None: info_dict = files.read_from_file(os.path.join(madgraph.__path__[0], "VERSION"), parse_info_str, print_error=False) else: info_dict = parse_info_str(StringIO.StringIO(info_str)) return info_dict
import madgraph.core.base_objects as base_objects import madgraph.core.drawing as drawing import tests.unit_tests.core.test_drawing as test_drawing import madgraph.iolibs.drawing_eps as draw_eps import madgraph.iolibs.import_v4 as import_v4 import madgraph.iolibs.files as files import madgraph.various.misc as misc import tests.unit_tests as unittest _file_path = os.path.split(os.path.dirname(os.path.realpath(__file__)))[0] # First define a valid model for Standard Model _model = base_objects.Model() # Import Particles information _input_path = os.path.join(_file_path, '../input_files/v4_sm_particles.dat') _model.set('particles', files.read_from_file(_input_path, import_v4.read_particles_v4)) # Import Interaction information _input_path = os.path.join(_file_path , '../input_files/v4_sm_interactions.dat') _model.set('interactions', files.read_from_file(_input_path, \ import_v4.read_interactions_v4, \ _model.get('particles'))) #=============================================================================== # TestDrawingEPS #=============================================================================== class TestDrawingOption(unittest.TestCase): """Sanity check for all combination of option. This check on a small sample of diagram that no line have zero lenght and that we don't have any line crossing for any combination of option."""
(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: