35 def __init__(self, process='generate p p > t t~\noutput -f', plugin=None, keepJpegs=False, usePMGSettings=False):
36 """ Generate a new process in madgraph.
37 Pass a process string.
38 Optionally request JPEGs to be kept and request for PMG settings to be used in the param card
39 Return the name of the process directory.
40 """
41 self.mglog = Logging.logging.getLogger('MadGraphUtils')
42 self.process = process
43 self.plugin = plugin
44 self.keepJpegs = keepJpegs
45 self.usePMGSettings = usePMGSettings
46 self.run_card_params = []
47
48 self.is_gen_from_gridpack = os.access(MADGRAPH_GRIDPACK_LOCATION,os.R_OK)
49
50 if self.is_gen_from_gridpack:
51 self.process_dir = MADGRAPH_GRIDPACK_LOCATION
52 return
53
54 card_loc='proc_card_mg5.dat'
55 mglog.info('Writing process card to '+card_loc)
56 a_card = open( card_loc , 'w' )
57 for l in process.split('\n'):
58 if 'output' not in l:
59 a_card.write(l+'\n')
60 else:
61
62 outline = l.strip()
63 if '-nojpeg' not in l and not keepJpegs:
64
65 if '#' in l:
66 outline = outline.split('#')[0]+' -nojpeg #'+outline.split('#')[1]
67 else:
68 outline = outline + ' -nojpeg'
69
70 if MADGRAPH_DEVICES is not None:
71 if MADGRAPH_DEVICES.lower() in ['madevent_simd','madevent_gpu']:
72 outline = 'output '+MADGRAPH_DEVICES.lower()+' '+outline.split('output')[1]
73 elif MADGRAPH_DEVICES.lower() == 'max':
74 self.mglog.warning('Not fully implemented yet; setting avx')
75 outline = 'output madevent_simd '+outline.split('output')[1]
76 a_card.write(outline+'\n')
77 a_card.close()
78
79 madpath=os.environ['MADPATH']
80
81 setup_path_protection()
82
83
84 process_dir = ''
85 for l in process.split('\n'):
86
87 if 'output' not in l.split(
'#')[0].
split():
88 continue
89
90 tmplist = l.split(
'#')[0].
split(
' -')[0]
91
92 if len(tmplist.split())==2:
93 process_dir = tmplist.split()[1]
94
95 elif len(tmplist.split())==3:
96 process_dir = tmplist.split()[2]
97
98 if ''!=process_dir:
99 mglog.info('Saw that you asked for a special output directory: '+str(process_dir))
100 break
101
102 mglog.info('Started process generation at '+str(time.asctime()))
103
104 plugin_cmd = '--mode='+plugin if plugin is not None else ''
105
106
107 self.MADGRAPH_COMMAND_STACK = []
108 self.MADGRAPH_COMMAND_STACK += ['# All jobs should start in a clean directory']
109 self.MADGRAPH_COMMAND_STACK += ['mkdir standalone_test; cd standalone_test']
110 self.MADGRAPH_COMMAND_STACK += [' '.join([python,madpath+'/bin/mg5_aMC '+plugin_cmd+' << EOF\n'+process+'\nEOF\n'])]
111 generate = subprocess.Popen([python,madpath+'/bin/mg5_aMC',plugin_cmd,card_loc],stdin=subprocess.PIPE,stderr=subprocess.PIPE if MADGRAPH_CATCH_ERRORS else None)
112 (out,err) = generate.communicate()
113 error_check(err,generate.returncode)
114
115 mglog.info('Finished process generation at '+str(time.asctime()))
116
117
118 if process_dir == '':
119 for adir in sorted(glob.glob( os.getcwd()+'/*PROC*' ),reverse=True):
120 if os.access('%s/SubProcesses/subproc.mg'%adir,os.R_OK):
121 if process_dir=='':
122 process_dir=adir
123 else:
124 mglog.warning('Additional possible process directory, '+adir+' found. Had '+process_dir)
125 mglog.warning('Likely this is because you did not run from a clean directory, and this may cause errors later.')
126 else:
127 if not os.access('%s/SubProcesses/subproc.mg'%process_dir,os.R_OK):
128 raise RuntimeError('No diagrams for this process in user-define dir='+str(process_dir))
129 if process_dir=='':
130 raise RuntimeError('No diagrams for this process from list: '+str(sorted(glob.glob(os.getcwd()+'/*PROC*'),reverse=True)))
131
132
133 needed_options = ['ninja','collier','fastjet','lhapdf','syscalc_path']
134 in_config = open(os.environ['MADPATH']+'/input/mg5_configuration.txt','r')
135 option_paths = {}
136 for l in in_config.readlines():
137 for o in needed_options:
138 if o+' =' in l.split('#')[0] and 'MCGenerators' in l.split('#')[0]:
139 old_path = l.split(
'#')[0].
split(
'=')[1].
strip().
split(
'MCGenerators')[1]
140 old_path = old_path[ old_path.find('/') : ]
141 if o =='lhapdf' and 'LHAPATH' in os.environ:
142
143 version = os.environ[
'LHAPATH'].
split(
'lhapdf/')[1].
split(
'/')[0]
144 old_version = old_path.split(
'lhapdf/')[1].
split(
'/')[0]
145 old_path = old_path.replace(old_version,version)
146 if o=='ninja':
147
148 old_path.replace('gosam_contrib','gosam-contrib')
149 option_paths[o] = os.environ[
'MADPATH'].
split(
'madgraph5amc')[0]+old_path
150
151 if o+' =' in l and o+' =' not in l.split('#')[0]:
152 mglog.info('Option '+o+' appears commented out in the config file')
153
154 in_config.close()
155 for o in needed_options:
156 if o not in option_paths:
157 mglog.info('Path for option '+o+' not found in original config')
158
159 mglog.info('Modifying config paths to avoid use of afs:')
160 mglog.info(option_paths)
161
162
163 self.runCardDict = getDictFromCard(process_dir+'/Cards/run_card.dat')
164
165
166 self.change_config_card(process_dir=process_dir,settings=option_paths,set_commented=False)
167
168
169
170 if usePMGSettings:
171 do_PMG_updates(process_dir)
172
173
174 if is_version_or_newer([2,9,3]) and not is_NLO_run(process_dir=process_dir):
175 mglog.info('Setting default sde_strategy to old default (1)')
176 self.runCardDict['sde_strategy']=1
177
178
179 self.change_config_card(process_dir=process_dir,settings={'notification_center':'False'})
180
181
182 if MADGRAPH_DEVICES is not None:
183 if MADGRAPH_DEVICES.lower()=='madevent_simd':
184 self.runCardDict['cudacpp_backend'] = 'cppauto'
185 elif MADGRAPH_DEVICES.lower()=='madevent_gpu':
186 self.runCardDict['cudacpp_backend'] = 'cuda'
187
188
189 os.environ['ALLOW_UNSUPPORTED_COMPILER_IN_CUDA'] = 'Y'
190 elif MADGRAPH_DEVICES.lower() == 'max':
191 self.mglog.warning('Not fully implemented yet; setting avx')
192 self.runCardDict['cudacpp_backend'] = 'cppauto'
193
194
195 self.MADGRAPH_COMMAND_STACK += ['export MGaMC_PROCESS_DIR='+os.path.basename(process_dir)]
196 self.process_dir = process_dir
197
std::vector< std::string > split(const std::string &s, const std::string &t=":")