Skip to content

Commit

Permalink
Bundle experimental feature warning
Browse files Browse the repository at this point in the history
  • Loading branch information
nabenabe0928 committed May 8, 2024
1 parent ab958d4 commit 55e1036
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 85 deletions.
8 changes: 8 additions & 0 deletions optuna/_experimental.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@
"""


def warn_experimental_option(option_name: str) -> None:
warnings.warn(
f"``{option_name}`` option is an experimental feature."
" The interface can change in the future.",
ExperimentalWarning,
)


def _validate_version(version: str) -> None:
if not isinstance(version, str) or len(version.split(".")) != 3:
raise ValueError(
Expand Down
7 changes: 2 additions & 5 deletions optuna/importance/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import Optional
import warnings

from optuna._experimental import warn_experimental_option
from optuna.exceptions import ExperimentalWarning
from optuna.importance._base import BaseImportanceEvaluator
from optuna.importance._fanova import FanovaImportanceEvaluator
Expand Down Expand Up @@ -119,9 +120,5 @@ def get_param_importances(
else:
return dict((param, value / s) for (param, value) in res.items())
else:
warnings.warn(
"`normalize` option is an experimental feature."
" The interface can change in the future.",
ExperimentalWarning,
)
warn_experimental_option("normalize")
return res
37 changes: 7 additions & 30 deletions optuna/samplers/_cmaes.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import optuna
from optuna import logging
from optuna._experimental import warn_experimental_option
from optuna._imports import _LazyImport
from optuna._transform import _SearchSpaceTransform
from optuna.distributions import BaseDistribution
Expand Down Expand Up @@ -282,46 +283,22 @@ def __init__(
self._source_trials = source_trials

if self._restart_strategy:
warnings.warn(
"`restart_strategy` option is an experimental feature."
" The interface can change in the future.",
ExperimentalWarning,
)
warn_experimental_option("restart_strategy")

if self._consider_pruned_trials:
warnings.warn(
"`consider_pruned_trials` option is an experimental feature."
" The interface can change in the future.",
ExperimentalWarning,
)
warn_experimental_option("consider_pruned_trials")

if self._use_separable_cma:
warnings.warn(
"`use_separable_cma` option is an experimental feature."
" The interface can change in the future.",
ExperimentalWarning,
)
warn_experimental_option("use_separable_cma")

if self._source_trials is not None:
warnings.warn(
"`source_trials` option is an experimental feature."
" The interface can change in the future.",
ExperimentalWarning,
)
warn_experimental_option("source_trials")

if self._with_margin:
warnings.warn(
"`with_margin` option is an experimental feature."
" The interface can change in the future.",
ExperimentalWarning,
)
warn_experimental_option("with_margin")

if self._lr_adapt:
warnings.warn(
"`lr_adapt` option is an experimental feature."
" The interface can change in the future.",
ExperimentalWarning,
)
warn_experimental_option("lr_adapt")

if source_trials is not None and (x0 is not None or sigma0 is not None):
raise ValueError(
Expand Down
31 changes: 6 additions & 25 deletions optuna/samplers/_tpe/sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import numpy as np

from optuna._experimental import warn_experimental_option
from optuna._hypervolume import WFG
from optuna._hypervolume.hssp import _solve_hssp
from optuna.distributions import BaseDistribution
Expand Down Expand Up @@ -322,44 +323,24 @@ def __init__(
self._parzen_estimator_cls = _ParzenEstimator

if multivariate:
warnings.warn(
"``multivariate`` option is an experimental feature."
" The interface can change in the future.",
ExperimentalWarning,
)
warn_experimental_option("multivariate")

if group:
if not multivariate:
raise ValueError(
"``group`` option can only be enabled when ``multivariate`` is enabled."
)
warnings.warn(
"``group`` option is an experimental feature."
" The interface can change in the future.",
ExperimentalWarning,
)
warn_experimental_option("group")
self._group_decomposed_search_space = _GroupDecomposedSearchSpace(True)

if constant_liar:
warnings.warn(
"``constant_liar`` option is an experimental feature."
" The interface can change in the future.",
ExperimentalWarning,
)
warn_experimental_option("constant_liar")

if constraints_func is not None:
warnings.warn(
"The ``constraints_func`` option is an experimental feature."
" The interface can change in the future.",
ExperimentalWarning,
)
warn_experimental_option("constraints_func")

if categorical_distance_func is not None:
warnings.warn(
"The ``categorical_distance_func`` option is an experimental feature."
" The interface can change in the future.",
ExperimentalWarning,
)
warn_experimental_option("categorical_distance_func")

def reseed_rng(self) -> None:
self._rng.rng.seed()
Expand Down
25 changes: 5 additions & 20 deletions optuna/samplers/nsgaii/_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import warnings

import optuna
from optuna._experimental import warn_experimental_option
from optuna.distributions import BaseDistribution
from optuna.exceptions import ExperimentalWarning
from optuna.samplers._base import BaseSampler
Expand Down Expand Up @@ -161,31 +162,15 @@ def __init__(
raise ValueError("`population_size` must be greater than or equal to 2.")

if constraints_func is not None:
warnings.warn(
"The constraints_func option is an experimental feature."
" The interface can change in the future.",
ExperimentalWarning,
)
warn_experimental_option("constraints_func")
if after_trial_strategy is not None:
warnings.warn(
"The after_trial_strategy option is an experimental feature."
" The interface can change in the future.",
ExperimentalWarning,
)
warn_experimental_option("after_trial_strategy")

if child_generation_strategy is not None:
warnings.warn(
"The child_generation_strategy option is an experimental feature."
" The interface can change in the future.",
ExperimentalWarning,
)
warn_experimental_option("child_generation_strategy")

if elite_population_selection_strategy is not None:
warnings.warn(
"The elite_population_selection_strategy option is an experimental feature."
" The interface can change in the future.",
ExperimentalWarning,
)
warn_experimental_option("elite_population_selection_strategy")

if crossover is None:
crossover = UniformCrossover(swapping_prob)
Expand Down
7 changes: 2 additions & 5 deletions optuna/visualization/_pareto_front.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import warnings

import optuna
from optuna._experimental import warn_experimental_option
from optuna.exceptions import ExperimentalWarning
from optuna.study import Study
from optuna.study._multi_objective import _get_pareto_front_trials_by_trials
Expand Down Expand Up @@ -252,11 +253,7 @@ def _get_pareto_front_info(
)

if constraints_func is not None:
warnings.warn(
"``constraints_func`` argument is an experimental feature."
" The interface can change in the future.",
ExperimentalWarning,
)
warn_experimental_option("constraints_func")
feasible_trials = []
infeasible_trials = []
for trial in study.get_trials(deepcopy=False, states=(TrialState.COMPLETE,)):
Expand Down

0 comments on commit 55e1036

Please sign in to comment.