5 from AthenaCommon
import Logging
6 mglog = Logging.logging.getLogger(
'MadGraphUtils')
9 MADGRAPH_GRIDPACK_LOCATION=
'madevent'
11 MADGRAPH_CATCH_ERRORS=
True
12 MADGRAPH_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']
70 version_file =
open(os.environ[
'MADPATH']+
'/VERSION',
'r')
72 for line
in version_file:
74 version=line.split(
'=')[1].strip()
78 raise RuntimeError(
'Failed to find MadGraph/MadGraph5_aMC@NLO version in '+version_file)
80 vs=[
int(v)
for v
in version.split(
'.')]
83 y=
int(100**
max(len(vs),len(args)))
89 y=
int(100**
max(len(vs),len(args)))
94 return versionnumber>=testnumber
97 f =
open(run_card,
'r')
98 if "parton_shower" in f.read().lower():
107 raise RuntimeError(
'runArgs must be provided!')
108 if hasattr(runArgs,
'ecmEnergy'):
109 beamEnergy = runArgs.ecmEnergy / 2.
111 raise RuntimeError(
"No center of mass energy found in runArgs.")
112 if hasattr(runArgs,
'randomSeed'):
113 random_seed = runArgs.randomSeed
115 raise RuntimeError(
"No random seed found in runArgs.")
116 return beamEnergy,random_seed
120 if not MADGRAPH_CATCH_ERRORS:
122 unmasked_error =
False
127 if type(errors)==bytes:
128 errors = errors.decode(
'utf-8')
130 mglog.info(
'Some errors detected by MadGraphControl - checking for serious errors')
131 for err
in errors.split(
'\n'):
132 if len(err.strip())==0:
135 if 'Inappropriate ioctl for device' in err:
138 if 'stty: standard input: Invalid argument' in err:
142 if 'PDF already installed' in err:
145 if 'Read-only file system' in err:
152 if 'impossible to set default multiparticles' in err:
156 if 'More information is found in' in err:
157 my_debug_file = err.split(
"'")[1]
158 if err.startswith(
'tar'):
161 if 'python2 support will be removed' in err:
164 if 'python3.12 support is still experimental' in err:
168 if 'required by /lib64/libfontconfig.so' in err
or\
169 'required by /lib64/libgs.so' in err:
172 if 'Error: Symbol' in err
and 'has no IMPLICIT type' in err:
173 bad_variables += [ err.split(
'Symbol ')[1].
split(
' at ')[0] ]
179 unmasked_error =
True
181 if my_debug_file
is None:
182 debug_files = glob.glob(
'*debug.log')+glob.glob(
'*/*debug.log')
183 for debug_file
in debug_files:
185 has_subproc = os.access(os.path.join(os.path.dirname(debug_file),
'SubProcesses'),os.R_OK)
187 my_debug_file = debug_file
190 if my_debug_file
is not None:
191 if not unmasked_error:
192 mglog.warning(
'Found a debug file at '+my_debug_file+
' but no apparent error. Will terminate.')
193 mglog.error(
'MadGraph5_aMC@NLO appears to have crashed. Debug file output follows.')
194 with open(my_debug_file,
'r')
as error_output:
195 for l
in error_output:
196 mglog.error(l.replace(
'\n',
''))
197 mglog.error(
'End of debug file output')
200 mglog.warning(
'Appeared to detect variables in your run card that MadGraph did not understand:')
201 mglog.warning(
' Check your run card / JO settings for %s',bad_variables)
205 mglog.error(f
'Detected a bad return code: {return_code}')
206 unmasked_error =
True
209 if unmasked_error
or my_debug_file
is not None:
211 raise RuntimeError(
'Error detected in MadGraphControl process')
217 mglog.info(
'Will write a stand-alone debugging script.')
218 mglog.info(
'This is an attempt to provide you commands that you can use')
219 mglog.info(
'to reproduce the error locally. If you make additional')
220 mglog.info(
'modifications by hand (not using MadGraphControl) in your JO,')
221 mglog.info(
'make sure that you check and modify the script as needed.\n\n')
222 mglog.info(
'# Script start; trim off columns left of the "#"')
224 with open(
'standalone_script.sh',
'w')
as standalone_script:
225 for command
in MADGRAPH_COMMAND_STACK:
226 for line
in command.split(
'\n'):
228 standalone_script.write(line+
'\n')
229 mglog.info(
'# Script end')
230 mglog.info(
'Script also written to %s/standalone_script.sh',os.getcwd())
234 global MADGRAPH_COMMAND_STACK
235 if 'PYTHONPATH' in os.environ:
236 if not any( [(
'Generators/madgraph/models' in x
and 'shutil_patch' not in x)
for x
in os.environ[
'PYTHONPATH'].
split(
':') ]):
237 os.environ[
'PYTHONPATH'] +=
':/cvmfs/atlas.cern.ch/repo/sw/Generators/madgraph/models/latest'
238 MADGRAPH_COMMAND_STACK += [
'export PYTHONPATH=${PYTHONPATH}:/cvmfs/atlas.cern.ch/repo/sw/Generators/madgraph/models/latest']
240 if 'GFORTRAN_TMPDIR' in os.environ:
242 if 'TMPDIR' in os.environ:
243 os.environ[
'GFORTRAN_TMPDIR']=os.environ[
'TMPDIR']
244 MADGRAPH_COMMAND_STACK += [
'export GFORTRAN_TMPDIR=${TMPDIR}']
246 if 'TMP' in os.environ:
247 os.environ[
'GFORTRAN_TMPDIR']=os.environ[
'TMP']
248 MADGRAPH_COMMAND_STACK += [
'export GFORTRAN_TMPDIR=${TMP}']
253 lo_config_card=process_dir+
'/Cards/me5_configuration.txt'
254 nlo_config_card=process_dir+
'/Cards/amcatnlo_configuration.txt'
256 if os.access(lo_config_card,os.R_OK)
and not os.access(nlo_config_card,os.R_OK):
257 return lo_config_card
258 elif os.access(nlo_config_card,os.R_OK)
and not os.access(lo_config_card,os.R_OK):
259 return nlo_config_card
260 elif os.access(nlo_config_card,os.R_OK)
and os.access(lo_config_card,os.R_OK):
261 mglog.error(
'Found both types of config card in '+process_dir)
263 mglog.error(
'No config card in '+process_dir)
264 raise RuntimeError(
'Unable to locate configuration card')