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
=== modified file 'madgraph/interface/common_run_interface.py'
--- madgraph/interface/common_run_interface.py 2020-06-16 12:49:37 +0000
+++ madgraph/interface/common_run_interface.py 2020-06-16 13:14:54 +0000
@@ -1036,7 +1036,11 @@
1036 out = ask(question, '0', possible_answer, timeout=int(1.5*timeout),1036 out = ask(question, '0', possible_answer, timeout=int(1.5*timeout),
1037 path_msg='enter path', ask_class = AskforEditCard,1037 path_msg='enter path', ask_class = AskforEditCard,
1038 cards=cards, mode=mode, **opt)1038 cards=cards, mode=mode, **opt)
10391039 if 'return_instance' in opt and opt['return_instance']:
1040 out, cmd = out
1041 if 'return_instance' in opt and opt['return_instance']:
1042 return (out, cmd)
1043 return out
10401044
1041 @staticmethod1045 @staticmethod
1042 def detect_card_type(path):1046 def detect_card_type(path):
@@ -4507,7 +4511,12 @@
4507 self.modified_card = set() #set of cards not in sync with filesystem4511 self.modified_card = set() #set of cards not in sync with filesystem
4508 # need to sync them before editing/leaving4512 # need to sync them before editing/leaving
4509 self.init_from_banner(from_banner, banner)4513 self.init_from_banner(from_banner, banner)
4510 4514 self.writting_card = True
4515 if 'write_file' in opt:
4516 if not opt['write_file']:
4517 self.writting_card = False
4518 self.param_consistency = False
4519
4511 #update default path by custom one if specify in cards4520 #update default path by custom one if specify in cards
4512 for card in cards:4521 for card in cards:
4513 if os.path.exists(card) and os.path.sep in cards:4522 if os.path.exists(card) and os.path.sep in cards:
@@ -5255,7 +5264,7 @@
5255 def do_set(self, line):5264 def do_set(self, line):
5256 """ edit the value of one parameter in the card"""5265 """ edit the value of one parameter in the card"""
5257 5266
5258 5267
5259 args = self.split_arg(line)5268 args = self.split_arg(line)
5260 5269
5261 5270
@@ -5979,8 +5988,9 @@
5979 self.do_set('shower_card extrapaths None ') 5988 self.do_set('shower_card extrapaths None ')
5980 5989
5981 # ensure that all cards are in sync5990 # ensure that all cards are in sync
5982 for key in list(self.modified_card):5991 if self.writting_card:
5983 self.write_card(key)5992 for key in list(self.modified_card):
5993 self.write_card(key)
59845994
59855995
5986 def reask(self, *args, **opt):5996 def reask(self, *args, **opt):
@@ -6106,7 +6116,8 @@
6106 self.run_card.write(self.paths['run'], self.paths['run_default'])6116 self.run_card.write(self.paths['run'], self.paths['run_default'])
6107 6117
6108 def write_card_param(self):6118 def write_card_param(self):
6109 """ write the param_card """ 6119 """ write the param_card """
6120
6110 self.param_card.write(self.paths['param'])6121 self.param_card.write(self.paths['param'])
6111 6122
6112 @staticmethod6123 @staticmethod
61136124
=== modified file 'madgraph/interface/reweight_interface.py'
--- madgraph/interface/reweight_interface.py 2020-05-26 19:31:47 +0000
+++ madgraph/interface/reweight_interface.py 2020-06-16 13:14:54 +0000
@@ -688,7 +688,8 @@
688 for i,card in enumerate(param_card_iterator):688 for i,card in enumerate(param_card_iterator):
689 if self.options['rwgt_name']:689 if self.options['rwgt_name']:
690 self.options['rwgt_name'] = '%s_%s' % (self.options['rwgt_name'].rsplit('_',1)[0], i+1)690 self.options['rwgt_name'] = '%s_%s' % (self.options['rwgt_name'].rsplit('_',1)[0], i+1)
691 card.write(pjoin(rw_dir, 'Cards', 'param_card.dat'))691 self.new_param_card = card
692 #card.write(pjoin(rw_dir, 'Cards', 'param_card.dat'))
692 self.exec_cmd("launch --keep_card", printcmd=False, precmd=True)693 self.exec_cmd("launch --keep_card", printcmd=False, precmd=True)
693 694
694 self.options['rwgt_name'] = None695 self.options['rwgt_name'] = None
@@ -708,24 +709,23 @@
708 709
709 710
710 if not '--keep_card' in args:711 if not '--keep_card' in args:
711 ff = open(pjoin(rw_dir,'Cards', 'param_card.dat'), 'w')
712 ff.write(self.banner['slha'])
713 ff.close()
714 if self.has_nlo and self.rwgt_mode != "LO":712 if self.has_nlo and self.rwgt_mode != "LO":
715 rwdir_virt = rw_dir.replace('rw_me', 'rw_mevirt')713 rwdir_virt = rw_dir.replace('rw_me', 'rw_mevirt')
716 files.ln(ff.name, starting_dir=pjoin(rwdir_virt, 'Cards')) 714
717 ff = open(pjoin(path_me, 'rw_me','Cards', 'param_card_orig.dat'), 'w')715 out, cmd = common_run_interface.CommonRunCmd.ask_edit_card_static(cards=['param_card.dat'],
718 ff.write(self.banner['slha'])716 ask=self.ask, pwd=rw_dir, first_cmd=self.stored_line,
719 ff.close() 717 write_file=False, return_instance=True
720 if self.has_nlo and self.rwgt_mode != "LO":718 )
721 files.ln(ff.name, starting_dir=pjoin(path_me, 'rw_mevirt', 'Cards'))
722 cmd = common_run_interface.CommonRunCmd.ask_edit_card_static(cards=['param_card.dat'],
723 ask=self.ask, pwd=rw_dir, first_cmd=self.stored_line)
724 self.stored_line = None719 self.stored_line = None
725 720 card = cmd.param_card
721 new_card = card.write()
722 elif self.new_param_card:
723 new_card = self.new_param_card.write()
724 else:
725 new_card = open(pjoin(rw_dir, 'Cards', 'param_card.dat')).read()
726
726 # check for potential scan in the new card 727 # check for potential scan in the new card
727 new_card = open(pjoin(rw_dir, 'Cards', 'param_card.dat')).read()728 pattern_scan = re.compile(r'''^(decay)?[\s\d]*scan''', re.I+re.M)
728 pattern_scan = re.compile(r'''^[\s\d]*scan''', re.I+re.M)
729 param_card_iterator = []729 param_card_iterator = []
730 if pattern_scan.search(new_card):730 if pattern_scan.search(new_card):
731 try:731 try:
@@ -744,11 +744,19 @@
744 param_card_iterator = main_card744 param_card_iterator = main_card
745 first_card = param_card_iterator.next(autostart=True)745 first_card = param_card_iterator.next(autostart=True)
746 new_card = first_card.write()746 new_card = first_card.write()
747 first_card.write(pjoin(rw_dir, 'Cards', 'param_card.dat')) 747 self.new_param_card = first_card
748 748 #first_card.write(pjoin(rw_dir, 'Cards', 'param_card.dat'))
749
749 # check if "Auto" is present for a width parameter)750 # check if "Auto" is present for a width parameter)
750 tmp_card = new_card.lower().split('block',1)[1]751 tmp_card = new_card.lower().split('block',1)[1]
751 if "auto" in tmp_card: 752 if "auto" in tmp_card:
753 if param_card_iterator:
754 first_card.write(pjoin(rw_dir, 'Cards', 'param_card.dat'))
755 else:
756 ff = open(pjoin(rw_dir, 'Cards', 'param_card.dat'),'w')
757 ff.write(new_card)
758 ff.close()
759
752 self.mother.check_param_card(pjoin(rw_dir, 'Cards', 'param_card.dat'))760 self.mother.check_param_card(pjoin(rw_dir, 'Cards', 'param_card.dat'))
753 new_card = open(pjoin(rw_dir, 'Cards', 'param_card.dat')).read()761 new_card = open(pjoin(rw_dir, 'Cards', 'param_card.dat')).read()
754762
@@ -795,6 +803,7 @@
795 # add the reweighting in the banner information:803 # add the reweighting in the banner information:
796 #starts by computing the difference in the cards.804 #starts by computing the difference in the cards.
797 s_orig = self.banner['slha']805 s_orig = self.banner['slha']
806 self.orig_param_card_text = s_orig
798 s_new = new_card807 s_new = new_card
799 self.new_param_card = check_param_card.ParamCard(s_new.splitlines())808 self.new_param_card = check_param_card.ParamCard(s_new.splitlines())
800 809
@@ -866,15 +875,25 @@
866 else:875 else:
867 tag_name = 'rwgt_%s' % rewgtid876 tag_name = 'rwgt_%s' % rewgtid
868877
878
869 #initialise module.879 #initialise module.
870 for (path,tag), module in self.f2pylib.items():880 for (path,tag), module in self.f2pylib.items():
871 with misc.chdir(pjoin(os.path.dirname(rw_dir), path)):881 with misc.chdir(pjoin(os.path.dirname(rw_dir), path)):
872 with misc.stdchannel_redirected(sys.stdout, os.devnull):882 with misc.stdchannel_redirected(sys.stdout, os.devnull):
873 if 'second' in path or tag == 3:883 if 'second' in path or tag == 3:
874 module.initialise(pjoin(rw_dir, 'Cards', 'param_card.dat'))884 param_card = self.new_param_card
875 else:885 else:
876 module.initialise(pjoin(path_me, 'rw_me', 'Cards', 'param_card_orig.dat'))886 param_card = check_param_card.ParamCard(self.orig_param_card_text)
887
888 for block in param_card:
877889
890 for param in param_card[block]:
891 lhacode = param.lhacode
892 value = param.value
893 name = '%s_%s' % (block.upper(), '_'.join([str(i) for i in lhacode]))
894 module.change_para(name, value)
895 module.update_all_coup()
896
878 return param_card_iterator, tag_name897 return param_card_iterator, tag_name
879898
880 899
881900
=== modified file 'madgraph/iolibs/export_v4.py'
--- madgraph/iolibs/export_v4.py 2020-06-11 16:04:47 +0000
+++ madgraph/iolibs/export_v4.py 2020-06-16 13:14:54 +0000
@@ -12,7 +12,6 @@
12# For more information, visit madgraph.phys.ucl.ac.be and amcatnlo.web.cern.ch12# For more information, visit madgraph.phys.ucl.ac.be and amcatnlo.web.cern.ch
13#13#
14################################################################################14################################################################################
15from madgraph.iolibs.helas_call_writers import HelasCallWriter
16"""Methods and classes to export matrix elements to v4 format."""15"""Methods and classes to export matrix elements to v4 format."""
1716
18import copy17import copy
@@ -2117,7 +2116,7 @@
2117 SELECT CASE (name)2116 SELECT CASE (name)
2118 %(parameter_setup)s2117 %(parameter_setup)s
2119 CASE DEFAULT2118 CASE DEFAULT
2120 stop 12119 write(*,*) 'no parameter matching'
2121 END SELECT2120 END SELECT
21222121
2123 return2122 return
@@ -2185,13 +2184,9 @@
21852184
2186 params = self.get_model_parameter(self.model)2185 params = self.get_model_parameter(self.model)
2187 parameter_setup =[]2186 parameter_setup =[]
2188 for p in params:2187 for key, var in params.items():
2189 if p.startswith('mdl_'):
2190 short_p = p[4:]
2191 else:
2192 short_p = p
2193 parameter_setup.append(' CASE ("%s")\n %s = value' 2188 parameter_setup.append(' CASE ("%s")\n %s = value'
2194 % (short_p, p))2189 % (key, var))
21952190
2196 formatting = {'python_information':'\n'.join(info), 2191 formatting = {'python_information':'\n'.join(info),
2197 'smatrixhel': '\n'.join(text),2192 'smatrixhel': '\n'.join(text),
@@ -2211,9 +2206,17 @@
2211 def get_model_parameter(self, model):2206 def get_model_parameter(self, model):
2212 """ returns all the model parameter2207 """ returns all the model parameter
2213 """2208 """
2209 params = {}
2210 for p in model.get('parameters')[('external',)]:
2211 name = p.name
2212 nopref = name[4:] if name.startswith('mdl_') else name
2213 params[nopref] = name
2214
2215 block = p.lhablock
2216 lha = '_'.join([str(i) for i in p.lhacode])
2217 params['%s_%s' % (block, lha)] = name
22142218
2215 params = [p.name for p in model.get('parameters')[('external',)]]2219 return params
2216 return params
2217 2220
2218 2221
2219 2222
22202223
=== modified file 'madgraph/loop/loop_exporters.py'
--- madgraph/loop/loop_exporters.py 2019-06-05 11:03:48 +0000
+++ madgraph/loop/loop_exporters.py 2020-06-16 13:14:54 +0000
@@ -297,6 +297,33 @@
297 RETURN297 RETURN
298 END298 END
299299
300 subroutine CHANGE_PARA(name, value)
301 implicit none
302CF2PY intent(in) :: name
303CF2PY intent(in) :: value
304
305 character*512 name
306 double precision value
307
308 include '../Source/MODEL/input.inc'
309 include '../Source/MODEL/coupl.inc'
310
311 SELECT CASE (name)
312 %(parameter_setup)s
313 CASE DEFAULT
314 write(*,*) 'no parameter matching'
315 END SELECT
316
317 return
318 end
319
320 subroutine update_all_coup()
321 implicit none
322 call coup()
323 return
324 end
325
326
300 SUBROUTINE SET_MADLOOP_PATH(PATH)327 SUBROUTINE SET_MADLOOP_PATH(PATH)
301C Routine to set the path of the folder 'MadLoop5_resources' to MadLoop328C Routine to set the path of the folder 'MadLoop5_resources' to MadLoop
302 CHARACTER(512) PATH329 CHARACTER(512) PATH
@@ -377,6 +404,14 @@
377 #close the function404 #close the function
378 if min_nexternal != max_nexternal:405 if min_nexternal != max_nexternal:
379 text.append('endif')406 text.append('endif')
407
408 params = self.get_model_parameter(self.model)
409 parameter_setup =[]
410 for key, var in params.items():
411 parameter_setup.append(' CASE ("%s")\n %s = value'
412 % (key, var))
413
414
380415
381 formatting = {'python_information':'\n'.join(info), 416 formatting = {'python_information':'\n'.join(info),
382 'smatrixhel': '\n'.join(text),417 'smatrixhel': '\n'.join(text),
@@ -385,7 +420,8 @@
385 'pdgs': ','.join([str(pdg[i]) if i<len(pdg) else '0' 420 'pdgs': ','.join([str(pdg[i]) if i<len(pdg) else '0'
386 for i in range(max_nexternal) \421 for i in range(max_nexternal) \
387 for pdg in allids]),422 for pdg in allids]),
388 'prefix':'\',\''.join(allprefix)423 'prefix':'\',\''.join(allprefix),
424 'parameter_setup': '\n'.join(parameter_setup),
389 }425 }
390 426
391 427

Subscribers

People subscribed via source and target branches

to all changes: