From afc0a52ba77a9f342ef3bbe9ab844aa40ffa8a5a Mon Sep 17 00:00:00 2001 From: Stefan Roiser Date: Mon, 8 Jul 2024 18:33:37 +0200 Subject: [PATCH 1/3] pass ordered couplings to ModelConverter --- .../CODEGEN/PLUGIN/CUDACPP_SA_OUTPUT/model_handling.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/epochX/cudacpp/CODEGEN/PLUGIN/CUDACPP_SA_OUTPUT/model_handling.py b/epochX/cudacpp/CODEGEN/PLUGIN/CUDACPP_SA_OUTPUT/model_handling.py index 7bb8c5fc8c..3517df6255 100644 --- a/epochX/cudacpp/CODEGEN/PLUGIN/CUDACPP_SA_OUTPUT/model_handling.py +++ b/epochX/cudacpp/CODEGEN/PLUGIN/CUDACPP_SA_OUTPUT/model_handling.py @@ -13,6 +13,8 @@ import logging logger = logging.getLogger('madgraph.PLUGIN.CUDACPP_OUTPUT.model_handling') +wanted_ordered_couplings = [] + #------------------------------------------------------------------------------------ # AV - import the independent 2nd copy of the export_cpp module (as PLUGIN_export_cpp), previously loaded in output.py @@ -1098,9 +1100,9 @@ def write_aloha_routines(self): % (os.path.split(model_h_file)[-1], os.path.split(model_h_file)[0] ) ) def prepare_couplings(self, wanted_couplings = []): - super().prepare_couplings(wanted_couplings) + super().prepare_couplings(wanted_ordered_couplings) # the two lines below fix #748, i.e. they re-order the dictionary keys following the order in wanted_couplings - running_wanted_couplings = [value for value in wanted_couplings if value in self.coups_dep] + running_wanted_couplings = [value for value in wanted_ordered_couplings if value in self.coups_dep] ordered_dict = [(k, self.coups_dep[k]) for k in running_wanted_couplings] self.coups_dep = dict((x, y) for x, y in ordered_dict) @@ -1787,10 +1789,12 @@ def format_coupling(self, call): aliastxt = 'PARAM' name = 'cIPD' elif model.is_running_coupling(coup): + if coup not in wanted_ordered_couplings: wanted_ordered_couplings.append(coup) alias = self.couporderdep aliastxt = 'COUPD' name = 'cIPC' else: + if coup not in wanted_ordered_couplings: wanted_ordered_couplings.append(coup) alias = self.couporderindep aliastxt = 'COUPI' name = 'cIPC' From d095ad4b66462a3fc4e9c270dcdade15ae50a835 Mon Sep 17 00:00:00 2001 From: Stefan Roiser Date: Wed, 17 Jul 2024 14:53:43 +0200 Subject: [PATCH 2/3] split couplings between dependent and independent ones --- .../CODEGEN/PLUGIN/CUDACPP_SA_OUTPUT/model_handling.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/epochX/cudacpp/CODEGEN/PLUGIN/CUDACPP_SA_OUTPUT/model_handling.py b/epochX/cudacpp/CODEGEN/PLUGIN/CUDACPP_SA_OUTPUT/model_handling.py index 3517df6255..f2976d852f 100644 --- a/epochX/cudacpp/CODEGEN/PLUGIN/CUDACPP_SA_OUTPUT/model_handling.py +++ b/epochX/cudacpp/CODEGEN/PLUGIN/CUDACPP_SA_OUTPUT/model_handling.py @@ -13,7 +13,8 @@ import logging logger = logging.getLogger('madgraph.PLUGIN.CUDACPP_OUTPUT.model_handling') -wanted_ordered_couplings = [] +wanted_ordered_dep_couplings = [] +wanted_ordered_indep_couplings = [] #------------------------------------------------------------------------------------ @@ -1100,6 +1101,7 @@ def write_aloha_routines(self): % (os.path.split(model_h_file)[-1], os.path.split(model_h_file)[0] ) ) def prepare_couplings(self, wanted_couplings = []): + wanted_ordered_couplings = wanted_ordered_dep_couplings + wanted_ordered_indep_couplings super().prepare_couplings(wanted_ordered_couplings) # the two lines below fix #748, i.e. they re-order the dictionary keys following the order in wanted_couplings running_wanted_couplings = [value for value in wanted_ordered_couplings if value in self.coups_dep] @@ -1789,12 +1791,12 @@ def format_coupling(self, call): aliastxt = 'PARAM' name = 'cIPD' elif model.is_running_coupling(coup): - if coup not in wanted_ordered_couplings: wanted_ordered_couplings.append(coup) + if coup not in wanted_ordered_dep_couplings: wanted_ordered_dep_couplings.append(coup) alias = self.couporderdep aliastxt = 'COUPD' name = 'cIPC' else: - if coup not in wanted_ordered_couplings: wanted_ordered_couplings.append(coup) + if coup not in wanted_ordered_indep_couplings: wanted_ordered_indep_couplings.append(coup) alias = self.couporderindep aliastxt = 'COUPI' name = 'cIPC' From 4cb696862d1a64cf1edff6d19dbc453170ed0972 Mon Sep 17 00:00:00 2001 From: Olivier Mattelaer Date: Wed, 17 Jul 2024 21:32:30 +0200 Subject: [PATCH 3/3] avoiding global variable --- .../CUDACPP_SA_OUTPUT/model_handling.py | 21 ++++++++++++------- .../PLUGIN/CUDACPP_SA_OUTPUT/output.py | 5 +++-- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/epochX/cudacpp/CODEGEN/PLUGIN/CUDACPP_SA_OUTPUT/model_handling.py b/epochX/cudacpp/CODEGEN/PLUGIN/CUDACPP_SA_OUTPUT/model_handling.py index f2976d852f..d3dca88ab2 100644 --- a/epochX/cudacpp/CODEGEN/PLUGIN/CUDACPP_SA_OUTPUT/model_handling.py +++ b/epochX/cudacpp/CODEGEN/PLUGIN/CUDACPP_SA_OUTPUT/model_handling.py @@ -13,8 +13,6 @@ import logging logger = logging.getLogger('madgraph.PLUGIN.CUDACPP_OUTPUT.model_handling') -wanted_ordered_dep_couplings = [] -wanted_ordered_indep_couplings = [] #------------------------------------------------------------------------------------ @@ -1101,10 +1099,9 @@ def write_aloha_routines(self): % (os.path.split(model_h_file)[-1], os.path.split(model_h_file)[0] ) ) def prepare_couplings(self, wanted_couplings = []): - wanted_ordered_couplings = wanted_ordered_dep_couplings + wanted_ordered_indep_couplings - super().prepare_couplings(wanted_ordered_couplings) + super().prepare_couplings(wanted_couplings) # the two lines below fix #748, i.e. they re-order the dictionary keys following the order in wanted_couplings - running_wanted_couplings = [value for value in wanted_ordered_couplings if value in self.coups_dep] + running_wanted_couplings = [value for value in wanted_couplings if value in self.coups_dep] ordered_dict = [(k, self.coups_dep[k]) for k in running_wanted_couplings] self.coups_dep = dict((x, y) for x, y in ordered_dict) @@ -1755,6 +1752,14 @@ class PLUGIN_GPUFOHelasCallWriter(helas_call_writers.GPUFOHelasCallWriter): # - PLUGIN_GPUFOHelasCallWriter(GPUFOHelasCallWriter) # This class + + def __init__(self, *args, **opts): + + self.wanted_ordered_dep_couplings = [] + self.wanted_ordered_indep_couplings = [] + super().__init__(*args,**opts) + + # AV - replace helas_call_writers.GPUFOHelasCallWriter method (improve formatting of CPPProcess.cc) # [GPUFOHelasCallWriter.format_coupling is called by GPUFOHelasCallWriter.get_external_line/generate_helas_call] # [GPUFOHelasCallWriter.get_external_line is called by GPUFOHelasCallWriter.get_external] @@ -1791,12 +1796,12 @@ def format_coupling(self, call): aliastxt = 'PARAM' name = 'cIPD' elif model.is_running_coupling(coup): - if coup not in wanted_ordered_dep_couplings: wanted_ordered_dep_couplings.append(coup) + if coup not in self.wanted_ordered_dep_couplings: self.wanted_ordered_dep_couplings.append(coup) alias = self.couporderdep aliastxt = 'COUPD' name = 'cIPC' else: - if coup not in wanted_ordered_indep_couplings: wanted_ordered_indep_couplings.append(coup) + if coup not in self.wanted_ordered_indep_couplings: self.wanted_ordered_indep_couplings.append(coup) alias = self.couporderindep aliastxt = 'COUPI' name = 'cIPC' @@ -1831,8 +1836,10 @@ def format_coupling(self, call): call = call.replace('CD_ACCESS', 'CI_ACCESS') call = call.replace('m_pars->%s%s' % (sign, coup), 'COUPs[ndcoup + %s], %s' % (alias[coup]-len(self.couporderdep), '1.0' if not sign else '-1.0')) + if newcoup: self.couplings2order = self.couporderdep | self.couporderindep + model.cudacpp_wanted_ordered_couplings = self.wanted_ordered_dep_couplings + self.wanted_ordered_indep_couplings return call # AV - new method for formatting wavefunction/amplitude calls diff --git a/epochX/cudacpp/CODEGEN/PLUGIN/CUDACPP_SA_OUTPUT/output.py b/epochX/cudacpp/CODEGEN/PLUGIN/CUDACPP_SA_OUTPUT/output.py index 2b8b36324b..5d5e803232 100644 --- a/epochX/cudacpp/CODEGEN/PLUGIN/CUDACPP_SA_OUTPUT/output.py +++ b/epochX/cudacpp/CODEGEN/PLUGIN/CUDACPP_SA_OUTPUT/output.py @@ -202,10 +202,11 @@ def generate_subprocess_directory(self, subproc_group, fortran_model, me=None): return out # AV (default from OM's tutorial) - add a debug printout def convert_model(self, model, wanted_lorentz=[], wanted_coupling=[]): - misc.sprint('Entering PLUGIN_ProcessExporter.convert_model (create the model)') + if hasattr(model , 'cudacpp_wanted_ordered_couplings'): + wanted_coupling = model.cudacpp_wanted_ordered_couplings + del model.cudacpp_wanted_ordered_couplings return super().convert_model(model, wanted_lorentz, wanted_coupling) - # AV (default from OM's tutorial) - add a debug printout def finalize(self, matrix_element, cmdhistory, MG5options, outputflag): """Typically creating jpeg/HTML output/ compilation/...