Skip to content

Commit

Permalink
mypy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
motus committed Jul 25, 2024
1 parent 18e42a2 commit 6413f8d
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions mlos_bench/mlos_bench/optimizers/convert_configspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,24 @@
"""

import logging
from typing import Dict, List, Optional, Tuple, Union
from typing import Dict, Hashable, List, Optional, Tuple, Union

from ConfigSpace import (
Beta,
BetaIntegerHyperparameter,
BetaFloatHyperparameter,
CategoricalHyperparameter,
Configuration,
ConfigurationSpace,
EqualsCondition,
Float,
Integer,
Normal,
NormalIntegerHyperparameter,
NormalFloatHyperparameter,
Uniform,
UniformIntegerHyperparameter,
UniformFloatHyperparameter,
)
from ConfigSpace.types import NotSet

Expand Down Expand Up @@ -71,7 +77,9 @@ def _tunable_to_configspace(
cs : ConfigurationSpace
A ConfigurationSpace object that corresponds to the Tunable.
"""
meta = {"group": group_name, "cost": cost} # {"scaling": ""}
meta: Dict[Hashable, TunableValue] = {"cost": cost}
if group_name is not None:
meta["group"] = group_name

if tunable.type == "categorical":
return ConfigurationSpace(
Expand Down Expand Up @@ -102,6 +110,14 @@ def _tunable_to_configspace(
elif tunable.distribution is not None:
raise TypeError(f"Invalid Distribution Type: {tunable.distribution}")

range_hp: Union[
UniformFloatHyperparameter,
NormalFloatHyperparameter,
BetaFloatHyperparameter,
UniformIntegerHyperparameter,
NormalIntegerHyperparameter,
BetaIntegerHyperparameter
]
if tunable.type == "int":
range_hp = Integer(
name=tunable.name,
Expand All @@ -120,7 +136,7 @@ def _tunable_to_configspace(
name=tunable.name,
bounds=tunable.range,
log=bool(tunable.is_log),
distribution=distribution, # type: ignore[arg-type]
distribution=distribution,
default=(
float(tunable.default)
if tunable.in_range(tunable.default) and tunable.default is not None
Expand Down

0 comments on commit 6413f8d

Please sign in to comment.