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

Fix bugs in kurobako/solver/optuna.py #19

Merged
merged 5 commits into from
Apr 13, 2022
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions kurobako/solver/optuna.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@

from kurobako import problem
from kurobako import solver
import logging

_optuna_logger = optuna.logging.get_logger(__name__)

_optuna_logger.setLevel(optuna.logging.INFO)
console = logging.StreamHandler()
_optuna_logger.addHandler(console)
Copy link
Member

Choose a reason for hiding this comment

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

Could you explain the necessity of this change?

Copy link
Member

@toshihikoyanase toshihikoyanase Apr 13, 2022

Choose a reason for hiding this comment

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

In my understanding, handlers and log levels are usually set in the user code, not library code.
I don't think it is a good practice to show log messages.


class OptunaSolverFactory(solver.SolverFactory):
def __init__(
Expand Down Expand Up @@ -121,7 +124,9 @@ def ask(self, idg: solver.TrialIdGenerator) -> solver.NextTrial:
next_step = self._next_step(0)
else:
kurobako_trial_id, trial = self._waitings.get()
current_step = trial.last_step
# TODO: remove access to self._study._storage
current_step = self._study._storage.get_trial(trial._trial_id).last_step

next_step = self._next_step(current_step)

params = [] # type: List[Optional[float]]
Expand Down Expand Up @@ -171,7 +176,6 @@ def tell(self, evaluated_trial: solver.EvaluatedTrial):
if len(values) == 0:
message = "Unevaluable trial#{}: step={}".format(trial.number, current_step)
_optuna_logger.info(message)

self._study.tell(trial, state=optuna.trial.TrialState.PRUNED)
return

Expand All @@ -182,11 +186,19 @@ def tell(self, evaluated_trial: solver.EvaluatedTrial):

assert current_step <= self._problem.last_step
if self._problem.last_step == current_step:
frozen_trial = self._study.tell(trial, values=values)
if version.parse(optuna_ver) >= version.Version("3.0.0b0"):
self._study._log_completed_trial(frozen_trial)
self._study.tell(trial, values=values)
if len(values) == 1:
_optuna_logger.info(
"Successful trial#{}: step={}, value={} (Best value: {})".format(
trial.number, current_step, values[0], self._study.best_value
)
)
else:
self._study._log_completed_trial(trial, values)
_optuna_logger.info(
"Successful trial#{}: step={}, value={}".format(
trial.number, current_step, values
)
)
HideakiImamura marked this conversation as resolved.
Show resolved Hide resolved
else:
if len(values) > 1:
raise NotImplementedError(
Expand Down