Esempio n. 1
0
        def _plot(self, gridFile, solutionFile=None, aggregatesFile=None, connectionsFile=None):
            config = DOUGConfigParser(name='Plot parameters')
            config.addConfig(self.app.config)
            configPanel = ConfigPanel(self.app.root, config, title="Plot configuration",
                                      sectionNames=['gridplot'])
            
            if not configPanel.done:
                return
            
            LOG.info("Show plot of %s", gridFile)

            gridplot=os.path.join(os.path.dirname(sys.argv[0]), 'gridplot.py')
            args = [gridplot, gridplot]
            args.extend(['--gin', gridFile])
            if solutionFile:
                args.extend(['--sin', solutionFile])
            if aggregatesFile:
                args.extend(['--ain', aggregatesFile])
            if connectionsFile:
                args.extend(['--cin', connectionsFile])

            plargs=[]
            device=config.get('gridplot', 'device')
            plargs.extend(['-dev', device])
            aggr=config.get('gridplot', 'aggr', None)
            if aggr:
                args.extend(['--aggr', aggr])
            args.extend(['--plplot', " ".join(plargs)])

            LOG.debug("Spawn '%s'", args)
            os.spawnvp(os.P_NOWAIT, 'python', args)
Esempio n. 2
0
class DOUGExecution:

    def __init__(self, config, dougControls=None):
        self.workdir = os.path.abspath(config.get('doug', 'workdir'))
        self.config = DOUGConfigParser(name='DOUG execution', basedir=self.workdir)
        # default config
        self.config.addConfig(getDefaultConfig())
        self.config.addControlFile(getDefaultControlFile(self.workdir))
        
        # copy controls from control file
        if dougControls is not None:
            self.config.addControlFile(dougControls)
        # copy config
        self.config.addConfig(config)

        # output or other files, exception grabs it on exit
        self.files = []

        # how many test results are using this test, files are deleted only after last free() call
        self._inUse = 0
        self.preserveOutput = self.config.getboolean("doug", "preserveOutput")
        self.result = DOUGConfigParser(self.config.defaults(), basedir=self.workdir)
        self.result.add_section('doug-result')

    def setUp(self):
        LOG.debug("Preparing testing environment")
        self.workdir = self.workdir
        if os.path.isdir(self.workdir):
            self.workdirExisted = True
        else:
            self.workdirExisted = False
            os.mkdir(self.workdir)
            LOG.debug("Working directory %s created" % self.workdir)

        try:
            # create control file
            self.testctrlfname = os.path.abspath(os.path.join(self.workdir, 'DOUG-exec.ctl'))
            controlFile = self.config.getControlFile(self.testctrlfname)
            controlFile.save(self.testctrlfname)
            self.files.append((self.testctrlfname, "Control file"))

            # run mpiboot
            mpibootname = self.config.get("doug", "mpiboot")
            outfilename = self.config.get("doug", "mpiboot-outfilename")
            errfilename = self.config.get("doug", "mpiboot-errfilename")

            if mpibootname:
                LOG.debug("Setting up mpi")
                mpiboot = subprocess.Popen("%s > %s 2> %s" % (mpibootname, outfilename, errfilename), shell=True)
                res = mpiboot.wait()
                if res:
                    raise ScriptException("Error running %s (%d)"
                                          "inspect output files (%s, %s) for error description."
                                          % (mpibootname, res, outfilename, errfilename))
        except:
            self._clean()
            raise
        
            
    def tearDown(self):
        try:
            mpihaltname = self.config.get("doug", "mpihalt")
            if mpihaltname:
                outfilename = self.config.get("doug", "mpihalt-outfilename")
                errfilename = self.config.get("doug", "mpihalt-errfilename")          
                LOG.debug("Shutting down mpi")
                mpihalt = subprocess.Popen("%s > %s 2> %s" % (mpihaltname, outfilename, errfilename), shell=True)
                import time
                time.sleep(4) # lamhalt <=7.1.1 does not wait until whole universe is shut down
                res = mpihalt.wait()
                if res:
                    LOG.warn("Error running %s (%d)"
                         "inspect output files (%s, %s) for error description."
                         % (mpihaltname, res, outfilename, errfilename))
        except Exception, e:
            LOG.warn("Exception running mpihalt: %s" % e)
Esempio n. 3
0
    def _solve(self, initialConfig, problemArchive):
        try:
            config = DOUGConfigParser(name='DOUG execution parameters')
            config.addConfigContents(doug.execution.getDefaultConfigContents())
            config.addConfig(initialConfig)
            
            suffix = time.strftime('--run-%y%m%d-%H%M%S')
            config.set('DEFAULT', 'doug-workdir', problemArchive.directoryName+suffix)
            config.set('DEFAULT', 'doug-datadir', problemArchive.directoryName)

            matrixFiles = problemArchive.getFiles('Matrix')
            if matrixFiles:
                matrixFile='%(doug-datadir)s/'+matrixFiles[0]
            else:
                matrixFile=''
            config.set('doug-controls', 'assembled_mtx_file', matrixFile)
                           
            rhsFiles = problemArchive.getFiles('Vector/RHS')
            if rhsFiles:
                rhsFile='%(doug-datadir)s/'+rhsFiles[0]
            else:
                rhsFile=''
            config.set('doug-controls', 'assembled_rhs_file', rhsFile)

            # change configurations
            configPanel = ConfigPanel(self.frame, config, title="DOUG configuration",
                                      sectionNames=['DEFAULT', 'doug', 'doug-controls'])
            if not configPanel.done:
                return
            
            # run            
            execution = doug.execution.DOUGExecution(config)
            try:
                archive = Archive(problemArchive.name+suffix,
                                  directoryName=problemArchive.directoryName+suffix,
                                  archiveType='solution')
                archive.info.set('general','problem-name',problemArchive.name)
                archive.info.addConfig(execution.config)

                archive.info.set('doug-execution', 'date', time.strftime('%y-%m-%d %H:%M:%S'), addsection=True)
                
                resultConfig=execution.run()
                archive.info.addConfig(resultConfig)

                if archive.info.has_option('doug-result', 'solutionfile'):
                    archive.setFileType(archive.info.get('doug-result', 'solutionfile'), 'Vector/Solution')
                if archive.info.has_option('doug-result', 'errorfile'):
                    archive.setFileType(archive.info.get('doug-result', 'errorfile'), 'Text/Error')
                if archive.info.has_option('doug-result', 'outputfile'):
                    archive.setFileType(archive.info.get('doug-result', 'outputfile'), 'Text/Output')
                if archive.info.has_option('doug-result', 'fineaggrsfile'):
                    archive.setFileType(archive.info.get('doug-result', 'fineaggrsfile'), 'Aggregates/Fine')
                if archive.info.has_option('doug-result', 'coarseaggrsfile'):
                    archive.setFileType(archive.info.get('doug-result', 'coarseaggrsfile'), 'Aggregates/Coarse')
                if archive.info.has_option('doug-result', 'profilefile'):
                    archive.setFileType(archive.info.get('doug-result', 'profilefile'), 'Text/Profile')
                    
            finally:
                self.app.addArchive(archive)
        except(Exception), e:
            LOG.error(e, exc_info=e)