mlos_bench.schedulers.trial_runner

Simple class to run an individual Trial on a given Environment.

Classes

TrialRunner

Simple class to help run an individual Trial on an environment.

Module Contents

class mlos_bench.schedulers.trial_runner.TrialRunner(trial_runner_id: int, env: mlos_bench.environments.base_environment.Environment)[source]

Simple class to help run an individual Trial on an environment.

TrialRunner manages the lifecycle of a single trial, including setup, run, teardown, and async status polling via EventLoopContext background threads.

Multiple TrialRunners can be used in a multi-processing pool to run multiple trials in parallel, for instance.

Parameters:
__enter__() TrialRunner[source]
Return type:

TrialRunner

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

Literal[False]

__repr__() str[source]
Return type:

str

__str__() str[source]
Return type:

str

classmethod create_from_json(*, config_loader: mlos_bench.services.base_service.Service, env_json: str, svcs_json: str | list[str] | None = None, num_trial_runners: int = 1, tunable_groups: mlos_bench.tunables.tunable_groups.TunableGroups | None = None, global_config: dict[str, Any] | None = None) list[TrialRunner][source]

Create a list of TrialRunner instances, and their associated Environments and Services, from JSON configurations.

Since each TrialRunner instance is independent, they can be run in parallel, and hence must each get their own copy of the Environment and Services to operate on.

The global_config is shared across all TrialRunners, but each copy gets its own unique trial_runner_id.

Parameters:
  • config_loader (Service) – A service instance capable of loading configuration (i.e., SupportsConfigLoading).

  • env_json (str) – JSON file or string representing the environment configuration.

  • svcs_json (str | list[str] | None) – JSON file(s) or string(s) representing the Services configuration.

  • num_trial_runners (int) – Number of TrialRunner instances to create. Default is 1.

  • tunable_groups (TunableGroups | None) – TunableGroups instance to use as the parent Tunables for the environment. Default is None.

  • global_config (dict[str, Any] | None) – Global configuration parameters. Default is None.

Returns:

A list of TrialRunner instances created from the provided configuration.

Return type:

list[TrialRunner]

run_trial(trial: mlos_bench.storage.base_storage.Storage.Trial, global_config: dict[str, Any] | None = None) None[source]

Run a single trial on this TrialRunner’s Environment and stores the results in the backend Trial Storage.

Parameters:
  • trial (Storage.Trial) – A Storage class based Trial used to persist the experiment trial data.

  • global_config (dict) – Global configuration parameters.

Returns:

(trial_status, trial_score) – Status and results of the trial.

Return type:

(Status, dict[str, float] | None)

teardown() None[source]

Tear down the Environment.

Call it after the completion of one (or more) .run() in the TrialRunner context.

Return type:

None

property environment: mlos_bench.environments.base_environment.Environment[source]

Get the Environment.

Return type:

mlos_bench.environments.base_environment.Environment

property is_running: bool[source]

Get the running state of the current TrialRunner.

Return type:

bool

property trial_runner_id: int[source]

Get the TrialRunner’s id.

Return type:

int