Пример #1
0
 def _handleInput(self, paramInput):
   """
     Function to handle the parsed paramInput for this class.
     @ In, paramInput, ParameterInput, the already parsed input.
     @ Out, None
   """
   self.toDo = {}
   for child in paramInput.subparts:
     tag = child.getName()
     #because percentile is strange (has an attached parameter), we address it first
     if tag in ['percentile'] + self.scalarVals + self.vectorVals:
       if 'prefix' not in child.parameterValues:
         self.raiseAnError(IOError, "No prefix is provided for node: ", tag)
       #get the prefix
       prefix = child.parameterValues['prefix']
     if tag == 'percentile':
       #get targets
       targets = set(child.value)
       #what if user didn't give any targets?
       if len(targets)<1:
         self.raiseAWarning('No targets were specified in text of <'+tag+'>!  Skipping metric...')
         continue
       #prepare storage dictionary, keys are percentiles, values are set(targets)
       if 'percentile' not in self.toDo.keys():
         self.toDo[tag] = [] # list of {'targets':(), 'prefix':str, 'percent':str}
       if 'percent' not in child.parameterValues:
         strPercent = ['5', '95']
       else:
         strPercent = [child.parameterValues['percent']]
       for reqPercent in strPercent:
         self.toDo[tag].append({'targets':set(targets),
                                'prefix':prefix,
                                'percent':reqPercent})
     elif tag in self.scalarVals:
       self.toDo[tag] = [] # list of {'targets':(), 'prefix':str}
       self.toDo[tag].append({'targets':set(child.value),
                              'prefix':prefix})
     elif tag in self.vectorVals:
       self.toDo[tag] = [] # list of {'targets':(),'features':(), 'prefix':str}
       tnode = child.findFirst('targets')
       if tnode is None:
         self.raiseAnError('Request for vector value <'+tag+'> requires a "targets" node, and none was found!')
       fnode = child.findFirst('features')
       if fnode is None:
         self.raiseAnError('Request for vector value <'+tag+'> requires a "features" node, and none was found!')
       # we're storing toDo[tag] as a list of dictionaries.  This is because the user might specify multiple
       #   nodes with the same metric (tag), but with different targets and features.  For instance, the user might
       #   want the sensitivity of A and B to X and Y, and the sensitivity of C to W and Z, but not the sensitivity
       #   of A to W.  If we didn't keep them separate, we could potentially waste a fair number of calculations.
       self.toDo[tag].append({'targets':set(tnode.value),
                              'features':set(fnode.value),
                              'prefix':prefix})
     elif tag == "biased":
       if child.value.lower() in utils.stringsThatMeanTrue():
         self.biased = True
     elif tag == "pivotParameter":
       self.pivotParameter = child.value
     else:
       self.raiseAWarning('Unrecognized node in BasicStatistics "',tag,'" has been ignored!')
   assert (len(self.toDo)>0), self.raiseAnError(IOError, 'BasicStatistics needs parameters to work on! Please check input for PP: ' + self.name)
Пример #2
0
    def genCommand(self,
                   inputFiles,
                   executable,
                   flags=None,
                   fileArgs=None,
                   preExec=None):
        """
      This method is used to retrieve the command (in tuple format) needed to launch the Code.
      This method checks a boolean environment variable called 'RAVENinterfaceCheck':
      if true, the subcodeCommand is going to be overwritten with an empty string. In this way we can check the functionality of the interface without having an executable.
      See Driver.py to understand how this Env variable is set
      @ In, inputFiles, list, List of input files (length of the list depends on the number of inputs have been added in the Step is running this code)
      @ In, executable, string, executable name with absolute path (e.g. /home/path_to_executable/code.exe)
      @ In, flags, dict, optional, dictionary containing the command-line flags the user can specify in the input (e.g. under the node < Code >< clargstype =0 input0arg =0 i0extension =0 .inp0/ >< /Code >)
      @ In, fileArgs, dict, optional, a dictionary containing the auxiliary input file variables the user can specify in the input (e.g. under the node < Code >< clargstype =0 input0arg =0 aux0extension =0 .aux0/ >< /Code >)
      @ In, preExec, string, optional, a string the command that needs to be pre-executed before the actual command here defined
      @ Out, returnCommand, tuple, tuple containing the generated command. returnCommand[0] is the command to run the code (string), returnCommand[1] is the name of the output root
    """
        if preExec is None:
            subcodeCommand, outputfileroot = self.generateCommand(
                inputFiles, executable, clargs=flags, fargs=fileArgs)
        else:
            subcodeCommand, outputfileroot = self.generateCommand(
                inputFiles,
                executable,
                clargs=flags,
                fargs=fileArgs,
                preExec=preExec)

        if os.environ.get('RAVENinterfaceCheck',
                          'False').lower() in utils.stringsThatMeanTrue():
            return [('parallel', '')], outputfileroot
        returnCommand = subcodeCommand, outputfileroot
        return returnCommand
Пример #3
0
 def setColor(self, inColor):
     """
   Allows output to screen to be colorized.
   @ In, inColor, string, boolean value
   @ Out, None
 """
     if inColor.lower() in utils.stringsThatMeanTrue():
         self.inColor = True
Пример #4
0
 def initialize(self,initDict):
   """
     Initializes basic instance attributes
     @ In, initDict, dict, dictionary of global options
     @ Out, None
   """
   self.verbosity     = initDict.get('verbosity','all').lower()
   self.callerLength  = initDict.get('callerLength',40)
   self.tagLength     = initDict.get('tagLength',30)
   self.suppressErrs  = initDict['suppressErrs'] in utils.stringsThatMeanTrue() if 'suppressErrs' in initDict.keys() else False
Пример #5
0
 def convert(cls, value):
     """
   Converts value from string to a bool.
   @ In, value, string, the value to convert
   @ Out, convert, bool, the converted value
 """
     if value.lower() in utils.stringsThatMeanTrue():
         return True
     else:
         return False
Пример #6
0
 def readSamplerInit(self, xmlNode):
     """
   This method is responsible to read only the samplerInit block in the .xml file.
   This method has been moved from the base sampler class since the samplerInit block is needed only for the MC and stratified (LHS) samplers
   @ In, xmlNode, xml.etree.ElementTree.Element, Xml element node
   @ Out, None
 """
     for child in xmlNode:
         if child.tag == "samplerInit":
             self.initSeed = randomUtils.randomIntegers(0, 2**31, self)
             for childChild in child:
                 if childChild.tag == "limit":
                     try:
                         self.limit = int(childChild.text)
                     except ValueError:
                         self.raiseAnError(
                             IOError,
                             'reading the attribute for the sampler ' +
                             self.name +
                             ' it was not possible to perform the conversion to integer for the attribute limit with value '
                             + str(childChild.text))
                 if childChild.tag == "initialSeed":
                     try:
                         self.initSeed = int(childChild.text)
                     except ValueError:
                         self.raiseAnError(
                             IOError,
                             'reading the attribute for the sampler ' +
                             self.name +
                             ' it was not possible to perform the conversion to integer for the attribute initialSeed with value '
                             + str(childChild.text))
                 elif childChild.tag == "reseedEachIteration":
                     if childChild.text.lower(
                     ) in utils.stringsThatMeanTrue():
                         self.reseedAtEachIteration = True
                 elif childChild.tag == "distInit":
                     for childChildChild in childChild:
                         NDdistData = {}
                         for childChildChildChild in childChildChild:
                             if childChildChildChild.tag == 'initialGridDisc':
                                 NDdistData[childChildChildChild.tag] = int(
                                     childChildChildChild.text)
                             elif childChildChildChild.tag == 'tolerance':
                                 NDdistData[
                                     childChildChildChild.tag] = float(
                                         childChildChildChild.text)
                             else:
                                 self.raiseAnError(
                                     IOError, 'Unknown tag ' +
                                     childChildChildChild.tag +
                                     ' .Available are: initialGridDisc and tolerance!'
                                 )
                         self.NDSamplingParams[
                             childChildChild.attrib['name']] = NDdistData
Пример #7
0
 def setTimePrint(self, msg):
     """
   Allows the code to toggle timestamp printing.
   @ In, msg, string, the string that means true or false
   @ Out, None
 """
     if msg.lower() in utils.stringsThatMeanTrue():
         self.callerLength = 40
         self.tagLength = 30
         self.printTime = True
     elif msg.lower() in utils.stringsThatMeanFalse():
         self.callerLength = 25
         self.tagLength = 15
         self.printTime = False
Пример #8
0
 def _readMoreXML(self, xmlNode):
     """
   Function to read the portion of the xml input that belongs to this
   specialized class and initialize some stuff based on the inputs received
   @ In, xmlNode, xml.etree.ElementTree.Element, Xml element node
   @ Out, None
   The text is supposed to contain the info where and which variable to change.
   In case of a code the syntax is specified by the code interface itself
 """
     if 'overwrite' in xmlNode.attrib.keys():
         if xmlNode.attrib['overwrite'].lower(
         ) in utils.stringsThatMeanTrue():
             self.overwrite = True
         else:
             self.overwrite = False
     self.localReadXML(xmlNode)
    def _handleInput(self, paramInput):
        """
      Function to handle the parsed paramInput for this class.
      @ In, paramInput, ParameterInput, the already parsed input.
      @ Out, None
    """
        for outer in paramInput.subparts:
            if outer.getName() == 'compare':
                compareGroup = ComparisonStatistics.CompareGroup()
                for child in outer.subparts:
                    if child.getName() == 'data':
                        dataName = child.value
                        splitName = dataName.split("|")
                        name, kind = splitName[:2]
                        rest = splitName[2:]
                        compareGroup.dataPulls.append([name, kind, rest])
                    elif child.getName() == 'reference':
                        # This has name=distribution
                        compareGroup.referenceData = dict(
                            child.parameterValues)
                        if "name" not in compareGroup.referenceData:
                            self.raiseAnError(
                                IOError,
                                'Did not find name in reference block')

                self.compareGroups.append(compareGroup)
            if outer.getName() == 'kind':
                self.methodInfo['kind'] = outer.value
                if 'numBins' in outer.parameterValues:
                    self.methodInfo['numBins'] = outer.parameterValues[
                        'numBins']
                if 'binMethod' in outer.parameterValues:
                    self.methodInfo['binMethod'] = outer.parameterValues[
                        'binMethod'].lower()
            if outer.getName() == 'fz':
                self.fZStats = (outer.value.lower()
                                in utils.stringsThatMeanTrue())
            if outer.getName() == 'interpolation':
                interpolation = outer.value.lower()
                if interpolation == 'linear':
                    self.interpolation = 'linear'
                elif interpolation == 'quadratic':
                    self.interpolation = 'quadratic'
                else:
                    self.raiseADebug('unexpected interpolation method ' +
                                     interpolation)
                    self.interpolation = interpolation
Пример #10
0
  def localInputAndChecks(self,xmlNode):
    """
      Class specific xml inputs will be read here and checked for validity.
      @ In, xmlNode, xml.etree.ElementTree.Element, The xml element node that will be checked against the available options specific to this Sampler.
      @ Out, None
    """
    #check if the hybrid DET has been activated, in case remove the nodes and treat them separaterly
    hybridNodes = xmlNode.findall("HybridSampler")
    if len(hybridNodes) != 0:
      # check the type of hybrid that needs to be performed
      limitSurfaceHybrid = False
      for elm in hybridNodes:
        samplType = elm.attrib['type'] if 'type' in elm.attrib.keys() else None
        if samplType == 'LimitSurface':
          if len(hybridNodes) != 1: self.raiseAnError(IOError,'if one of the HybridSampler is of type "LimitSurface", it can not be combined with other strategies. Only one HybridSampler node can be inputted!')
          limitSurfaceHybrid = True
      if limitSurfaceHybrid == True:
        #remove the elements from original xmlNode and check if the types are compatible
        for elm in hybridNodes: xmlNode.remove(elm)
        self.hybridDETstrategy = 1
      else: self.hybridDETstrategy = 2
      if self.hybridDETstrategy == 2: self.raiseAnError(IOError, 'The sheaf of LSs for the Adaptive Hybrid DET is not yet available. Use type "LimitSurface"!')

    DynamicEventTree.localInputAndChecks(self,xmlNode)
    # now we put back the nodes into the xmlNode to initialize the LimitSurfaceSearch with those variables as well
    for elm in hybridNodes:
      for child in elm:
        if limitSurfaceHybrid == True              : xmlNode.append(child)
        if child.tag in ['variable','Distribution']: self.epistemicVariables[child.attrib['name']] = None
    LimitSurfaceSearch._readMoreXMLbase(self,xmlNode)
    LimitSurfaceSearch.localInputAndChecks(self,xmlNode)
    if 'mode' in xmlNode.attrib.keys():
      if   xmlNode.attrib['mode'].lower() == 'online': self.detAdaptMode = 2
      elif xmlNode.attrib['mode'].lower() == 'post'  : self.detAdaptMode = 1
      else:  self.raiseAnError(IOError,'unknown mode ' + xmlNode.attrib['mode'] + '. Available are "online" and "post"!')
    if 'noTransitionStrategy' in xmlNode.attrib.keys():
      if xmlNode.attrib['noTransitionStrategy'].lower() == 'mc'    : self.noTransitionStrategy = 1
      elif xmlNode.attrib['noTransitionStrategy'].lower() == 'grid': self.noTransitionStrategy = 2
      else:  self.raiseAnError(IOError,'unknown noTransitionStrategy '+xmlNode.attrib['noTransitionStrategy']+'. Available are "mc" and "grid"!')
    if 'updateGrid' in xmlNode.attrib.keys():
      if xmlNode.attrib['updateGrid'].lower() in utils.stringsThatMeanTrue(): self.insertAdaptBPb = True
    # we add an artificial threshold because I need to find a way to prepend a rootbranch into a Tree object
    for  val in self.branchProbabilities.values():
      if min(val) != 1e-3: val.insert(0, 1e-3)
Пример #11
0
  def _localReadMoreXML(self, xmlNode):
    """
      Function to read the portion of the xml input that belongs to this specialized class
      and initialize some stuff based on the inputs got
      @ In, xmlNode, xml.etree.Element, Xml element node
      @ Out, None
    """
    paramInput = ComparisonStatistics.getInputSpecification()()
    paramInput.parseNode(xmlNode)
    for outer in paramInput.subparts:
      if outer.getName() == 'compare':
        compareGroup = ComparisonStatistics.CompareGroup()
        for child in outer.subparts:
          if child.getName() == 'data':
            dataName = child.value
            splitName = dataName.split("|")
            name, kind = splitName[:2]
            rest = splitName[2:]
            compareGroup.dataPulls.append([name, kind, rest])
          elif child.getName() == 'reference':
            # This has name=distribution
            compareGroup.referenceData = dict(child.parameterValues)
            if "name" not in compareGroup.referenceData:
              self.raiseAnError(IOError, 'Did not find name in reference block')

        self.compareGroups.append(compareGroup)
      if outer.getName() == 'kind':
        self.methodInfo['kind'] = outer.value
        if 'numBins' in outer.parameterValues:
          self.methodInfo['numBins'] = outer.parameterValues['numBins']
        if 'binMethod' in outer.parameterValues:
          self.methodInfo['binMethod'] = outer.parameterValues['binMethod'].lower()
      if outer.getName() == 'fz':
        self.fZStats = (outer.value.lower() in utils.stringsThatMeanTrue())
      if outer.getName() == 'interpolation':
        interpolation = outer.value.lower()
        if interpolation == 'linear':
          self.interpolation = 'linear'
        elif interpolation == 'quadratic':
          self.interpolation = 'quadratic'
        else:
          self.raiseADebug('unexpected interpolation method ' + interpolation)
          self.interpolation = interpolation
Пример #12
0
  def readSamplerInit(self,xmlNode):
    """
      This method is responsible to read only the samplerInit block in the .xml file.
      This method has been moved from the base sampler class since the samplerInit block is needed only for the MC and stratified (LHS) samplers
      @ In, xmlNode, xml.etree.ElementTree.Element, Xml element node
      @ Out, None
    """
    #TODO, this is redundant and paramInput should be directly passed in.
    paramInput = self.getInputSpecification()()
    paramInput.parseNode(xmlNode)

    for child in paramInput.subparts:
      if child.getName() == "samplerInit":
        self.initSeed = randomUtils.randomIntegers(0,2**31,self)
        for childChild in child.subparts:
          if childChild.getName() == "limit":
            try:
              self.limit = int(childChild.value)
            except ValueError:
              self.raiseAnError(IOError,'reading the attribute for the sampler '+self.name+' it was not possible to perform the conversion to integer for the attribute limit with value ' + str(childChild.value))
          if childChild.getName() == "initialSeed":
            try:
              self.initSeed = int(childChild.value)
            except ValueError:
              self.raiseAnError(IOError,'reading the attribute for the sampler '+self.name+' it was not possible to perform the conversion to integer for the attribute initialSeed with value ' + str(childChild.value))
          elif childChild.getName() == "reseedEachIteration":
            if childChild.value.lower() in utils.stringsThatMeanTrue():
              self.reseedAtEachIteration = True
          elif childChild.getName() == "distInit":
            for childChildChild in childChild.subparts:
              NDdistData = {}
              for childChildChildChild in childChildChild.subparts:
                if childChildChildChild.getName() == 'initialGridDisc':
                  NDdistData[childChildChildChild.getName()] = int(childChildChildChild.value)
                elif childChildChildChild.getName() == 'tolerance':
                  NDdistData[childChildChildChild.getName()] = float(childChildChildChild.value)
                else:
                  self.raiseAnError(IOError,'Unknown tag '+childChildChildChild.getName()+' .Available are: initialGridDisc and tolerance!')
              self.NDSamplingParams[childChildChild.parameterValues['name']] = NDdistData
Пример #13
0
    A type that allows True or False
  """
    @classmethod
    def convert(cls, value):
        """
      Converts value from string to a bool.
      @ In, value, string, the value to convert
      @ Out, convert, bool, the converted value
    """
        if value.lower() in utils.stringsThatMeanTrue():
            return True
        else:
            return False


boolTypeList = utils.stringsThatMeanTrue() + utils.stringsThatMeanFalse()
BoolType.createClass("bool", "boolType",
                     boolTypeList + [elm.capitalize() for elm in boolTypeList])


#
#
#
#
class Quantity:
    """
    A class that allows the quantity of a node to be specified.
    If python3.4+ is required, this should be switched to a Python 3.4 Enum.
  """
    zero_to_one = (0, 1)
    zero_to_infinity = (0, 2)
Пример #14
0
 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!')
Пример #15
0
  def _localInputAndChecksDET(self,xmlNode):
    """
      Class specific inputs will be read here and checked for validity.
      This method reads the standard DET portion only (no hybrid)
      @ In, xmlNode, xml.etree.ElementTree.Element, The xml element node that will be checked against the available options specific to this Sampler.
      @ Out, None
    """
    Grid.localInputAndChecks(self,xmlNode)
    if 'printEndXmlSummary'  in xmlNode.attrib.keys(): self.printEndXmlSummary  = xmlNode.attrib['printEndXmlSummary'].lower()  in utils.stringsThatMeanTrue()
    if 'removeXmlBranchInfo' in xmlNode.attrib.keys(): self.removeXmlBranchInfo = xmlNode.attrib['removeXmlBranchInfo'].lower() in utils.stringsThatMeanTrue()
    if 'maxSimulationTime'   in xmlNode.attrib.keys():
      try                        : self.maxSimulTime = float(xmlNode.attrib['maxSimulationTime'])
      except (KeyError,NameError): self.raiseAnError(IOError,'Can not convert maxSimulationTime in float number!!!')
    branchedLevel, error_found = {}, False
    gridInfo   = self.gridEntity.returnParameter("gridInfo")
    errorFound = False
    errorMsgs  = ''

    for keyk in self.axisName:
      branchedLevel[keyk] = 0
      #branchedLevel[self.toBeSampled[keyk]] = 0
      self.standardDETvariables.append(keyk)
      if self.gridInfo[keyk] == 'CDF':
        self.branchProbabilities[keyk] = gridInfo[keyk][2]
        self.branchProbabilities[keyk].sort(key=float)
        if max(self.branchProbabilities[keyk]) > 1:
          errorMsgs += "One of the Thresholds for distribution " + str(gridInfo[keyk][2]) + " is > 1 \n"
          errorFound = True
        probMultiplicities = Counter(self.branchProbabilities[keyk])
        multiples = [prob for prob,mult in probMultiplicities.items() if mult > 1]
        ## Only the multiple variables remain
        for prob in multiples:
          errorMsgs += "In variable " + str(keyk) + " the Threshold " + str(prob)+" appears multiple times!!\n"
          errorFound = True
#         self.branchProbabilities[self.toBeSampled[keyk]] = gridInfo[keyk][2]
#         self.branchProbabilities[self.toBeSampled[keyk]].sort(key=float)
#         if max(self.branchProbabilities[self.toBeSampled[keyk]]) > 1:
#           self.raiseAWarning("One of the Thresholds for distribution " + str(gridInfo[keyk][2]) + " is > 1")
#           errorFound = True
#           for index in range(len(sorted(self.branchProbabilities[self.toBeSampled[keyk]], key=float))):
#             if sorted(self.branchProbabilities[self.toBeSampled[keyk]], key=float).count(sorted(self.branchProbabilities[self.toBeSampled[keyk]], key=float)[index]) > 1:
#               self.raiseAWarning("In distribution " + str(self.toBeSampled[keyk]) + " the Threshold " + str(sorted(self.branchProbabilities[self.toBeSampled[keyk]], key=float)[index])+" appears multiple times!!")
#               errorFound = True
      else:
        self.branchValues[keyk] = gridInfo[keyk][2]
        self.branchValues[keyk].sort(key=float)
        valueMultiplicities = Counter(self.branchValues[keyk])
        multiples = [value for value,mult in valueMultiplicities.items() if mult > 1]
        ## Only the multiple variables remain
        for value in multiples:
          errorMsgs += "In variable " + str(keyk) + " the Threshold " + str(value)+" appears multiple times!!\n"
          errorFound = True
#         self.branchValues[self.toBeSampled[keyk]] = gridInfo[keyk][2]
#         self.branchValues[self.toBeSampled[keyk]].sort(key=float)
#         for index in range(len(sorted(self.branchValues[self.toBeSampled[keyk]], key=float))):
#           if sorted(self.branchValues[self.toBeSampled[keyk]], key=float).count(sorted(self.branchValues[self.toBeSampled[keyk]], key=float)[index]) > 1:
#             self.raiseAWarning("In distribution " + str(self.toBeSampled[keyk]) + " the Threshold " + str(sorted(self.branchValues[self.toBeSampled[keyk]], key=float)[index])+" appears multiple times!!")
#             errorFound = True

    # check if RELAP7 mode is activated, in case check that a <distribution> variable is unique in the input
    if any("<distribution>" in s for s in self.branchProbabilities.keys()):
      associatedDists = self.toBeSampled.values()
      if len(list(set(associatedDists))) != len(associatedDists):
        errorMsgs += "Distribution-mode sampling activated in " + self.name+". In this case every <distribution> needs to be assocaited with one single <Distribution> block!\n"
        errorFound = True
    if errorFound: self.raiseAnError(IOError,"In sampler named " + self.name+' the following errors have been found: \n'+errorMsgs )
    # Append the branchedLevel dictionary in the proper list
    self.branchedLevel.append(branchedLevel)
Пример #16
0
    def _readMoreXML(self, xmlNode):
        """
      Handles the reading of all the XML describing the step
      Since step are not reused there will not be changes in the parameter describing the step after this reading
      @ In, xmlNode, xml.etree.ElementTree.Element, XML element node that represents the portion of the input that belongs to this Step class
      @ Out, None
    """
        printString = 'For step of type {0:15} and name {1:15} the attribute {3:10} has been assigned to a not understandable value {2:10}'
        self.raiseADebug(
            'move this tests to base class when it is ready for all the classes'
        )
        if not set(xmlNode.attrib.keys()).issubset(set(self._knownAttribute)):
            self.raiseAnError(
                IOError,
                'In step of type {0:15} and name {1:15} there are unknown attributes {2:100}'
                .format(self.type, self.name, str(xmlNode.attrib.keys())))
        if 're-seeding' in xmlNode.attrib.keys():
            self.initSeed = xmlNode.attrib['re-seeding']
            if self.initSeed.lower() == "continue": self.initSeed = "continue"
            else:
                try:
                    self.initSeed = int(self.initSeed)
                except:
                    self.raiseAnError(
                        IOError,
                        printString.format(self.type, self.name, self.initSeed,
                                           're-seeding'))
        if 'sleepTime' in xmlNode.attrib.keys():
            try:
                self.sleepTime = float(xmlNode.attrib['sleepTime'])
            except:
                self.raiseAnError(
                    IOError,
                    printString.format(self.type, self.name,
                                       xmlNode.attrib['sleepTime'],
                                       'sleepTime'))
        for child in xmlNode:
            classType, classSubType = child.attrib.get(
                'class'), child.attrib.get('type')
            if None in [classType, classSubType]:
                self.raiseAnError(
                    IOError, "In Step named " + self.name + ", subnode " +
                    child.tag + ", and body content = " + child.text +
                    " the attribute class and/or type has not been found!")
            self.parList.append([
                child.tag,
                child.attrib.get('class'),
                child.attrib.get('type'), child.text
            ])

        self.pauseEndStep = False
        if 'pauseAtEnd' in xmlNode.attrib.keys():
            if xmlNode.attrib['pauseAtEnd'].lower(
            ) in utils.stringsThatMeanTrue():
                self.pauseEndStep = True
            elif xmlNode.attrib['pauseAtEnd'].lower(
            ) in utils.stringsThatMeanFalse():
                self.pauseEndStep = False
            else:
                self.raiseAnError(
                    IOError,
                    printString.format(self.type, self.name,
                                       xmlNode.attrib['pauseAtEnd'],
                                       'pauseAtEnd'))
        self._localInputAndChecks(xmlNode)
        if None in self.parList:
            self.raiseAnError(
                IOError,
                'A problem was found in  the definition of the step ' +
                str(self.name))
Пример #17
0
 def findSlaveFiles(self, tree, workingDir):
   """
     find Slave Files
     @ In, tree, xml.etree.ElementTree.Element, main node of RAVEN
     @ In, workingDir, string, current working directory
     @ Out, slaveFiles, list, list of slave input files
   """
   slaveFiles = [] # NOTE: this is only perturbable files
   # check in files
   filesNode = tree.find('.//Files')
   if filesNode is not None:
     for child in tree.find('.//Files'):
       # if the file is noted to be in a subdirectory, grab that
       subDirectory = child.attrib.get('subDirectory','')
       # this is the absolute path of the file on the system
       absPath = os.path.abspath(os.path.expanduser(os.path.join(workingDir, subDirectory, child.text.strip())))
       # is this file meant to be perturbed? Default to true.
       perturbable = child.attrib.get('perturbable', 'true').lower() in utils.stringsThatMeanTrue()
       if perturbable:
         # since it will be perturbed, track it so we can copy it to the eventual inner workdir
         slaveFiles.append(absPath)
         # we're going to copy it to the working dir, so just leave the file name
         child.text = os.path.basename(absPath)
       else:
         # change the path to be absolute so the inner workflow still knows where it is
         ## make sure we don't have a subdirectory messing with stuff
         child.attrib.pop('subDirectory', None)
         child.text = absPath
   # check in external models
   externalModels = tree.findall('.//Models/ExternalModel')
   if len(externalModels) > 0:
     for extModel in externalModels:
       if 'ModuleToLoad' in extModel.attrib:
         moduleToLoad = extModel.attrib['ModuleToLoad']
         if not moduleToLoad.endswith("py"):
           moduleToLoad += ".py"
         if self.workingDir not in moduleToLoad:
           absPath = os.path.abspath(os.path.expanduser(os.path.join(workingDir, moduleToLoad)))
         else:
           absPath = os.path.abspath(os.path.expanduser(moduleToLoad))
         # because ExternalModels aren't perturbed, just update the path to be absolute
         extModel.attrib['ModuleToLoad'] = absPath
       else:
         if 'subType' not in extModel.attrib or len(extModel.attrib['subType']) == 0:
           raise IOError(self.printTag+' ERROR: ExternalModel "'+extModel.attrib['name']+'" does not have any attribute named "ModuleToLoad" or "subType" with an available plugin name!')
   # check in external functions
   externalFunctions = tree.findall('.//Functions/External')
   if len(externalFunctions) > 0:
     for extFunct in externalFunctions:
       if 'file' in extFunct.attrib:
         moduleToLoad = extFunct.attrib['file']
         if not moduleToLoad.endswith("py"):
           moduleToLoad += ".py"
         if workingDir not in moduleToLoad:
           absPath = os.path.abspath(os.path.expanduser(os.path.join(workingDir, moduleToLoad)))
         else:
           absPath = os.path.abspath(os.path.expanduser(moduleToLoad))
         # because ExternalFunctions aren't perturbed, just update the path to be absolute
         extFunct.attrib['file'] = absPath
       else:
         raise IOError(self.printTag+' ERROR: Functions/External ' +extFunct.attrib['name']+ ' does not have any attribute named "file"!!')
   # make the paths absolute
   return slaveFiles