src.core.helpers

parse_hyperparameters_from_dict(items)

Convert a raw hyperparameter specification dict into a mapping of Hyperparameter objects.

Parameters:

items (dict[str, Any]) – Mapping of hyperparameter name to its specification.

Returns:

Parsed hyperparameters keyed by name.

Return type:

dict[str, Hyperparameter]

Raises:

ValueError – If a specification is malformed or an unsupported type is encountered.

Supported specification formats

Python value

Produced type

Notes

int, float, str

Constant

Fixed value; not searched.

(lower, upper) tuple

UniformFloatHyperparameter or UniformIntegerHyperparameter

Type inferred from bounds: float → Float HP, int → Int HP.

[choice1, choice2, …] list

CategoricalHyperparameter

First element used as default unless overridden.

{"val": …, "default": …, "log": …} dict

Same as above, extended format

"val" is required; "default" and "log" are optional. "log": True enables log-scale sampling for numeric ranges.

Hyperparameter instance

Passed through unchanged

Allows mixing raw specs and pre-built ConfigSpace objects.

Example

from src.core.helpers import parse_hyperparameters_from_dict

specs = {
    "lr":      {"val": (1e-4, 0.1), "default": 0.01, "log": True},
    "margin":  {"val": [0.6, 0.8, 1.0], "default": 1.0},
    "dropout": 0.5,
    "epochs":  (10, 100),
}

hps = parse_hyperparameters_from_dict(specs)
# hps["lr"]      → UniformFloatHyperparameter (log-scale)
# hps["margin"]  → CategoricalHyperparameter
# hps["dropout"] → Constant(0.5)
# hps["epochs"]  → UniformIntegerHyperparameter

Extended dict format

The {"val": …} dict format gives you fine-grained control:

# YAML equivalent used in AutoMAX config files
optimizer_kwargs:
  lr:
    val: [0.0001, 0.1]
    default: 0.01
    log: true
  margin:
    val: [0.6, 0.8, 1.0]
    default: 1.0

Note

If both "log": true and a list-of-choices val are supplied, the log flag is silently ignored (categorical HPs have no log-scale concept).