Skip to content
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

Implement optuna.terminator using optuna._gp #5241

Merged
merged 40 commits into from Feb 14, 2024

Conversation

y0z
Copy link
Member

@y0z y0z commented Feb 9, 2024

Motivation

  • Change the GP implementation used in optuna.terminator to optuna._gp from BoTorch.

Description of the changes

  • Refactoring optuna.terminator and related code for using optuna._gp.
  • Remove files that are no longer needed.

@github-actions github-actions bot added the optuna.samplers Related to the `optuna.samplers` submodule. This is automatically labeled by github-actions. label Feb 9, 2024
@contramundum53
Copy link
Member

contramundum53 commented Feb 9, 2024

image

The result looks good.

import optuna
import numpy as np
from optuna.terminator import RegretBoundEvaluator

study = optuna.study.create_study(sampler=optuna.samplers.TPESampler())

def objective(trial):
    x = trial.suggest_float("x", -3, 3)
    y = trial.suggest_float("y", -3, 3)
    return x ** 2 + y ** 2



study.optimize(objective, n_trials=50)
from optuna.visualization import plot_terminator_improvement

plot_terminator_improvement(study, improvement_evaluator=RegretBoundEvaluator(top_trials_ratio=1.0))

@contramundum53 contramundum53 added the compatibility Change that breaks compatibility. label Feb 9, 2024
@contramundum53 contramundum53 marked this pull request as ready for review February 9, 2024 09:22
Copy link
Member

@contramundum53 contramundum53 left a comment

Choose a reason for hiding this comment

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

LGTM!

@contramundum53
Copy link
Member

contramundum53 commented Feb 9, 2024

@nabenabe0928 Could you review this PR?

@contramundum53
Copy link
Member

Follow-up tasks:

  • Use kernel_params_cache to speed up evaluation
  • Set DEFAULT_TOP_TRIALS_RATIO to 1.0
  • Set beta to constant

Copy link

codecov bot commented Feb 9, 2024

Codecov Report

Attention: 8 lines in your changes are missing coverage. Please review.

Comparison is base (7f70eb2) 89.88% compared to head (5b52d8b) 89.72%.
Report is 15 commits behind head on master.

Files Patch % Lines
optuna/terminator/improvement/evaluator.py 89.09% 6 Missing ⚠️
optuna/_gp/prior.py 91.66% 1 Missing ⚠️
optuna/samplers/_gp/sampler.py 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5241      +/-   ##
==========================================
- Coverage   89.88%   89.72%   -0.16%     
==========================================
  Files         213      211       -2     
  Lines       14004    13835     -169     
==========================================
- Hits        12587    12414     -173     
- Misses       1417     1421       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@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 confirmed that we get the identical result with my modification as well!

import optuna
import numpy as np
from optuna.terminator import RegretBoundEvaluator

study = optuna.study.create_study(sampler=optuna.samplers.TPESampler(seed=42))

def objective(trial):
    x = trial.suggest_float("x", -3, 3)
    y = trial.suggest_float("y", -3, 3)
    return x ** 2 + y ** 2



study.optimize(objective, n_trials=50)
from optuna.visualization import plot_terminator_improvement

plot_terminator_improvement(study, improvement_evaluator=RegretBoundEvaluator(top_trials_ratio=1.0, seed=42))

optuna/terminator/improvement/evaluator.py Show resolved Hide resolved
optuna/terminator/improvement/evaluator.py Outdated Show resolved Hide resolved
optuna/terminator/improvement/evaluator.py Outdated Show resolved Hide resolved
optuna/terminator/improvement/evaluator.py Show resolved Hide resolved
optuna/terminator/improvement/evaluator.py Show resolved Hide resolved
Co-authored-by: Shuhei Watanabe <47781922+nabenabe0928@users.noreply.github.com>
y0z and others added 3 commits February 13, 2024 14:27
Co-authored-by: Shuhei Watanabe <47781922+nabenabe0928@users.noreply.github.com>
Co-authored-by: Shuhei Watanabe <47781922+nabenabe0928@users.noreply.github.com>
optuna/terminator/improvement/evaluator.py Outdated Show resolved Hide resolved
optuna/terminator/improvement/evaluator.py Outdated Show resolved Hide resolved
optuna/terminator/improvement/evaluator.py Outdated Show resolved Hide resolved
optuna/terminator/improvement/evaluator.py Outdated Show resolved Hide resolved
y0z and others added 13 commits February 13, 2024 15:37
Co-authored-by: Shuhei Watanabe <47781922+nabenabe0928@users.noreply.github.com>
Co-authored-by: Shuhei Watanabe <47781922+nabenabe0928@users.noreply.github.com>
Co-authored-by: Shuhei Watanabe <47781922+nabenabe0928@users.noreply.github.com>
Co-authored-by: Shuhei Watanabe <47781922+nabenabe0928@users.noreply.github.com>
This reverts commit e004e68.
Co-authored-by: Shuhei Watanabe <47781922+nabenabe0928@users.noreply.github.com>
Copy link
Collaborator

@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.

Let's add the version constraints to workflow.yml.

tests/terminator_tests/test_callback.py Outdated Show resolved Hide resolved
tests/terminator_tests/test_erroreval.py Outdated Show resolved Hide resolved
tests/terminator_tests/test_terminator.py Outdated Show resolved Hide resolved
tests/visualization_tests/test_terminator_improvement.py Outdated Show resolved Hide resolved
y0z and others added 4 commits February 13, 2024 17:13
Co-authored-by: Shuhei Watanabe <47781922+nabenabe0928@users.noreply.github.com>
Co-authored-by: Shuhei Watanabe <47781922+nabenabe0928@users.noreply.github.com>
Co-authored-by: Shuhei Watanabe <47781922+nabenabe0928@users.noreply.github.com>
Co-authored-by: Shuhei Watanabe <47781922+nabenabe0928@users.noreply.github.com>
Copy link
Collaborator

@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 was missing this bug until now.

optuna/_gp/acqf.py Outdated Show resolved Hide resolved
Co-authored-by: Shuhei Watanabe <47781922+nabenabe0928@users.noreply.github.com>
Copy link
Collaborator

@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.

Thank you for the work, LGTM!

@nabenabe0928 nabenabe0928 removed their assignment Feb 13, 2024
Copy link
Member

@contramundum53 contramundum53 left a comment

Choose a reason for hiding this comment

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

LGTM again!

@contramundum53 contramundum53 merged commit 5cc6b55 into optuna:master Feb 14, 2024
30 checks passed
@nabenabe0928 nabenabe0928 added this to the v3.6.0 milestone Feb 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compatibility Change that breaks compatibility. optuna.samplers Related to the `optuna.samplers` submodule. This is automatically labeled by github-actions.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants