Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
fb9fb1b
updating benchmark structure
Deathn0t Mar 14, 2025
4912d0a
update
Deathn0t Mar 14, 2025
08c3d64
adding branin
Deathn0t Mar 14, 2025
9f6b545
update
Deathn0t Mar 14, 2025
e880fc1
update
Deathn0t Mar 14, 2025
a372f4c
adding griewank
Deathn0t Mar 14, 2025
81874f4
add hartmann6d
Deathn0t Mar 14, 2025
938d86c
upload all other benchmarks for c_bbo
Deathn0t Mar 14, 2025
f18469b
adding optuna simple sequential
Deathn0t Mar 17, 2025
db215bd
Add uv lock file for development
wigging Mar 17, 2025
b91e416
Add classes and examples for ackley and branin
wigging Mar 18, 2025
abb926f
Merge remote-tracking branch 'origin/cbbo' into refactoring
Deathn0t Mar 24, 2025
9b746ac
updating ackley and branin
Deathn0t Mar 24, 2025
86f2376
adding readme to cbbo
Deathn0t Mar 24, 2025
c844f6a
Cleanup pyproject contents
wigging Mar 24, 2025
86bbde2
adding refactored dtlz benchmark
Deathn0t Mar 24, 2025
95ce3b7
adding refactored dtlz benchmark example
Deathn0t Mar 24, 2025
16adf9c
updating ackley and branin
Deathn0t Mar 24, 2025
0fe2444
adding readme to cbbo
Deathn0t Mar 24, 2025
e7293e2
reusable run_function cbbo
Deathn0t Mar 24, 2025
84553b7
updating branin
Deathn0t Mar 24, 2025
12c9a2c
adding easom
Deathn0t Mar 24, 2025
0a079a1
adding griewank
Deathn0t Mar 24, 2025
2c98c1f
moving cum_regret, simple_regret to HPOScorer
Deathn0t Mar 24, 2025
f365d8a
adding hartmann6D
Deathn0t Mar 24, 2025
716acde
adding benchmarks to top-level __init__
Deathn0t Mar 24, 2025
8073701
added tests
Deathn0t Mar 24, 2025
cfca6c8
reusable run_function cbbo
Deathn0t Mar 24, 2025
93b80ec
updating branin
Deathn0t Mar 24, 2025
4314806
adding easom
Deathn0t Mar 24, 2025
e074e30
adding griewank
Deathn0t Mar 24, 2025
12294b5
moving cum_regret, simple_regret to HPOScorer
Deathn0t Mar 24, 2025
bce0c80
adding hartmann6D
Deathn0t Mar 24, 2025
eaaad23
adding benchmarks to top-level __init__
Deathn0t Mar 24, 2025
a691a72
added tests
Deathn0t Mar 24, 2025
4ede965
adding pydantic validation for dtlz scorer
Deathn0t Mar 24, 2025
ecebf34
Merge remote-tracking branch 'origin/cbbo' into refactoring
Deathn0t Mar 24, 2025
94bd220
add default attribute in HPOScorer
Deathn0t Mar 24, 2025
29ca8dd
rolling back, removed pydantic validation
Deathn0t Mar 24, 2025
bfdba65
adding tests for dtlz
Deathn0t Mar 24, 2025
ae74a70
Add pyright settings
wigging Mar 24, 2025
4ec2797
Add levy and michal modules
wigging Mar 24, 2025
61d36f2
Add modules for rosen, schwefel, shekel benchmarks
wigging Mar 24, 2025
b461e76
Import run_function from utils
wigging Mar 24, 2025
8aa7696
fixed cbbo benchmark functions
Deathn0t Mar 25, 2025
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
21 changes: 21 additions & 0 deletions examples/bench_ackley.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""here."""

from deephyper.hpo import CBO
from deephyper_benchmark.benchmarks.cbbo import AckleyBenchmark


def main():
"""Run example."""
bench = AckleyBenchmark()

search = CBO(bench.problem, bench.run_function)
results = search.search(25)

print(results)

cumul_regret = bench.scorer.cumul_regret(results.objective)
print(cumul_regret)


if __name__ == "__main__":
main()
21 changes: 21 additions & 0 deletions examples/bench_branin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""here."""

from deephyper.hpo import CBO
from deephyper_benchmark.benchmarks.cbbo import BraninBenchmark


def main():
"""Run example."""
bench = BraninBenchmark()

search = CBO(bench.problem, bench.run_function)
results = search.search(25)

print(results)

cumul_regret = bench.scorer.cumul_regret(results.objective)
print(cumul_regret)


if __name__ == "__main__":
main()
26 changes: 0 additions & 26 deletions examples/bench_combo.py

This file was deleted.

76 changes: 27 additions & 49 deletions examples/bench_dtlz.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,28 @@
# Setup info-level logging
import logging
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s - %(levelname)s - %(filename)s:%(funcName)s - " + \
"%(message)s",
force=True,
)

# Set DTLZ problem environment variables
import os
os.environ["DEEPHYPER_BENCHMARK_NDIMS"] = "5" # 5 vars
os.environ["DEEPHYPER_BENCHMARK_NOBJS"] = "3" # 2 objs
os.environ["DEEPHYPER_BENCHMARK_DTLZ_PROB"] = "2" # DTLZ2 problem
os.environ["DEEPHYPER_BENCHMARK_DTLZ_OFFSET"] = "0.6" # [x_o, .., x_d]*=0.6

# Load DTLZ benchmark suite, nothing to install
import deephyper_benchmark as dhb
dhb.load("DTLZ")


# Necessary IF statement otherwise it will enter in a infinite loop
# when loading the 'run' function from a subprocess
if __name__ == "__main__":
from deephyper.problem import HpProblem
from deephyper.search.hps import CBO

# Run HPO-pipeline with default configuration of hyperparameters
from deephyper_benchmark.lib.dtlz import hpo
from deephyper.evaluator import RunningJob, Evaluator
config = hpo.problem.default_configuration
print(config)
res = hpo.run(RunningJob(parameters=config))
print(f"{res=}")

# define the evaluator to distribute the computation
evaluator = Evaluator.create(
hpo.run,
method="process",
method_kwargs={
"num_workers": 2,
},
)

# define your search and execute it
search = CBO(hpo.problem, evaluator)

# solve with 100 evals
results = search.search(max_evals=100)
"""here."""

import numpy as np
from deephyper.hpo import CBO
from deephyper_benchmark.benchmarks.dtlz import DTLZBenchmark


def main():
"""Run example."""
nobj = 2
bench = DTLZBenchmark(nobj=nobj)

search = CBO(bench.problem, bench.run_function, acq_optimizer="sampling")
results = search.search(25)

print(results)

obj = results[[f"objective_{i}" for i in range(nobj)]].values
print(np.shape(obj))
hvi = bench.scorer.hypervolume_score(obj)
print(hvi)

hvi_iter = bench.scorer.hypervolume(obj)
print(hvi_iter)


if __name__ == "__main__":
main()
21 changes: 8 additions & 13 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ build-backend = "hatchling.build"
name = "deephyper-benchmark"
version = "0.0.2"
dependencies = [
# "deephyper",
"deephyper>=0.9.3",
]
requires-python = ">=3.10"
Expand All @@ -29,23 +28,13 @@ classifiers = [
"Programming Language :: Python :: 3.13",
]

[project.optional-dependencies]


[project.scripts]


[project.urls]
Documentation = "http://deephyper.readthedocs.io"
Changes = "https://github.com/deephyper/deephyper/releases"
Forum = "https://github.com/deephyper/deephyper/discussions"
GitHub = "https://github.com/deephyper/deephyper"
Issues = "https://github.com/deephyper/deephyper/issues"

[tool.pytest.ini_options]
norecursedirs = ".git"


[tool.coverage.paths]
source = ["src/", "*/site-packages"]

Expand All @@ -56,9 +45,15 @@ source = ["deephyper"]
[tool.coverage.report]
exclude_lines = ["if __name__ == '__main__':"]

[tool.pyright]
pythonVersion = "3.13"
venvPath = "."
venv = ".venv"

[tool.pytest.ini_options]
norecursedirs = ".git"

[tool.ruff]
exclude = [
]
line-length = 100

[tool.ruff.lint]
Expand Down
13 changes: 10 additions & 3 deletions src/deephyper_benchmark/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
"""DeepHyper-Benchmark package."""
"""Public interface for deephyper_benchmark package."""

from ._benchmark import Benchmark, HPOBenchmark
from ._scorer import Scorer, HPOScorer
from ._scorer import Scorer, HPOScorer, MultiObjHPOScorer

__all__ = ["Benchmark", "HPOBenchmark", "Scorer", "HPOScorer"]

__all__ = [
"Benchmark",
"HPOBenchmark",
"Scorer",
"HPOScorer",
"MultiObjHPOScorer",
]
9 changes: 3 additions & 6 deletions src/deephyper_benchmark/_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@


class Benchmark(abc.ABC):
def __init__(self):
super().__init__()
self.refresh_settings()

def refresh_settings(self):
"""Refresh benchmark settings."""
"""Base class for benchmarks."""


class HPOBenchmark(Benchmark):
"""Base class for Hyperparameter optimization benchmarks."""

@property
@abc.abstractmethod
def problem(self):
Expand Down
57 changes: 55 additions & 2 deletions src/deephyper_benchmark/_scorer.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import abc

import numpy as np
from deephyper.skopt.moo import hypervolume


class Scorer(abc.ABC):
pass


class HPOScorer(Scorer):
@abc.abstractmethod
def __init__(self, nparams: int, y_max: float):
self.nparams = nparams
self.y_max = y_max

def simple_regret(self, y: np.ndarray) -> np.ndarray:
"""Compute the regret of a list of given solution.

Expand All @@ -17,8 +22,8 @@ def simple_regret(self, y: np.ndarray) -> np.ndarray:
Returns:
np.ndarray: An array of regret values.
"""
return self.y_max - y

@abc.abstractmethod
def cumul_regret(self, y: np.ndarray) -> np.ndarray:
"""Compute the cumulative regret of an array of ordered given solution.

Expand All @@ -28,3 +33,51 @@ def cumul_regret(self, y: np.ndarray) -> np.ndarray:
Returns:
np.ndarray: An array of cumulative regret values.
"""
return np.cumsum(self.simple_regret(y))


class MultiObjHPOScorer(Scorer):
def __init__(self, nobj: int):
self.nobj = nobj

def hypervolume_score(self, pts: np.ndarray):
"""Calculate the hypervolume dominated by soln, wrt the Nadir point.

Args:
pts (np.ndarray): A 2d array of objective values.
Each row is an objective value in the solution set.

Returns:
float: The total hypervolume dominated by the current solution,
filtering out points worse than the Nadir point and using the
Nadir point as the reference.

"""
if np.any(pts < 0):
filtered_pts = -pts.copy()
else:
filtered_pts = pts.copy()
nadir = self.nadir_point
for i in range(pts.shape[0]):
if np.any(filtered_pts[i, :] > nadir):
filtered_pts[i, :] = nadir
return hypervolume(filtered_pts, nadir)

@property
@abc.abstractmethod
def nadir_point(self):
pass

def hypervolume(self, y: np.ndarray) -> np.ndarray:
"""Compute the regret of a list of given solution.

Args:
y (np.ndarray): An array of solutions.

Returns:
np.ndarray: An array of regret values.
"""
scores = np.zeros(y.shape[0])
for i in range(1, y.shape[0] + 1):
scores[i - 1] = self.hypervolume_score(y[:i])
return scores
Empty file.
20 changes: 20 additions & 0 deletions src/deephyper_benchmark/benchmarks/cbbo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# C-BBO: Continuous Black-Box Optimization

> **Warning**
> Work in progress, this benchmark is not yet ready.

Set of continuous function benchmarks. The `DEEPHYPER_BENCHMARK_NDIMS` environment variable defines the number of dimensions of the problem.

| Function Name | Number of Dimensions | Comment |
| ------------- | --------------------- | ------------------------------------------- |
| ackley | $\infty$ (default 5) | Many local minima and single global optimum |
| branin | 2 | Three global optimum |
| cossin | 1 | Many local minima, good for visualisation. |
| easom | 2 | Almost flat everywhere |
| griewank | $\infty$ (default 5) | |
| hartmann6D | 6 | |
| levy | $\infty$ (default 5) | |
| michal | $\infty$ (default 2) | |
| rosen | $\infty$ (default 5) | |
| schwefel | $\infty$ (default 5) | |
| shekel | 4 | Many local minima with flat areas |
25 changes: 25 additions & 0 deletions src/deephyper_benchmark/benchmarks/cbbo/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""Subpackage for the C-BBO benchmarks."""

from .ackley import AckleyBenchmark
from .branin import BraninBenchmark
from .easom import EasomBenchmark
from .griewank import GriewankBenchmark
from .hartmann6D import Hartmann6DBenchmark
from .levy import LevyBenchmark
from .michal import MichalBenchmark
from .rosen import RosenBenchmark
from .schwefel import SchwefelBenchmark
from .shekel import ShekelBenchmark

__all__ = [
"AckleyBenchmark",
"BraninBenchmark",
"EasomBenchmark",
"GriewankBenchmark",
"Hartmann6DBenchmark",
"LevyBenchmark",
"MichalBenchmark",
"RosenBenchmark",
"SchwefelBenchmark",
"ShekelBenchmark",
]
Loading