Skip to content

removed strings in minimizer indexing mechanism #347 - #348

Merged
rozyczko merged 4 commits into
release-3.0from
347-enum-minimizers
Oct 30, 2026
Merged

rozyczko merged 4 commits into
release-3.0from
347-enum-minimizers

Conversation

@rozyczko

Copy link
Copy Markdown
Member

The Fitter.switch_minimizer method now only accepts AvailableMinimizers enum members, raising a TypeError if a string or invalid type is provided. The old create method and the from_string_to_enum conversion function are removed

The available_minimizers property now returns a list of enum members instead of strings.

@rozyczko rozyczko added [area] fitting Umbrella for fitting related work [scope] maintenance Code/tooling cleanup, no feature or bugfix (major.minor.PATCH) [priority] highest Urgent. Needs attention ASAP labels Oct 27, 2026
@codecov

codecov Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.67%. Comparing base (56d682a) to head (1c476b2).
⚠️ Report is 2 commits behind head on release-3.0.

Additional details and impacted files

Impacted file tree graph

@@               Coverage Diff               @@
##           release-3.0     #348      +/-   ##
===============================================
- Coverage        92.71%   92.67%   -0.05%     
===============================================
  Files               47       47              
  Lines             3406     3372      -34     
===============================================
- Hits              3158     3125      -33     
+ Misses             248      247       -1     
Flag Coverage Δ
unittests 92.67% <100.00%> (-0.05%) ⬇️

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

Files with missing lines Coverage Δ
src/easyscience/__init__.py 100.00% <100.00%> (ø)
src/easyscience/fitting/__init__.py 100.00% <ø> (ø)
src/easyscience/fitting/fitter.py 94.56% <100.00%> (-0.49%) ⬇️
src/easyscience/fitting/minimizers/__init__.py 100.00% <100.00%> (ø)
src/easyscience/fitting/minimizers/factory.py 100.00% <100.00%> (ø)
...c/easyscience/fitting/minimizers/minimizer_base.py 83.67% <100.00%> (ø)
.../easyscience/fitting/minimizers/minimizer_bumps.py 99.30% <100.00%> (ø)
...rc/easyscience/fitting/minimizers/minimizer_dfo.py 95.78% <100.00%> (ø)
.../easyscience/fitting/minimizers/minimizer_lmfit.py 98.29% <100.00%> (ø)
src/easyscience/fitting/minimizers/minimizers.py 85.36% <100.00%> (ø)
... and 1 more

fitter.switch_minimizer('Bumps')
from easyscience import AvailableMinimizers

fitter.switch_minimizer(AvailableMinimizers.Bumps)

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.

Defaulting the minimizer allows me to remove create entirely.

@rozyczko
rozyczko requested a review from damskii9992 October 29, 2026 07:57

@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 some small comments

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.

Should this file not be renamed to minimizers.py and be moved into the minimizers folder?

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.

err yes

Comment on lines +60 to +73
def test_available_minimizers():
assert AvailableMinimizers.LMFit
assert AvailableMinimizers.LMFit_leastsq
assert AvailableMinimizers.LMFit_powell
assert AvailableMinimizers.LMFit_cobyla
assert AvailableMinimizers.LMFit_differential_evolution
assert AvailableMinimizers.LMFit_scipy_least_squares
assert AvailableMinimizers.Bumps
assert AvailableMinimizers.Bumps_simplex
assert AvailableMinimizers.Bumps_newton
assert AvailableMinimizers.Bumps_lm
assert AvailableMinimizers.DFO
assert AvailableMinimizers.DFO_leastsq
assert len(AvailableMinimizers) == 12
assert Minimizers.LMFit
assert Minimizers.LMFit_leastsq
assert Minimizers.LMFit_powell
assert Minimizers.LMFit_cobyla
assert Minimizers.LMFit_differential_evolution
assert Minimizers.LMFit_scipy_least_squares
assert Minimizers.Bumps
assert Minimizers.Bumps_simplex
assert Minimizers.Bumps_newton
assert Minimizers.Bumps_lm
assert Minimizers.DFO
assert Minimizers.DFO_leastsq
assert len(Minimizers) == 12

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.

This test seems very redundant to me . . .

Comment on lines +80 to +87
def test_switch_minimizer_rejects_string(self, fitter: Fitter):
# When
mock_minimizer = MagicMock()
fitter._minimizer = mock_minimizer
mock_string_to_enum = MagicMock(return_value=10)
monkeypatch.setattr(easyscience.fitting.fitter, 'from_string_to_enum', mock_string_to_enum)

# Then
fitter.switch_minimizer('great-minimizer')
fitter._update_minimizer = MagicMock()

# Expect
fitter._update_minimizer.count(2)
mock_string_to_enum.assert_called_once_with('great-minimizer')
# Then Expect
with pytest.raises(TypeError, match='Minimizers'):
fitter.switch_minimizer('Bumps')
fitter._update_minimizer.assert_not_called()

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.

Here's another test for removed functionality.

@rozyczko rozyczko Oct 29, 2026 •

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.

Nope. This isn;t about removed string support.
The new isinstance check added in the PR adds to switch_minimizer.
The TypeError branch in the code has no test otherwise.
I think that the check is worth retaining. Without it, a caller who passes anything but a Minimizers type, gets AttributeError: object has no attribute 'package' from deep inside the code, instead of a message telling them to use Minimizers[name].

Comment thread tests/unit/fitting/test_fitter.py Outdated
Comment on lines +105 to +122
Minimizers.Bumps_newton,
Minimizers.Bumps_lm,
Minimizers.DFO,
Minimizers.DFO_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.

This test also seems a bit redundant, no?

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.

This test also seems a bit redundant, no?

The test copies the full enum into a list, so it breaks if a member is added or an engine is missing.
The property is public, though, so I'd keep a simple one-line test instead.
assert fitter.available_minimizers == list(Minimizers)

@rozyczko
rozyczko requested a review from damskii9992 October 30, 2026 13:24

@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.

Lets get this sucker merged.

@rozyczko
rozyczko merged commit 9feb730 into release-3.0 Oct 30, 2026
28 checks passed
@rozyczko
rozyczko deleted the 347-enum-minimizers branch October 30, 2026 13:30
@rozyczko rozyczko mentioned this pull request Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[area] fitting Umbrella for fitting related work [priority] highest Urgent. Needs attention ASAP [scope] maintenance Code/tooling cleanup, no feature or bugfix (major.minor.PATCH)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Removal of string-based minimizers remove minimizer checks in available_minimizers

2 participants