def localInputAndChecks(self, xmlNode): """ Method to read the portion of the xml input that belongs to all gradient based optimizer only and initialize some stuff based on the inputs got @ In, xmlNode, xml.etree.ElementTree.Element, Xml element node @ Out, None """ convergence = xmlNode.find("convergence") self.gradDict['normalize'] = utils.interpretBoolean(self.paramDict.get("normalize",self.gradDict['normalize'])) if convergence is not None: gradientThreshold = convergence.find("gradientThreshold") try: if gradientThreshold is not None and self.gradDict['normalize']: self.raiseAWarning("Conflicting inputs: gradientThreshold and normalized gradient have been inputed. These two intpus are conflicting. ") self.gradientNormTolerance = float(gradientThreshold.text) if gradientThreshold is not None else self.gradientNormTolerance except ValueError: self.raiseAnError(ValueError, 'Not able to convert <gradientThreshold> into a float')
def __readRunInfo(self,xmlNode,runInfoSkip,xmlFilename): """ Method that reads the xml input file for the RunInfo block @ In, xmlNode, xml.etree.Element, the xml node that belongs to Simulation @ In, runInfoSkip, string, the runInfo step to skip @ In, xmlFilename, string, xml input file name @ Out, None """ if 'verbosity' in xmlNode.attrib.keys(): self.verbosity = xmlNode.attrib['verbosity'] self.raiseAMessage('Global verbosity level is "',self.verbosity,'"',verbosity='quiet') for element in xmlNode: if element.tag in runInfoSkip: self.raiseAWarning("Skipped element ",element.tag) elif element.tag == 'printInput': text = element.text.strip() if element.text is not None else '' #extension fixing if len(text) >= 4 and text[-4:].lower() == '.xml': text = text[:-4] # if the user asked to not print input instead of leaving off tag, respect it if text.lower() in utils.stringsThatMeanFalse(): self.runInfoDict['printInput'] = False # if the user didn't provide a name, provide a default elif len(text)<1: self.runInfoDict['printInput'] = 'duplicated_input.xml' # otherwise, use the user-provided name else: self.runInfoDict['printInput'] = text+'.xml' elif element.tag == 'WorkingDir': # first store the cwd, the "CallDir" self.runInfoDict['CallDir'] = os.getcwd() # then get the requested "WorkingDir" tempName = element.text if '~' in tempName: tempName = os.path.expanduser(tempName) if os.path.isabs(tempName): self.runInfoDict['WorkingDir'] = tempName elif "runRelative" in element.attrib: self.runInfoDict['WorkingDir'] = os.path.abspath(tempName) else: if xmlFilename == None: self.raiseAnError(IOError,'Relative working directory requested but xmlFilename is None.') # store location of the input xmlDirectory = os.path.dirname(os.path.abspath(xmlFilename)) self.runInfoDict['InputDir'] = xmlDirectory rawRelativeWorkingDir = element.text.strip() # working dir is file location + relative working dir self.runInfoDict['WorkingDir'] = os.path.join(xmlDirectory,rawRelativeWorkingDir) utils.makeDir(self.runInfoDict['WorkingDir']) elif element.tag == 'maxQueueSize': try: self.runInfoDict['maxQueueSize'] = int(element.text) except ValueError: self.raiseAnError('Value give for RunInfo.maxQueueSize could not be converted to integer: {}'.format(element.text)) elif element.tag == 'RemoteRunCommand': tempName = element.text if '~' in tempName: tempName = os.path.expanduser(tempName) if os.path.isabs(tempName): self.runInfoDict['RemoteRunCommand'] = tempName else: self.runInfoDict['RemoteRunCommand'] = os.path.abspath(os.path.join(self.runInfoDict['FrameworkDir'],tempName)) elif element.tag == 'NodeParameter': self.runInfoDict['NodeParameter'] = element.text.strip() elif element.tag == 'MPIExec': self.runInfoDict['MPIExec'] = element.text.strip() elif element.tag == 'JobName': self.runInfoDict['JobName' ] = element.text.strip() elif element.tag == 'ParallelCommand': self.runInfoDict['ParallelCommand' ] = element.text.strip() elif element.tag == 'queueingSoftware': self.runInfoDict['queueingSoftware' ] = element.text.strip() elif element.tag == 'ThreadingCommand': self.runInfoDict['ThreadingCommand' ] = element.text.strip() elif element.tag == 'NumThreads': self.runInfoDict['NumThreads' ] = int(element.text) elif element.tag == 'totalNumCoresUsed': self.runInfoDict['totalNumCoresUsed' ] = int(element.text) elif element.tag == 'NumMPI': self.runInfoDict['NumMPI' ] = int(element.text) elif element.tag == 'internalParallel': self.runInfoDict['internalParallel' ] = utils.interpretBoolean(element.text) elif element.tag == 'batchSize': self.runInfoDict['batchSize' ] = int(element.text) elif element.tag.lower() == 'maxqueuesize': self.runInfoDict['maxQueueSize' ] = int(element.text) elif element.tag == 'MaxLogFileSize': self.runInfoDict['MaxLogFileSize' ] = int(element.text) elif element.tag == 'precommand': self.runInfoDict['precommand' ] = element.text elif element.tag == 'postcommand': self.runInfoDict['postcommand' ] = element.text elif element.tag == 'deleteOutExtension': self.runInfoDict['deleteOutExtension'] = element.text.strip().split(',') elif element.tag == 'delSucLogFiles' : if element.text.lower() in utils.stringsThatMeanTrue(): self.runInfoDict['delSucLogFiles' ] = True else: self.runInfoDict['delSucLogFiles' ] = False elif element.tag == 'logfileBuffer': self.runInfoDict['logfileBuffer'] = utils.convertMultipleToBytes(element.text.lower()) elif element.tag == 'clusterParameters': self.runInfoDict['clusterParameters'].extend(splitCommand(element.text)) #extend to allow adding parameters at different points. elif element.tag == 'mode' : self.runInfoDict['mode'] = element.text.strip().lower() #parallel environment if self.runInfoDict['mode'] in self.__modeHandlerDict: self.__modeHandler = self.__modeHandlerDict[self.runInfoDict['mode']](self.messageHandler) self.__modeHandler.XMLread(element) else: self.raiseAnError(IOError,"Unknown mode "+self.runInfoDict['mode']) elif element.tag == 'expectedTime': self.runInfoDict['expectedTime' ] = element.text.strip() elif element.tag == 'Sequence': for stepName in element.text.split(','): self.stepSequenceList.append(stepName.strip()) elif element.tag == 'DefaultInputFile': self.runInfoDict['DefaultInputFile'] = element.text.strip() elif element.tag == 'CustomMode' : modeName = element.text.strip() modeClass = element.attrib["class"] modeFile = element.attrib["file"] #XXX This depends on if the working directory has been set yet. # So switching the order of WorkingDir and CustomMode can # cause different results. modeFile = modeFile.replace("%BASE_WORKING_DIR%",self.runInfoDict['WorkingDir']) modeFile = modeFile.replace("%FRAMEWORK_DIR%",self.runInfoDict['FrameworkDir']) modeDir, modeFilename = os.path.split(modeFile) if modeFilename.endswith(".py"): modeModulename = modeFilename[:-3] else: modeModulename = modeFilename os.sys.path.append(modeDir) module = __import__(modeModulename) if modeName in self.__modeHandlerDict: self.raiseAWarning("duplicate mode definition " + modeName) self.__modeHandlerDict[modeName] = module.__dict__[modeClass] else: self.raiseAnError(IOError,'RunInfo element "'+element.tag +'" unknown!')