Skip to content

fixed two minor issues in the LMFit wrapper. #301 and #302 - #303

Open
rozyczko wants to merge 3 commits into
sampler-engine-structure-280from
assign-none-if-no-covariance
Open

fixed two minor issues in the LMFit wrapper. #301 and #302#303
rozyczko wants to merge 3 commits into
sampler-engine-structure-280from
assign-none-if-no-covariance

Conversation

@rozyczko

@rozyczko rozyczko commented Sep 2, 2026

Copy link
Copy Markdown
Member

Parameter error handling improvements:

  • Parameters resulting from fits without error bar information (e.g., gradient-free methods or aborted fits) now have their error attribute set to None instead of 0.0, making it clear when uncertainty is genuinely unknown rather than zero.

Tolerance keyword selection:

  • The logic for setting tolerance keywords in _get_fit_kws now determines the effective minimization method before choosing the appropriate tolerance parameter, ensuring correct configuration for different backends.

@rozyczko rozyczko added [scope] bug Bug report or fix (major.minor.PATCH) [priority] highest Urgent. Needs attention ASAP labels Sep 2, 2026
@rozyczko
rozyczko requested a review from damskii9992 September 2, 2026 12:53
@codecov

codecov Bot commented Sep 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.82%. Comparing base (59d0eb8) to head (fff7998).

Additional details and impacted files

Impacted file tree graph

@@                       Coverage Diff                        @@
##           sampler-engine-structure-280     #303      +/-   ##
================================================================
+ Coverage                         83.74%   83.82%   +0.07%     
================================================================
  Files                                68       68              
  Lines                              5347     5348       +1     
================================================================
+ Hits                               4478     4483       +5     
+ Misses                              869      865       -4     
Flag Coverage Δ
unittests 83.82% <100.00%> (+0.07%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
.../easyscience/fitting/minimizers/minimizer_lmfit.py 97.93% <100.00%> (+2.79%) ⬆️

@damskii9992 damskii9992 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just a small comment and a question. Otherwise LGTM 👍

effective_method = method if method is not None else self._method
if tolerance is not None:
if method in [None, 'least_squares', 'leastsq']:
if effective_method in [None, 'least_squares', 'leastsq']:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You can remove None from the list here, effective_method can never be None :)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

errr... the power of ctr-c/ctrl-v is strong

assert item1.error == pytest.approx(0, abs=2.1e-1)
# Methods without error bars (e.g. lmfit's gradient-free powell/cobyla)
# report error as None rather than a fake 0.0.
assert item1.error is None or item1.error == pytest.approx(0, abs=2.1e-1)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Are there anywhere this is used where this new assert is now too loose? Just asking, haven't checked myself.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

for powell/cobyla the old assert was only confirming a hard-coded fake 0.0.
This was too loose in that nothing pinned which methods may return None.
Now each call site declares it, so any future potential changes to None in leastsq/Bumps/DFO will fail the test.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I modified the test to explicitly include the new behaviour

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[priority] highest Urgent. Needs attention ASAP [scope] bug Bug report or fix (major.minor.PATCH)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LMFit powell/cobyla crash with ftol when a tolerance is set No error coming back from minimizers is masked by 0.0

2 participants