forked from optuna/optuna
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request optuna#5157 from Alnusjaponica/move-_create_frozen…
…_trial Unify the implementation of `_create_frozen_trial()` under `testing` module
- Loading branch information
Showing
3 changed files
with
97 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from __future__ import annotations | ||
|
||
from collections.abc import Sequence | ||
from typing import Any | ||
|
||
import optuna | ||
from optuna.distributions import BaseDistribution | ||
from optuna.samplers._base import _CONSTRAINTS_KEY | ||
from optuna.trial import FrozenTrial | ||
from optuna.trial import TrialState | ||
|
||
|
||
def _create_frozen_trial( | ||
number: int = 0, | ||
values: Sequence[float] | None = None, | ||
constraints: Sequence[float] | None = None, | ||
params: dict[str, Any] | None = None, | ||
param_distributions: dict[str, BaseDistribution] | None = None, | ||
state: TrialState = TrialState.COMPLETE, | ||
) -> optuna.trial.FrozenTrial: | ||
return FrozenTrial( | ||
number=number, | ||
value=1.0 if values is None else None, | ||
values=values, | ||
state=state, | ||
user_attrs={}, | ||
system_attrs={} if constraints is None else {_CONSTRAINTS_KEY: list(constraints)}, | ||
params=params or {}, | ||
distributions=param_distributions or {}, | ||
intermediate_values={}, | ||
datetime_start=None, | ||
datetime_complete=None, | ||
trial_id=number, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters