Skip to content

Consistently use suggest_float#2344

Merged
himkt merged 11 commits intooptuna:masterfrom
crcrpar:code-fix/suggest-float
Feb 21, 2021
Merged

Consistently use suggest_float#2344
himkt merged 11 commits intooptuna:masterfrom
crcrpar:code-fix/suggest-float

Conversation

@crcrpar
Copy link
Copy Markdown
Contributor

@crcrpar crcrpar commented Feb 14, 2021

In the pursuit of the comprehensive use of suggest_float instead of suggest_( | log | discrete)uniform.

@github-actions github-actions bot added the optuna.visualization Related to the `optuna.visualization` submodule. This is automatically labeled by github-actions. label Feb 14, 2021
@codecov-io
Copy link
Copy Markdown

codecov-io commented Feb 14, 2021

Codecov Report

Merging #2344 (dd903ea) into master (d25c7ee) will decrease coverage by 0.05%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2344      +/-   ##
==========================================
- Coverage   91.14%   91.08%   -0.06%     
==========================================
  Files         126      126              
  Lines       10556    10556              
==========================================
- Hits         9621     9615       -6     
- Misses        935      941       +6     
Impacted Files Coverage Δ
optuna/distributions.py 97.01% <ø> (ø)
optuna/exceptions.py 100.00% <ø> (ø)
optuna/integration/cma.py 99.57% <ø> (ø)
optuna/integration/mlflow.py 100.00% <ø> (ø)
optuna/integration/skopt.py 96.66% <ø> (ø)
optuna/logging.py 98.33% <ø> (ø)
optuna/multi_objective/samplers/_random.py 100.00% <ø> (ø)
optuna/pruners/_hyperband.py 98.80% <ø> (ø)
optuna/pruners/_median.py 100.00% <ø> (ø)
optuna/pruners/_nop.py 100.00% <ø> (ø)
... and 18 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d25c7ee...dd903ea. Read the comment docs.

@HideakiImamura HideakiImamura added the code-fix Change that does not change the behavior, such as code refactoring. label Feb 15, 2021
@crcrpar crcrpar force-pushed the code-fix/suggest-float branch from 355e987 to 7909955 Compare February 17, 2021 12:04
@crcrpar crcrpar marked this pull request as ready for review February 17, 2021 23:18
@HideakiImamura
Copy link
Copy Markdown
Member

@himkt Could you review this PR if you have time? Please feel free to remove the assignment if you are busy.

Copy link
Copy Markdown
Member

@HideakiImamura HideakiImamura left a comment

Choose a reason for hiding this comment

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

Thanks for the code-fix. I have a minor comment. PTAL.

Co-authored-by: Hideaki Imamura <38826298+HideakiImamura@users.noreply.github.com>
Copy link
Copy Markdown
Member

@HideakiImamura HideakiImamura left a comment

Choose a reason for hiding this comment

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

LGTM.

@himkt
Copy link
Copy Markdown
Member

himkt commented Feb 18, 2021

Sorry but I want to clarify what consistently use means. 🙏
Is the scope of this PR is to replace suggest_{log,discrete_}uniform (a) with suggest_float (b) where (a) and (b) both appear in the same script, right? (I'm asking because I found there were still suggest_{log,discrete_}uniform in Optuna)

Details
> git grep "suggest_discrete_uniform"
optuna/distributions.py:    This object is instantiated by :func:`~optuna.trial.Trial.suggest_discrete_uniform`, and passed
optuna/integration/chainermn.py:    def suggest_discrete_uniform(self, name: str, low: float, high: float, q: float) -> float:
optuna/integration/chainermn.py:            return self.delegate.suggest_discrete_uniform(name, low, high, q)
optuna/multi_objective/trial.py:    def suggest_discrete_uniform(self, name: str, low: float, high: float, q: float) -> float:
optuna/multi_objective/trial.py:        Please refer to the documentation of :func:`optuna.trial.Trial.suggest_discrete_uniform`
optuna/multi_objective/trial.py:        return self._trial.suggest_discrete_uniform(name, low, high, q)
optuna/trial/_base.py:    def suggest_discrete_uniform(self, name: str, low: float, high: float, q: float) -> float:
optuna/trial/_fixed.py:    def suggest_discrete_uniform(self, name: str, low: float, high: float, q: float) -> float:
optuna/trial/_frozen.py:    def suggest_discrete_uniform(self, name: str, low: float, high: float, q: float) -> float:
optuna/trial/_trial.py:        :func:`~optuna.trial.Trial.suggest_discrete_uniform`.
optuna/trial/_trial.py:            :func:`~optuna.trial.Trial.suggest_discrete_uniform`.
optuna/trial/_trial.py:                    this method falls back to :func:`~optuna.trial.Trial.suggest_discrete_uniform`.
optuna/trial/_trial.py:                return self.suggest_discrete_uniform(name, low, high, step)
optuna/trial/_trial.py:    def suggest_discrete_uniform(self, name: str, low: float, high: float, q: float) -> float:
optuna/trial/_trial.py:                    subsample = trial.suggest_discrete_uniform("subsample", 0.1, 1.0, 0.1)
tests/integration_tests/test_chainermn.py:    def test_suggest_discrete_uniform(storage_mode: str, comm: CommunicatorBase) -> None:
tests/integration_tests/test_chainermn.py:                x1 = mn_trial.suggest_discrete_uniform("x", low, high, q)
tests/integration_tests/test_chainermn.py:                x2 = mn_trial.suggest_discrete_uniform("x", low, high, q)
tests/integration_tests/test_sampler.py:        p3 = trial.suggest_discrete_uniform("p3", 0, 9, 3)
tests/integration_tests/test_sampler.py:        p3 = trial.suggest_discrete_uniform("p3", 0, 9, 3)
tests/integration_tests/test_sampler.py:        p3 = trial.suggest_discrete_uniform("p3", 0, 9, 3)
tests/integration_tests/test_sampler.py:    p6 = trial.suggest_discrete_uniform("p6", 10, 20, 2)
tests/integration_tests/test_sampler.py:    p7 = trial.suggest_discrete_uniform("p7", 0.1, 1.0, 0.1)
tests/integration_tests/test_sampler.py:    p8 = trial.suggest_discrete_uniform("p8", 2.2, 2.2, 0.5)
tests/samplers_tests/test_grid.py:        d = trial.suggest_discrete_uniform("d", -5, 5, 1)
tests/samplers_tests/tpe_tests/test_sampler.py:        t.suggest_discrete_uniform("c", 1.0, 100.0, 3.0)
tests/trial_tests/test_fixed.py:def test_suggest_discrete_uniform() -> None:
tests/trial_tests/test_fixed.py:    assert trial.suggest_discrete_uniform("x", 0.0, 1.0, 0.1) == 0.9
tests/trial_tests/test_fixed.py:        trial.suggest_discrete_uniform("y", 0.0, 1.0, 0.1)
tests/trial_tests/test_frozen.py:        c = trial.suggest_discrete_uniform("c", 0.0, 10.0, 1.0)
tests/trial_tests/test_frozen.py:def test_suggest_discrete_uniform() -> None:
tests/trial_tests/test_frozen.py:    assert trial.suggest_discrete_uniform("x", 0.0, 1.0, 0.1) == 0.9
tests/trial_tests/test_frozen.py:        trial.suggest_discrete_uniform("y", 0.0, 1.0, 0.1)
tests/trial_tests/test_trial.py:    x6 = trial.suggest_discrete_uniform("x3", 10, 20, 1.0)
tests/trial_tests/test_trial.py:def test_check_distribution_suggest_discrete_uniform(
tests/trial_tests/test_trial.py:        trial.suggest_discrete_uniform("x", 10, 20, 2)
tests/trial_tests/test_trial.py:        trial.suggest_discrete_uniform("x", 10, 20, 2)
tests/trial_tests/test_trial.py:        trial.suggest_discrete_uniform("x", 10, 22, 2)
tests/trial_tests/test_trial.py:def test_suggest_discrete_uniform(storage_init_func: Callable[[], storages.BaseStorage]) -> None:
tests/trial_tests/test_trial.py:        assert trial.suggest_discrete_uniform("c", 1.0, 1.0, 1.0) == 1.0  # Suggesting a param.
tests/trial_tests/test_trial.py:            trial.suggest_discrete_uniform("c", 1.0, 1.0, 1.0) == 1.0
tests/trial_tests/test_trial.py:def test_suggest_discrete_uniform_range(
tests/trial_tests/test_trial.py:            x = trial.suggest_discrete_uniform(
tests/trial_tests/test_trial.py:            x = trial.suggest_discrete_uniform(
2021-02-18 23:37:41 [~/work/github.com/himkt/optuna] @ pr
> git grep "trial.suggest_loguniform"
optuna/multi_objective/trial.py:        return self._trial.suggest_loguniform(name, low, high)
optuna/trial/_trial.py:                    c = trial.suggest_loguniform("c", 1e-5, 1e2)
tests/importance_tests/test_mean_decrease_impurity.py:    x2 = trial.suggest_loguniform("x2", 0.1, 3)
tests/importance_tests/test_mean_decrease_impurity.py:    x3 = trial.suggest_loguniform("x3", 2, 4)
tests/integration_tests/test_chainermn.py:        y = trial.suggest_loguniform("y", 20, 30)
tests/integration_tests/test_chainermn.py:                    mn_trial.suggest_loguniform("x1", low1, high1)
tests/integration_tests/test_chainermn.py:                x4 = mn_trial.suggest_loguniform("x2", low2, high2)
tests/integration_tests/test_chainermn.py:                    mn_trial.suggest_loguniform("x", low, high)
tests/integration_tests/test_chainermn.py:                x1 = mn_trial.suggest_loguniform("x", low, high)
tests/integration_tests/test_chainermn.py:                x2 = mn_trial.suggest_loguniform("x", low, high)
tests/integration_tests/test_mlflow.py:    y = trial.suggest_loguniform("y", 20, 30)
tests/integration_tests/test_mlflow.py:    y = trial.suggest_loguniform("y", 20, 30)
tests/integration_tests/test_sampler.py:        p1 = trial.suggest_loguniform("p1", 1, 10)
tests/integration_tests/test_sampler.py:        p1 = trial.suggest_loguniform("p1", 1, 10)
tests/integration_tests/test_sampler.py:        p1 = trial.suggest_loguniform("p1", 50, 100)  # The range has been changed
tests/integration_tests/test_sampler.py:    p2 = trial.suggest_loguniform("p2", 0.0001, 0.3)
tests/integration_tests/test_sampler.py:    p3 = trial.suggest_loguniform("p3", 1.1, 1.1)
tests/integration_tests/test_tensorboard.py:    y = trial.suggest_loguniform("y", 20.0, 30.0)
tests/samplers_tests/test_grid.py:        e = trial.suggest_loguniform("e", 0.0001, 1)
tests/samplers_tests/test_samplers.py:        assert trial.suggest_loguniform("d", 1, 100) == unknown_param_value
tests/study_tests/test_study.py:    y = trial.suggest_loguniform("y", 20, 30)
tests/test_dashboard.py:        y = trial.suggest_loguniform("y", 10, 20)
tests/trial_tests/test_fixed.py:    assert trial.suggest_loguniform("x", 0.1, 1.0) == 0.99
tests/trial_tests/test_fixed.py:        trial.suggest_loguniform("y", 0.0, 1.0)
tests/trial_tests/test_frozen.py:        b = trial.suggest_loguniform("b", 0.1, 10.0)
tests/trial_tests/test_frozen.py:    assert trial.suggest_loguniform("x", 0.1, 1.0) == 0.99
tests/trial_tests/test_frozen.py:        trial.suggest_loguniform("y", 0.0, 1.0)
tests/trial_tests/test_trial.py:    x4 = trial.suggest_loguniform("x2", 1e-5, 1e-3)
tests/trial_tests/test_trial.py:        trial.suggest_loguniform("x", 10, 20)
tests/trial_tests/test_trial.py:        trial.suggest_loguniform("x", 10, 20)
tests/trial_tests/test_trial.py:        trial.suggest_loguniform("x", 10, 30)
tests/trial_tests/test_trial.py:        assert trial.suggest_loguniform("b", 1.0, 1.0) == 1.0  # Suggesting a param.
tests/trial_tests/test_trial.py:        assert trial.suggest_loguniform("b", 1.0, 1.0) == 1.0  # Suggesting the same param.
tutorial/10_key_features/003_efficient_optimization_algorithms.py:    alpha = trial.suggest_loguniform("alpha", 1e-5, 1e-1)
tutorial/20_recipes/003_attributes.py:    svc_c = trial.suggest_loguniform("svc_c", 1e-10, 1e10)

@crcrpar
Copy link
Copy Markdown
Contributor Author

crcrpar commented Feb 19, 2021

Basically I want to replace *uniform with *float as possible entirely except for the implementations of *uniform methods.

Some calls of `trials.suggest_(float, loguniform, discreteuniform) are left there deliberately if the caller functions names include uniform. Otherwise, I overlooked them. Let me check them again.

@crcrpar
Copy link
Copy Markdown
Contributor Author

crcrpar commented Feb 20, 2021

I'd like this pull request to get "squash & merge" as this pull request has a bunch of meaningless commits.

@himkt
Copy link
Copy Markdown
Member

himkt commented Feb 20, 2021

@himkt
Copy link
Copy Markdown
Member

himkt commented Feb 20, 2021

I'd like this pull request to get "squash & merge" as this pull request has a bunch of meaningless commits.

Gotcha, I'll merge this PR with squashing!

Copy link
Copy Markdown
Member

@himkt himkt left a comment

Choose a reason for hiding this comment

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

Thank you for the patience. LGTM.

@himkt himkt merged commit 1eaccb5 into optuna:master Feb 21, 2021
@toshihikoyanase toshihikoyanase added this to the v2.6.0 milestone Mar 4, 2021
xadrianzetx added a commit to xadrianzetx/optuna that referenced this pull request Aug 24, 2021
This includes using `suggest_float` instead of `suggest_{log | discrete}uniform`as described in optuna#2344
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code-fix Change that does not change the behavior, such as code refactoring. optuna.visualization Related to the `optuna.visualization` submodule. This is automatically labeled by github-actions.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants