diff --git a/src/sas/qtgui/Perspectives/Fitting/GPUOptions.py b/src/sas/qtgui/Perspectives/Fitting/GPUOptions.py index 2a0ae35c5b..f90b009537 100644 --- a/src/sas/qtgui/Perspectives/Fitting/GPUOptions.py +++ b/src/sas/qtgui/Perspectives/Fitting/GPUOptions.py @@ -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) @@ -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: + self.set_sas_open_cl() + self._staged_open_cl = None def add_options(self): """ @@ -108,6 +116,11 @@ 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: @@ -115,9 +128,10 @@ def _stage_sas_open_cl(self, checked): 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 """ @@ -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) @@ -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): diff --git a/src/sas/sascalc/fit/BumpsFitting.py b/src/sas/sascalc/fit/BumpsFitting.py index 77f6b2f63d..7d2038d798 100644 --- a/src/sas/sascalc/fit/BumpsFitting.py +++ b/src/sas/sascalc/fit/BumpsFitting.py @@ -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 @@ -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 + 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())