mlos_bench.tunables.tunable_groups

TunableGroups definition.

Classes

TunableGroups

A collection of covariant groups of tunable parameters.

Module Contents

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

A collection of covariant groups of tunable parameters.

Create a new group of tunable parameters.

Parameters:

config (dict) – Python dict of serialized representation of the covariant tunable groups.

__bool__() bool[source]
Return type:

bool

__contains__(tunable: str | mlos_bench.tunables.tunable.Tunable) bool[source]

Checks if the given name/tunable is in this tunable group.

Parameters:

tunable (Union[str, mlos_bench.tunables.tunable.Tunable])

Return type:

bool

__eq__(other: object) bool[source]

Check if two TunableGroups are equal.

Parameters:

other (TunableGroups) – A tunable groups object to compare to.

Returns:

is_equal – True if two TunableGroups are equal.

Return type:

bool

__getitem__(tunable: str | mlos_bench.tunables.tunable.Tunable) mlos_bench.tunables.tunable.TunableValue[source]

Get the current value of a single tunable parameter.

Parameters:

tunable (Union[str, mlos_bench.tunables.tunable.Tunable])

Return type:

mlos_bench.tunables.tunable.TunableValue

__iter__() Generator[Tuple[mlos_bench.tunables.tunable.Tunable, mlos_bench.tunables.covariant_group.CovariantTunableGroup], None, None][source]

An iterator over all tunables in the group.

Returns:

[(tunable, group), …] – An iterator over all tunables in all groups. Each element is a 2-tuple of an instance of the Tunable parameter and covariant group it belongs to.

Return type:

Generator[Tuple[Tunable, CovariantTunableGroup], None, None]

__len__() int[source]
Return type:

int

__repr__() str[source]

Produce a human-readable version of the TunableGroups (mostly for logging).

Returns:

string – A human-readable version of the TunableGroups.

Return type:

str

__setitem__(tunable: str | mlos_bench.tunables.tunable.Tunable, tunable_value: mlos_bench.tunables.tunable.TunableValue | mlos_bench.tunables.tunable.Tunable) mlos_bench.tunables.tunable.TunableValue[source]

Update the current value of a single tunable parameter.

Parameters:
Return type:

mlos_bench.tunables.tunable.TunableValue

assign(param_values: Mapping[str, mlos_bench.tunables.tunable.TunableValue]) TunableGroups[source]

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

Parameters:

param_values (Mapping[str, TunableValue]) –

Dictionary mapping Tunable parameter names to new values.

As a special behavior when the mapping is empty the method will restore the default values rather than no-op. This allows an empty dictionary in json configs to be used to reset the tunables to defaults without having to copy the original values from the tunable_params definition.

Returns:

self – Self-reference for chaining.

Return type:

TunableGroups

copy() TunableGroups[source]

Deep copy of the TunableGroups object.

Returns:

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

Return type:

TunableGroups

get_covariant_group_names() Iterable[str][source]

Get the names of all covariance groups in the collection.

Returns:

group_names – IDs of the covariant tunable groups.

Return type:

[str]

get_param_values(group_names: Iterable[str] | None = None, into_params: Dict[str, mlos_bench.tunables.tunable.TunableValue] | None = None) Dict[str, mlos_bench.tunables.tunable.TunableValue][source]

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

Parameters:
  • group_names (list of str or None) – IDs of the covariant tunable groups. Select parameters from all groups if omitted.

  • into_params (dict) – An optional dict to copy the parameters and their values into.

Returns:

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

Return type:

dict

get_tunable(tunable: str | mlos_bench.tunables.tunable.Tunable) Tuple[mlos_bench.tunables.tunable.Tunable, mlos_bench.tunables.covariant_group.CovariantTunableGroup][source]

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

Parameters:

tunable (Union[str, Tunable]) – Name of the tunable parameter.

Returns:

(tunable, group) – A 2-tuple of an instance of the Tunable parameter and covariant group it belongs to.

Return type:

(Tunable, CovariantTunableGroup)

is_defaults() bool[source]

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

Return type:

bool

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

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

Parameters:

group_names (list of str or None) – IDs of the (covariant) tunable groups. Check all groups if omitted.

Returns:

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

Return type:

bool

merge(tunables: TunableGroups) TunableGroups[source]

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:

tunables (TunableGroups) – A collection of covariant tunable groups.

Returns:

self – Self-reference for chaining.

Return type:

TunableGroups

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

Clear the update flag of given covariant groups.

Parameters:

group_names (list of str or None) – IDs of the (covariant) tunable groups. Reset all groups if omitted.

Returns:

self – Self-reference for chaining.

Return type:

TunableGroups

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

Restore all tunable parameters to their default values.

Parameters:

group_names (list of str or None) – IDs of the (covariant) tunable groups. Restore all groups if omitted.

Returns:

self – Self-reference for chaining.

Return type:

TunableGroups

subgroup(group_names: Iterable[str]) TunableGroups[source]

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_names (list of str) – IDs of the covariant tunable groups.

Returns:

tunables – A collection of covariant tunable groups.

Return type:

TunableGroups