Skip to content

Commit

Permalink
Merge pull request #179 from y0z/feature/update-simplebasesampler
Browse files Browse the repository at this point in the history
Replace `load_module('simple')` to `optunahub.samplers`
  • Loading branch information
nabenabe0928 authored Nov 15, 2024
2 parents d4997d9 + 337b602 commit 47c1fcb
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 21 deletions.
5 changes: 1 addition & 4 deletions package/samplers/gp_pims/sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 1 addition & 4 deletions package/samplers/hebo/sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
5 changes: 1 addition & 4 deletions package/samplers/nelder_mead/nelder_mead.py
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
6 changes: 5 additions & 1 deletion package/samplers/simple/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@ 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

## Example

```python
import optunahub

class UserDefinedSampler(
optunahub.load_module("samplers/simple").SimpleBaseSampler
optunahub.samplers.SimpleBaseSampler
):
...
```
Expand Down
2 changes: 1 addition & 1 deletion package/samplers/simple/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 1 addition & 2 deletions package/samplers/smac_sampler/sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 1 addition & 4 deletions package/samplers/whale_optimization/whale_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 47c1fcb

Please sign in to comment.