5from AthenaCommon
import Logging
6mglog = Logging.logging.getLogger(
'MadGraphUtils')
9MADGRAPH_GRIDPACK_LOCATION=
'madevent'
11MADGRAPH_CATCH_ERRORS=
True
12MADGRAPH_COMMAND_STACK = []
17 if setting.replace(
"'",
'').
replace(
'"',
'').
replace(
'.',
'').lower()
in [
't',
'true']:
22 """Return MadGraph version string (e.g. '3.5.1')
24 Used to include MG version in gridpack names for better traceability.
25 Reads version from $MADPATH/VERSION file.
27 with open(os.environ[
'MADPATH']+
'/VERSION',
'r')
as version_file:
28 for line
in version_file:
30 return line.split(
'=')[1].
strip()
31 raise RuntimeError(
'Failed to find MadGraph/MadGraph5_aMC@NLO version')
37 version_file = open(os.environ[
'MADPATH']+
'/VERSION',
'r')
39 for line
in version_file:
41 version=line.split(
'=')[1].
strip()
45 raise RuntimeError(
'Failed to find MadGraph/MadGraph5_aMC@NLO version in '+version_file)
47 vs=[int(v)
for v
in version.split(
'.')]
50 y=int(100**
max(len(vs),len(args)))
56 y=int(100**
max(len(vs),len(args)))
61 return versionnumber>=testnumber
64 f = open(run_card,
'r')
65 if "parton_shower" in f.read().lower():
73 if not MADGRAPH_CATCH_ERRORS:
79 mglog.error(f
'Detected a bad return code: {return_code}')
81 raise RuntimeError(
'Error detected in MadGraphControl process')
83 unmasked_error =
False
88 if type(errors)==bytes:
89 errors = errors.decode(
'utf-8')
91 mglog.info(
'Some errors detected by MadGraphControl - checking for serious errors')
92 for err
in errors.split(
'\n'):
93 if len(err.strip())==0:
96 if 'Inappropriate ioctl for device' in err:
99 if 'stty: standard input: Invalid argument' in err:
103 if 'PDF already installed' in err:
106 if 'Read-only file system' in err:
113 if 'impossible to set default multiparticles' in err:
117 if 'More information is found in' in err:
118 my_debug_file = err.split(
"'")[1]
119 if err.startswith(
'tar'):
122 if 'python2 support will be removed' in err:
125 if 'python3.12 support is still experimental' in err:
129 if 'python3.12+ support: For reweighting feature, please use 3.6.X release.' in err:
133 if 'required by /lib64/libfontconfig.so' in err
or\
134 'required by /lib64/libgs.so' in err:
137 if 'Error: Symbol' in err
and 'has no IMPLICIT type' in err:
138 bad_variables += [ err.split(
'Symbol ')[1].
split(
' at ')[0] ]
144 unmasked_error =
True
146 if my_debug_file
is None:
147 debug_files = glob.glob(
'*debug.log')+glob.glob(
'*/*debug.log')
148 for debug_file
in debug_files:
150 has_subproc = os.access(os.path.join(os.path.dirname(debug_file),
'SubProcesses'),os.R_OK)
152 my_debug_file = debug_file
155 if my_debug_file
is not None:
156 if not unmasked_error:
157 mglog.warning(
'Found a debug file at '+my_debug_file+
' but no apparent error. Will terminate.')
158 mglog.error(
'MadGraph5_aMC@NLO appears to have crashed. Debug file output follows.')
159 with open(my_debug_file,
'r')
as error_output:
160 for l
in error_output:
161 mglog.error(l.replace(
'\n',
''))
162 mglog.error(
'End of debug file output')
165 mglog.warning(
'Appeared to detect variables in your run card that MadGraph did not understand:')
166 mglog.warning(
' Check your run card / JO settings for %s',bad_variables)
170 mglog.error(f
'Detected a bad return code: {return_code}')
171 unmasked_error =
True
174 if unmasked_error
or my_debug_file
is not None:
176 raise RuntimeError(
'Error detected in MadGraphControl process')
182 mglog.info(
'Will write a stand-alone debugging script.')
183 mglog.info(
'This is an attempt to provide you commands that you can use')
184 mglog.info(
'to reproduce the error locally. If you make additional')
185 mglog.info(
'modifications by hand (not using MadGraphControl) in your JO,')
186 mglog.info(
'make sure that you check and modify the script as needed.\n\n')
187 mglog.info(
'# Script start; trim off columns left of the "#"')
189 with open(
'standalone_script.sh',
'w')
as standalone_script:
190 for command
in MADGRAPH_COMMAND_STACK:
191 for line
in command.split(
'\n'):
193 standalone_script.write(line+
'\n')
194 mglog.info(
'# Script end')
195 mglog.info(
'Script also written to %s/standalone_script.sh',os.getcwd())
199 """ Helper function when looking at param cards
200 In some cases it's tricky to match keys - they may differ
201 only in white space. This tries to sort out when we have
202 a match, and then uses the one in blockParams afterwards.
203 In the case of no match, it returns the original key.
205 test_key =
' '.join(akey.strip().
replace(
'\t',
' ').
split())
206 for key
in dictionary:
207 mod_key =
' '.join(key.strip().
replace(
'\t',
' ').
split())
208 if mod_key==test_key:
std::string replace(std::string s, const std::string &s2, const std::string &s3)
std::vector< std::string > split(const std::string &s, const std::string &t=":")
find_key_and_update(akey, dictionary)
is_version_or_newer(args)
error_check(errors_a, return_code)
isNLO_from_run_card(run_card)