mlos_bench.tunables.tunable_groups module

TunableGroups definition.

class mlos_bench.tunables.tunable_groups.TunableGroups(config: dict | None = None)

Bases: object

A collection of covariant groups of tunable parameters.

Methods

assign(param_values)

In-place update the values of the tunables from the dictionary of (key, value) pairs.

copy()

Deep copy of the TunableGroups object.

get_covariant_group_names()

Get the names of all covariance groups in the collection.

get_param_values([group_names, into_params])

Get the current values of the tunables that belong to the specified covariance groups.

get_tunable(tunable)

Access the entire Tunable (not just its value) and its covariant group.

is_defaults()

Checks whether the currently assigned values of all tunables are at their defaults.

is_updated([group_names])

Check if any of the given covariant tunable groups has been updated.

merge(tunables)

Merge the two collections of covariant tunable groups.

reset([group_names])

Clear the update flag of given covariant groups.

restore_defaults([group_names])

Restore all tunable parameters to their default values.

subgroup(group_names)

Select the covariance groups from the current set and create a new TunableGroups object that consists of those covariance groups.

assign(param_values: Mapping[str, int | float | str | None]) TunableGroups

In-place update the values of the tunables from the dictionary of (key, value) pairs.

Parameters:
param_valuesMapping[str, TunableValue]

Dictionary mapping Tunable parameter names to new values.

Returns:
selfTunableGroups

Self-reference for chaining.

copy() TunableGroups

Deep copy of the TunableGroups object.

Returns:
tunablesTunableGroups

A new instance of the TunableGroups object that is a deep copy of the original one.

get_covariant_group_names() Iterable[str]

Get the names of all covariance groups in the collection.

Returns:
group_names[str]

IDs of the covariant tunable groups.

get_param_values(group_names: Iterable[str] | None = None, into_params: Dict[str, int | float | str | None] | None = None) Dict[str, int | float | str | None]

Get the current values of the tunables that belong to the specified covariance groups.

Parameters:
group_nameslist of str or None

IDs of the covariant tunable groups. Select parameters from all groups if omitted.

into_paramsdict

An optional dict to copy the parameters and their values into.

Returns:
into_paramsdict

Flat dict of all parameters and their values from given covariance groups.

get_tunable(tunable: str | Tunable) Tuple[Tunable, CovariantTunableGroup]

Access the entire Tunable (not just its value) and its covariant group. Throw KeyError if the tunable is not found.

Parameters:
tunableUnion[str, Tunable]

Name of the tunable parameter.

Returns:
(tunable, group)(Tunable, CovariantTunableGroup)

A 2-tuple of an instance of the Tunable parameter and covariant group it belongs to.

is_defaults() bool

Checks whether the currently assigned values of all tunables are at their defaults.

Returns:
bool
is_updated(group_names: Iterable[str] | None = None) bool

Check if any of the given covariant tunable groups has been updated.

Parameters:
group_nameslist of str or None

IDs of the (covariant) tunable groups. Check all groups if omitted.

Returns:
is_updatedbool

True if any of the specified tunable groups has been updated, False otherwise.

merge(tunables: TunableGroups) TunableGroups

Merge the two collections of covariant tunable groups.

Unlike the dict update method, this method does not modify the original when overlapping keys are found. It is expected be used to merge the tunable groups referenced by a standalone Environment config into a parent CompositeEnvironment, for instance. This allows self contained, potentially overlapping, but also overridable configs to be composed together.

Parameters:
tunablesTunableGroups

A collection of covariant tunable groups.

Returns:
selfTunableGroups

Self-reference for chaining.

reset(group_names: Iterable[str] | None = None) TunableGroups

Clear the update flag of given covariant groups.

Parameters:
group_nameslist of str or None

IDs of the (covariant) tunable groups. Reset all groups if omitted.

Returns:
selfTunableGroups

Self-reference for chaining.

restore_defaults(group_names: Iterable[str] | None = None) TunableGroups

Restore all tunable parameters to their default values.

Parameters:
group_nameslist of str or None

IDs of the (covariant) tunable groups. Restore all groups if omitted.

Returns:
selfTunableGroups

Self-reference for chaining.

subgroup(group_names: Iterable[str]) TunableGroups

Select the covariance groups from the current set and create a new TunableGroups object that consists of those covariance groups.

Note: The new TunableGroup will include references (not copies) to original ones, so each will get updated together. This is often desirable to support the use case of multiple related Environments (e.g. Local vs Remote) using the same set of tunables within a CompositeEnvironment.

Parameters:
group_nameslist of str

IDs of the covariant tunable groups.

Returns:
tunablesTunableGroups

A collection of covariant tunable groups.