示例#1
0
    def generate_production(self):
        """production"""
        
        if os.path.exists('%s/Cards/proc_card_mg5.dat' % self.path):
            proc_path = '%s/Cards/proc_card_mg5.dat' % self.path
            if 'p p > e+ ve [QCD]' in open(proc_path).read():
                if files.is_uptodate(proc_path, min_time=self.loadtime):
                    if hasattr(self, 'cmd_line'):
                        self.cmd_line.exec_cmd('quit')
                    os.system('rm -rf %s/RunWeb' % self.path)
                    os.system('rm -rf %s/Events/run_01' % self.path)
                    os.system('rm -rf %s/Events/run_01_LO' % self.path)                        
                    self.cmd_line = NLOCmd.aMCatNLOCmdShell(me_dir= '%s' % self.path)
                    self.cmd_line.run_cmd('set automatic_html_opening False --no_save')

                    card = open('%s/Cards/run_card_default.dat' % self.path).read()
                    self.assertTrue( '10000 = nevents' in card)
                    card = card.replace('10000 = nevents', '100 = nevents')
                    open('%s/Cards/run_card_default.dat' % self.path, 'w').write(card)
                    os.system('cp  %s/Cards/run_card_default.dat %s/Cards/run_card.dat'% (self.path, self.path))
                    os.system('cp  %s/Cards/shower_card_default.dat %s/Cards/shower_card.dat'% (self.path, self.path))
                    
                    return

        cmd = os.getcwd()
        self.generate(['p p > e+ ve [QCD]'], 'loop_sm')
        self.assertEqual(cmd, os.getcwd())
        self.do('quit')
        card = open('%s/Cards/run_card_default.dat' % self.path).read()
        self.assertTrue( '10000 = nevents' in card)
        card = card.replace('10000 = nevents', '100 = nevents')
        open('%s/Cards/run_card.dat' % self.path, 'w').write(card)
    def generate_production(self):
        """production"""
        
        if os.path.exists('%s/Cards/proc_card_mg5.dat' % self.path):
            proc_path = '%s/Cards/proc_card_mg5.dat' % self.path
            if 'p p > e+ ve [QCD]' in open(proc_path).read():
                if files.is_uptodate(proc_path, min_time=self.loadtime):
                    if hasattr(self, 'cmd_line'):
                        self.cmd_line.exec_cmd('quit')
                    os.system('rm -rf %s/RunWeb' % self.path)
                    os.system('rm -rf %s/Events/run_01' % self.path)
                    os.system('rm -rf %s/Events/run_01_LO' % self.path)                        
                    self.cmd_line = NLOCmd.aMCatNLOCmdShell(me_dir= '%s' % self.path)
                    self.cmd_line.run_cmd('set automatic_html_opening False --no_save')

                    card = open('%s/Cards/run_card_default.dat' % self.path).read()
                    self.assertTrue( '10000 = nevents' in card)
                    card = card.replace('10000 = nevents', '100 = nevents')
                    open('%s/Cards/run_card_default.dat' % self.path, 'w').write(card)
                    os.system('cp  %s/Cards/run_card_default.dat %s/Cards/run_card.dat'% (self.path, self.path))
                    os.system('cp  %s/Cards/shower_card_default.dat %s/Cards/shower_card.dat'% (self.path, self.path))
                    
                    return

        cmd = os.getcwd()
        self.generate(['p p > e+ ve [QCD]'], 'loop_sm')
        self.assertEqual(cmd, os.getcwd())
        self.do('quit')
        card = open('%s/Cards/run_card_default.dat' % self.path).read()
        self.assertTrue( '10000 = nevents' in card)
        card = card.replace('10000 = nevents', '100 = nevents')
        open('%s/Cards/run_card.dat' % self.path, 'w').write(card)
    def do_launch(self, line):
        """Main commands: Ask for editing the parameters and then execute the code (NLO or aMC@(N)LO)
        """
        old_cwd = os.getcwd()
        argss = self.split_arg(line)
        # check argument validity and normalise argument
        (options, argss) = _launch_parser.parse_args(argss)
        options = options.__dict__
        self.check_launch(argss, options)
        if not os.path.isdir(os.path.join(os.getcwd(), argss[0], 'Events')):
            self.do_switch('ML5')
            return mg_interface.MadGraphCmd.do_launch(self,line)
#        if self.options['automatic_html_opening']:
#            misc.open_file(os.path.join(os.getcwd(), argss[0], 'crossx.html'))
#            self.options['automatic_html_opening'] = False

        if options['interactive']:
            if hasattr(self, 'do_shell'):
                ME = run_interface.aMCatNLOCmdShell(me_dir=argss[0], options=self.options)
            else:
                ME = run_interface.aMCatNLOCmd(me_dir=argss[0],options=self.options)
                ME.pass_in_web_mode()
            # transfer interactive configuration
            config_line = [l for l in self.history if l.strip().startswith('set')]
            for line in config_line:
                ME.exec_cmd(line)
            stop = self.define_child_cmd_interface(ME)                
            return stop

        ext_program = launch_ext.aMCatNLOLauncher(argss[0], self, run_mode=argss[1], **options)
        ext_program.run()
class TestMECmdShell(unittest.TestCase):
    """this treats all the command not related to MG_ME"""

    loadtime = time.time()

    def setUp(self):

        self.tmpdir = tempfile.mkdtemp(prefix='amc')
        self.tmpdir = "/tmp/"
        # if we need to keep the directory for testing purpose
        #if os.path.exists(self.tmpdir):
        #    shutil.rmtree(self.tmpdir)
        #os.mkdir(self.tmpdir)
        self.path = pjoin(self.tmpdir, 'MGProcess')

    def tearDown(self):
        pass
        #shutil.rmtree(self.tmpdir)

    def generate(self, process, model, multiparticles=[]):
        """Create a process"""
        def run_cmd(cmd):
            interface.exec_cmd(cmd,
                               errorhandling=False,
                               printcmd=False,
                               precmd=True,
                               postcmd=True)

        try:
            shutil.rmtree(self.path)
        except Exception, error:
            pass

        interface = MGCmd.MasterCmd()

        run_cmd('import model %s' % model)
        for multi in multiparticles:
            run_cmd('define %s' % multi)
        if isinstance(process, str):
            run_cmd('generate %s' % process)
        else:
            for p in process:
                run_cmd('add process %s' % p)
        if logging.getLogger('madgraph').level <= 20:
            stdout = None
            stderr = None
        #else:
        #    devnull =open(os.devnull,'w')
        #    stdout=devnull
        #    stderr=devnull

        interface.onecmd('output %s -f' % self.path)
        proc_card = open('%s/Cards/proc_card_mg5.dat' % self.path).read()
        self.assertTrue('generate' in proc_card or 'add process' in proc_card)
        run_cmd('set automatic_html_opening False --no_save')
        self.cmd_line = NLOCmd.aMCatNLOCmdShell(me_dir='%s' % self.path)
        self.cmd_line.run_cmd('set automatic_html_opening False --no_save')
        self.assertFalse(self.cmd_line.options['automatic_html_opening'])
示例#5
0
    def launch_program(self):
        """launch the main program"""

        # Check for number of cores if multicore mode
        mode = str(self.cluster)
        nb_node = 1
        if mode == "2":
            import multiprocessing
            max_node = multiprocessing.cpu_count()
            if max_node == 1:
                logger.warning(
                    'Only one core is detected on your computer! Pass in single machine'
                )
                self.cluster = 0
                self.launch_program()
                return
            elif max_node == 2:
                nb_node = 2
            elif not self.force:
                nb_node = self.ask('How many cores do you want to use?',
                                   max_node, range(2, max_node + 1))
            else:
                nb_node = max_node

        import madgraph.interface.amcatnlo_run_interface as run_int

        if hasattr(self, 'shell') and self.shell:
            usecmd = run_int.aMCatNLOCmdShell(me_dir=self.running_dir,
                                              options=self.cmd_int.options)
        else:
            usecmd = run_int.aMCatNLOCmd(me_dir=self.running_dir,
                                         options=self.cmd_int.options)

        #Check if some configuration were overwritten by a command. If so use it
        set_cmd = [
            l for l in self.cmd_int.history if l.strip().startswith('set')
        ]
        all_options = usecmd.options_configuration.keys(
        ) + usecmd.options_madgraph.keys() + usecmd.options_madevent.keys()
        for line in set_cmd:
            arg = line.split()
            if arg[1] not in all_options:
                continue
            misc.sprint(line)
            try:
                usecmd.exec_cmd(line)
            except Exception, error:
                misc.sprint('Command %s fails with msg: %s'%(str(line), \
                                                                    str(error)))
                pass
示例#6
0
 def launch_program(self):
     """launch the main program"""
     
     # Check for number of cores if multicore mode
     mode = str(self.cluster)
     nb_node = 1
     if mode == "2":
         import multiprocessing
         max_node = multiprocessing.cpu_count()
         if max_node == 1:
             logger.warning('Only one core is detected on your computer! Pass in single machine')
             self.cluster = 0
             self.launch_program()
             return
         elif max_node == 2:
             nb_node = 2
         elif not self.force:
             nb_node = self.ask('How many cores do you want to use?', max_node, range(2,max_node+1))
         else:
             nb_node=max_node
             
     import madgraph.interface.amcatnlo_run_interface as run_int
     if hasattr(self, 'shell'):
         usecmd = run_int.aMCatNLOCmdShell(me_dir=self.running_dir, options = self.cmd_int.options)
     else:
         usecmd = run_int.aMCatNLOCmd(me_dir=self.running_dir, options = self.cmd_int.options)
     
     #Check if some configuration were overwritten by a command. If so use it    
     set_cmd = [l for l in self.cmd_int.history if l.strip().startswith('set')]
     all_options = usecmd.options_configuration.keys() +  usecmd.options_madgraph.keys() + usecmd.options_madevent.keys()
     for line in set_cmd:
         arg = line.split()
         if arg[1] not in all_options:
             continue
         misc.sprint(line)
         try:
             usecmd.exec_cmd(line)
         except Exception, error:
             misc.sprint('Command %s fails with msg: %s'%(str(line), \
                                                                 str(error)))
             pass
示例#7
0
    def generate(self, process, model, multiparticles=[]):
        """Create a process"""
        def run_cmd(cmd):
            interface.exec_cmd(cmd,
                               errorhandling=False,
                               printcmd=False,
                               precmd=True,
                               postcmd=True)

        try:
            shutil.rmtree(self.path)
        except Exception as error:
            pass

        interface = MGCmd.MasterCmd()
        interface.no_notification()

        run_cmd('import model %s' % model)
        for multi in multiparticles:
            run_cmd('define %s' % multi)
        if isinstance(process, str):
            run_cmd('generate %s' % process)
        else:
            for p in process:
                run_cmd('add process %s' % p)
        if logging.getLogger('madgraph').level <= 20:
            stdout = None
            stderr = None
        #else:
        #    devnull =open(os.devnull,'w')
        #    stdout=devnull
        #    stderr=devnull

        interface.onecmd('output %s -f' % self.path)
        proc_card = open('%s/Cards/proc_card_mg5.dat' % self.path).read()
        self.assertTrue('generate' in proc_card or 'add process' in proc_card)
        run_cmd('set automatic_html_opening False --no_save')
        self.cmd_line = NLOCmd.aMCatNLOCmdShell(me_dir='%s' % self.path)
        self.cmd_line.no_notification()
        self.cmd_line.run_cmd('set automatic_html_opening False --no_save')
        self.assertFalse(self.cmd_line.options['automatic_html_opening'])
示例#8
0
    def launch_program(self):
        """launch the main program"""

        # Check for number of cores if multicore mode
        mode = str(self.cluster)
        nb_node = 1
        if mode == "2":
            import multiprocessing
            max_node = multiprocessing.cpu_count()
            if max_node == 1:
                logger.warning(
                    'Only one core is detected on your computer! Pass in single machine'
                )
                self.cluster = 0
                self.launch_program()
                return
            elif max_node == 2:
                nb_node = 2
            elif not self.force:
                nb_node = self.ask('How many cores do you want to use?',
                                   max_node, list(range(2, max_node + 1)))
            else:
                nb_node = max_node

        import madgraph.interface.amcatnlo_run_interface as run_int

        if hasattr(self, 'shell') and self.shell:
            usecmd = run_int.aMCatNLOCmdShell(me_dir=self.running_dir,
                                              options=self.cmd_int.options)
        else:
            usecmd = run_int.aMCatNLOCmd(me_dir=self.running_dir,
                                         options=self.cmd_int.options)

        #Check if some configuration were overwritten by a command. If so use it
        set_cmd = [
            l for l in self.cmd_int.history if l.strip().startswith('set')
        ]
        all_options = list(usecmd.options_configuration.keys()) + list(
            usecmd.options_madgraph.keys()) + list(
                usecmd.options_madevent.keys())
        for line in set_cmd:
            arg = line.split()
            if arg[1] not in all_options:
                continue
            try:
                usecmd.exec_cmd(line)
            except Exception as error:
                misc.sprint('Command %s fails with msg: %s'%(str(line), \
                                                                    str(error)))
                pass
        launch = self.cmd_int.define_child_cmd_interface(usecmd,
                                                         interface=False)
        #launch.me_dir = self.running_dir
        option_line = ' '.join([' --%s' % opt for opt in self.options.keys() \
                if self.options[opt] and not opt in ['cluster', 'multicore', 'name', 'appl_start_grid','shell']])
        if self.options['name']:
            option_line += ' --name %s' % self.options['name']
        if 'appl_start_grid' in self.options and self.options[
                'appl_start_grid']:
            option_line += ' --appl_start_grid %s' % self.options[
                'appl_start_grid']
        command = 'launch ' + self.run_mode + ' ' + option_line

        if mode == "1":
            command += " -c"
        elif mode == "2":
            command += " -m"
            usecmd.nb_core = int(nb_node)
        try:
            os.remove('ME5_debug')
        except:
            pass
        launch.run_cmd(command)
        launch.run_cmd('quit')