Ejemplo n.º 1
0
    def ouu(self,
            fname,
            y,
            outputsAsConstraint,
            outputsAsDerivative,
            xtable,
            phi,
            x3sample=None,
            x4sample=None,
            useRS=False,
            useBobyqa=True,
            driver=None,
            optDriver=None,
            auxDriver=None,
            ensOptDriver=None,
            plotSignal=None,
            endFunction=None):

        # Function to execute after inference has finished.
        # Function would enable button again and such things.
        self.endFunction = endFunction

        # read data, assumes data already have fixed variables written to file
        data = LocalExecutionModule.readSampleFromPsuadeFile(fname)
        if optDriver == None and ensOptDriver == None and \
               data.getOptDriverName() == None and \
               data.getEnsembleOptDriverName() == None:
            Common.showError('Model file does not have any drivers set!', \
                             showDeveloperHelpMessage = False)
            self.hadError = True
            if endFunction is not None:
                endFunction()
            return
        if driver != None:
            data.setDriverName(driver)
        if optDriver != None:
            data.setOptDriverName(optDriver)
        if auxDriver != None:
            data.setAuxDriverName(auxDriver)
        if ensOptDriver != None:
            data.setEnsembleOptDriverName(ensOptDriver)
        else:
            ensOptDriver = data.getEnsembleOptDriverName()

        # Remove file that tells OUU to stop
        if os.path.exists(OUU.stopFile):
            os.remove(OUU.stopFile)

        # process input table
        dname = OUU.dname
        deleteFiles = True
        if x3sample is not None:
            deleteFiles = not x3sample['file'].startswith(dname)
        #Common.initFolder(dname, deleteFiles = deleteFiles)
        if platform.system() == 'Windows':
            import win32api
            dname = win32api.GetShortPathName(dname)
        fnameOUU = Common.getLocalFileName(dname, fname, '.ouudat')
        p = RSAnalyzer.parsePrior(data, xtable)
        if p is not None:
            inputLB = p['inputLB']
            inputUB = p['inputUB']
            dist = p['dist']

        init_input = []
        vartypes = []
        for e in xtable:
            t = e['type']
            if t == u'Opt: Primary Continuous (Z1)':
                vartypes.append(1)
            elif t == u'Opt: Primary Continuous (Z1c)':
                vartypes.append(1)
            elif t == u'Opt: Primary Discrete (Z1d)':
                vartypes.append(1)
            elif t == u'Opt: Recourse (Z2)':
                vartypes.append(2)
            elif t == u'UQ: Discrete (Z3)':
                vartypes.append(3)
            elif t == u'UQ: Continuous (Z4)':
                vartypes.append(4)
            if t != u'Fixed':
                init_input.append(e['value'])
        M1 = vartypes.count(1)
        M2 = vartypes.count(2)
        M3 = vartypes.count(3)
        M4 = vartypes.count(4)

        # check arguments
        if M1 < 1:
            error = 'OUU: In function ouu(), number of Z1 (design opt) '
            error = error + 'must be at least 1.'
        if M3 > 0:
            if x3sample == None:
                error = 'OUU: In function ouu(), "x3sample" is undefined.'
                Common.showError(error)
                return None

        if M4 > 0:
            if x4sample == None:
                error = 'OUU: In function ouu(), "x4sample" is undefined.'
                Common.showError(error)
                return None
            loadcs = 'file' in x4sample
            if loadcs:
                N = 0  # number of samples in x4sample['file']

                ### TO DO for Jeremy: check sample size in GUI
                with open(x4sample['file']) as f:
                    header = f.readline()
                    header = header.split()
                    N = int(header[0])

                Nmin = M4 + 1  # minimum number of samples
                if N < Nmin:
                    error = 'OUU: In function ouu(), "x4sample file" requires '
                    error = error + 'at least %d samples.' % Nmin
                    Common.showError(error)
                    return None
                if useRS:
                    Nrs = 'nsamplesRS' in x4sample
                    if not Nrs:
                        error = 'OUU: In function ouu(), "x4sample nsamplesRS" is '
                        error = error + 'required for setting up response surface.'
                        Common.showError(error)
                        return None
                    Nrs = x4sample['nsamplesRS']
                    Nrs = min(max(Nrs, Nmin),
                              N)  ### TO DO for Jeremy: check in GUI

        # TO DO: remove randSeed
        ouuFile = OUU.writeOUUdata(fnameOUU,
                                   y,
                                   outputsAsConstraint,
                                   outputsAsDerivative,
                                   data,
                                   xtable,
                                   randSeed=41491431,
                                   inputLowerBounds=inputLB,
                                   inputUpperBounds=inputUB,
                                   inputPDF=dist,
                                   useEnsOptDriver=(ensOptDriver != None),
                                   init_input=init_input)
        if (ouuFile == None):
            return None

        # write script
        f = OUU.writescript(vartypes,
                            fnameOUU,
                            outputsAsConstraint,
                            phi,
                            x3sample,
                            x4sample,
                            useRS,
                            useBobyqa,
                            useEnsOptDriver=(ensOptDriver != None))

        # delete previous history file
        if os.path.exists(OUU.hfile):
            os.remove(OUU.hfile)

        self.textDialog = Common.textDialog()
        self.thread = psuadeThread(self, f, self.finishOUU, self.textDialog,
                                   plotSignal)
        self.thread.start()
Ejemplo n.º 2
0
         MainWin.helpDock.setStopTrue)  #stop script for taking too long
addTimer('msg_okay',
         MainWin.helpDock.msgBoxOK)  #click okay on a pop up message box
addTimer('msg_no', MainWin.helpDock.msgBoxNo)  #Click no on a popup message box
addTimer('rs_analyze', rsAnalyze)
# Start timer to stop script for running too long
# This won't work it execution of the script is blocked.
timers['time_out'].start(MAX_RUN_TIME)

try:
    #raise(Exception("Test excpetion handeling"))
    while (1):

        ### This is the dialog I created for this type of stuff
        if TEXT_NOTEXT == 1:
            dialog = Common.textDialog(MainWin)
            dialog.show()
            textedit = dialog.textedit
            pText = 'Do not move your mouse or type anything until the end\n'
            textedit.insertPlainText(pText)
            textedit.ensureCursorVisible()  # Scroll the window to the bottom

        ### Go to main window home
        if TEXT_NOTEXT == 1:
            textedit.insertPlainText('Entering the home screen\n')
            textedit.ensureCursorVisible()  # Scroll the window to the bottom
        if not go(): break
        time.sleep(TIME_STEP)
        MainWin.homeAction.trigger()
        if not go(): break
        time.sleep(TIME_STEP)
Ejemplo n.º 3
0
# need to make sure that when this script exits all timers are stopped
# or some crazy stuff may happen untill you exit FOQUS.
addTimer('time_out', MainWin.helpDock.setStopTrue) #stop script for taking too long
addTimer('msg_okay', MainWin.helpDock.msgBoxOK) #click okay on a pop up message box
addTimer('msg_no', MainWin.helpDock.msgBoxNo) #Click no on a popup message box
# Start timer to stop script for running too long
# This won't work it execution of the script is blocked.
timers['time_out'].start(MAX_RUN_TIME) 

try:
    #raise(Exception("Test excpetion handeling"))
    while(1):

        ### This is the dialog I created for this type of stuff
        if (HAVE_TEXT == 1):
           dialog = Common.textDialog() 
           dialog.show() 
           textedit = dialog.textedit 
           textedit.insertPlainText('First move this screen to your upper right hand corner\n')
           textedit.ensureCursorVisible() # Scroll the window to the bottom

        ### Go to main window home
        if (HAVE_TEXT == 1):
           textedit.insertPlainText('Entering the home screen\n')
           textedit.ensureCursorVisible() # Scroll the window to the bottom
           if not go(): break
           time.sleep(TIME_STEP)
        MainWin.homeAction.trigger()
        if not go(): break
        time.sleep(TIME_STEP)