Merge lp:~maddevelopers/mg5amcnlo/2.7.3_rwgt into lp:~mg5core1/mg5amcnlo/2.7.3

Proposed by Olivier Mattelaer
Status: Merged
Merged at revision: 341
Proposed branch: lp:~maddevelopers/mg5amcnlo/2.7.3_rwgt
Merge into: lp:~mg5core1/mg5amcnlo/2.7.3
Diff against target: 289 lines (+105/-36)
4 files modified
madgraph/interface/common_run_interface.py (+17/-6)
madgraph/interface/reweight_interface.py (+38/-19)
madgraph/iolibs/export_v4.py (+13/-10)
madgraph/loop/loop_exporters.py (+37/-1)
To merge this branch: bzr merge lp:~maddevelopers/mg5amcnlo/2.7.3_rwgt
Reviewer Review Type Date Requested Status
Olivier Mattelaer Pending
Review via email: mp+385816@code.launchpad.net

Commit message

new strategy for getting the benchmark point.
Do not use file but pass the information from python to f2py via a new API function.
This allows to have multiple thread running in parallel without a race condition on the file.
(independently this should fasten the run on slow IO like some nfs filesystem)

To post a comment you must log in.
Revision history for this message
Olivier Mattelaer (olivier-mattelaer) wrote :

This sounds good to go.

Was validated by CMS for LO reweighting and Gauthier did also some validation.
(in top of mine)
I might wait a bit for formal approval of Gauthier but I already approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'madgraph/interface/common_run_interface.py'
2--- madgraph/interface/common_run_interface.py 2020-06-16 12:49:37 +0000
3+++ madgraph/interface/common_run_interface.py 2020-06-16 13:14:54 +0000
4@@ -1036,7 +1036,11 @@
5 out = ask(question, '0', possible_answer, timeout=int(1.5*timeout),
6 path_msg='enter path', ask_class = AskforEditCard,
7 cards=cards, mode=mode, **opt)
8-
9+ if 'return_instance' in opt and opt['return_instance']:
10+ out, cmd = out
11+ if 'return_instance' in opt and opt['return_instance']:
12+ return (out, cmd)
13+ return out
14
15 @staticmethod
16 def detect_card_type(path):
17@@ -4507,7 +4511,12 @@
18 self.modified_card = set() #set of cards not in sync with filesystem
19 # need to sync them before editing/leaving
20 self.init_from_banner(from_banner, banner)
21-
22+ self.writting_card = True
23+ if 'write_file' in opt:
24+ if not opt['write_file']:
25+ self.writting_card = False
26+ self.param_consistency = False
27+
28 #update default path by custom one if specify in cards
29 for card in cards:
30 if os.path.exists(card) and os.path.sep in cards:
31@@ -5255,7 +5264,7 @@
32 def do_set(self, line):
33 """ edit the value of one parameter in the card"""
34
35-
36+
37 args = self.split_arg(line)
38
39
40@@ -5979,8 +5988,9 @@
41 self.do_set('shower_card extrapaths None ')
42
43 # ensure that all cards are in sync
44- for key in list(self.modified_card):
45- self.write_card(key)
46+ if self.writting_card:
47+ for key in list(self.modified_card):
48+ self.write_card(key)
49
50
51 def reask(self, *args, **opt):
52@@ -6106,7 +6116,8 @@
53 self.run_card.write(self.paths['run'], self.paths['run_default'])
54
55 def write_card_param(self):
56- """ write the param_card """
57+ """ write the param_card """
58+
59 self.param_card.write(self.paths['param'])
60
61 @staticmethod
62
63=== modified file 'madgraph/interface/reweight_interface.py'
64--- madgraph/interface/reweight_interface.py 2020-05-26 19:31:47 +0000
65+++ madgraph/interface/reweight_interface.py 2020-06-16 13:14:54 +0000
66@@ -688,7 +688,8 @@
67 for i,card in enumerate(param_card_iterator):
68 if self.options['rwgt_name']:
69 self.options['rwgt_name'] = '%s_%s' % (self.options['rwgt_name'].rsplit('_',1)[0], i+1)
70- card.write(pjoin(rw_dir, 'Cards', 'param_card.dat'))
71+ self.new_param_card = card
72+ #card.write(pjoin(rw_dir, 'Cards', 'param_card.dat'))
73 self.exec_cmd("launch --keep_card", printcmd=False, precmd=True)
74
75 self.options['rwgt_name'] = None
76@@ -708,24 +709,23 @@
77
78
79 if not '--keep_card' in args:
80- ff = open(pjoin(rw_dir,'Cards', 'param_card.dat'), 'w')
81- ff.write(self.banner['slha'])
82- ff.close()
83 if self.has_nlo and self.rwgt_mode != "LO":
84 rwdir_virt = rw_dir.replace('rw_me', 'rw_mevirt')
85- files.ln(ff.name, starting_dir=pjoin(rwdir_virt, 'Cards'))
86- ff = open(pjoin(path_me, 'rw_me','Cards', 'param_card_orig.dat'), 'w')
87- ff.write(self.banner['slha'])
88- ff.close()
89- if self.has_nlo and self.rwgt_mode != "LO":
90- files.ln(ff.name, starting_dir=pjoin(path_me, 'rw_mevirt', 'Cards'))
91- cmd = common_run_interface.CommonRunCmd.ask_edit_card_static(cards=['param_card.dat'],
92- ask=self.ask, pwd=rw_dir, first_cmd=self.stored_line)
93+
94+ out, cmd = common_run_interface.CommonRunCmd.ask_edit_card_static(cards=['param_card.dat'],
95+ ask=self.ask, pwd=rw_dir, first_cmd=self.stored_line,
96+ write_file=False, return_instance=True
97+ )
98 self.stored_line = None
99-
100+ card = cmd.param_card
101+ new_card = card.write()
102+ elif self.new_param_card:
103+ new_card = self.new_param_card.write()
104+ else:
105+ new_card = open(pjoin(rw_dir, 'Cards', 'param_card.dat')).read()
106+
107 # check for potential scan in the new card
108- new_card = open(pjoin(rw_dir, 'Cards', 'param_card.dat')).read()
109- pattern_scan = re.compile(r'''^[\s\d]*scan''', re.I+re.M)
110+ pattern_scan = re.compile(r'''^(decay)?[\s\d]*scan''', re.I+re.M)
111 param_card_iterator = []
112 if pattern_scan.search(new_card):
113 try:
114@@ -744,11 +744,19 @@
115 param_card_iterator = main_card
116 first_card = param_card_iterator.next(autostart=True)
117 new_card = first_card.write()
118- first_card.write(pjoin(rw_dir, 'Cards', 'param_card.dat'))
119-
120+ self.new_param_card = first_card
121+ #first_card.write(pjoin(rw_dir, 'Cards', 'param_card.dat'))
122+
123 # check if "Auto" is present for a width parameter)
124 tmp_card = new_card.lower().split('block',1)[1]
125 if "auto" in tmp_card:
126+ if param_card_iterator:
127+ first_card.write(pjoin(rw_dir, 'Cards', 'param_card.dat'))
128+ else:
129+ ff = open(pjoin(rw_dir, 'Cards', 'param_card.dat'),'w')
130+ ff.write(new_card)
131+ ff.close()
132+
133 self.mother.check_param_card(pjoin(rw_dir, 'Cards', 'param_card.dat'))
134 new_card = open(pjoin(rw_dir, 'Cards', 'param_card.dat')).read()
135
136@@ -795,6 +803,7 @@
137 # add the reweighting in the banner information:
138 #starts by computing the difference in the cards.
139 s_orig = self.banner['slha']
140+ self.orig_param_card_text = s_orig
141 s_new = new_card
142 self.new_param_card = check_param_card.ParamCard(s_new.splitlines())
143
144@@ -866,15 +875,25 @@
145 else:
146 tag_name = 'rwgt_%s' % rewgtid
147
148+
149 #initialise module.
150 for (path,tag), module in self.f2pylib.items():
151 with misc.chdir(pjoin(os.path.dirname(rw_dir), path)):
152 with misc.stdchannel_redirected(sys.stdout, os.devnull):
153 if 'second' in path or tag == 3:
154- module.initialise(pjoin(rw_dir, 'Cards', 'param_card.dat'))
155+ param_card = self.new_param_card
156 else:
157- module.initialise(pjoin(path_me, 'rw_me', 'Cards', 'param_card_orig.dat'))
158+ param_card = check_param_card.ParamCard(self.orig_param_card_text)
159+
160+ for block in param_card:
161
162+ for param in param_card[block]:
163+ lhacode = param.lhacode
164+ value = param.value
165+ name = '%s_%s' % (block.upper(), '_'.join([str(i) for i in lhacode]))
166+ module.change_para(name, value)
167+ module.update_all_coup()
168+
169 return param_card_iterator, tag_name
170
171
172
173=== modified file 'madgraph/iolibs/export_v4.py'
174--- madgraph/iolibs/export_v4.py 2020-06-11 16:04:47 +0000
175+++ madgraph/iolibs/export_v4.py 2020-06-16 13:14:54 +0000
176@@ -12,7 +12,6 @@
177 # For more information, visit madgraph.phys.ucl.ac.be and amcatnlo.web.cern.ch
178 #
179 ################################################################################
180-from madgraph.iolibs.helas_call_writers import HelasCallWriter
181 """Methods and classes to export matrix elements to v4 format."""
182
183 import copy
184@@ -2117,7 +2116,7 @@
185 SELECT CASE (name)
186 %(parameter_setup)s
187 CASE DEFAULT
188- stop 1
189+ write(*,*) 'no parameter matching'
190 END SELECT
191
192 return
193@@ -2185,13 +2184,9 @@
194
195 params = self.get_model_parameter(self.model)
196 parameter_setup =[]
197- for p in params:
198- if p.startswith('mdl_'):
199- short_p = p[4:]
200- else:
201- short_p = p
202+ for key, var in params.items():
203 parameter_setup.append(' CASE ("%s")\n %s = value'
204- % (short_p, p))
205+ % (key, var))
206
207 formatting = {'python_information':'\n'.join(info),
208 'smatrixhel': '\n'.join(text),
209@@ -2211,9 +2206,17 @@
210 def get_model_parameter(self, model):
211 """ returns all the model parameter
212 """
213+ params = {}
214+ for p in model.get('parameters')[('external',)]:
215+ name = p.name
216+ nopref = name[4:] if name.startswith('mdl_') else name
217+ params[nopref] = name
218+
219+ block = p.lhablock
220+ lha = '_'.join([str(i) for i in p.lhacode])
221+ params['%s_%s' % (block, lha)] = name
222
223- params = [p.name for p in model.get('parameters')[('external',)]]
224- return params
225+ return params
226
227
228
229
230=== modified file 'madgraph/loop/loop_exporters.py'
231--- madgraph/loop/loop_exporters.py 2019-06-05 11:03:48 +0000
232+++ madgraph/loop/loop_exporters.py 2020-06-16 13:14:54 +0000
233@@ -297,6 +297,33 @@
234 RETURN
235 END
236
237+ subroutine CHANGE_PARA(name, value)
238+ implicit none
239+CF2PY intent(in) :: name
240+CF2PY intent(in) :: value
241+
242+ character*512 name
243+ double precision value
244+
245+ include '../Source/MODEL/input.inc'
246+ include '../Source/MODEL/coupl.inc'
247+
248+ SELECT CASE (name)
249+ %(parameter_setup)s
250+ CASE DEFAULT
251+ write(*,*) 'no parameter matching'
252+ END SELECT
253+
254+ return
255+ end
256+
257+ subroutine update_all_coup()
258+ implicit none
259+ call coup()
260+ return
261+ end
262+
263+
264 SUBROUTINE SET_MADLOOP_PATH(PATH)
265 C Routine to set the path of the folder 'MadLoop5_resources' to MadLoop
266 CHARACTER(512) PATH
267@@ -377,6 +404,14 @@
268 #close the function
269 if min_nexternal != max_nexternal:
270 text.append('endif')
271+
272+ params = self.get_model_parameter(self.model)
273+ parameter_setup =[]
274+ for key, var in params.items():
275+ parameter_setup.append(' CASE ("%s")\n %s = value'
276+ % (key, var))
277+
278+
279
280 formatting = {'python_information':'\n'.join(info),
281 'smatrixhel': '\n'.join(text),
282@@ -385,7 +420,8 @@
283 'pdgs': ','.join([str(pdg[i]) if i<len(pdg) else '0'
284 for i in range(max_nexternal) \
285 for pdg in allids]),
286- 'prefix':'\',\''.join(allprefix)
287+ 'prefix':'\',\''.join(allprefix),
288+ 'parameter_setup': '\n'.join(parameter_setup),
289 }
290
291

Subscribers

People subscribed via source and target branches

to all changes: