Skip to content

Commit

Permalink
Merge pull request optuna#5434 from nabenabe0928/code-fix/use-experim…
Browse files Browse the repository at this point in the history
…ental-template

Bundle experimental feature warning
  • Loading branch information
eukaryo authored May 22, 2024
2 parents 04d9536 + c4de828 commit 1a2dfd4
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 93 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_argument(option_name: str) -> None:
warnings.warn(
f"Argument ``{option_name}`` 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
9 changes: 2 additions & 7 deletions optuna/importance/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
from typing import Dict
from typing import List
from typing import Optional
import warnings

from optuna.exceptions import ExperimentalWarning
from optuna._experimental import warn_experimental_argument
from optuna.importance._base import BaseImportanceEvaluator
from optuna.importance._fanova import FanovaImportanceEvaluator
from optuna.importance._mean_decrease_impurity import MeanDecreaseImpurityImportanceEvaluator
Expand Down Expand Up @@ -119,9 +118,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_argument("normalize")
return res
39 changes: 7 additions & 32 deletions optuna/samplers/_cmaes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,17 @@
from typing import Tuple
from typing import TYPE_CHECKING
from typing import Union
import warnings

import numpy as np

import optuna
from optuna import logging
from optuna._experimental import warn_experimental_argument
from optuna._imports import _LazyImport
from optuna._transform import _SearchSpaceTransform
from optuna.distributions import BaseDistribution
from optuna.distributions import FloatDistribution
from optuna.distributions import IntDistribution
from optuna.exceptions import ExperimentalWarning
from optuna.samplers import BaseSampler
from optuna.samplers._lazy_random_state import LazyRandomState
from optuna.search_space import IntersectionSearchSpace
Expand Down Expand Up @@ -282,46 +281,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_argument("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_argument("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_argument("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_argument("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_argument("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_argument("lr_adapt")

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

import numpy as np

from optuna._experimental import warn_experimental_argument
from optuna._hypervolume import WFG
from optuna._hypervolume.hssp import _solve_hssp
from optuna.distributions import BaseDistribution
from optuna.distributions import CategoricalChoiceType
from optuna.exceptions import ExperimentalWarning
from optuna.logging import get_logger
from optuna.samplers._base import _CONSTRAINTS_KEY
from optuna.samplers._base import _process_constraints_after_trial
Expand Down Expand Up @@ -320,44 +320,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_argument("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_argument("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_argument("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_argument("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_argument("categorical_distance_func")

def reseed_rng(self) -> None:
self._rng.rng.seed()
Expand Down
27 changes: 5 additions & 22 deletions optuna/samplers/nsgaii/_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
import hashlib
from typing import Any
from typing import TYPE_CHECKING
import warnings

import optuna
from optuna._experimental import warn_experimental_argument
from optuna.distributions import BaseDistribution
from optuna.exceptions import ExperimentalWarning
from optuna.samplers._base import BaseSampler
from optuna.samplers._lazy_random_state import LazyRandomState
from optuna.samplers._random import RandomSampler
Expand Down Expand Up @@ -161,31 +160,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_argument("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_argument("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_argument("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_argument("elite_population_selection_strategy")

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

import optuna
from optuna.exceptions import ExperimentalWarning
from optuna._experimental import warn_experimental_argument
from optuna.study import Study
from optuna.study._multi_objective import _get_pareto_front_trials_by_trials
from optuna.trial import FrozenTrial
Expand Down Expand Up @@ -252,11 +252,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_argument("constraints_func")
feasible_trials = []
infeasible_trials = []
for trial in study.get_trials(deepcopy=False, states=(TrialState.COMPLETE,)):
Expand Down

0 comments on commit 1a2dfd4

Please sign in to comment.