Skip to content

Update the FAQ on reproducible optimization results to remove note on HyperbandPruner#5075

Merged
eukaryo merged 1 commit intooptuna:masterfrom
felix-cw:patch-1
Oct 30, 2023
Merged

Update the FAQ on reproducible optimization results to remove note on HyperbandPruner#5075
eukaryo merged 1 commit intooptuna:masterfrom
felix-cw:patch-1

Conversation

@felix-cw
Copy link
Copy Markdown
Contributor

Motivation

The FAQ contains a note on HyperbandPruner advising setting the python hash seed to ensure reproducible results.
It's in the paragraph after the code block.
It seems like this this is no longer applicable since #4131 and a similar note on in the API docs for HyperbandPruner was removed at that time

Description of the changes

Remove paragraph

To make the pruning by :class:`~optuna.pruners.HyperbandPruner` reproducible, you can specify ``study_name`` of :class:`~optuna.study.Study` and `hash seed <https://docs.python.org/3/using/cmdline.html#envvar-PYTHONHASHSEED>`_.

remove note on reproducibility for HyperbandPruner
@codecov
Copy link
Copy Markdown

codecov bot commented Oct 26, 2023

Codecov Report

Merging #5075 (f4e1d9a) into master (43c74b5) will increase coverage by 0.00%.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master    #5075   +/-   ##
=======================================
  Coverage   89.40%   89.40%           
=======================================
  Files         205      205           
  Lines       15116    15116           
=======================================
+ Hits        13514    13515    +1     
+ Misses       1602     1601    -1     

see 1 file with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@HideakiImamura
Copy link
Copy Markdown
Member

@eukaryo @nabenabe0928 Could you review this PR?

Copy link
Copy Markdown
Contributor

@nabenabe0928 nabenabe0928 left a comment

Choose a reason for hiding this comment

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

I tried the following code with different setups for study_name, n_jobs, and seed.

import optuna

study_name = ...
n_jobs = ...
seed = ...

def objective(trial):
    x = trial.suggest_float("x", -5.0, 5.0)
    for i in range(100):
        trial.report(x + (100 - i) * (6 - x), i + 1)

    return x

study = optuna.create_study(
    sampler=optuna.samplers.TPESampler(seed=seed),
    pruner=optuna.pruners.HyperbandPruner(min_resource=1, max_resource=101, reduction_factor=3),
    study_name=study_name,
)
study.optimize(objective, n_trials=30, n_jobs=n_jobs)

So basically, the result is reproducible only if n_jobs=1 and seed is not None.
Probably, we could mention this as HyperbandPruner by itself cannot guarantee reproducible optimizations.

@felix-cw
Copy link
Copy Markdown
Contributor Author

So basically, the result is reproducible only if n_jobs=1 and seed is not None. Probably, we could mention this as HyperbandPruner by itself cannot guarantee reproducible optimizations.

Thanks for having a look!
Just above in the FAQ it says to set a seed in the sampler for reproducibility and below it says that reproducibility is only feasible when studies are run sequentially. I think the latter point corresponds to setting n_jobs=1.

@nzw0301 nzw0301 added the document Documentation related. label Oct 27, 2023
Copy link
Copy Markdown
Contributor

@nabenabe0928 nabenabe0928 left a comment

Choose a reason for hiding this comment

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

So basically, the result is reproducible only if n_jobs=1 and seed is not None. Probably, we could mention this as HyperbandPruner by itself cannot guarantee reproducible optimizations.

Thanks for having a look! Just above in the FAQ it says to set a seed in the sampler for reproducibility and below it says that reproducibility is only feasible when studies are run sequentially. I think the latter point corresponds to setting n_jobs=1.

You are right! I approved the change:)

Copy link
Copy Markdown
Collaborator

@eukaryo eukaryo left a comment

Choose a reason for hiding this comment

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

I read the conversation, LGTM.

@eukaryo eukaryo added this to the v3.5.0 milestone Oct 30, 2023
@eukaryo eukaryo merged commit ae83e24 into optuna:master Oct 30, 2023
@felix-cw felix-cw deleted the patch-1 branch October 30, 2023 09:03
@nzw0301
Copy link
Copy Markdown
Member

nzw0301 commented Mar 23, 2025

Actually, we still need to study_name for reproducibility. I will send a PR to partially revert this and the parent PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

document Documentation related.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants