def nodeToUQModel(name, node): ''' This function converts a node model to a UQ model for UQ analysis. This is temporary solution. The extra python calculations that are include in a node are not converted, just the simulation. ''' uqModel = Model() uqModel.setName(name) uqModel.setRunType(Model.GATEWAY) #Basically run through John's stuff keys = list(node.inVars.keys()) typ = [] # Type for each input (Fixed or Variable) val = [] # Current value of inputs in the node min = [] # minimums for inputs max = [] # maximums for inputs default = [] # defaults for inputs for key in keys: # key is input variable name, make lists #if node.inVars[key].uqVar: typ.append(Model.VARIABLE) #else: # typ.append( Model.FIXED ) val.append(node.inVars[key].value) min.append(node.inVars[key].min) max.append(node.inVars[key].max) default.append(node.inVars[key].default) # Set input values uqModel.setInputNames(['%s.%s' % (name, key) for key in keys]) uqModel.setInputTypes(typ) uqModel.setInputMins(min) uqModel.setInputMaxs(max) uqModel.setInputDefaults(default) # Set output names and set all outputs as selected keys = list(node.outVars.keys()) uqModel.setOutputNames(['%s.%s' % (name, key) for key in keys]) uqModel.setSelectedOutputs(list(range(len(keys)))) return uqModel
def loadDict(self, sd, filename, stopConsumers=True): ''' Load a session from a string ''' # Clear session information self.new(stopConsumers=stopConsumers) # Read metaData information metaData = sd.get("CCSIFileMetaData", None) if metaData: # Read information from meta data if it exists self.description = metaData.get("Description", "None") self.creationTime = metaData.get("CreationTime", "") self.changeLog = metaData.get("ChangeLog", {}) self.parents = metaData.get("Parents", []) self.originalFileName = metaData.get("OriginalFilename", "") self.date = metaData.get("ModificationTime", "") self.version = metaData.get("Version", "00.00") self.name = metaData.get("DisplayName", "") self.uid = metaData.get("ID", self.uid) self.confidence = metaData.get("Confidence", "experimental") else: # Older session files read data from old locations self.description = sd.get("description", "None") self.date = sd.get("date", "") #Read flowsheet self.flowsheet.loadDict(sd["flowsheet"]) #Read ID for UQ archives, should prob get rid of this and use #metadata ID fullFile = os.path.abspath(filename) pathName, baseName = os.path.split(fullFile) base, ext = os.path.splitext(baseName) self.ID = sd.get("ID", self.ID) self.archiveFolder = os.path.join( os.path.dirname(os.path.abspath(filename)), '%s_files' % self.ID) # Load the surrogate model settings self.surrogateProblem = sd.get('surrogateProblem', {}) self.surrogateCurrent = sd.get("surrogateCurrent", None) # Load the optimization problem if exists self.optProblem = oprob.problem() self.optProblem.dat = self p = sd.get('optProblem', None) if p: self.optProblem.loadDict(p) # Load UQ Stuff self.uqSimList = [] if 'uqSimList' in sd: for simDict in sd['uqSimList']: model = Model() model.loadDict(simDict['model']) sim = SampleData(model) sim.setSession(self) sim.loadDict(simDict) self.uqSimList.append(sim) self.uqFilterResultsList = [] if 'uqFilterResultsList' in sd: for filterDict in sd['uqFilterResultsList']: filterResults = Results() filterResults.loadDict(filterDict) self.uqFilterResultsList.append(filterResults) self.currentFile = None
def flowsheetToUQModel(gr): ''' This function converts a node model to a UQ model for UQ analysis. This is temporary solution. The extra python calculations that are include in a node are not converted, just the simulation. ''' uqModel = Model() uqModel.setName('Flowsheet') uqModel.setRunType(Model.GATEWAY) #Basically run through John's stuff uqModel.setNamesIncludeNodes(True) keys = gr.input.compoundNames() names = [] typ = [] # Type for each input (Fixed or Variable) val = [] # Current value of inputs in the node mins = [] # minimums for inputs maxs = [] # maximums for inputs dists = [] default = [] # defaults for inputs flowsheetFixed = [] gr.generateGlobalVariables() for key in keys: # key is input variable name, make lists if not gr.input.get(key).con: names.append(key) typ.append(Model.VARIABLE) val.append(gr.input.get(key).value) mins.append(gr.input.get(key).min) maxs.append(gr.input.get(key).max) default.append(gr.input.get(key).default) dists.append(gr.input.get(key).dist) flowsheetFixed.append(False) # Set input values uqModel.setInputNames(names) uqModel.setInputTypes(typ) uqModel.setInputMins(mins) uqModel.setInputMaxs(maxs) uqModel.setInputDistributions(dists) uqModel.setInputDefaults(default) uqModel.setInputFlowsheetFixed(flowsheetFixed) # Set output names and set all outputs as selected keys = gr.output.compoundNames() uqModel.setOutputNames(keys) uqModel.setSelectedOutputs(list(range(len(keys)))) return uqModel