Skip to content

Commit

Permalink
fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
bpkroth committed Aug 20, 2024
1 parent 2ff1678 commit 057f553
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
17 changes: 12 additions & 5 deletions mlos_bench/mlos_bench/optimizers/convert_configspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
from mlos_bench.tunables.tunable import Tunable, TunableValue
from mlos_bench.tunables.tunable_groups import TunableGroups
from mlos_bench.util import try_parse_val
from mlos_core.spaces.converters.util import QUANTIZATION_BINS_META_KEY
from mlos_core.spaces.converters.util import (
QUANTIZATION_BINS_META_KEY,
monkey_patch_hp_quantization,
)

_LOG = logging.getLogger(__name__)

Expand Down Expand Up @@ -77,10 +80,6 @@ def _tunable_to_configspace(
meta: Dict[Hashable, TunableValue] = {"cost": cost}
if group_name is not None:
meta["group"] = group_name
if tunable.is_numerical and tunable.quantization_bins:
# Temporary workaround to dropped quantization support in ConfigSpace 1.0
# See Also: https://github.com/automl/ConfigSpace/issues/390
meta[QUANTIZATION_BINS_META_KEY] = tunable.quantization_bins

if tunable.type == "categorical":
return ConfigurationSpace(
Expand Down Expand Up @@ -141,6 +140,14 @@ def _tunable_to_configspace(
else:
raise TypeError(f"Invalid Parameter Type: {tunable.type}")

if tunable.is_numerical and tunable.quantization_bins:
# Temporary workaround to dropped quantization support in ConfigSpace 1.0
# See Also: https://github.com/automl/ConfigSpace/issues/390
new_meta = dict(range_hp.meta or {})
new_meta[QUANTIZATION_BINS_META_KEY] = tunable.quantization_bins
range_hp.meta = new_meta
monkey_patch_hp_quantization(range_hp)

if not tunable.special:
return ConfigurationSpace({tunable.name: range_hp})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
UniformFloatHyperparameter,
UniformIntegerHyperparameter,
)
from ConfigSpace.hyperparameters import NumericalHyperparameter

from mlos_bench.optimizers.convert_configspace import (
TunableValueKind,
Expand Down Expand Up @@ -128,6 +127,8 @@ def _cmp_tunable_hyperparameter_numerical(tunable: Tunable, space: Configuration
if tunable.in_range(tunable.value):
assert param.default_value == tunable.value
assert (param.meta or {}).get(QUANTIZATION_BINS_META_KEY) == tunable.quantization_bins
if tunable.quantization_bins:
assert param.sample_value() in list(tunable.quantized_values or [])


def test_tunable_to_configspace_categorical(tunable_categorical: Tunable) -> None:
Expand Down

0 comments on commit 057f553

Please sign in to comment.