mlos_bench.tunables.tunable module

Tunable parameter definition.

class mlos_bench.tunables.tunable.DistributionDict

Bases: TypedDict

A typed dict for tunable parameters’ distributions.

Methods

clear()

copy()

fromkeys(iterable[, value])

Create a new dictionary with keys from iterable and values set to value.

get(key[, default])

Return the value for key if key is in the dictionary, else default.

items()

keys()

pop(key[, default])

If the key is not found, return the default if given; otherwise, raise a KeyError.

popitem(/)

Remove and return a (key, value) pair as a 2-tuple.

setdefault(key[, default])

Insert key with a value of default if key is not in the dictionary.

update([E, ]**F)

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values()

params: Dict[str, float] | None
type: Literal['uniform', 'normal', 'beta']
class mlos_bench.tunables.tunable.Tunable(name: str, config: TunableDict)

Bases: object

A tunable parameter definition and its current value.

Attributes:
cardinality

Gets the cardinality of elements in this tunable, or else None.

categories

Get the list of all possible values of a categorical tunable.

category

Get the current value of the tunable as a number.

default

Get the default value of the tunable.

distribution

Get the name of the distribution (uniform, normal, or beta) if specified.

distribution_params

Get the parameters of the distribution, if specified.

dtype

Get the actual Python data type of the tunable.

is_categorical

Check if the tunable is categorical.

is_log

Check if numeric tunable is log scale.

is_numerical

Check if the tunable is an integer or float.

is_special

Check if the current value of the tunable is special.

meta

Get the tunable’s metadata.

name

Get the name / string ID of the tunable.

numerical_value

Get the current value of the tunable as a number.

quantization_bins

Get the number of quantization bins, if specified.

quantized_values

Get a sequence of quanitized values for this tunable.

range

Get the range of the tunable if it is numerical, None otherwise.

range_weight

Get weight of the range of the numeric tunable.

span

Gets the span of the range.

special

Get the special values of the tunable.

type

Get the data type of the tunable.

value

Get the current value of the tunable.

values

Gets the categories or quantized values for this tunable.

weights

Get the weights of the categories or special values of the tunable.

Methods

copy()

Deep copy of the Tunable object.

in_range(value)

Check if the value is within the range of the tunable.

is_default()

Checks whether the currently assigned value of the tunable is at its default.

is_valid(value)

Check if the value can be assigned to the tunable.

update(value)

Assign the value to the tunable.

property cardinality: int | None

Gets the cardinality of elements in this tunable, or else None. (i.e., when the tunable is continuous float and not quantized).

If the tunable has quantization set, this

Returns:
cardinalityint

Either the number of points in the tunable or else None.

property categories: List[str | None]

Get the list of all possible values of a categorical tunable. Return None if the tunable is not categorical.

Returns:
valuesList[str]

List of all possible values of a categorical tunable.

property category: str | None

Get the current value of the tunable as a number.

copy() Tunable

Deep copy of the Tunable object.

Returns:
tunableTunable

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

property default: int | float | str | None

Get the default value of the tunable.

property distribution: Literal['uniform', 'normal', 'beta'] | None

Get the name of the distribution (uniform, normal, or beta) if specified.

Returns:
distributionstr

Name of the distribution (uniform, normal, or beta) or None.

property distribution_params: Dict[str, float]

Get the parameters of the distribution, if specified.

Returns:
distribution_paramsDict[str, float]

Parameters of the distribution or None.

property dtype: Type[int] | Type[float] | Type[str]

Get the actual Python data type of the tunable.

This is useful for bulk conversions of the input data.

Returns:
dtypetype

Data type of the tunable - one of {int, float, str}.

in_range(value: int | float | str | None) bool

Check if the value is within the range of the tunable.

Do NOT check for special values. Return False if the tunable or value is categorical or None.

property is_categorical: bool

Check if the tunable is categorical.

Returns:
is_categoricalbool

True if the tunable is categorical, False otherwise.

is_default() int | float | str | None

Checks whether the currently assigned value of the tunable is at its default.

property is_log: bool | None

Check if numeric tunable is log scale.

Returns:
logbool

True if numeric tunable is log scale, False if linear.

property is_numerical: bool

Check if the tunable is an integer or float.

Returns:
is_intbool

True if the tunable is an integer or float, False otherwise.

property is_special: bool

Check if the current value of the tunable is special.

Returns:
is_specialbool

True if the current value of the tunable is special, False otherwise.

is_valid(value: int | float | str | None) bool

Check if the value can be assigned to the tunable.

Parameters:
valueUnion[int, float, str]

Value to validate.

Returns:
is_validbool

True if the value is valid, False otherwise.

property meta: Dict[str, Any]

Get the tunable’s metadata.

This is a free-form dictionary that can be used to store any additional information about the tunable (e.g., the unit information).

property name: str

Get the name / string ID of the tunable.

property numerical_value: int | float

Get the current value of the tunable as a number.

property quantization_bins: int | None

Get the number of quantization bins, if specified.

Returns:
quantization_binsint | None

Number of quantization bins, or None.

property quantized_values: Iterable[int] | Iterable[float] | None

Get a sequence of quanitized values for this tunable.

Returns:
Optional[Union[Iterable[int], Iterable[float]]]

If the Tunable is quantizable, returns a sequence of those elements, else None (e.g., for unquantized float type tunables).

property range: Tuple[int, int] | Tuple[float, float]

Get the range of the tunable if it is numerical, None otherwise.

Returns:
range(number, number)

A 2-tuple of numbers that represents the range of the tunable. Numbers can be int or float, depending on the type of the tunable.

property range_weight: float | None

Get weight of the range of the numeric tunable. Return None if there are no weights or a tunable is categorical.

Returns:
weightfloat

Weight of the range or None.

property span: int | float

Gets the span of the range.

Note: this does not take quantization into account.

Returns:
Union[int, float]

(max - min) for numerical tunables.

property special: List[int] | List[float]

Get the special values of the tunable. Return an empty list if there are none.

Returns:
special[int] | [float]

A list of special values of the tunable. Can be empty.

property type: Literal['int', 'float', 'categorical']

Get the data type of the tunable.

Returns:
typestr

Data type of the tunable - one of {‘int’, ‘float’, ‘categorical’}.

update(value: int | float | str | None) bool

Assign the value to the tunable. Return True if it is a new value, False otherwise.

Parameters:
valueUnion[int, float, str]

Value to assign.

Returns:
is_updatedbool

True if the new value is different from the previous one, False otherwise.

property value: int | float | str | None

Get the current value of the tunable.

property values: Iterable[str | None] | Iterable[int] | Iterable[float] | None

Gets the categories or quantized values for this tunable.

Returns:
Optional[Union[Iterable[Optional[str]], Iterable[int], Iterable[float]]]

Categories or quantized values.

property weights: List[float] | None

Get the weights of the categories or special values of the tunable. Return None if there are none.

Returns:
weights[float]

A list of weights or None.

class mlos_bench.tunables.tunable.TunableDict

Bases: TypedDict

A typed dict for tunable parameters.

Mostly used for mypy type checking.

These are the types expected to be received from the json config.

Methods

clear()

copy()

fromkeys(iterable[, value])

Create a new dictionary with keys from iterable and values set to value.

get(key[, default])

Return the value for key if key is in the dictionary, else default.

items()

keys()

pop(key[, default])

If the key is not found, return the default if given; otherwise, raise a KeyError.

popitem(/)

Remove and return a (key, value) pair as a 2-tuple.

setdefault(key[, default])

Insert key with a value of default if key is not in the dictionary.

update([E, ]**F)

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values()

default: int | float | str | None
description: str | None
distribution: DistributionDict | None
log: bool | None
meta: Dict[str, Any]
quantization_bins: int | None
range: Sequence[int] | Sequence[float] | None
range_weight: float | None
special: List[int] | List[float] | None
special_weights: List[float] | None
type: Literal['int', 'float', 'categorical']
values_weights: List[float] | None
mlos_bench.tunables.tunable.TunableValue

Tunable value type.

alias of int | float | str | None

mlos_bench.tunables.tunable.TunableValueType

Tunable value type tuple.

For checking with isinstance()

alias of Type[int] | Type[float] | Type[str]

mlos_bench.tunables.tunable.TunableValueTypeName

Tunable values dictionary type.

alias of Literal[‘int’, ‘float’, ‘categorical’]

mlos_bench.tunables.tunable.TunableValueTypeTuple = (<class 'int'>, <class 'float'>, <class 'str'>, <class 'NoneType'>)

The string name of a tunable value type.

mlos_bench.tunables.tunable.TunableValuesDict

Tunable value distribution type.

alias of Dict[str, int | float | str | None]