Skip to content

Commit c5695f8

Browse files
feslimaFelipe
authored andcommitted
Minor bug fixes.
The following files were changed: - doetab.py: Fixed the empty bounds field when editing; - optimizationtab.py: Fixed parameters proper validation behavior; - sampling.py: Removed ptvsd import for debugging purposes;
1 parent 68ab21e commit c5695f8

File tree

3 files changed

+53
-49
lines changed

3 files changed

+53
-49
lines changed

gui/calls/tabs/doetab.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from PyQt5.QtWidgets import (QAbstractItemView, QApplication, QHeaderView,
77
QTableView, QTableWidgetItem, QWidget)
88

9+
from gui.calls.base import DoubleEditorDelegate
910
from gui.calls.dialogs.csveditor import CsvEditorDialog
1011
from gui.calls.dialogs.samplingassistant import (InputBoundsModel,
1112
SamplingAssistantDialog)
@@ -206,6 +207,12 @@ def __init__(self, application_database: DataStorage, parent_tab=None):
206207
bounds_table.horizontalHeader().setSectionResizeMode(
207208
QHeaderView.Stretch)
208209

210+
self._lb_delegate = DoubleEditorDelegate()
211+
self._ub_delegate = DoubleEditorDelegate()
212+
213+
bounds_table.setItemDelegateForColumn(1, self._lb_delegate)
214+
bounds_table.setItemDelegateForColumn(2, self._ub_delegate)
215+
209216
results_table = DoeResultsView(parent=self.ui.groupBox_4)
210217
results_model = DoeResultsModel(self.application_database,
211218
parent=results_table)

gui/calls/tabs/optimizationtab.py

Lines changed: 44 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import pandas as pd
22
from PyQt5.QtCore import (QAbstractTableModel, QModelIndex, Qt, QThread,
33
pyqtSignal)
4-
from PyQt5.QtGui import QFont, QDoubleValidator, QIntValidator, QBrush, QPalette
5-
from PyQt5.QtWidgets import QApplication, QHeaderView, QMessageBox, QWidget
4+
from PyQt5.QtGui import (QBrush, QDoubleValidator, QFont, QIntValidator,
5+
QPalette)
6+
from PyQt5.QtWidgets import (
7+
QApplication, QHeaderView, QLineEdit, QMessageBox, QWidget)
68
from surropt.core.options.nlp import DockerNLPOptions
79
from win32com.client import Dispatch
810

@@ -103,29 +105,12 @@ def __init__(self, application_database: DataStorage, parent_tab=None):
103105
std_val.setRange(0.0, 1.0, 2)
104106
std_val.setNotation(QDoubleValidator.StandardNotation)
105107

106-
sci_val = QDoubleValidator()
107-
pen_val = QDoubleValidator()
108-
pen_val.setRange(0.0, 10000.0, 4)
108+
self.sci_val = QDoubleValidator()
109+
self.pen_val = QDoubleValidator()
110+
self.pen_val.setRange(0.0, 10000.0, 4)
109111

110-
maxfun_val = QIntValidator()
111-
maxfun_val.setRange(0, 10000)
112-
113-
factor1_le.setValidator(std_val)
114-
factor2_le.setValidator(std_val)
115-
tol_contract_le.setValidator(sci_val)
116-
con_tol_le.setValidator(sci_val)
117-
penalty_le.setValidator(pen_val)
118-
tol1_le.setValidator(sci_val)
119-
tol2_le.setValidator(sci_val)
120-
maxfunevals_le.setValidator(maxfun_val)
121-
122-
self.ui.ipoptLocalDualFeasLineEdit.setValidator(sci_val)
123-
self.ui.ipoptLocalConTolLineEdit.setValidator(sci_val)
124-
self.ui.ipoptLocalMaxIterLineEdit.setValidator(maxfun_val)
125-
126-
self.ui.ipoptServerDualFeasLineEdit.setValidator(sci_val)
127-
self.ui.ipoptServerConTolLineEdit.setValidator(sci_val)
128-
self.ui.ipoptServerMaxIterLineEdit.setValidator(maxfun_val)
112+
self.maxfun_val = QIntValidator()
113+
self.maxfun_val.setRange(0, 10000)
129114

130115
# --------------------------- Signals/Slots ---------------------------
131116
self.ui.startOptPushButton.clicked.connect(self.on_start_pressed)
@@ -137,26 +122,26 @@ def __init__(self, application_database: DataStorage, parent_tab=None):
137122
)
138123

139124
# whenever any of the opt parameters changes update the underlying obj
140-
factor1_le.textChanged.connect(self.set_opt_params)
141-
factor2_le.textChanged.connect(self.set_opt_params)
142-
tol_contract_le.textChanged.connect(self.set_opt_params)
143-
con_tol_le.textChanged.connect(self.set_opt_params)
144-
penalty_le.textChanged.connect(self.set_opt_params)
145-
tol1_le.textChanged.connect(self.set_opt_params)
146-
tol2_le.textChanged.connect(self.set_opt_params)
147-
maxfunevals_le.textChanged.connect(self.set_opt_params)
125+
factor1_le.editingFinished.connect(self.set_opt_params)
126+
factor2_le.editingFinished.connect(self.set_opt_params)
127+
tol_contract_le.editingFinished.connect(self.set_opt_params)
128+
con_tol_le.editingFinished.connect(self.set_opt_params)
129+
penalty_le.editingFinished.connect(self.set_opt_params)
130+
tol1_le.editingFinished.connect(self.set_opt_params)
131+
tol2_le.editingFinished.connect(self.set_opt_params)
132+
maxfunevals_le.editingFinished.connect(self.set_opt_params)
148133
regrpoly_cb.currentIndexChanged.connect(self.set_opt_params)
149-
self.ui.ipoptLocalDualFeasLineEdit.textChanged.connect(
134+
self.ui.ipoptLocalDualFeasLineEdit.editingFinished.connect(
150135
self.set_opt_params)
151-
self.ui.ipoptLocalMaxIterLineEdit.textChanged.connect(
136+
self.ui.ipoptLocalMaxIterLineEdit.editingFinished.connect(
152137
self.set_opt_params)
153-
self.ui.ipoptLocalConTolLineEdit.textChanged.connect(
138+
self.ui.ipoptLocalConTolLineEdit.editingFinished.connect(
154139
self.set_opt_params)
155-
self.ui.ipoptServerDualFeasLineEdit.textChanged.connect(
140+
self.ui.ipoptServerDualFeasLineEdit.editingFinished.connect(
156141
self.set_opt_params)
157-
self.ui.ipoptServerMaxIterLineEdit.textChanged.connect(
142+
self.ui.ipoptServerMaxIterLineEdit.editingFinished.connect(
158143
self.set_opt_params)
159-
self.ui.ipoptServerConTolLineEdit.textChanged.connect(
144+
self.ui.ipoptServerConTolLineEdit.editingFinished.connect(
160145
self.set_opt_params)
161146

162147
# control panel related stuff
@@ -316,45 +301,57 @@ def set_opt_params(self):
316301

317302
opt_params['nlp_params'] = solver_params
318303

319-
self.application_database.optimization_parameters = opt_params
320-
321-
def _set_value(self, editor, opt_param_key, val_type='float', min_val=0.0,
322-
max_val=1.0):
304+
def _set_value(self, editor: QLineEdit, opt_param_key, val_type='float',
305+
min_val=0.0, max_val=1.0):
306+
opt_params = self.application_database.optimization_parameters
323307
try:
324308
if val_type == 'float':
325309
value = float(editor.text())
326310
else:
327311
value = int(editor.text())
328312
except ValueError:
329-
pass
313+
# text is invalid, resort to value in storage
314+
editor.setText(str(opt_params[opt_param_key]))
315+
330316
else:
331-
opt_params = self.application_database.optimization_parameters
332317
opt_params[opt_param_key] = value
333318
if not (min_val < value < max_val):
334319
color = 'red'
320+
tooltip_msg = ("Parameter outside valid range "
321+
"({0} < value < {1})")
322+
tooltip_msg = tooltip_msg.format(min_val, max_val)
335323
else:
336324
color = 'white'
325+
tooltip_msg = ""
337326

327+
editor.setToolTip(tooltip_msg)
338328
editor.setStyleSheet("background: " + color)
339329

340330
def _set_nlp_param(self, editor, nlp_param_key, val_type='float',
341331
min_val=0.0, max_val=1.0):
332+
opt_params = self.application_database.optimization_parameters
333+
solver_params = opt_params['nlp_params']
342334
try:
343335
if val_type == 'float':
344336
value = float(editor.text())
345337
else:
346338
value = int(editor.text())
347339
except ValueError:
348-
pass
340+
# text is invalid, resort to value in storage
341+
editor.setText(str(solver_params[nlp_param_key]))
342+
349343
else:
350-
opt_params = self.application_database.optimization_parameters
351-
solver_params = opt_params['nlp_params']
352344
solver_params[nlp_param_key] = value
353345
if not (min_val < value < max_val):
354346
color = 'red'
347+
tooltip_msg = ("Parameter outside valid range "
348+
"({0} < value < {1})")
349+
tooltip_msg = tooltip_msg.format(min_val, max_val)
355350
else:
356351
color = 'white'
352+
tooltip_msg = ""
357353

354+
editor.setToolTip(tooltip_msg)
358355
editor.setStyleSheet("background: " + color)
359356

360357
def on_start_pressed(self):

gui/models/sampling.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from gui.models.data_storage import DataStorage
1616
from gui.models.sim_connections import AspenConnection
1717

18-
import ptvsd
18+
# import ptvsd
1919

2020

2121
def lhs(n_samples: int, lb: list, ub: list, n_iter: int, inc_vertices: bool) \
@@ -294,7 +294,7 @@ def __del__(self):
294294
self.asp_obj.close_connection()
295295

296296
def start_optimization(self):
297-
ptvsd.debug_this_thread()
297+
# ptvsd.debug_this_thread()
298298
params = self.params
299299

300300
# unzip parameter data

0 commit comments

Comments
 (0)