Skip to content

Commit a5bba06

Browse files
authored
Merge pull request #21 from Sohambasu07/main
Update to ConfigSpace>=1.0
2 parents 0c7498b + 7c87864 commit a5bba06

File tree

22 files changed

+122
-66
lines changed

22 files changed

+122
-66
lines changed

.github/workflows/pre-commit.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ jobs:
1919
- uses: actions/checkout@v4
2020
with:
2121
submodules: recursive
22-
- name: Setup Python 3.8
22+
- name: Setup Python 3.10
2323
uses: actions/setup-python@v4
2424
with:
25-
python-version: 3.8
25+
python-version: "3.10"
2626
- run: pip install pre-commit
2727
- run: pre-commit install
2828
- run: pre-commit run --all-files

.github/workflows/pytest.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
strategy:
1717
fail-fast: false
1818
matrix:
19-
python-version: ["3.8", "3.9", "3.10", "3.11"]
19+
python-version: ["3.10", "3.11"]
2020
os: ["ubuntu-latest", "macos-latest", "windows-latest"]
2121
steps:
2222
- uses: actions/checkout@v4

pyproject.toml

+11-9
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
name = "mf-prior-bench"
55
dependencies = [
66
"pyyaml",
7-
"numpy",
8-
"configspace<=0.7",
7+
"numpy<2.0",
8+
"configspace>=1.0",
99
"pandas",
1010
"more_itertools",
1111
"pyarrow"
@@ -15,7 +15,7 @@ description = "A wrapper for multi-fidelity benchmarks with priors"
1515
authors = [{name = "Eddie Bergman", email="[email protected]"}]
1616
readme = "README.md"
1717
license = { file = "LICENSE.txt" }
18-
requires-python = ">=3.8"
18+
requires-python = ">=3.10"
1919
classifiers = [
2020
'Intended Audience :: Science/Research',
2121
'Intended Audience :: Developers',
@@ -32,11 +32,13 @@ classifiers = [
3232
[project.optional-dependencies]
3333
yahpo = ["yahpo-gym==1.0.1"]
3434
jahs-bench = [
35-
"jahs_bench==1.1",
36-
"pandas<1.4",
35+
"jahs_bench==1.2.0",
36+
"pandas<2.0",
37+
"numpy<2.0.0"
3738
]
3839
tabular = ["pandas>2", "pyarrow"]
39-
pd1 = ["xgboost>=1.7"]
40+
pd1 = ["xgboost[scikit-learn]>=1.7"]
41+
taskset_tabular = ["tensorflow<=2.18.0"]
4042
surrogates = ["dehb"]
4143
docs = [
4244
"mkdocs",
@@ -82,10 +84,10 @@ exclude_lines = [
8284
] # These are lines to exclude from coverage
8385

8486
[tool.black]
85-
target-version = ['py38']
87+
target-version = ['py310']
8688

8789
[tool.ruff]
88-
target-version = "py38"
90+
target-version = "py310"
8991
line-length = 88
9092
src = ["src", "tests"]
9193

@@ -224,7 +226,7 @@ convention = "google"
224226
max-args = 10 # Changed from default of 5
225227

226228
[tool.mypy]
227-
python_version = "3.8"
229+
python_version = "3.10"
228230
packages = ["src/mfpbench", "tests"]
229231

230232
show_error_codes = true

src/mfpbench/config.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,9 @@ def set_as_default_prior(self, configspace: ConfigurationSpace) -> None:
146146
)
147147
# No need to do anything here
148148
else:
149-
hp.default_value = hp.check_default(v)
149+
if not hp.legal_value(v):
150+
raise ValueError(f"Value {v} is not legal for {k}")
151+
hp.default_value = v
150152

151153
@classmethod
152154
def from_file(cls, path: str | Path) -> Self:

src/mfpbench/jahs/benchmark.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ def _jahs_configspace(
264264
) from e
265265

266266
space = ConfigurationSpace(name=name, seed=seed)
267-
space.add_hyperparameters(
267+
space.add(
268268
[
269269
Constant(
270270
"N",
@@ -342,5 +342,5 @@ def _jahs_configspace(
342342
log=True,
343343
)
344344

345-
space.add_hyperparameters([optimizers, lr, weight_decay])
345+
space.add([optimizers, lr, weight_decay])
346346
return space

src/mfpbench/lcbench_tabular/benchmark.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def _get_raw_lcbench_space(
4343
"""
4444
# obtained from https://github.com/automl/lcbench#dataset-overview
4545
cs = ConfigurationSpace(name=name, seed=seed)
46-
cs.add_hyperparameters(
46+
cs.add(
4747
[
4848
UniformIntegerHyperparameter(
4949
"batch_size",
@@ -98,7 +98,7 @@ def _get_raw_lcbench_space(
9898
)
9999

100100
if with_constants:
101-
cs.add_hyperparameters(
101+
cs.add(
102102
[
103103
Constant("cosine_annealing_T_max", 50),
104104
Constant("cosine_annealing_eta_min", 0.0),

src/mfpbench/nb201_tabular/benchmark.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
"""
66
from __future__ import annotations
77

8+
from collections.abc import Mapping
89
from dataclasses import dataclass
910
from pathlib import Path
10-
from typing import Any, ClassVar, Literal, Mapping
11+
from typing import Any, ClassVar, Literal
1112

1213
import numpy as np
1314
import pandas as pd
@@ -28,7 +29,7 @@ def _raw_space(name: str, *, seed: int | None = None) -> ConfigurationSpace:
2829
"avg_pool_3x3",
2930
]
3031
cs = ConfigurationSpace(name=name, seed=seed)
31-
cs.add_hyperparameters(
32+
cs.add(
3233
[
3334
CategoricalHyperparameter("edge_0_1", choices=choices.copy()),
3435
CategoricalHyperparameter("edge_0_2", choices=choices.copy()),

src/mfpbench/pd1/benchmarks/cifar100.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class PD1cifar100_wideresnet_2048(PD1Benchmark):
1313
@classmethod
1414
def _create_space(cls, seed: int | None = None) -> ConfigurationSpace:
1515
cs = ConfigurationSpace(seed=seed)
16-
cs.add_hyperparameters(
16+
cs.add(
1717
[
1818
UniformFloatHyperparameter(
1919
"lr_decay_factor",

src/mfpbench/pd1/benchmarks/imagenet.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class PD1imagenet_resnet_512(PD1Benchmark):
1313
@classmethod
1414
def _create_space(cls, seed: int | None = None) -> ConfigurationSpace:
1515
cs = ConfigurationSpace(seed=seed)
16-
cs.add_hyperparameters(
16+
cs.add(
1717
[
1818
UniformFloatHyperparameter(
1919
"lr_decay_factor",

src/mfpbench/pd1/benchmarks/lm1b.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class PD1lm1b_transformer_2048(PD1Benchmark):
1313
@classmethod
1414
def _create_space(cls, seed: int | None = None) -> ConfigurationSpace:
1515
cs = ConfigurationSpace(seed=seed)
16-
cs.add_hyperparameters(
16+
cs.add(
1717
[
1818
UniformFloatHyperparameter(
1919
"lr_decay_factor",

src/mfpbench/pd1/benchmarks/translate_wmt.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class PD1translatewmt_xformer_64(PD1Benchmark):
1313
@classmethod
1414
def _create_space(cls, seed: int | None = None) -> ConfigurationSpace:
1515
cs = ConfigurationSpace(seed=seed)
16-
cs.add_hyperparameters(
16+
cs.add(
1717
[
1818
UniformFloatHyperparameter(
1919
"lr_decay_factor",

src/mfpbench/pd1/benchmarks/uniref50.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class PD1uniref50_transformer_128(PD1Benchmark):
1313
@classmethod
1414
def _create_space(cls, seed: int | None = None) -> ConfigurationSpace:
1515
cs = ConfigurationSpace(seed=seed)
16-
cs.add_hyperparameters(
16+
cs.add(
1717
[
1818
UniformFloatHyperparameter(
1919
"lr_decay_factor",

src/mfpbench/pd1/processing/process_script.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ def process_pd1( # noqa: C901, PLR0912, PLR0915
235235
for r in dataset["train_cost"] # type: ignore
236236
]
237237

238-
# Explode out the lists in the entries of the datamframe to be a single long
238+
# Explode out the lists in the entries of the dataframe to be a single long
239239
# dataframe with each element of that list on its own row
240240
dataset = dataset.explode(explode_columns, ignore_index=True)
241241
logger.info(f"{len(dataset)} rows")

src/mfpbench/pd1/surrogate/train_xgboost.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
from pathlib import Path
4-
from typing import TYPE_CHECKING
4+
from typing import TYPE_CHECKING, Any
55

66
import pandas as pd
77

@@ -17,7 +17,7 @@
1717

1818

1919
def train_xgboost(
20-
config: Configuration,
20+
config: Configuration | dict[str, Any],
2121
budget: int,
2222
X: pd.DataFrame,
2323
y: pd.Series,

src/mfpbench/pd1/surrogate/training.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def find_xgboost_surrogate(
131131
dehb = DEHB(
132132
f=dehb_target_function,
133133
cs=cs,
134-
dimensions=len(cs.get_hyperparameters()),
134+
dimensions=len(list(cs.values())),
135135
min_budget=MIN_ESTIMATORS,
136136
max_budget=MAX_ESTIMATORS,
137137
n_workers=n_workers,

src/mfpbench/pd1/surrogate/xgboost_space.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def space(seed: int | None) -> ConfigurationSpace:
1515
"""Space for the xgboost surrogate."""
1616
cs = ConfigurationSpace(seed=seed)
1717

18-
cs.add_hyperparameters(
18+
cs.add(
1919
[
2020
UniformFloatHyperparameter(
2121
"learning_rate",

src/mfpbench/pd1_tabular/benchmark.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ def _get_raw_pd1_space(
2323
name: str,
2424
seed: int | None = None,
2525
*,
26-
with_constants: bool | None = None,
26+
with_constants: bool | None = None, # noqa: ARG001
2727
) -> ConfigurationSpace:
2828
cs = ConfigurationSpace(name=name, seed=seed)
29-
cs.add_hyperparameters(
29+
cs.add(
3030
[
3131
UniformFloatHyperparameter(
3232
"lr_decay_factor",
@@ -117,7 +117,7 @@ class PD1TabularBenchmark(TabularBenchmark):
117117
"translate_wmt-xformer_translate-64_tabular",
118118
)
119119

120-
def __init__(
120+
def __init__( # noqa: D107, PLR0913
121121
self,
122122
dataset: str,
123123
model: str,

src/mfpbench/result.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,18 @@ def from_dict(
6868
renames: Mapping[str, str] | None = None,
6969
) -> Self:
7070
"""Create from a dict or mapping object."""
71+
if renames is not None:
72+
values = {renames.get(k, k): v for k, v in result.items()}
73+
else:
74+
values = result
7175
values = {
7276
k: (
7377
metric.as_value(v)
7478
if (metric := cls.metric_defs.get(k)) is not None
7579
else v
7680
)
77-
for k, v in result.items()
81+
for k, v in values.items()
7882
}
79-
if renames is not None:
80-
values = {renames.get(k, k): v for k, v in values.items()}
81-
8283
if value_metric is None:
8384
value_metric = cls.default_value_metric
8485

src/mfpbench/synthetic/hartmann/benchmark.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def __init__(
151151
else f"mfh{cls.mfh_dims}"
152152
)
153153
space = ConfigurationSpace(name=name, seed=seed)
154-
space.add_hyperparameters(
154+
space.add(
155155
[
156156
UniformFloatHyperparameter(f"X_{i}", lower=0.0, upper=1.0)
157157
for i in range(cls.mfh_dims)

src/mfpbench/taskset_tabular/benchmark.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def _get_raw_taskset_space(
2424
optimizer: str,
2525
) -> ConfigurationSpace:
2626
cs = ConfigurationSpace(name=name, seed=seed)
27-
cs.add_hyperparameters(
27+
cs.add(
2828
[
2929
UniformFloatHyperparameter(
3030
"learning_rate",
@@ -35,7 +35,7 @@ def _get_raw_taskset_space(
3535
],
3636
)
3737
if optimizer.split("_")[0] in ["adam4p", "adam6p", "adam8p"]:
38-
cs.add_hyperparameters(
38+
cs.add(
3939
[
4040
UniformFloatHyperparameter(
4141
"beta1",
@@ -58,7 +58,7 @@ def _get_raw_taskset_space(
5858
],
5959
)
6060
if optimizer.split("_")[0] in ["adam6p", "adam8p"]:
61-
cs.add_hyperparameters(
61+
cs.add(
6262
[
6363
UniformFloatHyperparameter(
6464
"l1",
@@ -75,7 +75,7 @@ def _get_raw_taskset_space(
7575
],
7676
)
7777
if optimizer.split("_")[0] in ["adam8p"]:
78-
cs.add_hyperparameters(
78+
cs.add(
7979
[
8080
UniformFloatHyperparameter(
8181
"linear_decay",
@@ -1128,7 +1128,7 @@ def _normalize_metrics(config_frame_column: pd.DataFrame) -> pd.DataFrame:
11281128
return df.groupby("id").transform(_normalize_metrics)
11291129

11301130
def _remove_zero_step(self, df: pd.DataFrame) -> pd.DataFrame:
1131-
"""Drops the loss curve at step 0, that is, at initialization"""
1131+
"""Drops the loss curve at step 0, that is, at initialization."""
11321132
unique_ids = df.index.get_level_values(0).unique()
11331133
# check if step=0 exists for all unique IDs
11341134
step_zero_exists_for_all = sum(df["step"] == 0) == len(unique_ids)

0 commit comments

Comments
 (0)