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

Fitting fails/hangs on some fits #2994

Closed
tsole0 opened this issue Jul 29, 2024 · 5 comments · Fixed by #3079
Closed

Fitting fails/hangs on some fits #2994

tsole0 opened this issue Jul 29, 2024 · 5 comments · Fixed by #3079
Assignees
Labels
Defect Bug or undesirable behaviour Fitting Perspective Concerns the fitting perspective Major Big change in the code or important change in behaviour SasView 6.0.1

Comments

@tsole0
Copy link
Contributor

tsole0 commented Jul 29, 2024

Describe the bug
On some fits, the fitting will hang--i.e. will not return a fit. The fit button will remain in the red "Stop fit" state, the status bar remains as "Fitting started...", and no plots appear. When the Stop fit button is clicked, this error will appear:

15:19:38 - sas.qtgui.Perspectives.Fitting.FittingWidget - ERROR - Traceback (most recent call last):
  File "C:\Users\myUser\sasview\src\sas\qtgui\Perspectives\Fitting\FittingWidget.py", line 2111, in fitComplete
    res_list = result[0][0]
               ~~~~~~~~~^^^
IndexError: string index out of range

I have done some investigating as to the cause of the bug, and it seems that the Bumps mpfit function will hang consistently on step 8 of the fitting process in my specific context (mileage may vary on other data files/fitted parameters). It is unclear to me whether or not fitting parameters are being passed to bumps incorrectly from FittingWidget.py or if this is a fundamental error with Bumps. I'll note that this bugged behavior is distinctly different from the normal way Bumps exits a fit, in which the current state of Bumps is returned when the thread is cancelled. In the bug, None is returned when the thread exits with an error, which is what causes the visible error message upstream:

(src/sas/sascalc/fit/BumpsFitting.py, run_bumps method):

try:
    best, fbest = fitdriver.fit()
except Exception as exc:
    best, fbest = None, np.NaN
    errors.extend([str(exc), traceback.format_exc()])
finally:
    mapper.stop_mapper(fitdriver.mapper)

The specific reason why fitdriver.fit() returns an error turns out to be what I think is a bug in Bumps, but doesn't seem related to the reason as to why the process hangs (if fixed does not fix the underlying problem):

(bumps/mpfit.py)

catch_msg = 'calling '+str(fcn)
[self.status, wa4] = self.call(fcn, self.params, functkw)
if (self.status < 0):
    self.errmsg = 'WARNING: premature termination by "'+fcn+'"'
                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
TypeError: can only concatenate str (not "method") to str

To Reproduce

  1. Download
    TMGel_RT4days_30C.txt
  2. Open SasView and Load data the file above
  3. Send to Fitting
  4. Category > Sphere
  5. Model Name > Sphere
  6. Structure factor > hayter_msa
  7. Check scale, volfraction, charge, and concentration for fitting
  8. Fit
  9. Fitting will hang, press Stop fit to view error

N.B. The bug can also sometimes be triggered by hitting the 'Fit' and 'Stop fitting' buttons multiple times in rapid succession

NOTE: Only fitting with one parameter selected after selecting the structure factor will result in a correct fit. If you then select the other fitting parameters, fitting will proceed as normal

Expected behavior
SasView to run a fit correctly and allow the user to interrupt the fitting process

Screenshots
Fitting hanging:
image
Fitting canceled:
image

SasView version (please complete the following information):

  • Version: 6.0.0b2, 5.0.6. From eye-witness accounts seems to have been present in previous versions.

Operating system (please complete the following information):

  • OS: Windows 10, also observed on MacOS Ventura

Additional context | IMPORTANT
Trying to fit with the same parameters but with a different model such as core_shell_sphere from start will cause a similar issue, but instead of hanging will automatically return the results[0][0] error.

@tsole0
Copy link
Contributor Author

tsole0 commented Jul 29, 2024

For anyone trying to investigate--I originally thought that #2751 was related (hence the branch 2751-fitting-errors), but I now believe that #2751 has the same surface manifestation (the result variable isn't returning what it should on a fit) but different underlying errors.

@tsole0 tsole0 added Defect Bug or undesirable behaviour Major Big change in the code or important change in behaviour Fitting Perspective Concerns the fitting perspective labels Jul 29, 2024
@krzywon krzywon added the SasView 6.0.0 Required for 6.0.0 release label Jul 30, 2024
@butlerpd
Copy link
Member

Identified during NIST CNR summer school hence the 6.0.0 label

@krzywon
Copy link
Contributor

krzywon commented Aug 20, 2024

Tested in 6.0.0 and 5.0.6. Both versions have the same behavior. If this is a small fix, I would say include it, otherwise, let's move to the next release.

@krzywon krzywon added SasView 6.0.1 and removed SasView 6.0.0 Required for 6.0.0 release labels Aug 20, 2024
@rozyczko
Copy link
Member

One obvious check to be added is testing for results actually having the [0][0] item before querying for it.
If the info is not in the results, the fitting should be marked as a failure.
This would at least show a proper message about failed fitting and allow subsequent attemtps

@rozyczko
Copy link
Member

... and addressed in 2994-fitting-failshangs-on-some-fits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Defect Bug or undesirable behaviour Fitting Perspective Concerns the fitting perspective Major Big change in the code or important change in behaviour SasView 6.0.1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants