scalarstop.hyperparams

Utilities for creating typed Python dataclasses for storing hyperparameters.

Module Contents

Classes

HyperparamsType

Parent class for all dataclasses containing hyperparameters.

NestedHyperparamsType

Hyperparams dataclass for encapsulating the hyperparams for another model.

AppendHyperparamsType

Hyperparams for “child” datasets or models.

Functions

enforce_dict(hyperparams: Any) → Dict[(Any, Any)]

Convert the input into a dictionary, whether it is a dataclass or not.

hash_hyperparams(hyperparams: Any) → str

Return a string hash of a given Hyperparams dataclass.

init_hyperparams(*, class_name: str, hyperparams, hyperparams_class) → Any

Construct a hyperparams object from either a mapping or another hyperparams object.

flatten_hyperparams(hyperparams: Any) → Dict[(str, Any)]

Recursively flatten the hyperparams embedded

enforce_dict(hyperparams: Any)Dict[Any, Any]

Convert the input into a dictionary, whether it is a dataclass or not.

hash_hyperparams(hyperparams: Any)str

Return a string hash of a given Hyperparams dataclass.

init_hyperparams(*, class_name: str, hyperparams, hyperparams_class)Any

Construct a hyperparams object from either a mapping or another hyperparams object.

flatten_hyperparams(hyperparams: Any)Dict[str, Any]

Recursively flatten the hyperparams embedded in a NestedHyperparamsType instance.

class HyperparamsType

Parent class for all dataclasses containing hyperparameters.

You will still need the @sp.dataclass decorator over all classes that inherit from HyperparamsType.

class NestedHyperparamsType

Bases: scalarstop.hyperparams.HyperparamsType

Hyperparams dataclass for encapsulating the hyperparams for another model.

When you create a dataset or model template that inherits from or combines other models, you should use this dataclass to store the hyperparams of the other model(s).

name :str
group_name :str
hyperparams :HyperparamsType
class AppendHyperparamsType

Bases: scalarstop.hyperparams.HyperparamsType

Hyperparams for “child” datasets or models.

Subclass this dataclass and automatically create a parent attribute for storing the hyperparams of a parent class.

parent :NestedHyperparamsType