-
Notifications
You must be signed in to change notification settings - Fork 2
11 poc minimizer factory #13
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
Conversation
There was a problem hiding this 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']
There was a problem hiding this 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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this 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: |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
This PR is a change to how we in
Fitter
access different minimizers as described in ADR suggestionThe 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:
MinimizerBase
class.Fitter
should therefore only use the minimizer methods defined inMinimizerBase