예제 #1
0
 def scaleHelper(self, ind=0):
     '''
         If a descision variable has a none scale type set the scale
         to lineae.  For other variables set the scale type to none
         and disable the scale selection.
     '''
     table = self.varForm
     typeCol = self.vtCols["Type"]
     scaleCol = self.vtCols["Scale"]
     for row in range(table.rowCount()):
         vtype = gh.getCellText(table, row, typeCol)
         stype = gh.getCellText(table, row, scaleCol)
         if vtype == 'Decision':
             if stype == 'None':
                 gh.cellPulldownSetText(table,row,scaleCol, "Linear")
             table.cellWidget(row, scaleCol).setEnabled(True)
         else:
             gh.cellPulldownSetText(table, row, scaleCol, "None")
             table.cellWidget(row, scaleCol).setEnabled(False)
예제 #2
0
    def _load(self, file="test.json"):
        try:
            with open(file, "r") as fp:
                d = json.load(fp)
        except:
            _log.exception("Couldn't load file {}".format(file))
            return

        # Currently doesn't load these because you can't change them
        # filetype, filetype-version, and SignatureMethodAlgorithm
        index = self.application_name.findText(d["application"].get(
            "name", ""))
        if index >= 0:
            self.application_name.setCurrentIndex(index)
        self.application_version.setText(d["application"].get("version", ""))
        self.title.setText(d.get("title", ""))
        self.author.setText(d.get("author", ""))
        self.date.setText(d.get("date", ""))
        self.description.setText(d.get("description", ""))
        self.config_version.setText(d.get("config-version", "1.0"))
        if "model" in d:
            self.model_file.setText(d["model"].get("file", ""))
            self.model_digest_value.setText(d["model"].get("DigestValue", ""))
        tbl = self.settings_table
        for row in range(tbl.rowCount()):
            if not "settings" in d:
                break
            sname = tbl.verticalHeaderItem(row).text()
            if sname in d["settings"]:
                gh.setCellText(tbl, row, 0, d["settings"][sname]["type"])
                gh.setCellText(tbl, row, 1, d["settings"][sname]["default"])
                gh.setCellText(tbl, row, 2,
                               d["settings"][sname]["description"])
        files = d.get("input-files", [])
        tbl = self.input_files_table
        tbl.setRowCount(0)
        for row, file in enumerate(files):
            self._add_blank_input_file()
            gh.setCellText(tbl, row, 0, file["file"])
            gh.setCellText(tbl, row, 1, file["DigestValue"])
            gh.cellPulldownSetText(tbl, row, 2,
                                   file["SignatureMethodAlgorithm"])
        tbl = self.inputs_table
        tbl.setRowCount(0)
        for x, xd in d.get("inputs", {}).items():
            row = tbl.rowCount()
            self._add_input()
            gh.setCellText(tbl, row, 0, x)
            gh.setCellText(tbl, row, 1, xd.get("path", [""])[0])
            gh.cellPulldownSetText(tbl, row, 2, xd.get("type", "double"))
            gh.setCellText(tbl, row, 3, xd.get("default", ""))
            gh.setCellText(tbl, row, 4, xd.get("max", ""))
            gh.setCellText(tbl, row, 5, xd.get("min", ""))
            units = xd.get("units", "")
            if units is None:
                units = ""
            gh.setCellText(tbl, row, 6, units)
            gh.setCellText(tbl, row, 7, xd.get("description", ""))
        tbl = self.outputs_table
        tbl.setRowCount(0)
        for x, xd in d.get("outputs", {}).items():
            row = tbl.rowCount()
            self._add_output()
            gh.setCellText(tbl, row, 0, x)
            gh.setCellText(tbl, row, 1, xd.get("path", [""])[0])
            gh.cellPulldownSetText(tbl, row, 2, xd.get("type", "double"))
            gh.setCellText(tbl, row, 3, xd.get("default", ""))
            units = xd.get("units", "")
            if units is None:
                units = ""
            gh.setCellText(tbl, row, 4, units)
            gh.setCellText(tbl, row, 5, xd.get("description", ""))
예제 #3
0
 def refreshContents(self):
     '''
     '''
     self.dat.flowsheet.generateGlobalVariables()
     prob = self.dat.optProblem
     x = self.dat.flowsheet.x
     # Set up problem selection combo box
     o = self.dat.optProblem
     # Setup optimization solver selection box
     self.solverBox.blockSignals(True)
     self.solverBox.clear()
     self.solverBox.addItems(self.osolvers)
     if self.osolvers: #at least on solver available
         indx = self.solverBox.findText(o.solver)
         if indx == -1:
             indx = 0
         self.solverBox.setCurrentIndex(indx)
         self.lastSolver = self.solverBox.currentText()
         self.setSolver(self.lastSolver)
         self.solverBox.blockSignals(False)
     else: #if no solvers are available
         pass
     # put data into variable table
     row = 0
     self.varForm.clearContents()
     self.varForm.setRowCount(0)
     table = self.varForm
     for vkey in x:
         #only list inputs that are not set by other variables
         if not x[vkey].con:
             self.varForm.setRowCount(self.varForm.rowCount() + 1)
             scale = x[vkey].scaling
             gh.setTableItem(
                 table,
                 row,
                 self.vtCols["Variable"],
                 vkey)
             gh.setTableItem(
                 table,
                 row,
                 self.vtCols["Type"],
                 "Fixed",
                 pullDown = ["Fixed", "Decision", "Sample"])
             if vkey in prob.v:
                 gh.cellPulldownSetText(table, row,
                     self.vtCols["Type"], "Decision")
             elif vkey in prob.vs:
                 gh.cellPulldownSetText(table, row,
                     self.vtCols["Type"], "Sample")
             table.cellWidget(row, self.vtCols["Type"])\
                 .currentIndexChanged.connect(self.scaleHelper)
             gh.setTableItem(
                 table,
                 row,
                 self.vtCols["Scale"],
                 x[vkey].scaling,
                 pullDown=self.scalingOpts)
             gh.setTableItem(
                 table,
                 row,
                 self.vtCols["Min"],
                 x[vkey].min,
                 jsonEnc=True)
             gh.setTableItem(
                 table,
                 row,
                 self.vtCols["Max"],
                 x[vkey].max,
                 jsonEnc=True)
             gh.setTableItem(
                 table,
                 row,
                 self.vtCols["Value"],
                 x[vkey].value,
                 jsonEnc=True)
             row += 1
     self.scaleHelper()
     table.resizeColumnsToContents()
     if not o:
         self.fTable.setRowCount(0)
         self.gTable.setRowCount(0)
         return
     # put data in objective function table
     self.fTable.setRowCount(  len(o.obj) )
     row = 0
     table = self.fTable
     for f in o.obj:
         gh.setTableItem(
             table,
             row,
             self.ofCols["Expression"],
             f.pycode)
         gh.setTableItem(
             table,
             row,
             self.ofCols["Penalty Scale"],
             f.penScale,
             jsonEnc=True)
         gh.setTableItem(
             table,
             row,
             self.ofCols["Value for Failure"],
             f.fail,
             jsonEnc=True)
         row += 1
     table.resizeColumnsToContents()
     # put data in inequality constraint table
     self.gTable.setRowCount(len(o.g))
     row = 0
     table = self.gTable
     for f in o.g:
         gh.setTableItem(
             table,
             row,
             self.icCols["Expression"],
             f.pycode)
         gh.setTableItem(
             table,
             row,
             self.icCols["Penalty Factor"],
             f.penalty,
             jsonEnc=True)
         gh.setTableItem(
             table,
             row,
             self.icCols["Form"],
             f.penForm,
             pullDown=self.penForms)
         row += 1
     table.resizeColumnsToContents()
     # Get objective type
     if prob.objtype == prob.OBJ_TYPE_EVAL:
         self.objTypeCombo.setCurrentIndex(0)
     elif prob.objtype == prob.OBJ_TYPE_CUST:
         self.objTypeCombo.setCurrentIndex(1)
     # Get custom code
     self.customCodeEdit.setPlainText(prob.custpy)
     self.updateSampleVarsTable()