mlos_bench.schedulers.trial_runner
Simple class to run an individual Trial on a given Environment.
Classes
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:
trial_runner_id (int)
- __enter__() TrialRunner [source]
- Return type:
- __exit__(ex_type: type[BaseException] | None, ex_val: BaseException | None, ex_tb: types.TracebackType | None) Literal[False] [source]
- Parameters:
ex_type (type[BaseException] | None)
ex_val (BaseException | None)
ex_tb (types.TracebackType | None)
- Return type:
Literal[False]
- 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:
- 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.
- 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: