-
Notifications
You must be signed in to change notification settings - Fork 2
60 add support lmfit differential evolution #61
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
Merged
andped10
merged 10 commits into
develop
from
60-add-support-lmfit-differential_evolution
Aug 28, 2024
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d1cf4d4
LMFit differnetial_evolution
andped10 874cbf2
ruff
andped10 009f054
expose available minimizers in fitter module
andped10 abf7671
introduced available_minimizers module
andped10 14c88dc
moved method dict to base class
andped10 cb50108
fix typing
andped10 3989a25
syntax
andped10 32cc794
Merge remote-tracking branch 'origin/develop' into 60-add-support-lmf…
andped10 ad69f25
PR response
andped10 3fccc9d
revert change as importlib.metadata.distributions is not supported in…
andped10 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,8 @@ | ||
| from .available_minimizers import AvailableMinimizers | ||
| from .fitter import Fitter | ||
| from .minimizers.utils import FitResults | ||
|
|
||
| # Causes circular import | ||
| # from .multi_fitter import MultiFitter # noqa: F401, E402 | ||
|
|
||
| all = [Fitter, FitResults] | ||
| all = [AvailableMinimizers, Fitter, FitResults] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| import warnings | ||
| from enum import Enum | ||
| from enum import auto | ||
|
|
||
| import pkg_resources | ||
|
|
||
| installed_packages = {pkg.key for pkg in pkg_resources.working_set} | ||
|
|
||
| # Change to importlib.metadata when Python 3.10 is the minimum version | ||
| # import importlib.metadata | ||
| # installed_packages = [x.name for x in importlib.metadata.distributions()] | ||
|
|
||
| lmfit_engine_available = False | ||
| if 'lmfit' in installed_packages: | ||
| lmfit_engine_available = True | ||
| else: | ||
| # TODO make this a proper message (use logging?) | ||
| warnings.warn('LMFit minimization is not available. Probably lmfit has not been installed.', ImportWarning, stacklevel=2) | ||
|
|
||
| bumps_engine_available = False | ||
| if 'bumps' in installed_packages: | ||
| bumps_engine_available = True | ||
| else: | ||
| # TODO make this a proper message (use logging?) | ||
| warnings.warn('Bumps minimization is not available. Probably bumps has not been installed.', ImportWarning, stacklevel=2) | ||
|
|
||
| dfo_engine_available = False | ||
| if 'dfo-ls' in installed_packages: | ||
| dfo_engine_available = True | ||
| else: | ||
| # TODO make this a proper message (use logging?) | ||
| warnings.warn('DFO minimization is not available. Probably dfols has not been installed.', ImportWarning, stacklevel=2) | ||
|
|
||
|
|
||
| class AvailableMinimizers(Enum): | ||
| if lmfit_engine_available: | ||
| LMFit = auto() | ||
| LMFit_leastsq = auto() | ||
| LMFit_powell = auto() | ||
| LMFit_cobyla = auto() | ||
| LMFit_differential_evolution = auto() | ||
|
|
||
| if bumps_engine_available: | ||
| Bumps = auto() | ||
| Bumps_simplex = auto() | ||
| Bumps_newton = auto() | ||
| Bumps_lm = auto() | ||
|
|
||
| if dfo_engine_available: | ||
| DFO = auto() | ||
| DFO_leastsq = auto() | ||
|
|
||
|
|
||
| # Temporary solution to convert string to enum | ||
| def from_string_to_enum(minimizer_name: str) -> AvailableMinimizers: | ||
| if minimizer_name == 'LMFit': | ||
| minmizer_enum = AvailableMinimizers.LMFit | ||
| elif minimizer_name == 'LMFit_leastsq': | ||
| minmizer_enum = AvailableMinimizers.LMFit_leastsq | ||
| elif minimizer_name == 'LMFit_powell': | ||
| minmizer_enum = AvailableMinimizers.LMFit_powell | ||
| elif minimizer_name == 'LMFit_cobyla': | ||
| minmizer_enum = AvailableMinimizers.LMFit_cobyla | ||
| elif minimizer_name == 'LMFit_differential_evolution': | ||
| minmizer_enum = AvailableMinimizers.LMFit_differential_evolution | ||
|
|
||
| elif minimizer_name == 'Bumps': | ||
| minmizer_enum = AvailableMinimizers.Bumps | ||
| elif minimizer_name == 'Bumps_simplex': | ||
| minmizer_enum = AvailableMinimizers.Bumps_simplex | ||
| elif minimizer_name == 'Bumps_newton': | ||
| minmizer_enum = AvailableMinimizers.Bumps_newton | ||
| elif minimizer_name == 'Bumps_lm': | ||
| minmizer_enum = AvailableMinimizers.Bumps_lm | ||
|
|
||
| elif minimizer_name == 'DFO': | ||
| minmizer_enum = AvailableMinimizers.DFO | ||
| elif minimizer_name == 'DFO_leastsq': | ||
| minmizer_enum = AvailableMinimizers.DFO_leastsq | ||
| else: | ||
| raise ValueError( | ||
| f'Invalid minimizer name: {minimizer_name}. The following minimizers are available: {[minimize.name for minimize in AvailableMinimizers]}' # noqa: E501 | ||
| ) | ||
|
|
||
| return minmizer_enum | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.