| 56 | | |
| 57 | | |
| | 56 | == create new output mode |
| | 57 | |
| | 58 | === Base class which can be use to create a new exporter from scratch: |
| | 59 | |
| | 60 | At the beginning of madgraph/various/iolibs/export_v4.py. |
| | 61 | A virtual class "VirtualExporter" is defined all exporter class should derive from that class. |
| | 62 | That virtual class list all the functions called by the interface that you can define (that class in itself does nothing) |
| | 63 | and list all the common attribute that need to be defined with the explanation of their impact. |
| | 64 | |
| | 65 | In Most of the case, it is more convenient to subclass one of the class creating a real output like ProcessExporterFortran. |
| | 66 | |
| | 67 | |
| | 68 | === List of function that need to be defined in the exporter For Fortran/CPP output: |
| | 69 | |
| | 70 | This list correspond to the call to the exporter performed outside the class itself. Please check the VirtualExporter class (begin of madgraph/various/iolibs/export_v4.py) to check that the following list is up-to-date with your version of MG5aMC. |
| | 71 | |
| | 72 | 1. __init__(self, dir_path = "", opt=None) |
| | 73 | 2. copy_template(self, modelname) |
| | 74 | 3. generate_subprocess_directory(self, subproc_group, helicity_model, me=None) [for grouped] |
| | 75 | 4. generate_subprocess_directory(self, matrix_element, helicity_model, me_number) [for ungrouped] |
| | 76 | 4. convert_model(model, wanted_lorentz=[], wanted_coupling=[]) |
| | 77 | 5. finalize(self,matrix_element, cmdhistory, MG5options, outputflag) |
| | 78 | 6. modify_grouping(self, matrix_element) |
| | 79 | 7. export_model_files(self, model_v4_path) [only if you want to support old model format] |
| | 80 | 8. export_helas(self, HELAS_PATH) [only if you want to support old model format] |
| | 81 | |
| | 82 | |
| | 83 | === List of class variable that need to be defined in the exporter: |
| | 84 | |
| | 85 | This list correspond to the attribute of the exporter called outside the exporter class. Please check the VirtualExporter class (begin of madgraph/various/iolibs/export_v4.py) to check that the following list is up-to-date with your version of MG5aMC. |
| | 86 | |
| | 87 | 1. '''grouped_mode''' This variable changes the type of object called within 'generate_subprocess_directory' functions. |
| | 88 | a. '''False''' to avoid grouping (only identical matrix element are merged) |
| | 89 | b. ''' 'madevent' ''' group the massless quark and massless lepton |
| | 90 | c. ''' 'madweight' ''' group the gluon with the massless quark |
| | 91 | 2. '''sa_symmetry''' If no grouped_mode=False, uu~ and u~u will be called independently. Putting sa_symmetry generates only one of the two matrix-element. (might not work for cpp output. |
| | 92 | 3. '''check''' Ask madgraph to check if the directory already exists and propose to the user to remove it first if this is the case |
| | 93 | 4. '''output''' [Template, None, dir] |
| | 94 | a. ''''Template'''', madgraph will call copy_template |
| | 95 | b. ''''dir'''', madgraph will just create an empty directory for initialisation |
| | 96 | c. '''None''', madgraph do nothing for initialisation |
| | 97 | 5. '''exporter''' ['v4'/'cpp'] language of the output 'v4' for Fortran output, 'cpp' for C++ output |
| | 98 | |
| | 99 | |
| | 100 | |
| | 101 | = Example |
| 268 | | === List of function that need to be defined in the exporter For Fortran/CPP output: |
| 269 | | |
| 270 | | Note: All of them are defined in ProcessExporterFortran. So you need to define them only if you start a class from scratch. |
| 271 | | This list correspond to the call to the exporter performed outside the class itself. |
| 272 | | |
| 273 | | 1. __init__(self, dir_path = "", opt=None) |
| 274 | | 2. copy_template(self, modelname) |
| 275 | | 3. generate_subprocess_directory(self, subproc_group, helicity_model, me=None) [for grouped] |
| 276 | | 4. generate_subprocess_directory(self, matrix_element, helicity_model, me_number) [for ungrouped] |
| 277 | | 4. convert_model(model, wanted_lorentz=[], wanted_coupling=[]) |
| 278 | | 5. finalize(self,matrix_element, cmdhistory, MG5options, outputflag) |
| 279 | | 6. modify_grouping(self, matrix_element) |
| 280 | | 7. export_model_files(self, model_v4_path) [only if you want to support old model format] |
| 281 | | 8. export_helas(self, HELAS_PATH) [only if you want to support old model format] |
| 282 | | |
| 283 | | |
| 284 | | === List of class variable that need to be defined in the exporter: |
| 285 | | |
| 286 | | Note: All of them are defined in ProcessExporterFortran/ProcessExporterCPP. So you need to define them only if you start a class from scratch. |
| 287 | | This list correspond to the attribute of the exporter called outside the exporter class. |
| 288 | | |
| 289 | | 1. '''grouped_mode''' This variable changes the type of object called within 'generate_subprocess_directory' functions. |
| 290 | | a. '''False''' to avoid grouping (only identical matrix element are merged) |
| 291 | | b. ''' 'madevent' ''' group the massless quark and massless lepton |
| 292 | | c. ''' 'madweight' ''' group the gluon with the massless quark |
| 293 | | 2. '''sa_symmetry''' If no grouped_mode=False, uu~ and u~u will be called independently. Putting sa_symmetry generates only one of the two matrix-element. (might not work for cpp output. |
| 294 | | 3. '''check''' Ask madgraph to check if the directory already exists and propose to the user to remove it first if this is the case |
| 295 | | 4. '''output''' [Template, None, dir] |
| 296 | | a. ''''Template'''', madgraph will call copy_template |
| 297 | | b. ''''dir'''', madgraph will just create an empty directory for initialisation |
| 298 | | c. '''None''', madgraph do nothing for initialisation |
| 299 | | 5. '''exporter''' ['v4'/'cpp'] language of the output 'v4' for Fortran output, 'cpp' for C++ output |
| 300 | | |
| 301 | | |
| 302 | | |
| 303 | | === Base class which can be use to create a new exporter from scratch: |
| 304 | | |
| 305 | | at the beginning of madgraph/various/iolibs/export_v4.py. |
| 306 | | A virtual class "VirtualExporter" is defined all exporter class should derive from that class. |
| 307 | | That virtual class list all the functions called by the interface that you can define (that class in itself does nothing) |
| 308 | | |
| | 312 | === Example 3: New Cluster |
| | 313 | |
| | 314 | A condor cluster not submitting more than a given number of job simultaneously: |
| | 315 | |
| | 316 | |
| | 317 | !__init!__.py |
| | 318 | {{{ |
| | 319 | ## import the required files |
| | 320 | # example: import maddm_interface as maddm_interface # local file |
| | 321 | # import madgraph.various.cluster as cluster #MG5 distribution file |
| | 322 | |
| | 323 | import magraph.various.cluster as cluster |
| | 324 | import time |
| | 325 | |
| | 326 | #local file |
| | 327 | |
| | 328 | class MYcluster(cluster.MultiCore): |
| | 329 | |
| | 330 | maximum_submited_jobs = 100 |
| | 331 | restart_submission = 50 |
| | 332 | |
| | 333 | def submit(self, prog, argument=[], cwd=None, stdout=None, stderr=None, log=None, |
| | 334 | required_output=[], nb_submit=0): |
| | 335 | """pause the submission of jobs if more than """ |
| | 336 | |
| | 337 | me_dir = self.get_jobs_identifier(cwd, prog) |
| | 338 | if len(self.submitted_ids) > self.maximum_submited_jobs: |
| | 339 | fct = lambda idle, run, finish: logger.info('Waiting for free slot: %s %s %s' % (idle, run, finish)) |
| | 340 | self.wait(me_dir, fct, self.restart_submission) |
| | 341 | |
| | 342 | |
| | 343 | # call the normal submission scheme |
| | 344 | super(MYcluster, self).submit( prog, argument, cwd, stdout, stderr, log, required_output, nb_submit) |
| | 345 | |
| | 346 | |
| | 347 | # Three types of functionality are allowed in a plugin |
| | 348 | # 1. new output mode |
| | 349 | # 2. new cluster support |
| | 350 | # 3. new interface |
| | 351 | |
| | 352 | # 1. Define new output mode |
| | 353 | # example: new_output = {'myformat': MYCLASS} |
| | 354 | # madgraph will then allow the command "output myformat PATH" |
| | 355 | # MYCLASS should inherated of the class madgraph.iolibs.export_v4.VirtualExporter |
| | 356 | new_output = {} |
| | 357 | |
| | 358 | # 2. Define new way to handle the cluster. |
| | 359 | # example new_cluster = {'mycluster': MYCLUSTERCLASS} |
| | 360 | # allow "set cluster_type mycluster" in madgraph |
| | 361 | # MYCLUSTERCLASS should inherated from madgraph.various.cluster.Cluster |
| | 362 | new_cluster = {'new_condor': MYcluster} |
| | 363 | |
| | 364 | |
| | 365 | # 3. Define a new interface (allow to add/modify MG5 command) |
| | 366 | # This can be activated via ./bin/mg5_aMC --mode=PLUGINNAME |
| | 367 | ## Put None if no dedicated command are required |
| | 368 | new_interface = None |
| | 369 | |
| | 370 | |
| | 371 | ########################## CONTROL VARIABLE #################################### |
| | 372 | __author__ = 'Mattelaer Olivier' |
| | 373 | __email__ = 'o.p.c.mattelaer@durham.ac.uk' |
| | 374 | __version__ = (1,0,0) |
| | 375 | minimal_mg5amcnlo_version = (2,5,0) |
| | 376 | maximal_mg5amcnlo_version = (1000,1000,1000) |
| | 377 | latest_validated_version = (2,5,0) |
| | 378 | }}} |
| | 379 | |
| | 380 | |