5from AthenaCommon
import Logging
6mglog = Logging.logging.getLogger(
'MadGraphUtils')
9MADGRAPH_GRIDPACK_LOCATION=
'madevent'
11MADGRAPH_CATCH_ERRORS=
True
12MADGRAPH_COMMAND_STACK = []
17 for line
in iter(card):
18 if not line.strip().startswith(
'#'):
19 command = line.split(
'!', 1)[0]
21 setting = command.split(
'=')[-1].
strip()
22 value =
'='.join(command.split(
'=')[:-1]).
strip()
25 setting=setting.lower()
31 if setting.replace(
"'",
'').
replace(
'"',
'').
replace(
'.',
'').lower()
in [
't',
'true']:
36 y=str(x).lower().
strip()
38 while len(y)>0
and (y[0]==
'"' or y[0]==
"'"):
40 while len(y)>0
and (y[-1]==
'"' or y[-1]==
"'"):
50 return key
in mydict
and mydict[key]==value
57 return key
in mydict
and mydict[key]
in [
't',
'true']
67 """Return MadGraph version string (e.g. '3.5.1')
69 Used to include MG version in gridpack names for better traceability.
70 Reads version from $MADPATH/VERSION file.
72 with open(os.environ[
'MADPATH']+
'/VERSION',
'r')
as version_file:
73 for line
in version_file:
75 return line.split(
'=')[1].
strip()
76 raise RuntimeError(
'Failed to find MadGraph/MadGraph5_aMC@NLO version')
82 version_file = open(os.environ[
'MADPATH']+
'/VERSION',
'r')
84 for line
in version_file:
86 version=line.split(
'=')[1].
strip()
90 raise RuntimeError(
'Failed to find MadGraph/MadGraph5_aMC@NLO version in '+version_file)
92 vs=[int(v)
for v
in version.split(
'.')]
95 y=int(100**
max(len(vs),len(args)))
101 y=int(100**
max(len(vs),len(args)))
106 return versionnumber>=testnumber
109 f = open(run_card,
'r')
110 if "parton_shower" in f.read().lower():
119 raise RuntimeError(
'runArgs must be provided!')
120 if hasattr(runArgs,
'ecmEnergy'):
121 beamEnergy = runArgs.ecmEnergy / 2.
123 raise RuntimeError(
"No center of mass energy found in runArgs.")
124 if hasattr(runArgs,
'randomSeed'):
125 random_seed = runArgs.randomSeed
127 raise RuntimeError(
"No random seed found in runArgs.")
128 return beamEnergy,random_seed
132 if not MADGRAPH_CATCH_ERRORS:
134 unmasked_error =
False
139 if type(errors)==bytes:
140 errors = errors.decode(
'utf-8')
142 mglog.info(
'Some errors detected by MadGraphControl - checking for serious errors')
143 for err
in errors.split(
'\n'):
144 if len(err.strip())==0:
147 if 'Inappropriate ioctl for device' in err:
150 if 'stty: standard input: Invalid argument' in err:
154 if 'PDF already installed' in err:
157 if 'Read-only file system' in err:
164 if 'impossible to set default multiparticles' in err:
168 if 'More information is found in' in err:
169 my_debug_file = err.split(
"'")[1]
170 if err.startswith(
'tar'):
173 if 'python2 support will be removed' in err:
176 if 'python3.12 support is still experimental' in err:
180 if 'required by /lib64/libfontconfig.so' in err
or\
181 'required by /lib64/libgs.so' in err:
184 if 'Error: Symbol' in err
and 'has no IMPLICIT type' in err:
185 bad_variables += [ err.split(
'Symbol ')[1].
split(
' at ')[0] ]
191 unmasked_error =
True
193 if my_debug_file
is None:
194 debug_files = glob.glob(
'*debug.log')+glob.glob(
'*/*debug.log')
195 for debug_file
in debug_files:
197 has_subproc = os.access(os.path.join(os.path.dirname(debug_file),
'SubProcesses'),os.R_OK)
199 my_debug_file = debug_file
202 if my_debug_file
is not None:
203 if not unmasked_error:
204 mglog.warning(
'Found a debug file at '+my_debug_file+
' but no apparent error. Will terminate.')
205 mglog.error(
'MadGraph5_aMC@NLO appears to have crashed. Debug file output follows.')
206 with open(my_debug_file,
'r')
as error_output:
207 for l
in error_output:
208 mglog.error(l.replace(
'\n',
''))
209 mglog.error(
'End of debug file output')
212 mglog.warning(
'Appeared to detect variables in your run card that MadGraph did not understand:')
213 mglog.warning(
' Check your run card / JO settings for %s',bad_variables)
217 mglog.error(f
'Detected a bad return code: {return_code}')
218 unmasked_error =
True
221 if unmasked_error
or my_debug_file
is not None:
223 raise RuntimeError(
'Error detected in MadGraphControl process')
229 mglog.info(
'Will write a stand-alone debugging script.')
230 mglog.info(
'This is an attempt to provide you commands that you can use')
231 mglog.info(
'to reproduce the error locally. If you make additional')
232 mglog.info(
'modifications by hand (not using MadGraphControl) in your JO,')
233 mglog.info(
'make sure that you check and modify the script as needed.\n\n')
234 mglog.info(
'# Script start; trim off columns left of the "#"')
236 with open(
'standalone_script.sh',
'w')
as standalone_script:
237 for command
in MADGRAPH_COMMAND_STACK:
238 for line
in command.split(
'\n'):
240 standalone_script.write(line+
'\n')
241 mglog.info(
'# Script end')
242 mglog.info(
'Script also written to %s/standalone_script.sh',os.getcwd())
246 global MADGRAPH_COMMAND_STACK
247 if 'PYTHONPATH' in os.environ:
248 if not any( [(
'Generators/madgraph/models' in x
and 'shutil_patch' not in x)
for x
in os.environ[
'PYTHONPATH'].
split(
':') ]):
249 os.environ[
'PYTHONPATH'] +=
':/cvmfs/atlas.cern.ch/repo/sw/Generators/madgraph/models/latest'
250 MADGRAPH_COMMAND_STACK += [
'export PYTHONPATH=${PYTHONPATH}:/cvmfs/atlas.cern.ch/repo/sw/Generators/madgraph/models/latest']
252 if 'GFORTRAN_TMPDIR' in os.environ:
254 if 'TMPDIR' in os.environ:
255 os.environ[
'GFORTRAN_TMPDIR']=os.environ[
'TMPDIR']
256 MADGRAPH_COMMAND_STACK += [
'export GFORTRAN_TMPDIR=${TMPDIR}']
258 if 'TMP' in os.environ:
259 os.environ[
'GFORTRAN_TMPDIR']=os.environ[
'TMP']
260 MADGRAPH_COMMAND_STACK += [
'export GFORTRAN_TMPDIR=${TMP}']
265 lo_config_card=process_dir+
'/Cards/me5_configuration.txt'
266 nlo_config_card=process_dir+
'/Cards/amcatnlo_configuration.txt'
268 if os.access(lo_config_card,os.R_OK)
and not os.access(nlo_config_card,os.R_OK):
269 return lo_config_card
270 elif os.access(nlo_config_card,os.R_OK)
and not os.access(lo_config_card,os.R_OK):
271 return nlo_config_card
272 elif os.access(nlo_config_card,os.R_OK)
and os.access(lo_config_card,os.R_OK):
273 mglog.error(
'Found both types of config card in '+process_dir)
275 mglog.error(
'No config card in '+process_dir)
276 raise RuntimeError(
'Unable to locate configuration card')
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=":")
get_runArgs_info(runArgs)
checkSettingExists(key_, mydict_)
checkSettingIsTrue(key_, mydict_)
is_version_or_newer(args)
error_check(errors_a, return_code)
is_NLO_run(process_dir=MADGRAPH_GRIDPACK_LOCATION)
getDictFromCard(card_loc, lowercase=False)
get_default_config_card(process_dir=MADGRAPH_GRIDPACK_LOCATION)
isNLO_from_run_card(run_card)
checkSetting(key_, value_, mydict_)