示例#1
0
    def __init__(self, filename = None, configString = None, cleanOutDir = False):
       # parallelization parameters
       # Default values, see explanations below:
        #self.name = 'Launcher'

        self._isSerial = True

        self._mergedTask = False

        configDic = {
        'useTorque' : 'False',
        'paraTorqueParams':  '-l nodes=1:ppn=1',
        'serialTorqueParams': '-l nodes=1:ppn=1',        
        'paraPrefix': '',
        'paraPostfix': '',
        'serialPrefix': '',
        'serialPostfix': '',
        'paraRemoteShell': '',
        'outdir': None
        }


        if filename == None and configString == None:
            filename = 'config.ini'

        self.setting = Setting(filename, configString)
        self.setting.section(QETask.name(self), configDic)

        self.cleanOutDir = cleanOutDir

        if self.setting.get('useTorque') == 'True':
            self.setting.set('useTorque', True)
        else:
            self.setting.set('useTorque', False)

        if self.setting.get('useTorque'):
            if self.isSerial():
                self._torque = QETorque(self.setting.get('serialTorqueParams'))
            else:
                self._torque = QETorque(self.setting.get('paraTorqueParams'))
示例#2
0
    def __init__(self, filename, cleanOutDir=None):
        # parallelization parameters
        # Default values, see explanations below:
        self.name = 'Launcher'
        configDic = {
            'useTorque': 'False',
            'torqueResourceList': '-l nodes=1:ppn=1',
            'paraPrefix': '',
            'paraPostfix': ''
        }
        self.setting = Setting(filename)
        self.setting.section(self.name, configDic)

        self.cleanOutDir = cleanOutDir

        if self.setting.useTorque == 'True':
            self.setting.useTorque = True
        else:
            self.setting.useTorque = False

        if self.setting.useTorque:
            self._torque = QETorque(self.setting.torqueResourceList)
示例#3
0
    def __init__(self, filename = None, configString = None, cleanOutDir = None):
       # parallelization parameters
       # Default values, see explanations below:
        #self.name = 'Launcher'
        configDic = {
        'useTorque' : 'False',
        'torqueResourceList': '-l nodes=1:ppn=1',
        'paraPrefix': '',
        'paraPostfix': ''
        }
        self.setting = Setting(filename, configString)
        self.setting.section(QETask.name(self), configDic)

        self.cleanOutDir = cleanOutDir

        if self.setting.useTorque == 'True':
            self.setting.useTorque = True
        else:
            self.setting.useTorque = False

        if self.setting.useTorque:
            self._torque = QETorque(self.setting.torqueResourceList)
示例#4
0
    def readSetting(self, filename = None, configString = None, \
                                                            sectionName = None):
        """
        Initializes setting class
        """
        
        configDic = {
        'useTorque' : 'False',
        'paraTorqueParams':  '-l nodes=1:ppn=1',
        'serialTorqueParams': '-l nodes=1:ppn=1',        
        'paraPrefix': '',
        'paraPostfix': '',
        'serialPrefix': '',
        'serialPostfix': '',
        'paraRemoteShell': '',
        'outdir': None
        }        
        
       # if filename == None and configString == None:
       #     configString = ''
       #     filename = 'config.ini'
        if filename == None and configString == None:
            self.setting = Setting(configString = "")
        else:
            self.setting = Setting(filename, configString)
            
        self.setting.section(QETask.name(self), configDic)
        

        if self.setting.get('useTorque') == 'True':
            self.setting.set('useTorque', True)
        else:
            self.setting.set('useTorque', False)

        if self.setting.get('useTorque'):
            if self.isSerial():
                self._torque = QETorque(self.setting.get('serialTorqueParams'))
            else:
                self._torque = QETorque(self.setting.get('paraTorqueParams'))
        
        # **********************************************************************        
        # Task subclass  specific part:        

        if hasattr(self, '_type'):
            
            defaultModName = 'QESInput'
            
            modname = self._inputConstructor
            
            #Input = __import__("qeparser." + modname.lower(), globals(), \
            #                    locals(), [modname], -1)  
            
            mod_cmd = "from qeparser.%s import %s as Input"%(modname.lower(), modname)
            exec(mod_cmd)
            from qeparser.qeoutput import QEOutput
                                          
            if sectionName == None:
                name = self.name()
            else:
                name = sectionName
    
            self.setting.section(name, self._configDic)
        
            
            # add pointer to setting for input filenames synchronization 
            #self.input._setting = self.setting
            self.output = QEOutput(self.setting, type = self._type)
                    
            args = {
                   'setting': self.setting,                                                
                   }
            if modname == defaultModName:
                args['type'] = self._type
            if filename != None or configString != None:
                self.input = Input(**args)     
                self.syncSetting()
            else:
                # add parse:
                args['parse'] = False
                self.input = Input( **args)     
示例#5
0
class QETask(object):
    """
    Base abstract class for 'TaskNameTask' family of classes. It also provides
    the interface to launch tasks

    All user defined tasks should be derived from this class

    setting -- provides access to parallel environment and QE input/output files
    """
    def __init__(self, filename = None, configString = None, cleanOutDir = False):
       # parallelization parameters
       # Default values, see explanations below:
        #self.name = 'Launcher'

        self._isSerial = True

        self._mergedTask = False
        
        self.cleanOutDir = cleanOutDir

        QETask.readSetting(self, filename, configString)


    def readSetting(self, filename = None, configString = None, \
                                                            sectionName = None):
        """
        Initializes setting class
        """
        
        configDic = {
        'useTorque' : 'False',
        'paraTorqueParams':  '-l nodes=1:ppn=1',
        'serialTorqueParams': '-l nodes=1:ppn=1',        
        'paraPrefix': '',
        'paraPostfix': '',
        'serialPrefix': '',
        'serialPostfix': '',
        'paraRemoteShell': '',
        'outdir': None
        }        
        
       # if filename == None and configString == None:
       #     configString = ''
       #     filename = 'config.ini'
        if filename == None and configString == None:
            self.setting = Setting(configString = "")
        else:
            self.setting = Setting(filename, configString)
            
        self.setting.section(QETask.name(self), configDic)
        

        if self.setting.get('useTorque') == 'True':
            self.setting.set('useTorque', True)
        else:
            self.setting.set('useTorque', False)

        if self.setting.get('useTorque'):
            if self.isSerial():
                self._torque = QETorque(self.setting.get('serialTorqueParams'))
            else:
                self._torque = QETorque(self.setting.get('paraTorqueParams'))
        
        # **********************************************************************        
        # Task subclass  specific part:        

        if hasattr(self, '_type'):
            
            defaultModName = 'QESInput'
            
            modname = self._inputConstructor
            
            #Input = __import__("qeparser." + modname.lower(), globals(), \
            #                    locals(), [modname], -1)  
            
            mod_cmd = "from qeparser.%s import %s as Input"%(modname.lower(), modname)
            exec(mod_cmd)
            from qeparser.qeoutput import QEOutput
                                          
            if sectionName == None:
                name = self.name()
            else:
                name = sectionName
    
            self.setting.section(name, self._configDic)
        
            
            # add pointer to setting for input filenames synchronization 
            #self.input._setting = self.setting
            self.output = QEOutput(self.setting, type = self._type)
                    
            args = {
                   'setting': self.setting,                                                
                   }
            if modname == defaultModName:
                args['type'] = self._type
            if filename != None or configString != None:
                self.input = Input(**args)     
                self.syncSetting()
            else:
                # add parse:
                args['parse'] = False
                self.input = Input( **args)     


    def name(self):
        return 'Launcher'


    def parse(self):
        
        self.syncSetting()


    def syncSetting(self):
        """
        Will syncronise QE input file with class Setting for given task (QE input
        files may contain multiple input/ouput file names  definitions which
        can be overriden in this method)
        """
        pass


    def cleanOutputDir(self, cleanOutDir = None):
        """
        Cleans the output directory (directory, where large files, used
        for calculation are stored, can be for example  'temp/' or 'scratch/')
        """
#        import shutil
        if cleanOutDir == None:
            cleanOutDir = self.cleanOutDir
#        if cleanOutDir == None:
#            raise Exception('outDir can not be cleaned, since it was not defined')



        if cleanOutDir:
            outDir = self.setting.get('outdir')
            os.system(self.setting.paraRemoteShell + ' rm -r -f ' + outDir)
            os.system(self.setting.paraRemoteShell + ' mkdir ' + outDir)
#        if self.setting.useTorque:
#
#        else:
#            shutil.rmtree(cleanOutDir)
#            os.mkdir(cleanOutDir)
    
#    def cmdLine(self):
#        """
#        returns command string of a given task
#        """
#        return self._cmdStr

    def launch(self, cleanOutDir = False):
        """
        Parses input. Launches task. Parses output.
        """
#        if cleanOutDir == None:
#            cleanOutDir = self.cleanOutDir
#        if cleanOutDir != None:
#            self.cleanOutputDir(cleanOutDir)
        #self.input.parse()
        self.syncSetting() # sync setting with QE input file
        self.input.save()
        self.cleanOutputDir(cleanOutDir)
        self._run()
        self.output.parse(parserList = 'all')

    def setSerial(self):
        #self._serialThroughMPI = serialThroughMPI
        self._isSerial = True


    def setParallel(self):
        self._isSerial = False

    def isSerial(self):
        if self._isSerial:
            return True
        else:
            return False

    def getPrefix(self) :
        if self.isSerial():
 #           if self._isSerialThroughMPI():
 #               return ''
 #           else:
            return self.setting.get('serialPrefix')
        else:
            return self.setting.get('paraPrefix')


    def getPostfix(self):
        if self.isSerial():
            return self.setting.get('serialPostfix')
        else:
            return self.setting.get('paraPostfix')


    def isMerged(self):
        return self._mergedTask


    def _initCmdLineParams(self):
        self._inp = '-inp'
        self._devnul = '< /dev/null'
        if self.isSerial():
            self._inp = '<'
            self._devnul = ''


#    def _isSerialThroughMPI(self):
#        if self.isSerial():
#            if self._serialThroughMPI:
#                return True
#            else:
#                return False


    def _check(self, x):
        """
        Will check the exit status of the program to be executed
        """
        signal = x & 0xFF
        exitcode = (x >> 8) & 0xFF
        if exitcode != 0:
            raise Exception("Task " + self.name() + " crashed: check your \
settings!\n" + "Command string: " + self.cmdLine())

    def _run(self):
        if os.path.exists('CRASH'):
            os.remove('CRASH')

        outdir = self.setting.get('outdir')
        if outdir != None:
            os.system(self.setting.paraRemoteShell + ' mkdir -p ' + outdir)

        if self.setting.get('useTorque'):
            if self.isSerial():
                if self.setting.get('serialPrefix') == '':
                    self._check(os.system(self.cmdLine()))
                else:
                    self._torque.serial(self.cmdLine(), torqueParams = self.setting.serialTorqueParams)
            else:
                self._torque.serial(self.cmdLine(), torqueParams = self.setting.paraTorqueParams)
        else:
            self._check(os.system(self.cmdLine()))

#        if self.setting.paraPrefix != '' and self.setting.paraPrefix in self.cmdLine():
#            if self.setting.useTorque:
#                self._torque.serial(self.cmdLine())
#            else:
#                self._check(os.system(self.cmdLine()))
#        else:
#            self._check(os.system(self.cmdLine()))
        if os.path.exists('CRASH'):
            raise Exception("Task " + self.name() + " crashed: 'CRASH' file was discovered")

    def _getCmdLine(self, executable, input, output):
        self._initCmdLineParams()
        return  self.getPrefix() + ' ' + executable + " " + self.getPostfix() + \
                ' ' + self._inp + ' ' +  self.setting.get(input) + ' > ' + \
                self.setting.get(output) + self._devnul
                
                
    def _setSetiingInputOutput(self, configDic, filename = None, configString = None, sectionName = None):
        """
        Helper method for readSetting()
        """
        if sectionName == None:
            name = self.name()
        else:
            name = sectionName

        self.setting.section(name, configDic)
        self.input = PWInput( self.setting.pwInput ) #self.setting.get('pwInput') )
        # add pointer to setting for input filenames synchronization 
        self.input._setting = self.setting
        self.output = QEOutput(self.setting, type='pw')
        
        if filename != None or configString != None:
            self.syncSetting()        
示例#6
0
    def readSetting(self, filename = None, configString = None, \
                                                            sectionName = None):
        """
        Initializes setting class
        """

        configDic = {
            'useTorque': 'False',
            'paraTorqueParams': '-l nodes=1:ppn=1',
            'serialTorqueParams': '-l nodes=1:ppn=1',
            'paraPrefix': '',
            'paraPostfix': '',
            'serialPrefix': '',
            'serialPostfix': '',
            'paraRemoteShell': '',
            'outdir': None
        }

        # if filename == None and configString == None:
        #     configString = ''
        #     filename = 'config.ini'
        if filename == None and configString == None:
            self.setting = Setting(configString="")
        else:
            self.setting = Setting(filename, configString)

        self.setting.section(QETask.name(self), configDic)

        if self.setting.get('useTorque') == 'True':
            self.setting.set('useTorque', True)
        else:
            self.setting.set('useTorque', False)

        if self.setting.get('useTorque'):
            if self.isSerial():
                self._torque = QETorque(self.setting.get('serialTorqueParams'))
            else:
                self._torque = QETorque(self.setting.get('paraTorqueParams'))

        # **********************************************************************
        # Task subclass  specific part:

        if hasattr(self, '_type'):

            defaultModName = 'QESInput'

            modname = self._inputConstructor

            #Input = __import__("qeparser." + modname.lower(), globals(), \
            #                    locals(), [modname], -1)

            mod_cmd = "from qeparser.%s import %s as Input" % (modname.lower(),
                                                               modname)
            exec(mod_cmd)
            from qeparser.qeoutput import QEOutput

            if sectionName == None:
                name = self.name()
            else:
                name = sectionName

            self.setting.section(name, self._configDic)

            # add pointer to setting for input filenames synchronization
            #self.input._setting = self.setting
            self.output = QEOutput(self.setting, type=self._type)

            args = {
                'setting': self.setting,
            }
            if modname == defaultModName:
                args['type'] = self._type
            if filename != None or configString != None:
                self.input = Input(**args)
                self.syncSetting()
            else:
                # add parse:
                args['parse'] = False
                self.input = Input(**args)
示例#7
0
class QETask(object):
    """
    Base abstract class for 'TaskNameTask' family of classes. It also provides
    the interface to launch tasks

    All user defined tasks should be derived from this class

    setting -- provides access to parallel environment and QE input/output files
    """
    def __init__(self, filename=None, configString=None, cleanOutDir=False):
        # parallelization parameters
        # Default values, see explanations below:
        #self.name = 'Launcher'

        self._isSerial = True

        self._mergedTask = False

        self.cleanOutDir = cleanOutDir

        QETask.readSetting(self, filename, configString)


    def readSetting(self, filename = None, configString = None, \
                                                            sectionName = None):
        """
        Initializes setting class
        """

        configDic = {
            'useTorque': 'False',
            'paraTorqueParams': '-l nodes=1:ppn=1',
            'serialTorqueParams': '-l nodes=1:ppn=1',
            'paraPrefix': '',
            'paraPostfix': '',
            'serialPrefix': '',
            'serialPostfix': '',
            'paraRemoteShell': '',
            'outdir': None
        }

        # if filename == None and configString == None:
        #     configString = ''
        #     filename = 'config.ini'
        if filename == None and configString == None:
            self.setting = Setting(configString="")
        else:
            self.setting = Setting(filename, configString)

        self.setting.section(QETask.name(self), configDic)

        if self.setting.get('useTorque') == 'True':
            self.setting.set('useTorque', True)
        else:
            self.setting.set('useTorque', False)

        if self.setting.get('useTorque'):
            if self.isSerial():
                self._torque = QETorque(self.setting.get('serialTorqueParams'))
            else:
                self._torque = QETorque(self.setting.get('paraTorqueParams'))

        # **********************************************************************
        # Task subclass  specific part:

        if hasattr(self, '_type'):

            defaultModName = 'QESInput'

            modname = self._inputConstructor

            #Input = __import__("qeparser." + modname.lower(), globals(), \
            #                    locals(), [modname], -1)

            mod_cmd = "from qeparser.%s import %s as Input" % (modname.lower(),
                                                               modname)
            exec(mod_cmd)
            from qeparser.qeoutput import QEOutput

            if sectionName == None:
                name = self.name()
            else:
                name = sectionName

            self.setting.section(name, self._configDic)

            # add pointer to setting for input filenames synchronization
            #self.input._setting = self.setting
            self.output = QEOutput(self.setting, type=self._type)

            args = {
                'setting': self.setting,
            }
            if modname == defaultModName:
                args['type'] = self._type
            if filename != None or configString != None:
                self.input = Input(**args)
                self.syncSetting()
            else:
                # add parse:
                args['parse'] = False
                self.input = Input(**args)

    def name(self):
        return 'Launcher'

    def parse(self):

        self.syncSetting()

    def syncSetting(self):
        """
        Will syncronise QE input file with class Setting for given task (QE input
        files may contain multiple input/ouput file names  definitions which
        can be overriden in this method)
        """
        pass

    def cleanOutputDir(self, cleanOutDir=None):
        """
        Cleans the output directory (directory, where large files, used
        for calculation are stored, can be for example  'temp/' or 'scratch/')
        """
        #        import shutil
        if cleanOutDir == None:
            cleanOutDir = self.cleanOutDir
#        if cleanOutDir == None:
#            raise Exception('outDir can not be cleaned, since it was not defined')

        if cleanOutDir:
            outDir = self.setting.get('outdir')
            os.system(self.setting.paraRemoteShell + ' rm -r -f ' + outDir)
            os.system(self.setting.paraRemoteShell + ' mkdir ' + outDir)
#        if self.setting.useTorque:
#
#        else:
#            shutil.rmtree(cleanOutDir)
#            os.mkdir(cleanOutDir)

#    def cmdLine(self):
#        """
#        returns command string of a given task
#        """
#        return self._cmdStr

    def launch(self, cleanOutDir=False):
        """
        Parses input. Launches task. Parses output.
        """
        #        if cleanOutDir == None:
        #            cleanOutDir = self.cleanOutDir
        #        if cleanOutDir != None:
        #            self.cleanOutputDir(cleanOutDir)
        #self.input.parse()
        self.syncSetting()  # sync setting with QE input file
        self.input.save()
        self.cleanOutputDir(cleanOutDir)
        self._run()
        self.output.parse(parserList='all')

    def setSerial(self):
        #self._serialThroughMPI = serialThroughMPI
        self._isSerial = True

    def setParallel(self):
        self._isSerial = False

    def isSerial(self):
        if self._isSerial:
            return True
        else:
            return False

    def getPrefix(self):
        if self.isSerial():
            #           if self._isSerialThroughMPI():
            #               return ''
            #           else:
            return self.setting.get('serialPrefix')
        else:
            return self.setting.get('paraPrefix')

    def getPostfix(self):
        if self.isSerial():
            return self.setting.get('serialPostfix')
        else:
            return self.setting.get('paraPostfix')

    def isMerged(self):
        return self._mergedTask

    def _initCmdLineParams(self):
        self._inp = '-inp'
        self._devnul = '< /dev/null'
        if self.isSerial():
            self._inp = '<'
            self._devnul = ''

#    def _isSerialThroughMPI(self):
#        if self.isSerial():
#            if self._serialThroughMPI:
#                return True
#            else:
#                return False

    def _check(self, x):
        """
        Will check the exit status of the program to be executed
        """
        signal = x & 0xFF
        exitcode = (x >> 8) & 0xFF
        if exitcode != 0:
            raise Exception("Task " + self.name() + " crashed: check your \
settings!\n" + "Command string: " + self.cmdLine())

    def _run(self):
        if os.path.exists('CRASH'):
            os.remove('CRASH')

        outdir = self.setting.get('outdir')
        if outdir != None:
            os.system(self.setting.paraRemoteShell + ' mkdir -p ' + outdir)

        if self.setting.get('useTorque'):
            if self.isSerial():
                if self.setting.get('serialPrefix') == '':
                    self._check(os.system(self.cmdLine()))
                else:
                    self._torque.serial(
                        self.cmdLine(),
                        torqueParams=self.setting.serialTorqueParams)
            else:
                self._torque.serial(self.cmdLine(),
                                    torqueParams=self.setting.paraTorqueParams)
        else:
            self._check(os.system(self.cmdLine()))


#        if self.setting.paraPrefix != '' and self.setting.paraPrefix in self.cmdLine():
#            if self.setting.useTorque:
#                self._torque.serial(self.cmdLine())
#            else:
#                self._check(os.system(self.cmdLine()))
#        else:
#            self._check(os.system(self.cmdLine()))
        if os.path.exists('CRASH'):
            raise Exception("Task " + self.name() +
                            " crashed: 'CRASH' file was discovered")

    def _getCmdLine(self, executable, input, output):
        self._initCmdLineParams()
        return  self.getPrefix() + ' ' + executable + " " + self.getPostfix() + \
                ' ' + self._inp + ' ' +  self.setting.get(input) + ' > ' + \
                self.setting.get(output) + self._devnul

    def _setSettingInputOutput(self,
                               configDic,
                               filename=None,
                               configString=None,
                               sectionName=None):
        """
        Helper method for readSetting()
        """
        if sectionName == None:
            name = self.name()
        else:
            name = sectionName

        self.setting.section(name, configDic)
        self.input = PWInput(
            self.setting.pwInput)  #self.setting.get('pwInput') )
        # add pointer to setting for input filenames synchronization
        self.input._setting = self.setting
        self.output = QEOutput(self.setting, type='pw')

        if filename != None or configString != None:
            self.syncSetting()
示例#8
0
class QETask(object):
    """
    Base abstract class for 'TaskNameTask' family of classes. It also provides
    the interface to loumch tasks

    All user defined tasks should be derived from this class

    setting -- provides access to parallel environment and QE input/output files
    """
    def __init__(self, filename, cleanOutDir=None):
        # parallelization parameters
        # Default values, see explanations below:
        self.name = 'Launcher'
        configDic = {
            'useTorque': 'False',
            'torqueResourceList': '-l nodes=1:ppn=1',
            'paraPrefix': '',
            'paraPostfix': ''
        }
        self.setting = Setting(filename)
        self.setting.section(self.name, configDic)

        self.cleanOutDir = cleanOutDir

        if self.setting.useTorque == 'True':
            self.setting.useTorque = True
        else:
            self.setting.useTorque = False

        if self.setting.useTorque:
            self._torque = QETorque(self.setting.torqueResourceList)

    def _check(self, x):
        """
        Will check the exit status of the program to be executed
        """
        signal = x & 0xFF
        exitcode = (x >> 8) & 0xFF
        if exitcode != 0:
            raise Exception("Task " + self.name +
                            " crashed: check your settings" +
                            "Command string:" + self._cmdStr)

    def _run(self):
        if os.path.exists('CRASH'):
            os.remove('CRASH')
        if self.setting.paraPrefix != '' and self.setting.paraPrefix in self._cmdStr:
            if self.setting.useTorque:
                self._torque.serial(self._cmdStr)
            else:
                self._check(os.system(self._cmdStr))
        else:
            self._check(os.system(self._cmdStr))
        if os.path.exists('CRASH'):
            raise Exception("Task " + self.name +
                            " crashed: 'CRASH' file was discovered")

    def cleanOutputDir(self, cleanOutDir=None):
        """
        Cleans the output directory (directory, where large files, used
        for calculation are stored, can be for example  'temp/' or 'scratch/')
        """
        import shutil
        if cleanOutDir == None:
            cleanOutDir = self.cleanOutDir
        if cleanOutDir == None:
            raise Exception(
                'outDir can not be cleaned, since it was not defined')
        if self.setting.useTorque:
            os.system('bpsh -a rm -r -f ' + cleanOutDir)
            os.system('bpsh -a mkdir ' + cleanOutDir)
        else:
            shutil.rmtree(cleanOutDir)
            os.mkdir(cleanOutDir)

    def cmdLine(self):
        """
        returns command string of a given task
        """
        return self._cmdStr

    def launch(self, cleanOutDir=None):
        """
        Parses input. Launches task. Parses output.
        """
        if cleanOutDir == None:
            cleanOutDir = self.cleanOutDir
        if cleanOutDir != None:
            self.cleanOutputDir(cleanOutDir)
        self.input.parse()
        self._run()
        self.output.parse(parserList='all')
示例#9
0
class QETask(object):
    """
    Base abstract class for 'TaskNameTask' family of classes. It also provides
    the interface to loumch tasks

    All user defined tasks should be derived from this class

    setting -- provides access to parallel environment and QE input/output files
    """
    def __init__(self, filename = None, configString = None, cleanOutDir = False):
       # parallelization parameters
       # Default values, see explanations below:
        #self.name = 'Launcher'

        self._isSerial = True

        configDic = {
        'useTorque' : 'False',
        'paraTorqueParams':  '-l nodes=1:ppn=1',
        'serialTorqueParams': '-l nodes=1:ppn=1',        
        'paraPrefix': '',
        'paraPostfix': '',
        'serialPrefix': '',
        'serialPostfix': '',
        'paraRemoteShell': '',
        'outdir': None
        }

        if filename == None and configString == None:
            filename = 'config.ini'

        self.setting = Setting(filename, configString)
        self.setting.section(QETask.name(self), configDic)

        self.cleanOutDir = cleanOutDir

        if self.setting.get('useTorque') == 'True':
            self.setting.set('useTorque', True)
        else:
            self.setting.set('useTorque', False)

        if self.setting.get('useTorque'):
            if self.isSerial():
                self._torque = QETorque(self.setting.get('serialTorqueParams'))
            else:
                self._torque = QETorque(self.setting.get('paraTorqueParams'))


    def name(self):
        return 'Launcher'


    def _check(self, x):
        """
        Will check the exit status of the program to be executed
        """
        signal = x & 0xFF
        exitcode = (x >> 8) & 0xFF
        if exitcode != 0:
            raise Exception("Task " + self.name() + " crashed: check your settings" + "Command string:" + self.cmdLine())

    def _run(self):
        if os.path.exists('CRASH'):
            os.remove('CRASH')

        outdir = self.setting.get('outdir')
        if outdir != None:
            os.system(self.setting.paraRemoteShell + ' mkdir -p ' + outdir)

        if self.setting.get('useTorque'):
            if self.isSerial():
                if self.setting.get('serialPrefix') == '':
                    self._check(os.system(self.cmdLine()))
                else:
                    self._torque.serial(self.cmdLine(), torqueParams = self.setting.serialTorqueParams)
            else:
                self._torque.serial(self.cmdLine(), torqueParams = self.setting.paraTorqueParams)
        else:
            self._check(os.system(self.cmdLine()))

#        if self.setting.paraPrefix != '' and self.setting.paraPrefix in self.cmdLine():
#            if self.setting.useTorque:
#                self._torque.serial(self.cmdLine())
#            else:
#                self._check(os.system(self.cmdLine()))
#        else:
#            self._check(os.system(self.cmdLine()))
        if os.path.exists('CRASH'):
            raise Exception("Task " + self.name() + " crashed: 'CRASH' file was discovered")


    def syncSetting(self):
        """
        Will syncronise QE input file with class Setting for given task (QE input
        files may contain multiple input/ouput file names  definitions which
        can be overriden in this method)
        """
        pass


    def cleanOutputDir(self, cleanOutDir = None):
        """
        Cleans the output directory (directory, where large files, used
        for calculation are stored, can be for example  'temp/' or 'scratch/')
        """
#        import shutil
        if cleanOutDir == None:
            cleanOutDir = self.cleanOutDir
#        if cleanOutDir == None:
#            raise Exception('outDir can not be cleaned, since it was not defined')



        if cleanOutDir:
            outDir = self.setting.get('outdir')
            os.system(self.setting.paraRemoteShell + ' rm -r -f ' + outDir)
            os.system(self.setting.paraRemoteShell + ' mkdir ' + outDir)
#        if self.setting.useTorque:
#
#        else:
#            shutil.rmtree(cleanOutDir)
#            os.mkdir(cleanOutDir)
    
#    def cmdLine(self):
#        """
#        returns command string of a given task
#        """
#        return self._cmdStr

    def launch(self, cleanOutDir = False):
        """
        Parses input. Launches task. Parses output.
        """
#        if cleanOutDir == None:
#            cleanOutDir = self.cleanOutDir
#        if cleanOutDir != None:
#            self.cleanOutputDir(cleanOutDir)
        self.input.parse()
        self.syncSetting() # sync setting with QE input file
        self.input.save()
        self.cleanOutputDir(cleanOutDir)
        self._run()
        self.output.parse(parserList = 'all')

    def setSerial(self):
        #self._serialThroughMPI = serialThroughMPI
        self._isSerial = True


    def setParallel(self):
        self._isSerial = False

    def isSerial(self):
        if self._isSerial:
            return True
        else:
            return False

    def getPrefix(self) :
        if self.isSerial():
 #           if self._isSerialThroughMPI():
 #               return ''
 #           else:
            return self.setting.get('serialPrefix')
        else:
            return self.setting.get('paraPrefix')


    def getPostfix(self):
        if self.isSerial():
            return self.setting.get('serialPostfix')
        else:
            return self.setting.get('paraPostfix')

    def _initCmdLineParams(self):
        self._inp = '-inp'
        self._devnul = '< /dev/null'
        if self.isSerial():
            self._inp = '<'
            self._devnul = ''


#    def _isSerialThroughMPI(self):
#        if self.isSerial():
#            if self._serialThroughMPI:
#                return True
#            else:
#                return False


    def _getCmdLine(self, executable, input, output):
        self._initCmdLineParams()
        return  self.getPrefix() + ' ' + executable + " " + self.getPostfix() + \
                ' ' + self._inp + ' ' +  self.setting.get(input) + ' > ' + \
                self.setting.get(output) + self._devnul
示例#10
0
class QETask(object):
    """
    Base abstract class for 'TaskNameTask' family of classes. It also provides
    the interface to loumch tasks

    All user defined tasks should be derived from this class

    setting -- provides access to parallel environment and QE input/output files
    """
    def __init__(self, filename = None, configString = None, cleanOutDir = None):
       # parallelization parameters
       # Default values, see explanations below:
        #self.name = 'Launcher'
        configDic = {
        'useTorque' : 'False',
        'torqueResourceList': '-l nodes=1:ppn=1',
        'paraPrefix': '',
        'paraPostfix': ''
        }
        self.setting = Setting(filename, configString)
        self.setting.section(QETask.name(self), configDic)

        self.cleanOutDir = cleanOutDir

        if self.setting.useTorque == 'True':
            self.setting.useTorque = True
        else:
            self.setting.useTorque = False

        if self.setting.useTorque:
            self._torque = QETorque(self.setting.torqueResourceList)


    def name(self):
        return 'Launcher'


    def _check(self, x):
        """
        Will check the exit status of the program to be executed
        """
        signal = x & 0xFF
        exitcode = (x >> 8) & 0xFF
        if exitcode != 0:
            raise Exception("Task " + self.name() + " crashed: check your settings" + "Command string:" + self.cmdLine())

    def _run(self):
        if os.path.exists('CRASH'):
            os.remove('CRASH')
        if self.setting.paraPrefix != '' and self.setting.paraPrefix in self.cmdLine():
            if self.setting.useTorque:
                self._torque.serial(self.cmdLine())
            else:
                self._check(os.system(self.cmdLine()))
        else:
            self._check(os.system(self.cmdLine()))
        if os.path.exists('CRASH'):
            raise Exception("Task " + self.name() + " crashed: 'CRASH' file was discovered")


    def _syncSetting(self):
        """
        Will syncronise QE input file with class Setting for given task (QE input
        files may contain multiple input/ouput file names  definitions which
        can be overriden in this method)
        """
        pass


    def cleanOutputDir(self, cleanOutDir = None):
        """
        Cleans the output directory (directory, where large files, used
        for calculation are stored, can be for example  'temp/' or 'scratch/')
        """
        import shutil
        if cleanOutDir == None:
            cleanOutDir = self.cleanOutDir
        if cleanOutDir == None:
            raise Exception('outDir can not be cleaned, since it was not defined')
        if self.setting.useTorque:
            os.system('bpsh -a rm -r -f ' + cleanOutDir)
            os.system('bpsh -a mkdir ' + cleanOutDir)
        else:
            shutil.rmtree(cleanOutDir)
            os.mkdir(cleanOutDir)
    
#    def cmdLine(self):
#        """
#        returns command string of a given task
#        """
#        return self._cmdStr

    def launch(self, cleanOutDir = None):
        """
        Parses input. Launches task. Parses output.
        """
        if cleanOutDir == None:
            cleanOutDir = self.cleanOutDir
        if cleanOutDir != None:
            self.cleanOutputDir(cleanOutDir)
        self.input.parse()
        self._syncSetting() # sync setting with QE input file
        self.input.save()
        self._run()
        self.output.parse(parserList = 'all')
示例#11
0
class QETask(object):
    """
    Base abstract class for 'TaskNameTask' family of classes. It also provides
    the interface to loumch tasks

    All user defined tasks should be derived from this class

    setting -- provides access to parallel environment and QE input/output files
    """
    def __init__(self, filename=None, configString=None, cleanOutDir=False):
        # parallelization parameters
        # Default values, see explanations below:
        #self.name = 'Launcher'

        self._isSerial = True

        configDic = {
            'useTorque': 'False',
            'paraTorqueParams': '-l nodes=1:ppn=1',
            'serialTorqueParams': '-l nodes=1:ppn=1',
            'paraPrefix': '',
            'paraPostfix': '',
            'serialPrefix': '',
            'serialPostfix': '',
            'paraRemoteShell': '',
            'outdir': None
        }

        if filename == None and configString == None:
            filename = 'config.ini'

        self.setting = Setting(filename, configString)
        self.setting.section(QETask.name(self), configDic)

        self.cleanOutDir = cleanOutDir

        if self.setting.get('useTorque') == 'True':
            self.setting.set('useTorque', True)
        else:
            self.setting.set('useTorque', False)

        if self.setting.get('useTorque'):
            if self.isSerial():
                self._torque = QETorque(self.setting.get('serialTorqueParams'))
            else:
                self._torque = QETorque(self.setting.get('paraTorqueParams'))

    def name(self):
        return 'Launcher'

    def _check(self, x):
        """
        Will check the exit status of the program to be executed
        """
        signal = x & 0xFF
        exitcode = (x >> 8) & 0xFF
        if exitcode != 0:
            raise Exception("Task " + self.name() +
                            " crashed: check your settings" +
                            "Command string:" + self.cmdLine())

    def _run(self):
        if os.path.exists('CRASH'):
            os.remove('CRASH')

        outdir = self.setting.get('outdir')
        if outdir != None:
            os.system(self.setting.paraRemoteShell + ' mkdir -p ' + outdir)

        if self.setting.get('useTorque'):
            if self.isSerial():
                if self.setting.get('serialPrefix') == '':
                    self._check(os.system(self.cmdLine()))
                else:
                    self._torque.serial(
                        self.cmdLine(),
                        torqueParams=self.setting.serialTorqueParams)
            else:
                self._torque.serial(self.cmdLine(),
                                    torqueParams=self.setting.paraTorqueParams)
        else:
            self._check(os.system(self.cmdLine()))

#        if self.setting.paraPrefix != '' and self.setting.paraPrefix in self.cmdLine():
#            if self.setting.useTorque:
#                self._torque.serial(self.cmdLine())
#            else:
#                self._check(os.system(self.cmdLine()))
#        else:
#            self._check(os.system(self.cmdLine()))
        if os.path.exists('CRASH'):
            raise Exception("Task " + self.name() +
                            " crashed: 'CRASH' file was discovered")

    def syncSetting(self):
        """
        Will syncronise QE input file with class Setting for given task (QE input
        files may contain multiple input/ouput file names  definitions which
        can be overriden in this method)
        """
        pass

    def cleanOutputDir(self, cleanOutDir=None):
        """
        Cleans the output directory (directory, where large files, used
        for calculation are stored, can be for example  'temp/' or 'scratch/')
        """
        #        import shutil
        if cleanOutDir == None:
            cleanOutDir = self.cleanOutDir
#        if cleanOutDir == None:
#            raise Exception('outDir can not be cleaned, since it was not defined')

        if cleanOutDir:
            outDir = self.setting.get('outdir')
            os.system(self.setting.paraRemoteShell + ' rm -r -f ' + outDir)
            os.system(self.setting.paraRemoteShell + ' mkdir ' + outDir)
#        if self.setting.useTorque:
#
#        else:
#            shutil.rmtree(cleanOutDir)
#            os.mkdir(cleanOutDir)

#    def cmdLine(self):
#        """
#        returns command string of a given task
#        """
#        return self._cmdStr

    def launch(self, cleanOutDir=False):
        """
        Parses input. Launches task. Parses output.
        """
        #        if cleanOutDir == None:
        #            cleanOutDir = self.cleanOutDir
        #        if cleanOutDir != None:
        #            self.cleanOutputDir(cleanOutDir)
        self.input.parse()
        self.syncSetting()  # sync setting with QE input file
        self.input.save()
        self.cleanOutputDir(cleanOutDir)
        self._run()
        self.output.parse(parserList='all')

    def setSerial(self):
        #self._serialThroughMPI = serialThroughMPI
        self._isSerial = True

    def setParallel(self):
        self._isSerial = False

    def isSerial(self):
        if self._isSerial:
            return True
        else:
            return False

    def getPrefix(self):
        if self.isSerial():
            #           if self._isSerialThroughMPI():
            #               return ''
            #           else:
            return self.setting.get('serialPrefix')
        else:
            return self.setting.get('paraPrefix')

    def getPostfix(self):
        if self.isSerial():
            return self.setting.get('serialPostfix')
        else:
            return self.setting.get('paraPostfix')

    def _initCmdLineParams(self):
        self._inp = '-inp'
        self._devnul = '< /dev/null'
        if self.isSerial():
            self._inp = '<'
            self._devnul = ''


#    def _isSerialThroughMPI(self):
#        if self.isSerial():
#            if self._serialThroughMPI:
#                return True
#            else:
#                return False

    def _getCmdLine(self, executable, input, output):
        self._initCmdLineParams()
        return  self.getPrefix() + ' ' + executable + " " + self.getPostfix() + \
                ' ' + self._inp + ' ' +  self.setting.get(input) + ' > ' + \
                self.setting.get(output) + self._devnul