Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace load_module('simple') to optunahub.samplers #179

Merged
merged 2 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
7 changes: 6 additions & 1 deletion package/samplers/simple/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,20 @@ 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
# optunahub.load_module("samplers/simple").SimpleBaseSampler
nabenabe0928 marked this conversation as resolved.
Show resolved Hide resolved
):
...
```
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