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

Better checks on result object so failed fitting is shown as such. #3079

Merged
merged 1 commit into from
Aug 22, 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
2 changes: 1 addition & 1 deletion src/sas/qtgui/MainWindow/GuiManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1148,7 +1148,7 @@ def showFitResults(self, output_data):
Show bumps convergence plots
"""
self.results_frame.setVisible(True)
if output_data:
if output_data and len(output_data) > 0 and len(output_data[0]) > 0:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any way output_data can be a scalar quantity if it has any truthiness?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any way output_data can be a scalar quantity if it has any truthiness?

Regardless of the failure/success, output_data should always be a tuple, as passed from FitThread/compute, so checking for the truthiness of it is probably unnecessary but maybe prudent.

self.results_panel.onPlotResults(output_data, optimizer=self.perspective().optimizer)

def actionAdd_Custom_Model(self):
Expand Down
6 changes: 4 additions & 2 deletions src/sas/qtgui/Perspectives/Fitting/ConstraintWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,13 +663,15 @@ def fitComplete(self, result):
self.parent.communicate.statusBarUpdateSignal.emit(msg)
return

# Get the results list
results = result[0][0]
if isinstance(result[0], str):
msg = ("Fitting failed with the following message: " +
result[0])
self.parent.communicate.statusBarUpdateSignal.emit(msg)
return

# Get the results list
results = result[0][0]

if not results[0].success:
if isinstance(results[0].mesg[0], str):
msg = ("Fitting failed with the following message: " +
Expand Down
4 changes: 4 additions & 0 deletions src/sas/qtgui/Perspectives/Fitting/FittingWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -2110,6 +2110,10 @@ def fitComplete(self, result):

# Don't recalculate chi2 - it's in res.fitness already
self.fitResults = True
if result is None or len(result) == 0 or len(result[0]) == 0:
msg = "Fitting failed."
self.communicate.statusBarUpdateSignal.emit(msg)
return
res_list = result[0][0]
res = res_list[0]
self.chi2 = res.fitness
Expand Down
Loading