HPO tool with a modular API that allows for the easy interfacing of a new Optimizer and a new Benchmark
Project description
hpoglue
HPO tool with a modular API that allows for the easy interfacing of a new Optimizer and a new Benchmark
Minimal Example to run hpoglue
from hpoglue.run_glue import run_glue
df = run_glue(
run_name="hpoglue_ex",
optimizer = ...,
benchmark = ...,
seed = 1,
budget = 50
)
[!TIP]
Installation
Create a Virtual Environment using Venv
python -m venv hpoglue_env
source hpoglue_env/bin/activate
Installing from PyPI
pip install hpoglue
[!TIP]
pip install hpoglue["notebook"]
- For usage in a notebook
Installation from source
git clone https://github.com/automl/hpoglue.git
cd hpoglue
pip install -e . # -e for editable install
Example Optimizer Definition
from ConfigSpace import ConfigurationSpace
from hpoglue import Config, Optimizer, Problem, Query
from pathlib import Path
class RandomSearch(Optimizer):
name = "RandomSearch"
support = Problem.Support()
def __init__(
self,
problem: Problem,
working_directory: str | Path,
seed: int | None = None,
):
"""
Args:
problem: Source of task information.
working_directory: TODO
seed: TODO
"""
self.config_space = problem.config_space
self.config_space.seed(seed)
self.problem = problem
self._optmizer_unique_id = 0
def ask(self) -> Query:
self._optmizer_unique_id += 1
config = Config(
config_id=str(self._optmizer_unique_id),
values=dict(self.config_space.sample_configuration()),
)
return Query(config=config, fidelity=None)
def tell(self, result: Result) -> None:
# Update the optimizer (not needed for RandomSearch)
return
Example Benchmark Definition
import numpy as np
from ConfigSpace import ConfigurationSpace
from hpoglue import FunctionalBenchmark, Measure, Result, Query
def ackley_fn(x1: float, x2: float) -> float:
x = np.array([x1, x2])
n_var=len(x)
a=20
b=1/5
c=2 * np.pi
part1 = -1. * a * np.exp(-1. * b * np.sqrt((1. / n_var) * np.sum(x * x)))
part2 = -1. * np.exp((1. / n_var) * np.sum(np.cos(c * x)))
out = part1 + part2 + a + np.exp(1)
return out
def wrapped_ackley(query: Query) -> Result:
y = ackley_fn(x1=query.config.values["x1"], x2=query.config.values["x2"])
return Result(query=query, fidelity=None, values={"y": y})
ACKLEY_BENCH = FunctionalBenchmark(
name="ackley",
config_space=ConfigurationSpace({"x1": (-32.768, 32.768), "x2": (-32.768, 32.768)}),
metrics={"y": Measure.metric((0.0, np.inf), minimize=True)},
query=wrapped_ackley,
)
Run hpoglue on the examples
from hpoglue.run_glue import run_glue
df = run_glue(
run_name="hpoglue_demo",
optimizer = RandomSearch,
benchmark = ACKLEY_BENCH,
seed = 1,
budget = 50
)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
hpoglue-0.1.1.tar.gz
(26.9 kB
view details)
File details
Details for the file hpoglue-0.1.1.tar.gz
.
File metadata
- Download URL: hpoglue-0.1.1.tar.gz
- Upload date:
- Size: 26.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77fc670a79d31e90aeb191a79caa6159fa6ff82cb28cf91a4658749948476d3f |
|
MD5 | 143b46442334852782220b458ccde08f |
|
BLAKE2b-256 | 1ae733140211a1ca18dde8a72163526cde4984f6de1fc6107a1661c991d49d7f |