From c47d1e4f4617c95a2eee3d15614f56b53d509171 Mon Sep 17 00:00:00 2001 From: y0z Date: Thu, 14 Nov 2024 17:05:08 +0900 Subject: [PATCH 1/2] Replace optunahub.load_module('simple').SimpleBaseSampler to optunahub.samplers.SimpleBaseSampler --- package/samplers/gp_pims/sampler.py | 5 +---- .../grey_wolf_optimization/grey_wolf_optimization.py | 2 +- package/samplers/hebo/sampler.py | 5 +---- package/samplers/nelder_mead/nelder_mead.py | 5 +---- package/samplers/simple/README.md | 7 ++++++- package/samplers/simple/example.py | 2 +- package/samplers/smac_sampler/sampler.py | 3 +-- package/samplers/whale_optimization/whale_optimization.py | 5 +---- 8 files changed, 13 insertions(+), 21 deletions(-) diff --git a/package/samplers/gp_pims/sampler.py b/package/samplers/gp_pims/sampler.py index 92469fa1..6ee587ff 100644 --- a/package/samplers/gp_pims/sampler.py +++ b/package/samplers/gp_pims/sampler.py @@ -469,10 +469,7 @@ def acq(self, x: np.ndarray) -> np.ndarray: return ((self.maximums - mean) / std).ravel() -SimpleBaseSampler = optunahub.load_module("samplers/simple").SimpleBaseSampler - - -class PIMSSampler(SimpleBaseSampler): # type: ignore +class PIMSSampler(optunahub.samplers.SimpleBaseSampler): def __init__( self, search_space: dict[str, optuna.distributions.BaseDistribution], diff --git a/package/samplers/grey_wolf_optimization/grey_wolf_optimization.py b/package/samplers/grey_wolf_optimization/grey_wolf_optimization.py index edf65987..1017088d 100644 --- a/package/samplers/grey_wolf_optimization/grey_wolf_optimization.py +++ b/package/samplers/grey_wolf_optimization/grey_wolf_optimization.py @@ -10,7 +10,7 @@ import optunahub -class GreyWolfOptimizationSampler(optunahub.load_module("samplers/simple").SimpleBaseSampler): # type: ignore +class GreyWolfOptimizationSampler(optunahub.samplers.SimpleBaseSampler): def __init__( self, search_space: dict[str, BaseDistribution] | None = None, diff --git a/package/samplers/hebo/sampler.py b/package/samplers/hebo/sampler.py index 38423d24..b76cd5bf 100644 --- a/package/samplers/hebo/sampler.py +++ b/package/samplers/hebo/sampler.py @@ -17,10 +17,7 @@ from hebo.optimizers.hebo import HEBO -SimpleBaseSampler = optunahub.load_module("samplers/simple").SimpleBaseSampler - - -class HEBOSampler(SimpleBaseSampler): # type: ignore +class HEBOSampler(optunahub.samplers.SimpleBaseSampler): def __init__(self, search_space: dict[str, BaseDistribution]) -> None: super().__init__(search_space) self._hebo = HEBO(self._convert_to_hebo_design_space(search_space)) diff --git a/package/samplers/nelder_mead/nelder_mead.py b/package/samplers/nelder_mead/nelder_mead.py index 5b39d1e5..887da5b6 100644 --- a/package/samplers/nelder_mead/nelder_mead.py +++ b/package/samplers/nelder_mead/nelder_mead.py @@ -10,10 +10,7 @@ from .generate_initial_simplex import generate_initial_simplex -SimpleBaseSampler = optunahub.load_module("samplers/simple").SimpleBaseSampler - - -class NelderMeadSampler(SimpleBaseSampler): # type: ignore +class NelderMeadSampler(optunahub.samplers.SimpleBaseSampler): """A sampler based on the Nelder-Mead simplex algorithm. This algorithm does not support conditional parameters that make a tree-structured search space. Sampling for such parameters is delegated to independent_sampler (default: RandomSampler). diff --git a/package/samplers/simple/README.md b/package/samplers/simple/README.md index eced9191..08c3a158 100644 --- a/package/samplers/simple/README.md +++ b/package/samplers/simple/README.md @@ -7,6 +7,8 @@ optuna_versions: [3.6.1] license: MIT License --- +`SimpleBaseSampler` has been moved to [`optunahub.samplers`](https://optuna.github.io/optunahub/samplers.html). Please use [`optunahub.samplers.SimpleBaseSampler`](https://optuna.github.io/optunahub/generated/optunahub.samplers.SimpleBaseSampler.html#optunahub.samplers.SimpleBaseSampler) instead of this package. + ## Class or Function Names - SimpleBaseSampler @@ -14,8 +16,11 @@ license: MIT License ## Example ```python +import optunahub + class UserDefinedSampler( - optunahub.load_module("samplers/simple").SimpleBaseSampler + optunahub.samplers.SimpleBaseSampler + # optunahub.load_module("samplers/simple").SimpleBaseSampler ): ... ``` diff --git a/package/samplers/simple/example.py b/package/samplers/simple/example.py index 4e536dc3..ed976519 100644 --- a/package/samplers/simple/example.py +++ b/package/samplers/simple/example.py @@ -12,7 +12,7 @@ import optunahub -class UserDefinedSampler(optunahub.load_module("samplers/simple").SimpleBaseSampler): # type: ignore +class UserDefinedSampler(optunahub.samplers.SimpleBaseSampler): def __init__(self, search_space: dict[str, BaseDistribution] | None = None) -> None: super().__init__(search_space) self._rng = np.random.RandomState() diff --git a/package/samplers/smac_sampler/sampler.py b/package/samplers/smac_sampler/sampler.py index 10c43204..964748d9 100644 --- a/package/samplers/smac_sampler/sampler.py +++ b/package/samplers/smac_sampler/sampler.py @@ -34,12 +34,11 @@ from smac.scenario import Scenario -SimpleBaseSampler = optunahub.load_module("samplers/simple").SimpleBaseSampler _SMAC_INSTANCE_KEY = "smac:instance" _SMAC_SEED_KEY = "smac:seed" -class SMACSampler(SimpleBaseSampler): # type: ignore +class SMACSampler(optunahub.samplers.SimpleBaseSampler): """ A sampler that uses SMAC3 v2.2.0. diff --git a/package/samplers/whale_optimization/whale_optimization.py b/package/samplers/whale_optimization/whale_optimization.py index b8337ac0..7f805968 100644 --- a/package/samplers/whale_optimization/whale_optimization.py +++ b/package/samplers/whale_optimization/whale_optimization.py @@ -7,10 +7,7 @@ import optunahub -SimpleBaseSampler = optunahub.load_module("samplers/simple").SimpleBaseSampler - - -class WhaleOptimizationSampler(SimpleBaseSampler): # type: ignore +class WhaleOptimizationSampler(optunahub.samplers.SimpleBaseSampler): def __init__( self, search_space: dict[str, optuna.distributions.BaseDistribution] | None = None, From 337b602f16eee40e3f4424ac78f3dff51007d04a Mon Sep 17 00:00:00 2001 From: Shuhei Watanabe <47781922+nabenabe0928@users.noreply.github.com> Date: Fri, 15 Nov 2024 05:50:56 +0100 Subject: [PATCH 2/2] Update package/samplers/simple/README.md --- package/samplers/simple/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/package/samplers/simple/README.md b/package/samplers/simple/README.md index 08c3a158..11bf34a9 100644 --- a/package/samplers/simple/README.md +++ b/package/samplers/simple/README.md @@ -20,7 +20,6 @@ import optunahub class UserDefinedSampler( optunahub.samplers.SimpleBaseSampler - # optunahub.load_module("samplers/simple").SimpleBaseSampler ): ... ```