mlos_bench.services.types.config_loader_type module

Protocol interface for helper functions to lookup and load configs.

class mlos_bench.services.types.config_loader_type.SupportsConfigLoading(*args, **kwargs)

Bases: Protocol

Protocol interface for helper functions to lookup and load configs.

Methods

build_environment(config, tunables[, ...])

Factory method for a new environment with a given config.

load_config(json_file_name, schema_type)

Load JSON config file.

load_environment_list(json_file_name, tunables)

Load and build a list of environments from the config file.

load_services(json_file_names[, ...])

Read the configuration files and bundle all service methods from those configs into a single Service object.

resolve_path(file_path[, extra_paths])

Prepend the suitable _config_path to path if the latter is not absolute.

build_environment(config: dict, tunables: TunableGroups, global_config: dict | None = None, parent_args: Dict[str, int | float | str | None] | None = None, service: Service | None = None) Environment

Factory method for a new environment with a given config.

Parameters:
configdict
A dictionary with three mandatory fields:

“name”: Human-readable string describing the environment; “class”: FQN of a Python class to instantiate; “config”: Free-format dictionary to pass to the constructor.

tunablesTunableGroups

A (possibly empty) collection of groups of tunable parameters for all environments.

global_configOptional[dict]

Global parameters to add to the environment config.

parent_argsOptional[Dict[str, TunableValue]]

An optional reference of the parent CompositeEnv’s const_args used to expand dynamic config parameters from.

service: Optional[Service]

An optional service object (e.g., providing methods to deploy or reboot a VM, etc.).

Returns:
envEnvironment

An instance of the Environment class initialized with config.

load_config(json_file_name: str, schema_type: ConfigSchema | None) dict | List[dict]

Load JSON config file. Search for a file relative to _config_path if the input path is not absolute. This method is exported to be used as a service.

Parameters:
json_file_namestr

Path to the input config file.

schema_typeOptional[ConfigSchema]

The schema type to validate the config against.

Returns:
configUnion[dict, List[dict]]

Free-format dictionary that contains the configuration.

load_environment_list(json_file_name: str, tunables: TunableGroups, global_config: dict | None = None, parent_args: Dict[str, int | float | str | None] | None = None, service: Service | None = None) List[Environment]

Load and build a list of environments from the config file.

Parameters:
json_file_namestr

The environment JSON configuration file. Can contain either one environment or a list of environments.

tunablesTunableGroups

A (possibly empty) collection of tunables to add to the environment.

global_configOptional[dict]

Global parameters to add to the environment config.

parent_argsOptional[Dict[str, TunableValue]]

An optional reference of the parent CompositeEnv’s const_args used to expand dynamic config parameters from.

serviceOptional[Service]

An optional reference of the parent service to mix in.

Returns:
envList[Environment]

A list of new benchmarking environments.

load_services(json_file_names: Iterable[str], global_config: Dict[str, Any] | None = None, parent: Service | None = None) Service

Read the configuration files and bundle all service methods from those configs into a single Service object.

Parameters:
json_file_nameslist of str

A list of service JSON configuration files.

global_configdict

Global parameters to add to the service config.

parentService

An optional reference of the parent service to mix in.

Returns:
serviceService

A collection of service methods.

resolve_path(file_path: str, extra_paths: Iterable[str] | None = None) str

Prepend the suitable _config_path to path if the latter is not absolute. If _config_path is None or path is absolute, return path as is.

Parameters:
file_pathstr

Path to the input config file.

extra_pathsIterable[str]

Additional directories to prepend to the list of search paths.

Returns:
pathstr

An actual path to the config or script.