~maddevelopers/mg5amcnlo/color_ordering

« back to all changes in this revision

Viewing changes to madgraph/madevent/gen_ximprove.py

  • Committer: olivier-mattelaer
  • Date: 2021-02-21 11:03:42 UTC
  • mfrom: (50.85.73 madgraph5)
  • Revision ID: olivier-mattelaer-20210221110342-wn2nvdefctey5e0k
merge up to 2.8.0 --not python3 compatible

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
"""
19
19
from __future__ import division
20
20
 
 
21
from __future__ import absolute_import
21
22
import collections
22
23
import os
23
24
import glob
28
29
import shutil
29
30
import stat
30
31
import sys
 
32
from six.moves import range
 
33
from six.moves import zip
31
34
 
32
35
try:
33
36
    import madgraph
151
154
            #compile gensym
152
155
            self.cmd.compile(['gensym'], cwd=Pdir)
153
156
            if not os.path.exists(pjoin(Pdir, 'gensym')):
154
 
                raise Exception, 'Error make gensym not successful'  
 
157
                raise Exception('Error make gensym not successful')  
155
158
            
156
159
            # Launch gensym
157
160
            p = misc.Popen(['./gensym'], stdout=subprocess.PIPE, 
158
161
                                 stderr=subprocess.STDOUT, cwd=Pdir)
159
162
            #sym_input = "%(points)d %(iterations)d %(accuracy)f \n" % self.opts
160
 
            (stdout, _) = p.communicate('')
161
 
            
 
163
            (stdout, _) = p.communicate(''.encode())
 
164
            stdout = stdout.decode('ascii')
162
165
            if os.path.exists(pjoin(self.me_dir,'error')):
163
166
                files.mv(pjoin(self.me_dir,'error'), pjoin(Pdir,'ajob.no_ps.log'))
164
167
                P_zero_result.append(subdir)
181
184
                        continue
182
185
                    else:
183
186
                        if done:
184
 
                            raise Exception, 'Parsing error in gensym: %s' % stdout 
 
187
                            raise Exception('Parsing error in gensym: %s' % stdout) 
185
188
                        job_list[Pdir] = l.split()        
186
189
                        done = True
187
190
                if not done:
188
 
                    raise Exception, 'Parsing error in gensym: %s' % stdout
 
191
                    raise Exception('Parsing error in gensym: %s' % stdout)
189
192
                     
190
193
            self.cmd.compile(['madevent'], cwd=Pdir)
191
194
            if to_submit:
222
225
                for G in to_resub:
223
226
                    try:
224
227
                        shutil.rmtree(pjoin(P, 'G%s' % G))
225
 
                    except Exception, error:
 
228
                    except Exception as error:
226
229
                        misc.sprint(error)
227
230
                        pass
228
231
            misc.sprint(to_resub) 
246
249
                for path, dirs in job_list.items():
247
250
                    self.submit_to_cluster({path:dirs})
248
251
                return
249
 
            path, value = job_list.items()[0]
 
252
            path, value = list(job_list.items())[0]
250
253
            nexternal = self.cmd.proc_characteristics['nexternal']
251
254
            current = open(pjoin(path, "nexternal.inc")).read()
252
255
            ext = re.search(r"PARAMETER \(NEXTERNAL=(\d+)\)", current).group(1)
288
291
           This is the old mode which is still usefull in single core"""
289
292
     
290
293
        # write the template file for the parameter file   
291
 
        self.write_parameter(parralelization=False, Pdirs=job_list.keys())
 
294
        self.write_parameter(parralelization=False, Pdirs=list(job_list.keys()))
292
295
        
293
296
        
294
297
        # launch the job with the appropriate grouping
347
350
            self.lastoffset[(Pdir, G)] = 0 
348
351
        
349
352
        # resubmit the new jobs            
350
 
        for i in xrange(int(nb_job)):
 
353
        for i in range(int(nb_job)):
351
354
            name = "G%s_%s" % (G,i+1)
352
355
            self.lastoffset[(Pdir, G)] += 1
353
356
            offset = self.lastoffset[(Pdir, G)]            
415
418
            need_submit = False
416
419
        elif self.cmd.opts['accuracy'] < 0:
417
420
            #check for luminosity
418
 
            raise Exception, "Not Implemented"
 
421
            raise Exception("Not Implemented")
419
422
        elif self.abscross[(Pdir,G)] == 0:
420
423
            need_submit = False 
421
424
        else:   
621
624
            path = pjoin(Pdir, "G%s_%s" % (G, i+1))
622
625
            try: 
623
626
                os.remove(pjoin(path, 'grid_information'))
624
 
            except OSError, oneerror:
 
627
            except OSError as oneerror:
625
628
                if oneerror.errno != 2:
626
629
                    raise
627
630
        return grid_calculator, cross, error
643
646
             logger.warning(msg%(G,EPS_fraction))
644
647
        elif EPS_fraction > 0.01:
645
648
             logger.critical((msg%(G,EPS_fraction)).replace('might', 'can'))
646
 
             raise Exception, (msg%(G,EPS_fraction)).replace('might', 'can')
 
649
             raise Exception((msg%(G,EPS_fraction)).replace('might', 'can'))
647
650
    
648
651
    def get_current_axsec(self):
649
652
        
801
804
        """Choose in which type of refine we want to be"""
802
805
 
803
806
        if cmd.proc_characteristics['loop_induced']:
804
 
            return super(gen_ximprove, cls).__new__(gen_ximprove_share, cmd, opt)
 
807
            return super(gen_ximprove, cls).__new__(gen_ximprove_share)
805
808
        elif gen_ximprove.format_variable(cmd.run_card['gridpack'], bool):
806
 
            return super(gen_ximprove, cls).__new__(gen_ximprove_gridpack, cmd, opt)
 
809
            return super(gen_ximprove, cls).__new__(gen_ximprove_gridpack)
807
810
        elif cmd.run_card["job_strategy"] == 2:
808
 
            return super(gen_ximprove, cls).__new__(gen_ximprove_share, cmd, opt)
 
811
            return super(gen_ximprove, cls).__new__(gen_ximprove_share)
809
812
        else:
810
 
            return super(gen_ximprove, cls).__new__(gen_ximprove_v4, cmd, opt)
 
813
            return super(gen_ximprove, cls).__new__(gen_ximprove_v4)
811
814
            
812
815
            
813
816
    def __init__(self, cmd, opt=None):
878
881
                targettype = type(getattr(self, key))
879
882
                setattr(self, key, self.format_variable(value, targettype, key))
880
883
            else:
881
 
                raise Exception, '%s not define' % key
 
884
                raise Exception('%s not define' % key)
882
885
                        
883
886
            
884
887
        # special treatment always do outside the loop to avoid side effect
906
909
        logger.info('Effective Luminosity %s pb^-1', goal_lum)
907
910
        
908
911
        all_channels = sum([list(P) for P in self.results],[])
909
 
        all_channels.sort(cmp= lambda x,y: 1 if y.get('luminosity') - \
910
 
                                                x.get('luminosity') > 0 else -1) 
 
912
        all_channels.sort(key= lambda x:x.get('luminosity'), reverse=True) 
911
913
                          
912
914
        to_refine = []
913
915
        for C in all_channels:
1613
1615
    max_request_event = 1e12         # split jobs if a channel if it needs more than that 
1614
1616
    max_event_in_iter = 4000
1615
1617
    min_event_in_iter = 500
1616
 
    combining_job = sys.maxint
 
1618
    combining_job = sys.maxsize
1617
1619
    gen_events_security = 1.00
1618
1620
 
1619
1621
    def __new__(cls, *args, **opts):