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

Failed S(Q) fitting causes loss of function #3147

Open
olihammond opened this issue Nov 12, 2024 · 6 comments · May be fixed by #3172
Open

Failed S(Q) fitting causes loss of function #3147

olihammond opened this issue Nov 12, 2024 · 6 comments · May be fixed by #3172
Assignees
Labels
Critical High priority Defect Bug or undesirable behaviour Fitting Perspective Concerns the fitting perspective

Comments

@olihammond
Copy link

Describe the bug
Fitting with a structure factor can take a long time to converge, or can fail, due to a large number of free/correlated parameters. In this case the fit can be manually stopped by the user. Once the fit has been stopped, the fitting function is lost. The user must then either reselect the model, or resend the data to fit and start again, inputting all parameters repeatedly, to continue fitting their data. Several errors are printed following this:

10:39:08 - ERROR: can only concatenate str (not "method") to str Traceback (most recent call last): File "sas/sascalc/fit/BumpsFitting.py", line 403, in run_bumps File "bumps/fitters.py", line 970, in fit File "bumps/fitters.py", line 567, in solve File "bumps/mpfit.py", line 1223, in init TypeError: can only concatenate str (not "method") to str SVD did not converge Traceback (most recent call last): File "sas/sascalc/fit/BumpsFitting.py", line 423, in run_bumps File "bumps/fitters.py", line 1056, in cov File "bumps/lsqerror.py", line 277, in jacobian_cov File "numpy/linalg/linalg.py", line 1681, in svd File "numpy/linalg/linalg.py", line 121, in _raise_linalgerror_svd_nonconvergence numpy.linalg.LinAlgError: SVD did not converge === Steps: 5 of 200 chisq: 209 ETA: 2024-11-12 10:39 (2s from now) M15.background : 0.514 | M15.charge : 1e-06 | M15.length : 57.3 M15.radius : 4.44 | M15.volfraction : 0.153 |
10:39:08 - ERROR: Traceback (most recent call last): File "sas/qtgui/Perspectives/Fitting/FittingWidget.py", line 2123, in fitComplete IndexError: list index out of range

To Reproduce
Steps to reproduce the behavior:

  1. Send a dataset for fitting
  2. Choose a shape-dependent function and the hayter_msa S(Q)
  3. Start fitting, but hit the stop fit button
  4. See error (subsequent fitting attempts will fail instantly unless a different model is chosen, or data are refreshed)

Expected behavior
In the case of nonconvergence, one should be able to continue working from the state of the fitting parameters prior to the failed attempt. Once this error occurs one must either reload the file, or reselect the desired model and input the parameters once more, which is cumbersome.

Screenshots
If applicable, add screenshots to help explain your problem.

SasView version (please complete the following information):

  • Version: 6.0.0, but has been observed in 5.0.5, 5.0.6, etc.

Operating system (please complete the following information):

  • OS: OSX Ventura 13.7.1

Additional context
Add any other context about the problem here.

@smk78
Copy link
Contributor

smk78 commented Nov 25, 2024

Thank you for this report @olihammond . This behaviour, or at least something similar, had been noted in the pre-release testing for 6.0.0 (see #3101). The problem was finding a reproducible way to track it down.

@smk78 smk78 added Defect Bug or undesirable behaviour Critical High priority Fitting Perspective Concerns the fitting perspective labels Nov 25, 2024
@rozyczko
Copy link
Member

rozyczko commented Jan 8, 2025

The way to reproduce the issue:

  1. Load a larger dataset (e.g. hSDS_D2O_2p0_percent.xml and set the sphere model (sphere/sphere)
  2. Add hayter_msa structure factor
  3. Click on Compute/Plot
  4. Select all sphere and hayter_msa parameters for fitting
  5. Click on Fit
  6. Click on Stop Fitting
    --> Observe an error from bumps
  7. Click on Compute/Plot
    --> Observe bad plots and NaN for hayter_msa radius parameter

@rozyczko
Copy link
Member

rozyczko commented Jan 8, 2025

Looks like this is a bumps issue, since the original assertion happens there.

  File "C:\projects\sas\sasview\src\sas\sascalc\fit\BumpsFitting.py", line 284, in fit
    assert values is not None and errs is not None
                                  ^^^^^^^^^^^^^^^^

However, we should not care whether the minimizer throws and just silently go on with unchanged dataset, in such case.

@olihammond
Copy link
Author

It is worth noting that this issue did not occur when we tested the same with DREAM rather than Levenberg-Marquardt. And also that it's not just the sphere model that triggers it; I saw it with the ellipsoid and cylinder models, too.

@rozyczko rozyczko linked a pull request Jan 8, 2025 that will close this issue
7 tasks
@olihammond olihammond linked a pull request Jan 9, 2025 that will close this issue
7 tasks
@olihammond
Copy link
Author

olihammond commented Jan 17, 2025

This fix seems to be working now with the sphere model we originally tested. However I have been testing it with more advanced models with a large number of free parameters and the issue is seen once again; see below errors thrown when attempting to fit using core_shell_cylinder, and cancelling the fit:

11:01:42 - INFO: Fitting: Terminated!!! === Steps: 2 of 200 chisq: 1.17e+05 ETA: 2025-01-17 11:01 (2s from now) M2.background : 0.00749 | M2.charge : 24.2 | M2.concentration_salt: 0 M2.dielectconst : 93.4 | M2.length : 363 | M2.radius : 0 M2.radius_effective : 20.8 | M2.sld_core : 15.9 | M2.sld_shell : 15.8 M2.sld_solvent : 12.9 | M2.temperature : 418 | M2.thickness : 39.8 M2.volfraction : 0.0196 |
11:01:42 - ERROR: can only concatenate str (not "method") to str Traceback (most recent call last): File "/Users/oliverhammond/sasview/src/sas/sascalc/fit/BumpsFitting.py", line 403, in run_bumps best, fbest = fitdriver.fit() ^^^^^^^^^^^^^^^ File "/opt/homebrew/anaconda3/envs/sasview_dev/lib/python3.11/site-packages/bumps/fitters.py", line 970, in fit x, fx = fitter.solve(monitors=self.monitors, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/anaconda3/envs/sasview_dev/lib/python3.11/site-packages/bumps/fitters.py", line 567, in solve result = mpfit( ^^^^^^ File "/opt/homebrew/anaconda3/envs/sasview_dev/lib/python3.11/site-packages/bumps/mpfit.py", line 1223, in __init__ self.errmsg = 'WARNING: premature termination by "'+fcn+'"' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~ TypeError: can only concatenate str (not "method") to str SVD did not converge Traceback (most recent call last): File "/Users/oliverhammond/sasview/src/sas/sascalc/fit/BumpsFitting.py", line 423, in run_bumps cov = fitdriver.cov() ^^^^^^^^^^^^^^^ File "/opt/homebrew/anaconda3/envs/sasview_dev/lib/python3.11/site-packages/bumps/fitters.py", line 1056, in cov self._cov = lsqerror.jacobian_cov(J) ^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/anaconda3/envs/sasview_dev/lib/python3.11/site-packages/bumps/lsqerror.py", line 277, in jacobian_cov u, s, vh = np.linalg.svd(J, 0) ^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/anaconda3/envs/sasview_dev/lib/python3.11/site-packages/numpy/linalg/linalg.py", line 1681, in svd u, s, vh = gufunc(a, signature=signature, extobj=extobj) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/anaconda3/envs/sasview_dev/lib/python3.11/site-packages/numpy/linalg/linalg.py", line 121, in _raise_linalgerror_svd_nonconvergence raise LinAlgError("SVD did not converge") numpy.linalg.LinAlgError: SVD did not converge === Steps: 2 of 200 chisq: 1.17e+05 ETA: 2025-01-17 11:01 (2s from now) M2.background : 0.00749 | M2.charge : 24.2 | M2.concentration_salt: 0 M2.dielectconst : 93.4 | M2.length : 363 | M2.radius : 0 M2.radius_effective : 20.8 | M2.sld_core : 15.9 | M2.sld_shell : 15.8 M2.sld_solvent : 12.9 | M2.temperature : 418 | M2.thickness : 39.8 M2.volfraction : 0.0196 |


At which point hitting Compute/Plot also fails:

11:06:05 - ERROR: Traceback (most recent call last): File "/Users/oliverhammond/sasview/src/sas/qtgui/MainWindow/DataExplorer.py", line 1318, in updatePlot self.active_plots[data_id].replacePlot(data_id, data) File "/Users/oliverhammond/sasview/src/sas/qtgui/Plotting/Plotter.py", line 693, in replacePlot self.plot(data=new_plot) File "/Users/oliverhammond/sasview/src/sas/qtgui/Plotting/Plotter.py", line 311, in plot self.ax.set_ybound(y_range[0], y_range[1]) File "/opt/homebrew/anaconda3/envs/sasview_dev/lib/python3.11/site-packages/matplotlib/axes/_base.py", line 3915, in set_ybound self.set_ylim(sorted((lower, upper), File "/opt/homebrew/anaconda3/envs/sasview_dev/lib/python3.11/site-packages/matplotlib/axes/_base.py", line 4017, in set_ylim return self.yaxis._set_lim(bottom, top, emit=emit, auto=auto) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/anaconda3/envs/sasview_dev/lib/python3.11/site-packages/matplotlib/axis.py", line 1227, in _set_lim v0 = self.axes._validate_converted_limits(v0, self.convert_units) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/anaconda3/envs/sasview_dev/lib/python3.11/site-packages/matplotlib/axes/_base.py", line 3704, in _validate_converted_limits raise ValueError("Axis limits cannot be NaN or Inf") ValueError: Axis limits cannot be NaN or Inf

@rozyczko
Copy link
Member

I am not able to reproduce the problem, using the sequence of operations mentioned above but with core shell cylinder + hayter_msa.

I see that your error message mentions M2 parameters - are you doing constrained fitting?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Critical High priority Defect Bug or undesirable behaviour Fitting Perspective Concerns the fitting perspective
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants