def test_parse_info_str_correct(self): "Test parse_info_str converts info strings to dictionaries" mystr = "param1 = value1\n param2=value 2\n \n" rightdict = {'param1':'value1', 'param2':'value 2'} self.assertEqual(rightdict, misc.get_pkg_info(mystr))
def get_mg5_info_lines(self): """Return info lines for MG5, suitable to place at beginning of Python files""" info = misc.get_pkg_info() info_lines = "" if info and info.has_key('version') and info.has_key('date'): info_lines = "# MadGraph 5 v. %s, %s\n" % \ (info['version'], info['date']) info_lines = info_lines + \ " # By the MadGraph Development Team\n" + \ " # Please visit us at https://launchpad.net/madgraph5" else: info_lines = " # by MadGraph 5\n" + \ " # By the MadGraph Development Team\n" + \ " # Please visit us at https://launchpad.net/madgraph5" return info_lines
def test_get_python_matrix_methods(self): """Test getting the matrix methods for Python for a matrix element.""" goal_method = (\ """class Matrix_0_uux_uux(object): def __init__(self): \"\"\"define the object\"\"\" self.clean() def clean(self): self.jamp = [] def smatrix(self,p, model): # # MadGraph 5 v. %(version)s, %(date)s # By the MadGraph Development Team # Please visit us at https://launchpad.net/madgraph5 # # MadGraph StandAlone Version # # Returns amplitude squared summed/avg over colors # and helicities # for the point in phase space P(0:3,NEXTERNAL) # # Process: u u~ > u u~ # Process: c c~ > c c~ # # Clean additional output # self.clean() # # CONSTANTS # nexternal = 4 ndiags = 4 ncomb = 16 # # LOCAL VARIABLES # helicities = [ \\ [-1,-1,-1,-1], [-1,-1,-1,1], [-1,-1,1,-1], [-1,-1,1,1], [-1,1,-1,-1], [-1,1,-1,1], [-1,1,1,-1], [-1,1,1,1], [1,-1,-1,-1], [1,-1,-1,1], [1,-1,1,-1], [1,-1,1,1], [1,1,-1,-1], [1,1,-1,1], [1,1,1,-1], [1,1,1,1]] denominator = 36 # ---------- # BEGIN CODE # ---------- self.amp2 = [0.] * ndiags ans = 0. for hel in helicities: t = self.matrix(p, hel, model) ans = ans + t ans = ans / denominator return ans.real def matrix(self, p, hel, model): # # MadGraph 5 v. %(version)s, %(date)s # By the MadGraph Development Team # Please visit us at https://launchpad.net/madgraph5 # # Returns amplitude squared summed/avg over colors # for the point with external lines W(0:6,NEXTERNAL) # # Process: u u~ > u u~ # Process: c c~ > c c~ # # # Process parameters # ngraphs = 4 nexternal = 4 nwavefuncs = 8 ncolor = 2 ZERO = 0. # # Color matrix # denom = [1,1]; cf = [[9,3], [3,9]]; # # Model parameters # WZ = model.get('parameter_dict')["WZ"] MZ = model.get('parameter_dict')["MZ"] GC_47 = model.get('coupling_dict')["GC_47"] GC_35 = model.get('coupling_dict')["GC_35"] GC_10 = model.get('coupling_dict')["GC_10"] # ---------- # Begin code # ---------- amp = [None] * ngraphs w = [None] * nwavefuncs w[0] = ixxxxx(p[0],ZERO,hel[0],+1) w[1] = oxxxxx(p[1],ZERO,hel[1],-1) w[2] = oxxxxx(p[2],ZERO,hel[2],+1) w[3] = ixxxxx(p[3],ZERO,hel[3],-1) w[4] = FFV1_3(w[0],w[1],GC_10,ZERO, ZERO) # Amplitude(s) for diagram number 1 amp[0] = FFV1_0(w[3],w[2],w[4],GC_10) w[5] = FFV2_5_3(w[0],w[1],GC_35,GC_47,MZ, WZ) # Amplitude(s) for diagram number 2 amp[1] = FFV2_5_0(w[3],w[2],w[5],GC_35,GC_47) w[6] = FFV1_3(w[0],w[2],GC_10,ZERO, ZERO) # Amplitude(s) for diagram number 3 amp[2] = FFV1_0(w[3],w[1],w[6],GC_10) w[7] = FFV2_5_3(w[0],w[2],GC_35,GC_47,MZ, WZ) # Amplitude(s) for diagram number 4 amp[3] = FFV2_5_0(w[3],w[1],w[7],GC_35,GC_47) jamp = [None] * ncolor jamp[0] = +1./6.*amp[0]-amp[1]+1./2.*amp[2] jamp[1] = -1./2.*amp[0]-1./6.*amp[2]+amp[3] self.amp2[0]+=abs(amp[0]*amp[0].conjugate()) self.amp2[1]+=abs(amp[1]*amp[1].conjugate()) self.amp2[2]+=abs(amp[2]*amp[2].conjugate()) self.amp2[3]+=abs(amp[3]*amp[3].conjugate()) matrix = 0. for i in range(ncolor): ztemp = 0 for j in range(ncolor): ztemp = ztemp + cf[i][j]*jamp[j] matrix = matrix + ztemp * jamp[i].conjugate()/denom[i] self.jamp.append(jamp) return matrix """ % misc.get_pkg_info()).split('\n') exporter = export_python.ProcessExporterPython(self.mymatrixelement, self.mypythonmodel) matrix_methods = exporter.get_python_matrix_methods()["0_uux_uux"].\ split('\n') self.assertEqual(matrix_methods, goal_method)
def import_full_model(model_path): """ a practical and efficient way to import one of those models (no restriction file use)""" assert model_path == find_ufo_path(model_path) # Check the validity of the model files_list_prov = ['couplings.py','lorentz.py','parameters.py', 'particles.py', 'vertices.py'] files_list = [] for filename in files_list_prov: filepath = os.path.join(model_path, filename) if not os.path.isfile(filepath): raise UFOImportError, "%s directory is not a valid UFO model: \n %s is missing" % \ (model_path, filename) files_list.append(filepath) # use pickle files if defined and up-to-date if files.is_uptodate(os.path.join(model_path, 'model.pkl'), files_list): try: model = save_load_object.load_from_file( \ os.path.join(model_path, 'model.pkl')) except Exception, error: logger.info('failed to load model from pickle file. Try importing UFO from File') else: # check path is correct if model.has_key('version_tag') and model.get('version_tag') == os.path.realpath(model_path) + str(misc.get_pkg_info()): _import_once.append(model_path) return model
# check path is correct if model.has_key('version_tag') and model.get('version_tag') == os.path.realpath(model_path) + str(misc.get_pkg_info()): _import_once.append(model_path) return model if model_path in _import_once: raise MadGraph5Error, 'This model is modified on disk. To reload it you need to quit/relaunch mg5' # Load basic information 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
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 MadGraph5Error, "%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