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 = ..., # type[hpoglue.Optimizer]
benchmark = ..., # type[hpoglue.BenchmarkDescription] | type[hpoglue.FunctionalBenchmark]
seed = 1,
budget = 50
)
Installation
Create a Virtual Environment using Venv
python -m venv hpoglue_env
source hpoglue_env/bin/activate
Installing from PyPI
pip install hpoglue
Installation from source
git clone https://github.com/automl/hpoglue.git
cd hpoglue
pip install -e . # -e for editable install
Example Optimizer Definition
from pathlib import Path
from hpoglue import Config, Optimizer, Problem, Query, Result
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: Directory to save the optimizer's state.
seed: seed for random number generator.
"""
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
)
Using Environments from hpoglue.env.Env
Environments for Optimizers and Benchmarks can be defined in the following way:
from hpoglue.env import Env
environ = Env(
name="Dummy_env",
python_version="3.10"
requirements=("numpy==1.24.4", "scikit-learn==1.5.2")
post_install=("mybenchmark --download_data mydataset --datadir /home/someuser/data/")
# Only python CLI commands are supported. We automatically append the python -m with the
# appropriate python executable from the environment's absolute path
)
Metadata
Release files for hpoglue 0.2.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hpoglue-0.2.5.tar.gz | 33.7 kB | Without provenance | Details for hpoglue-0.2.5.tar.gz |
Release files / hpoglue-0.2.5.tar.gz
| Download URL | hpoglue-0.2.5.tar.gz |
|---|---|
| Size | 33.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
748fe7b29271b96f84aff5ce2c14734daf3754b1bd980728d101cc0327fb0e48
|
|
BLAKE2b-256 checksum How to use checksums |
e8e255b55c9680431c0ffa0e2fc6029ffc484755e4b7cc62b65e70d6797351ad
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.12
|
Security for hpoglue 0.2.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.