mlos_bench.services.base_service

Base class for the service mix-ins.

Classes

Service

An abstract base of all Environment Services and used to build up mix-ins.

Module Contents

class mlos_bench.services.base_service.Service(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)[source]

An abstract base of all Environment Services and used to build up mix-ins.

Create a new service with a given config.

Parameters:
  • config (dict) – Free-format dictionary that contains the service configuration. It will be passed as a constructor parameter of the class specified by class_name.

  • global_config (dict) – Free-format dictionary of global parameters.

  • parent (Service) – An optional parent service that can provide mixin functions.

  • methods (Union[Dict[str, Callable], List[Callable], None]) – New methods to register with the service.

__enter__() Service[source]

Enter the Service mix-in context.

Calls the _enter_context() method of all the Services registered under this one.

Return type:

Service

__exit__(ex_type: Type[BaseException] | None, ex_val: BaseException | None, ex_tb: types.TracebackType | None) Literal[False][source]

Exit the Service mix-in context.

Calls the _exit_context() method of all the Services registered under this one.

Parameters:
Return type:

Literal[False]

__repr__() str[source]
Return type:

str

export() Dict[str, Callable][source]

Return a dictionary of functions available in this service.

Returns:

services – A dictionary of string -> function pairs.

Return type:

dict

static merge_methods(ext_methods: Dict[str, Callable] | List[Callable] | None, local_methods: Dict[str, Callable] | List[Callable]) Dict[str, Callable][source]

Merge methods from the external caller with the local ones.

This function is usually called by the derived class constructor just before invoking the constructor of the base class.

Parameters:
  • ext_methods (Union[Dict[str, Callable], List[Callable], None])

  • local_methods (Union[Dict[str, Callable], List[Callable]])

Return type:

Dict[str, Callable]

classmethod new(class_name: str, config: Dict[str, Any] | None = None, global_config: Dict[str, Any] | None = None, parent: Service | None = None) Service[source]

Factory method for a new service with a given config.

Parameters:
  • class_name (str) – FQN of a Python class to instantiate, e.g., “mlos_bench.services.remote.azure.AzureVMService”. Must be derived from the Service class.

  • config (dict) – Free-format dictionary that contains the service configuration. It will be passed as a constructor parameter of the class specified by class_name.

  • global_config (dict) – Free-format dictionary of global parameters.

  • parent (Service) – A parent service that can provide mixin functions.

Returns:

svc – An instance of the Service class initialized with config.

Return type:

Service

pprint() str[source]

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

Return type:

str

register(services: Dict[str, Callable] | List[Callable]) None[source]

Register new mix-in services.

Parameters:

services (dict or list) – A dictionary of string -> function pairs.

Return type:

None

config[source]
property config_loader_service: mlos_bench.services.types.config_loader_type.SupportsConfigLoading[source]

Return a config loader service.

Returns:

config_loader_service – A config loader service.

Return type:

SupportsConfigLoading