Example #1
0
    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
Example #2
0
 def new(self, stopConsumers=True):
     '''
         Create a new clean session object
     '''
     tc = None
     if stopConsumers:
         try:
             self.flowsheet.turbConfig.stopAllConsumers()
         except:
             pass
     else:
         #if not stoppoing consumers then reuse them
         tc = self.flowsheet.turbConfig
     self.name = ""
     self.originalFileName = ""
     self.uid = uuid.uuid4().hex
     self.creationTime = ""
     self.changeLog = {}
     self.parents = []
     self.version = "00.00"
     self.confidence = "experimental"
     try:
         self.flowsheet.turbConfig.closeTurbineLiteDB()
     except:
         pass
     self.flowsheet = Graph()  # meta-flowsheet linking sims
     if tc is not None:
         #keeping the consumers around and reusing them
         #for the simulation I'm opening.
         self.flowsheet.turbConfig = tc
     self.flowsheet.turbConfig.dat = self
     self.flowsheet.turbConfig.updateSettings()
     self.flowsheet.turbchkfreq = self.turbineChkFreq
     self.flowsheet.resubMax = self.resubMax
     self.description = "None"  # description of the session
     self.currentFile = ""  # path for current session file
     self.date = ""  # date that a session file was saved
     self.optProblem = oprob.problem()  #optimization problems
     self.optProblem.dat = self
     self.surrogateProblem = {}  # saved dict of surrogate setup
     self.surrogateCurrent = None
     self.uqSimList = []  # list of UQ simulation ensembles
     self.uqFilterResultsList = []  # list of UQ filter results
     self.sdoeSimList = []  # list of SDOE simulation ensembles
     self.odoeCandList = []  # list of ODOE candidate sets
     self.odoeEvalList = []  # list of ODOE evaluation sets
     self.sdoeFilterResultsList = []  # list of SDOE filter results
     self.ID = time.strftime('Session_%y%m%d%H%M%S')  #session id
     self.archiveFolder = \
         os.path.join(os.getcwd(), '%s_files' % self.ID)
     self.newArchiveItemsSinceLastSave = []
     # add the pymodel plugin list to the flowsheet so node can
     # make instances of pymodels to run.  the nodes don't have
     # access to the session object
     self.flowsheet.pymodels = self.pymodels