Merge lp:~maddevelopers/mg5amcnlo/limit_process_size into lp:~madteam/mg5amcnlo/trunk

Proposed by Olivier Mattelaer
Status: Merged
Merge reported by: Olivier Mattelaer
Merged at revision: not available
Proposed branch: lp:~maddevelopers/mg5amcnlo/limit_process_size
Merge into: lp:~madteam/mg5amcnlo/trunk
Diff against target: 175 lines (+61/-8)
4 files modified
madgraph/core/base_objects.py (+18/-5)
madgraph/core/diagram_generation.py (+8/-1)
madgraph/interface/cmd_interface.py (+7/-1)
tests/unit_tests/core/test_base_objects.py (+28/-1)
To merge this branch: bzr merge lp:~maddevelopers/mg5amcnlo/limit_process_size
Reviewer Review Type Date Requested Status
Johan Alwall (community) Needs Information
Review via email: mp+52781@code.launchpad.net

Description of the change

- limit process-size to 80 character. (avoid fortran problem)
- load automaticaly the SM if the model is not define in the define command.
(needed if a proc_card_v5 start with define)

To post a comment you must log in.
Revision history for this message
Johan Alwall (johan-alwall) wrote :

Hello Olivier,

This looks nice, except I have one question: With the "uid" an attribute of the process, can you guarantee that this is unique across different processes? I would have expected to have it as a static variable (since the whole problem is combining different processes with different excluded particles but the same initial and final state).

review: Needs Information
Revision history for this message
Olivier Mattelaer (olivier-mattelaer) wrote :

Indeed, another possibility whould be to use a global.
Here I choose to initialize the uid before the export. (with assign_uid)
Then I'm sure that the uid is indeed unique.

I always prefer to minimize the use of global variable. But indeed this might be a more elegant solution.

def assign_uid(self):
80 + """ assign a unique identification to all process of the Amplitude
81 + present in the AmplitudeList"""
82 +
83 + for i, amp in enumerate(self):
84 + amp['process'].set('uid', i)

Revision history for this message
Johan Alwall (johan-alwall) wrote :

Ah, that is a nice solution, sorry I missed that. Thanks for the clarification!

Johan

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'madgraph/core/base_objects.py'
2--- madgraph/core/base_objects.py 2011-01-26 13:23:54 +0000
3+++ madgraph/core/base_objects.py 2011-03-09 23:08:48 +0000
4@@ -1385,6 +1385,7 @@
5 self['model'] = Model()
6 # Optional number to identify the process
7 self['id'] = 0
8+ self['uid'] = 0 # should be a uniq id number
9 # Required s-channels are given as a list of id lists. Only
10 # diagrams with all s-channels in any of the lists are
11 # allowed. This enables generating e.g. Z/gamma as s-channel
12@@ -1412,7 +1413,7 @@
13 if not isinstance(value, Model):
14 raise self.PhysicsObjectError, \
15 "%s is not a valid Model object" % str(value)
16- if name == 'id':
17+ if name in ['id', 'uid']:
18 if not isinstance(value, int):
19 raise self.PhysicsObjectError, \
20 "Process id %s is not an integer" % repr(value)
21@@ -1637,7 +1638,7 @@
22 # Remove last space
23 return mystr[:-1]
24
25- def shell_string(self):
26+ def shell_string(self, schannel=True, forbid=True):
27 """Returns process as string with '~' -> 'x', '>' -> '_',
28 '+' -> 'p' and '-' -> 'm', including process number,
29 intermediate s-channels and forbidden particles"""
30@@ -1655,7 +1656,7 @@
31 mystr = mystr + '_'
32 # Add required s-channels
33 if self['required_s_channels'] and \
34- self['required_s_channels'][0]:
35+ self['required_s_channels'][0] and schannel:
36 mystr += "_or_".join(["".join([self['model'].\
37 get('particle_dict')[req_id].get_name() \
38 for req_id in id_list]) \
39@@ -1668,7 +1669,7 @@
40 prevleg = leg
41
42 # Check for forbidden particles
43- if self['forbidden_particles']:
44+ if self['forbidden_particles'] and forbid:
45 mystr = mystr + '_no_'
46 for forb_id in self['forbidden_particles']:
47 forbpart = self['model'].get('particle_dict')[forb_id]
48@@ -1684,7 +1685,19 @@
49 mystr = mystr.replace(' ', '')
50
51 for decay in self.get('decay_chains'):
52- mystr = mystr + "_" + decay.shell_string()
53+ mystr = mystr + "_" + decay.shell_string(schannel,forbid)
54+
55+ # Too long name are problematic so restrict them to a maximal of 80 char
56+ if len(mystr) > 76:
57+ if schannel and forbid:
58+ return self.shell_string(True, False)+ '-%s' % self['uid']
59+ elif schannel:
60+ return self.shell_string(False, False)+'-%s' % self['uid']
61+ else:
62+ return mystr[:76]+'-%s' % self['uid']
63+
64+
65+
66
67 return mystr
68
69
70=== modified file 'madgraph/core/diagram_generation.py'
71--- madgraph/core/diagram_generation.py 2010-12-19 03:57:07 +0000
72+++ madgraph/core/diagram_generation.py 2011-03-09 23:08:48 +0000
73@@ -623,7 +623,14 @@
74 """Test if object obj is a valid Amplitude for the list."""
75
76 return isinstance(obj, Amplitude)
77-
78+
79+ def assign_uid(self):
80+ """ assign a unique identification to all process of the Amplitude
81+ present in the AmplitudeList"""
82+
83+ for i, amp in enumerate(self):
84+ amp['process'].set('uid', i)
85+
86 #===============================================================================
87 # DecayChainAmplitude
88 #===============================================================================
89
90=== modified file 'madgraph/interface/cmd_interface.py'
91--- madgraph/interface/cmd_interface.py 2011-01-27 12:30:18 +0000
92+++ madgraph/interface/cmd_interface.py 2011-03-09 23:08:48 +0000
93@@ -637,7 +637,8 @@
94 raise self.InvalidCmd('\"define\" command requires symbols \"=\" at the second position')
95
96 if not self._curr_model:
97- raise self.InvalidCmd("No particle list currently active, please import a model first")
98+ logger.info('No model currently active. Try with the Standard Model')
99+ self.do_import('model sm')
100
101 if self._curr_model['particles'].find_name(args[0]):
102 raise MadGraph5Error("label %s is a particle name in this model\n\
103@@ -1422,6 +1423,9 @@
104 amp.nice_string_processes()
105 logger.warning(warning)
106
107+ # assign a unique id to all amplitude
108+ self._curr_amps.assign_uid()
109+
110 # Reset _done_export, since we have new process
111 self._done_export = False
112
113@@ -1788,6 +1792,8 @@
114 # Generate processes
115 myproc = diagram_generation.MultiProcess(myprocdef)
116 self._curr_amps = myproc.get('amplitudes')
117+ # assign a unique id to all amplitude
118+ self._curr_amps.assign_uid()
119 cpu_time2 = time.time()
120
121 nprocs = len(self._curr_amps)
122
123=== modified file 'tests/unit_tests/core/test_base_objects.py'
124--- tests/unit_tests/core/test_base_objects.py 2011-01-17 15:12:08 +0000
125+++ tests/unit_tests/core/test_base_objects.py 2011-03-09 23:08:48 +0000
126@@ -1405,6 +1405,7 @@
127 'orders':{'QCD':5, 'QED':1},
128 'model':self.mymodel,
129 'id': 1,
130+ 'uid':0,
131 'required_s_channels':[],
132 'forbidden_s_channels':[],
133 'forbidden_particles':[],
134@@ -1524,7 +1525,32 @@
135 goal_str = "2_cc_cxcc"
136
137 self.assertEqual(goal_str, self.myprocess.shell_string())
138-
139+
140+ def test_long_shell_string(self):
141+ """Test Process nice_string representation"""
142+
143+ goal_str = '1_cc_ccc_c_cccc_c_cccc_c_cccc_c_cccc_c_cccc_c_cccc-4'
144+
145+ decay = copy.copy(self.myprocess)
146+ decay.set('legs', copy.deepcopy(decay.get('legs')))
147+ decay.get('legs')[1].set('state', True)
148+ decay.set('is_decay_chain', True)
149+ decay.set('orders', {})
150+ decay.set('forbidden_particles',[3])
151+ decay2 = copy.copy(decay)
152+ decay3 = copy.copy(decay)
153+ decay4 = copy.copy(decay)
154+ decay5 = copy.copy(decay)
155+ decay6 = copy.copy(decay)
156+ self.myprocess.set('uid',4)
157+ self.myprocess.set('decay_chains', base_objects.ProcessList([decay]))
158+ decay.set('decay_chains', base_objects.ProcessList([decay2]))
159+ decay2.set('decay_chains', base_objects.ProcessList([decay3]))
160+ decay3.set('decay_chains', base_objects.ProcessList([decay4]))
161+ decay4.set('decay_chains', base_objects.ProcessList([decay5]))
162+ decay5.set('decay_chains', base_objects.ProcessList([decay6]))
163+ self.assertEqual(goal_str, self.myprocess.shell_string())
164+
165 #===============================================================================
166 # ProcessDefinitionTest
167 #===============================================================================
168@@ -1557,6 +1583,7 @@
169 'orders':{'QCD':5, 'QED':1},
170 'model':self.mymodel,
171 'id':3,
172+ 'uid':0,
173 'required_s_channels':[],
174 'forbidden_s_channels':[],
175 'forbidden_particles':[],

Subscribers

People subscribed via source and target branches