Remove restart_strategy and inc_popsize to simplify CmaEsSampler#6025
Remove restart_strategy and inc_popsize to simplify CmaEsSampler#6025c-bata merged 16 commits intooptuna:masterfrom
restart_strategy and inc_popsize to simplify CmaEsSampler#6025Conversation
|
@c-bata @HideakiImamura |
HideakiImamura
left a comment
There was a problem hiding this comment.
Thanks for the PR. Basically, LGTM. I have several comments. PTAL.
optuna/samplers/_cmaes.py
Outdated
| versions without prior notice. See | ||
| https://github.com/optuna/optuna/releases/tag/v2.1.0. | ||
| .. warning:: | ||
| Deprecated in v4.3.0. ``consider_prior`` argument will be removed in the future. |
There was a problem hiding this comment.
| Deprecated in v4.3.0. ``consider_prior`` argument will be removed in the future. | |
| Deprecated in v4.4.0. ``restart_strategy`` argument will be removed in the future. |
optuna/samplers/_cmaes.py
Outdated
| Deprecated in v4.3.0. ``consider_prior`` argument will be removed in the future. | ||
| The removal of this feature is currently scheduled for v6.0.0, | ||
| but this schedule is subject to change. | ||
| See https://github.com/optuna/optuna/releases/tag/v4.3.0. |
There was a problem hiding this comment.
| See https://github.com/optuna/optuna/releases/tag/v4.3.0. | |
| See https://github.com/optuna/optuna/releases/tag/v4.4.0. |
There was a problem hiding this comment.
In addition, inc_popsize also should be deprecated and the explanation of popsize should be changed.
optuna/samplers/_cmaes.py
Outdated
| ) -> None: | ||
| if restart_strategy is not None: | ||
| msg = _deprecated._DEPRECATION_WARNING_TEMPLATE.format( | ||
| name="`restart_strategy`", d_ver="4.3.0", r_ver="6.0.0" |
There was a problem hiding this comment.
| name="`restart_strategy`", d_ver="4.3.0", r_ver="6.0.0" | |
| name="`restart_strategy`", d_ver="4.4.0", r_ver="6.0.0" |
optuna/samplers/_cmaes.py
Outdated
| self._search_space = IntersectionSearchSpace() | ||
| self._consider_pruned_trials = consider_pruned_trials | ||
| self._restart_strategy = restart_strategy | ||
| self._initial_popsize = popsize |
There was a problem hiding this comment.
The population size is fixed (here or in the sample_relative). How about renaming this self._popsize?
|
Thank you for the review. I’ll make the necessary updates later. |
HideakiImamura
left a comment
There was a problem hiding this comment.
Thanks for the update. I have several another comments. Please take a look.
optuna/samplers/_cmaes.py
Outdated
| Deprecated in v4.4.0. ``restart_strategy`` argument will be removed in the future. | ||
| The removal of this feature is currently scheduled for v6.0.0, | ||
| but this schedule is subject to change. | ||
| See https://github.com/optuna/optuna/releases/tag/v4.4.0. | ||
| `restart_strategy` will be supported in OptunaHub. |
There was a problem hiding this comment.
There seems to be a missing message that says you can't actually use the feature.
optuna/samplers/_cmaes.py
Outdated
| .. warning:: | ||
| Deprecated along with ``restart_strategy``. |
There was a problem hiding this comment.
Deprecation messages should be written at the same level of text as restart_strategy without simplification.
optuna/samplers/_cmaes.py
Outdated
| lr_adapt: bool = False, | ||
| source_trials: list[FrozenTrial] | None = None, | ||
| ) -> None: | ||
| if restart_strategy is not None: |
There was a problem hiding this comment.
The deprecation message should also be emitted for inc_popsize.
|
@HideakiImamura Thank you for the review. I've made the update accordingly. PTAL! |
c-bata
left a comment
There was a problem hiding this comment.
Thank you for your pull request! I confirmed that this PR does not break the exisiting behavior using the following code.
import optuna
import optunahub
bbob = optunahub.load_module("benchmarks/bbob")
sphere2d = bbob.Problem(function_id=1, dimension=2, instance_id=1)
storage = optuna.storages.get_storage("sqlite:///cmaes_benchmark.db")
sampler = optuna.samplers.CmaEsSampler(seed=1)
study = optuna.create_study(
sampler=sampler,
directions=sphere2d.directions,
study_name="cmaes_pr6025",
storage=storage
)
study.optimize(sphere2d, n_trials=500)I've also left a few minor suggestions.
optuna/samplers/_cmaes.py
Outdated
| lr_adapt: bool = False, | ||
| source_trials: list[FrozenTrial] | None = None, | ||
| ) -> None: | ||
| if restart_strategy is not None or inc_popsize != 2: |
There was a problem hiding this comment.
How about changing the default value for inc_popsize to -1?
| if restart_strategy is not None or inc_popsize != 2: | |
| if restart_strategy is not None or inc_popsize != -1: |
This would allow us to show a warning message when users explicitly specify inc_popsize=2.
optuna/samplers/_cmaes.py
Outdated
| optimizer = self._init_optimizer( | ||
| trans, study.direction, population_size=self._initial_popsize | ||
| ) | ||
| optimizer = self._init_optimizer(trans, study.direction, population_size=self._popsize) |
There was a problem hiding this comment.
I think we could simply removing population_size argument from _init_optimizer() method. What do you think?
| optimizer = self._init_optimizer(trans, study.direction, population_size=self._popsize) | |
| optimizer = self._init_optimizer(trans, study.direction) |
optuna/samplers/_cmaes.py
Outdated
| if self._popsize is None: | ||
| self._popsize = 4 + math.floor(3 * math.log(len(trans.bounds))) |
There was a problem hiding this comment.
These lines can be simply removed. You can access to optimizer.population_size property method instead.
| if self._popsize is None: | |
| self._popsize = 4 + math.floor(3 * math.log(len(trans.bounds))) |
See https://github.com/CyberAgentAILab/cmaes/blob/f0749088ec53aca6f056c93faed71a775351591a/cmaes/_cma.py#L240-L243 for details.
HideakiImamura
left a comment
There was a problem hiding this comment.
Thanks for the update. Almost LGTM! I have two minor comments. PTAL.
optuna/samplers/_cmaes.py
Outdated
| or ``restart_strategy = 'bipop'`` is specified. | ||
|
|
||
| .. warning:: | ||
| Deprecated in v4.4.0. ``restart_strategy`` argument will be removed in the future. |
There was a problem hiding this comment.
| Deprecated in v4.4.0. ``restart_strategy`` argument will be removed in the future. | |
| Deprecated in v4.4.0. ``inc_popsize`` argument will be removed in the future. |
optuna/samplers/_cmaes.py
Outdated
| From v4.4.0 onward, ``restart_strategy`` automatically falls back to ``None``, and | ||
| ``restart_strategy`` will be supported in OptunaHub. |
There was a problem hiding this comment.
| From v4.4.0 onward, ``restart_strategy`` automatically falls back to ``None``, and | |
| ``restart_strategy`` will be supported in OptunaHub. | |
| From v4.4.0 onward, ``inc_popsize`` automatically falls back to ``None``, and | |
| ``inc_popsize`` will be supported in OptunaHub. |
8dc9671 to
a87d238
Compare
This reverts commit 8dab48d.
a87d238 to
0245e8c
Compare
|
Still investigating the cause of the |
|
@c-bata @HideakiImamura Thank you for your feedback and patience. Everything should be updated now. PTAL! |
HideakiImamura
left a comment
There was a problem hiding this comment.
Thanks for the update! LGTM!
c-bata
left a comment
There was a problem hiding this comment.
LGTM! Thank you for your contribution.
| def optimizer_key_template(restart: int) -> str: | ||
| if self._restart_strategy is None: | ||
| return attr_prefix + "optimizer" | ||
| else: | ||
| return attr_prefix + "{}:restart_{}:optimizer".format( | ||
| self._restart_strategy, restart | ||
| ) | ||
|
|
||
| def generation_attr_key_template(restart: int) -> str: | ||
| if self._restart_strategy is None: | ||
| return attr_prefix + "generation" | ||
| else: | ||
| return attr_prefix + "{}:restart_{}:generation".format( | ||
| self._restart_strategy, restart | ||
| ) | ||
|
|
||
| def popsize_attr_key_template() -> str: | ||
| if self._restart_strategy is None: | ||
| return attr_prefix + "popsize" | ||
| else: | ||
| return attr_prefix + "{}:popsize".format(self._restart_strategy) | ||
|
|
||
| def n_restarts_attr_key_template() -> str: | ||
| if self._restart_strategy is None: | ||
| return attr_prefix + "n_restarts" | ||
| else: | ||
| return attr_prefix + "{}:n_restarts".format(self._restart_strategy) | ||
|
|
There was a problem hiding this comment.
We could simply remove the _CmaEsAttrKeys class and return a string object, since all callable functions have been removed in this PR. This could be addressed in a follow-up PR.
There was a problem hiding this comment.
Thank you for the suggestion. I created the follow-up PR, #6068

Motivation
Simplify the implementation of
CmaEsSamplerby removing support for restart strategies. The current implementation withrestart_strategywill be put into OptunaHubSummary of Changes
restart_strategyandinc_popsizeoptions inCmaEsSampler_CmaEsAttrKeys, includingpopsize,n_restarts,n_restarts_with_large,poptype,small_n_eval, andlarge_n_evalset_trial_system_attrsince state tracking is no longer needed