mlos_bench.services.config_persistence.ConfigPersistenceService

class mlos_bench.services.config_persistence.ConfigPersistenceService(config: Dict[str, Any] | None = None, global_config: Dict[str, Any] | None = None, parent: Service | None = None, methods: Dict[str, Callable] | List[Callable] | None = None)

Collection of methods to deserialize the Environment, Service, and TunableGroups objects.

Attributes:
config_loader_service

Return a config loader service.

config_paths

Gets the list of config paths this service will search for config files.

Methods

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

Factory method for a new environment with a given config.

build_optimizer(*, tunables, service, config)

Instantiation of mlos_bench Optimizer that depend on Service and TunableGroups.

build_scheduler(*, config, global_config, ...)

Instantiation of mlos_bench Scheduler.

build_service(config[, global_config, parent])

Factory method for a new service with a given config.

build_storage(*, service, config[, ...])

Instantiation of mlos_bench Storage objects.

export()

Return a dictionary of functions available in this service.

load_config(json_file_name, schema_type)

Load JSON config file.

load_environment(json_file_name, tunables[, ...])

Load and build new environment from the 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.

merge_methods(ext_methods, local_methods)

Merge methods from the external caller with the local ones.

new(class_name[, config, global_config, parent])

Factory method for a new service with a given config.

pprint()

Produce a human-readable string listing all public methods of the service.

prepare_class_load(config[, global_config, ...])

Extract the class instantiation parameters from the configuration.

register(services)

Register new mix-in services.

resolve_path(file_path[, extra_paths])

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

__init__(config: Dict[str, Any] | None = None, global_config: Dict[str, Any] | None = None, parent: Service | None = None, methods: Dict[str, Callable] | List[Callable] | None = None)

Create a new instance of config persistence service.

Parameters:
configdict

Free-format dictionary that contains parameters for the service. (E.g., root path for config files, etc.)

global_configdict

Free-format dictionary of global parameters.

parentService

An optional parent service that can provide mixin functions.

methodsUnion[Dict[str, Callable], List[Callable], None]

New methods to register with the service.

BUILTIN_CONFIG_PATH = '/workspaces/MLOS/mlos_bench/mlos_bench/config'
build_environment(config: Dict[str, Any], tunables: TunableGroups, global_config: Dict[str, Any] | 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_configdict

Global parameters to add to the environment config.

parent_argsDict[str, TunableValue]

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

service: 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.

build_optimizer(*, tunables: TunableGroups, service: Service, config: Dict[str, Any], global_config: Dict[str, Any] | None = None) Optimizer

Instantiation of mlos_bench Optimizer that depend on Service and TunableGroups.

A class MUST have a constructor that takes four named arguments: (tunables, config, global_config, service)

Parameters:
tunablesTunableGroups

Tunable parameters of the environment. We need them to validate the configurations of merged-in experiments and restored/pending trials.

service: Service

An optional service object (e.g., providing methods to load config files, etc.)

configdict

Configuration of the class to instantiate, as loaded from JSON.

global_configdict

Global configuration parameters (optional).

Returns:
instOptimizer

A new instance of the Optimizer class.

build_scheduler(*, config: Dict[str, Any], global_config: Dict[str, Any], environment: Environment, optimizer: Optimizer, storage: Storage, root_env_config: str) Scheduler

Instantiation of mlos_bench Scheduler.

Parameters:
configdict

Configuration of the class to instantiate, as loaded from JSON.

global_configdict

Global configuration parameters.

environmentEnvironment

The environment to benchmark/optimize.

optimizerOptimizer

The optimizer to use.

storageStorage

The storage to use.

root_env_configstr

Path to the root environment configuration.

Returns:
instScheduler

A new instance of the Scheduler.

build_service(config: Dict[str, Any], global_config: Dict[str, Any] | None = None, parent: Service | None = None) Service

Factory method for a new service with a given config.

Parameters:
configdict
A dictionary with 2 mandatory fields:

“class”: FQN of a Python class to instantiate; “config”: Free-format dictionary to pass to the constructor.

global_configdict

Global parameters to add to the service config.

parent: Service

An optional reference of the parent service to mix in.

Returns:
svcService

An instance of the Service class that is a combination of all services from the list plus the parent mix-in.

build_storage(*, service: Service, config: Dict[str, Any], global_config: Dict[str, Any] | None = None) Storage

Instantiation of mlos_bench Storage objects.

Parameters:
service: Service

An optional service object (e.g., providing methods to load config files, etc.)

configdict

Configuration of the class to instantiate, as loaded from JSON.

global_configdict

Global configuration parameters (optional).

Returns:
instStorage

A new instance of the Storage class.

property config_paths: List[str]

Gets the list of config paths this service will search for config files.

Returns:
List[str]
load_config(json_file_name: str, schema_type: ConfigSchema | None) Dict[str, Any]

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(json_file_name: str, tunables: TunableGroups, global_config: Dict[str, Any] | None = None, parent_args: Dict[str, int | float | str | None] | None = None, service: Service | None = None) Environment

Load and build new environment from the config file.

Parameters:
json_file_namestr

The environment JSON configuration file.

tunablesTunableGroups

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

global_configdict

Global parameters to add to the environment config.

parent_argsDict[str, TunableValue]

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

serviceService

An optional reference of the parent service to mix in.

Returns:
envEnvironment

A new benchmarking environment.

load_environment_list(json_file_name: str, tunables: TunableGroups, global_config: Dict[str, Any] | 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

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

global_configdict

Global parameters to add to the environment config.

serviceService

An optional reference of the parent service to mix in.

parent_argsDict[str, TunableValue]

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

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.

prepare_class_load(config: Dict[str, Any], global_config: Dict[str, Any] | None = None, parent_args: Dict[str, int | float | str | None] | None = None) Tuple[str, Dict[str, Any]]

Extract the class instantiation parameters from the configuration. Mix-in the global parameters and resolve the local file system paths, where it is required.

Parameters:
configdict

Configuration of the optimizer.

global_configdict

Global configuration parameters (optional).

parent_argsDict[str, TunableValue]

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

Returns:
(class_name, class_config)(str, dict)

Name of the class to instantiate and its configuration.

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.