Skip to content

Conversation

andped10
Copy link
Contributor

@andped10 andped10 commented Jun 12, 2024

This PR is a change to how we in Fitter access different minimizers as described in ADR suggestion
The largest changes are in the fitter.py

Fitter now relies on a factory to produce the required minimizer.

All minimizers are a child of MinimizerBase.

The factory will:

  • only be able to produce the minimizers for which an explicit class exists.
  • the produced minimizers will all fulfill the interface described by the abstract MinimizerBase class.
  • Fitter should therefore only use the minimizer methods defined in MinimizerBase

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

This pull request does not contain a valid label. Please add one of the following labels: ['chore', 'fix', 'bugfix', 'bug', 'enhancement', 'feature', 'dependencies', 'documentation']

@andped10 andped10 added chore PR label fitting Umbrella for fitting related work labels Jun 12, 2024
@andped10 andped10 marked this pull request as ready for review June 12, 2024 11:20
Copy link
Member

@rozyczko rozyczko left a comment

Choose a reason for hiding this comment

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

Using enum in a factory pattern makes things simple and understandable.
We probably want to warn users if any of the "standard" minimizes are not imported, though.
I'm surprised there were no tests for that.


from .minimizer_bumps import Bumps
from .minimizer_dfo import DFO
from .minimizer_lmfit import LMFit
Copy link
Member

Choose a reason for hiding this comment

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

Any of these will throw if the given minimizer is not installed.
Originally (__init__.py), we would allow failures but kept going after notifying the user.
Why this (inflexible) choice?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The code should now be able to run with or without all the minimizer engines.

Furthermore, the factory now explicitly list the minimizers methods from the minimizer engines that are directly supported

Copy link
Contributor

@damskii9992 damskii9992 left a comment

Choose a reason for hiding this comment

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

A nice step in the right direction to make EasyScience easy to actually read for developers

self._update_minimizer(DEFAULT_MINIMIZER)

def __initialize(self):
def create(self, minimizer_name: str = DEFAULT_MINIMIZER) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the purpose of the create method? Seems to be redundant now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, you are right, but I did not dare to remove it yet since it is a public method and might be used in other codes.

I will add a code comment that I should be cleaned up.

def convert_to_pars_obj(self, pars) -> object:
return self._minimizer.convert_to_pars_obj(pars)

def initialize(self, fit_object, fit_function: Callable) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems to me like the initialize method is simply a combined setter method for the fit_object and the fit_function. So isn't this method also redundant?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right again. I will add a code comment and we can clean up these seemingly redundant methods at a later state.

I have also added an issue: #15

@andped10 andped10 merged commit 5240f15 into develop Jun 18, 2024
@andped10 andped10 deleted the 11-poc-minimizer-factory branch June 18, 2024 11:56
@andped10 andped10 mentioned this pull request Jun 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore PR label fitting Umbrella for fitting related work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants