Skip to content

Commit

Permalink
Merge remote-tracking branch 'glav/plugin' into cudacpp_plugin (inclu…
Browse files Browse the repository at this point in the history
…de new changes to cudacpp from MR madgraph5/madgraph4gpu#752)
  • Loading branch information
valassi committed Aug 16, 2023
2 parents 5ad97cd + f1c851c commit ed3452d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
9 changes: 6 additions & 3 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
# Created by: O. Mattelaer (Sep 2021) for the MG5aMC CUDACPP plugin.
# Further modified by: O. Mattelaer, A. Valassi (2021-2023) for the MG5aMC CUDACPP plugin.

print('Load PLUGIN.CUDACPP_SA_OUTPUT')
# AV - Rename the plugin as CUDACPP_OUTPUT (was CUDACPP_SA_OUTPUT)
# [NB: madgraph4gpu's directory CUDACPP_SA_OUTPUT is copied to mg5amcnlo as directory CUDACPP_OUTPUT]
# [NB: eventually, the git repo mg5amcnlo_cudacpp will become mg5amcnlo's submodule CUDACPP_OUTPUT]
print('Load PLUGIN.CUDACPP_OUTPUT')

# AV - Require Python >= 3.8 to ensure that {} dictionaries preserve the order of item insertion
# (note: python3.7 would probably be enough but this plugin has only been tested using python3.8)
import sys
minpython = (3,8)
if sys.version_info < minpython :

print('ERROR! Cannot load PLUGIN.CUDACPP_SA_OUTPUT: Python >= %s.%s is required' % minpython)
print('ERROR! Cannot load PLUGIN.CUDACPP_OUTPUT: Python >= %s.%s is required' % minpython)

else:

Expand All @@ -28,7 +31,7 @@
# Example: new_output = {'myformat': MYCLASS}
# allows the command "output myformat PATH" in madgraph.
# MYCLASS should inherit from class madgraph.iolibs.export_v4.VirtualExporter
import PLUGIN.CUDACPP_SA_OUTPUT.output as output
import PLUGIN.CUDACPP_OUTPUT.output as output
new_output = { 'standalone_cudacpp' : output.PLUGIN_ProcessExporter }

# 2. Define new way to handle the cluster.
Expand Down
6 changes: 3 additions & 3 deletions model_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

# AV - create a plugin-specific logger
import logging
logger = logging.getLogger('madgraph.PLUGIN.CUDACPP_SA_OUTPUT.model_handling')
logger = logging.getLogger('madgraph.PLUGIN.CUDACPP_OUTPUT.model_handling')

#------------------------------------------------------------------------------------

# AV - import the independent 2nd copy of the export_cpp module (as PLUGIN_export_cpp), previously loaded in output.py
###import madgraph.iolibs.export_cpp as export_cpp # 1st copy
######import madgraph.iolibs.export_cpp as PLUGIN_export_cpp # this is not enough to define an independent 2nd copy: id(export_cpp)==id(PLUGIN_export_cpp)
import PLUGIN.CUDACPP_SA_OUTPUT.PLUGIN_export_cpp as PLUGIN_export_cpp # 2nd copy loaded in the plugin's output.py
import PLUGIN.CUDACPP_OUTPUT.PLUGIN_export_cpp as PLUGIN_export_cpp # 2nd copy loaded in the plugin's output.py
###print('id(export_cpp)=%s'%id(export_cpp))
###print('id(PLUGIN_export_cpp)=%s'%id(PLUGIN_export_cpp))

Expand All @@ -41,7 +41,7 @@ def PLUGIN_get_mg5_info_lines():
SPEC_WRITERS = importlib.util.find_spec('madgraph.iolibs.file_writers')
PLUGIN_writers = importlib.util.module_from_spec(SPEC_WRITERS)
SPEC_WRITERS.loader.exec_module(PLUGIN_writers)
###sys.modules['PLUGIN.CUDACPP_SA_OUTPUT.PLUGIN_writers'] = PLUGIN_writers # would allow 'import PLUGIN.CUDACPP_SA_OUTPUT.PLUGIN_writers' (not needed)
###sys.modules['PLUGIN.CUDACPP_OUTPUT.PLUGIN_writers'] = PLUGIN_writers # would allow 'import PLUGIN.CUDACPP_OUTPUT.PLUGIN_writers' (not needed)
del SPEC_WRITERS

# AV - use the independent 2nd copy of the writers module within the PLUGIN_export_cpp module (workaround for #341)
Expand Down
8 changes: 4 additions & 4 deletions output.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
SPEC_EXPORTCPP = importlib.util.find_spec('madgraph.iolibs.export_cpp')
PLUGIN_export_cpp = importlib.util.module_from_spec(SPEC_EXPORTCPP)
SPEC_EXPORTCPP.loader.exec_module(PLUGIN_export_cpp)
sys.modules['PLUGIN.CUDACPP_SA_OUTPUT.PLUGIN_export_cpp'] = PLUGIN_export_cpp # allow 'import PLUGIN.CUDACPP_SA_OUTPUT.PLUGIN_export_cpp' in model_handling.py
sys.modules['PLUGIN.CUDACPP_OUTPUT.PLUGIN_export_cpp'] = PLUGIN_export_cpp # allow 'import PLUGIN.CUDACPP_OUTPUT.PLUGIN_export_cpp' in model_handling.py
del SPEC_EXPORTCPP
###print('id(export_cpp)=%s'%id(export_cpp))
###print('id(PLUGIN_export_cpp)=%s'%id(PLUGIN_export_cpp))
Expand All @@ -24,11 +24,11 @@
PLUGINDIR = os.path.dirname( __file__ )

# AV - model_handling includes the custom FileWriter, ALOHAWriter, UFOModelConverter, OneProcessExporter and HelasCallWriter, plus additional patches
import PLUGIN.CUDACPP_SA_OUTPUT.model_handling as model_handling
import PLUGIN.CUDACPP_OUTPUT.model_handling as model_handling

# AV - create a plugin-specific logger
import logging
logger = logging.getLogger('madgraph.PLUGIN.CUDACPP_SA_OUTPUT.output')
logger = logging.getLogger('madgraph.PLUGIN.CUDACPP_OUTPUT.output')

#------------------------------------------------------------------------------------

Expand Down Expand Up @@ -206,7 +206,7 @@ def finalize(self, matrix_element, cmdhistory, MG5options, outputflag):
self.add_input_for_banner()
if 'CUDACPP_CODEGEN_PATCHLEVEL' in os.environ: patchlevel = os.environ['CUDACPP_CODEGEN_PATCHLEVEL']
else: patchlevel = ''
path = os.path.realpath(os.curdir + os.sep + 'PLUGIN' + os.sep + 'CUDACPP_SA_OUTPUT')
path = os.path.realpath(os.curdir + os.sep + 'PLUGIN' + os.sep + 'CUDACPP_OUTPUT')
if os.system(path + os.sep + 'patchMad.sh ' + self.dir_path + ' PROD ' + patchlevel) != 0:
raise Exception('ERROR! the O/S call to patchMad.sh failed')
return super().finalize(matrix_element, cmdhistory, MG5options, outputflag)
Expand Down

0 comments on commit ed3452d

Please sign in to comment.