mlos_bench.tunables.tunable_groups
TunableGroups definition.
Classes
A collection of |
Module Contents
- class mlos_bench.tunables.tunable_groups.TunableGroups(config: dict | None = None)[source]
A collection of
CovariantTunableGroup
s ofTunable
parameters.Create a new group of tunable parameters.
- Parameters:
config (dict) – Python dict of serialized representation of the covariant tunable groups.
See also
mlos_bench.tunables
for more information on tunable parameters and their configuration.
- __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:
- __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:
- __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:
- __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]
- __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:
- __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:
tunable (Union[str, mlos_bench.tunables.tunable.Tunable])
tunable_value (Union[mlos_bench.tunables.tunable.TunableValue, mlos_bench.tunables.tunable.Tunable])
- Return type:
- 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:
- 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:
- 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:
- Returns:
into_params – Flat dict of all parameters and their values from given covariance groups.
- Return type:
- 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.
- is_defaults() bool [source]
Checks whether the currently assigned values of all tunables are at their defaults.
- Return type:
- is_updated(group_names: Iterable[str] | None = None) bool [source]
Check if any of the given covariant tunable groups has been updated.
- 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:
- reset(group_names: Iterable[str] | None = None) TunableGroups [source]
Clear the update flag of given covariant groups.
- restore_defaults(group_names: Iterable[str] | None = None) TunableGroups [source]
Restore all tunable parameters to their default values.
- 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.