A lightweight framework for benchmarking HPO algorithms
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.config import Config
from hpoglue.optimizer import Optimizer
from hpoglue.problem import Problem
from hpoglue.query import Query
class RandomSearch(Optimizer):
name = "RandomSearch"
support = Problem.Support()
def __init__(self, problem, seed, working_directory, config_space):
self.config_space = config_space
self.config_space.seed(seed)
self.problem = problem
self._counter = 0
def ask(self):
self._counter += 1
config = Config(
config_id=str(self._counter),
values=self.config_space.sample_configuration().get_dictionary(),
)
return Query(config=config, fidelity=None)
def tell(self, result):
return
Example Benchmark Definition
import numpy as np
from ConfigSpace import ConfigurationSpace, Float
from hpoglue.benchmark import FunctionalBenchmark
from hpoglue.measure import Measure
from hpoglue.result import Result
def ackley_bench():
ackley_space = ConfigurationSpace()
for i in range(2):
ackley_space.add(Float(name=f"x{i}", bounds=[-32.768, 32.768]))
return FunctionalBenchmark(
name="ackley",
config_space=ackley_space,
metrics={"value": Measure.metric((0.0, np.inf), minimize=True)},
query=ackley,
)
def ackley(query):
x = np.array(query.config.to_tuple())
n_var=2
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 Result(
query=query,
fidelity=None,
values={"value": out},
)
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.0.tar.gz
(26.6 kB
view details)
File details
Details for the file hpoglue-0.1.0.tar.gz
.
File metadata
- Download URL: hpoglue-0.1.0.tar.gz
- Upload date:
- Size: 26.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a969068e0bc41f750f1cc1f826a0ec92b28aa10abba2d6fa3e3b9f3d92592ebc |
|
MD5 | 672744f0697f46ddd9b8b268f44e5417 |
|
BLAKE2b-256 | 9f6505e3f5a3bef5c3332bab42de9dca8f3841c13c4a14936802950a741b35bd |