Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3126: Fix OpenCl and covariance issues #3129

Merged
merged 6 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions src/sas/qtgui/Perspectives/Fitting/GPUOptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ def __init__(self):
self.progressBar.setVisible(False)
self.progressBar.setFormat(" Test %v / %m")

# A local flag to know if opencl options have been staged or not. This is to prevent an OpenCL context refresh
# when no refresh is required.
self._staged_open_cl = None

self.testButton.clicked.connect(self.testButtonClicked)
self.helpButton.clicked.connect(self.helpButtonClicked)
self.testingDoneSignal.connect(self.testCompleted)
Expand All @@ -76,7 +80,11 @@ def _addAllWidgets(self):

def applyNonConfigValues(self):
"""Applies values that aren't stored in config. Only widgets that require this need to override this method."""
self.set_sas_open_cl()
# This is called anytime *any* preference change is made, not only from this widget, but any other preferences
# widget. Track if openCL is changed locally to be sure the setter should be invoked.
if self._staged_open_cl:
krzywon marked this conversation as resolved.
Show resolved Hide resolved
self.set_sas_open_cl()
self._staged_open_cl = None

def add_options(self):
"""
Expand Down Expand Up @@ -108,16 +116,22 @@ def add_options(self):

self.openCLCheckBoxGroup.setMinimumWidth(self.optionsLayout.sizeHint().width()+10)

def _unStageChange(self, key: str):
# The only staged change in this panel is the OpenCL selection. If any change is being unstaged, reset the flag.
self._staged_open_cl = None
super()._unStageChange(key)

def _stage_sas_open_cl(self, checked):
checked = None
for box in self.radio_buttons:
if box.isChecked():
checked = box
if checked:
sas_open_cl = self.cl_options[str(checked.text())]
self._staged_open_cl = sas_open_cl
self._stageChange('SAS_OPENCL', sas_open_cl)

def set_sas_open_cl(self):
def get_sas_open_cl(self):
"""
Set SAS_OPENCL value when tests run or OK button clicked
"""
Expand All @@ -131,17 +145,25 @@ def set_sas_open_cl(self):
raise RuntimeError("Error: No radio button selected somehow")

sas_open_cl = self.cl_options[str(checked.text())]
no_opencl_msg = sas_open_cl.lower() == "none"
return sas_open_cl

def set_sas_open_cl(self):
sas_open_cl = self.get_sas_open_cl()
lib.reset_sasmodels(sas_open_cl)

return no_opencl_msg
return sas_open_cl

def testButtonClicked(self):
"""
Run sasmodels check from here and report results from
"""
# Set the SAS_OPENCL value prior to running to ensure proper value is used
no_opencl_msg = self.set_sas_open_cl()
if self._staged_open_cl is not None:
sas_open_cl = self.set_sas_open_cl()
self._staged_open_cl = None
else:
sas_open_cl = self.get_sas_open_cl()
no_opencl_msg = sas_open_cl.lower() == "none"
self._unStageChange('SAS_OPENCL')
self.model_tests = sasmodels.model_test.make_suite('opencl', ['all'])
number_of_tests = len(self.model_tests._tests)
Expand Down Expand Up @@ -292,7 +314,7 @@ def accept(self):
"""
Close the window after modifying the SAS_OPENCL value
"""
self.set_sas_open_cl()
self.applyNonConfigValues()
self.closeEvent(None)

def closeEvent(self, event):
Expand Down
11 changes: 9 additions & 2 deletions src/sas/sascalc/fit/BumpsFitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ def fit(self, msg_q=None,
# Run the fit
result = run_bumps(problem, handler, curr_thread)
if handler is not None:
if result['errors']:
handler.error(result['errors'])
return []
handler.update_fit(last=True)

# TODO: shouldn't reference internal parameters of fit problem
Expand Down Expand Up @@ -412,8 +415,12 @@ def abort_test():
success = best is not None
try:
stderr = fitdriver.stderr() if success else None
cov = (fitdriver.cov() if not hasattr(fitdriver.fitter, 'state') else
np.cov(fitdriver.fitter.state.draw().points.T))
if hasattr(fitdriver.fitter, 'state'):
x = fitdriver.fitter.state.draw().points
lucas-wilkins marked this conversation as resolved.
Show resolved Hide resolved
n_parameters = x.shape[1]
cov = np.cov(x.T, bias=True).reshape((n_parameters, n_parameters))
else:
cov = fitdriver.cov()
except Exception as exc:
errors.append(str(exc))
errors.append(traceback.format_exc())
Expand Down
Loading