feat: Add max_iter stopping criteria and refactor sampling API#18
Draft
pFornagiel wants to merge 5 commits intomainfrom
Draft
feat: Add max_iter stopping criteria and refactor sampling API#18pFornagiel wants to merge 5 commits intomainfrom
max_iter stopping criteria and refactor sampling API#18pFornagiel wants to merge 5 commits intomainfrom
Conversation
…for stopping criteria
…onfig parameters and usage
max_iter stopping criteria and refactor sampling APImax_iter stopping criteria and refactor sampling API
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
This PR introduces a
max_iterstopping criterion for Basin-Hopping sampling, which caps the total number of iterations per run, and renamesmax_perturbations_without_improvementton_iters_no_changeto align API naming with the one ofscikitlibraries.It also simplifies the
compute_lonpublic API by merging configuration parameters into a singleBasinHoppingSamplerConfigobject, consistent with howBasinHoppingSampleris already used directly.Fixes #13
Changes made
src/lonpy/sampling.pyBasinHoppingSamplerConfigRenamed
max_perturbations_without_improvementton_iter_no_change(int | None, default1000):None) to allow disabling this criterion entirely whenmax_iteris set.Added
max_iter: int | None = None:Added
__post_init__validation:ValueErrorif bothn_iter_no_changeandmax_iterareNone, ensuring at least one stopping criterion is always active.Improved docstrings for
minimizer_methodandminimizer_optionsto include cross-references toscipy.optimize.minimizedocumentation and clarify accepted argument types.BasinHoppingSampler._basin_hopping_sampling()while perturbations_without_improvement < ...loop condition withwhile True:and explicitbreakstatements for both stopping criteria.compute_lon()Replaced the following flat parameters:
seed,step_size,step_mode,n_runs,max_perturbations_without_improvement,fitness_precision,coordinate_precision,boundedwith a single
config: BasinHoppingSamplerConfig | None = Noneparameter.This makes
compute_lonconsistent withBasinHoppingSampler.sample_to_lon()and removes the risk of the two APIs diverging during the development. We did not accept all the possible options already and constructed the config itself inside the method, so this seems like a right decision in my opinion.Updated docstring accordingly.
Docs
Documentation has been updated to reflect all of the above API changes.