imitation.scripts.parallel#

Runs a Sacred experiment in parallel.

Functions

main_console()

parallel(sacred_ex_name, run_name, ...)

Parallelize multiple runs of another Sacred Experiment using Ray Tune.

imitation.scripts.parallel.main_console()[source]#
imitation.scripts.parallel.parallel(sacred_ex_name, run_name, num_samples, search_space, base_named_configs, base_config_updates, resources_per_trial, init_kwargs, repeat, experiment_checkpoint_path, tune_run_kwargs)[source]#

Parallelize multiple runs of another Sacred Experiment using Ray Tune.

A Sacred FileObserver is attached to the inner experiment and writes Sacred logs to “{RAY_LOCAL_DIR}/sacred/”. These files are automatically copied over to upload_dir if that argument is provided in tune_run_kwargs.

Parameters
  • sacred_ex_name (str) – The Sacred experiment to tune. Either “train_rl”, “train_imitation”, “train_adversarial” or “train_preference_comparisons”.

  • run_name (str) – A name describing this parallelizing experiment. This argument is also passed to ray.tune.run as the name argument. It is also saved in ‘sacred/run.json’ of each inner Sacred experiment under the ‘experiment.name’ key. This is equivalent to using the Sacred CLI ‘–name’ option on the inner experiment. Offline analysis jobs can use this argument to group similar data.

  • num_samples (int) – Number of times to sample from the hyperparameter space without considering repetition using repeat.

  • search_space (Mapping[str, Any]) – A dictionary which can contain Ray Tune search objects like ray.tune.grid_search and ray.tune.sample_from, and is passed as the config argument to ray.tune.run(). After the search_space is transformed by Ray, it passed into sacred_ex.run(**run_kwargs) as run_kwargs (sacred_ex is the Sacred Experiment selected via sacred_ex_name). Usually search_space only has the keys “named_configs” and “config_updates”, but any parameter names to sacred.Experiment.run() are okay.

  • base_named_configs (Sequence[str]) – Default Sacred named configs. Any named configs taken from search_space are higher priority than the base_named_configs. Concretely, this priority is implemented by appending named configs taken from search_space to the run’s named configs after base_named_configs. Named configs in base_named_configs don’t appear in the automatically generated Ray directory name, unlike named configs from search_space.

  • base_config_updates (Mapping[str, Any]) – Default Sacred config updates. Any config updates taken from search_space are higher priority than base_config_updates. Config updates in base_config_updates don’t appear in the automatically generated Ray directory name, unlike config updates from search_space.

  • resources_per_trial (Mapping[str, Any]) – Argument to ray.tune.run().

  • init_kwargs (Mapping[str, Any]) – Arguments to pass to ray.init.

  • repeat (int) – Number of runs to repeat each trial for. If repeat > 1, then optuna is used as the default search algorithm unless specified otherwise in tune_run_kwargs.

  • experiment_checkpoint_path (str) – Path containing the checkpoints of a previous experiment ran using this script. Useful for evaluating the best trial of the experiment.

  • tune_run_kwargs (Dict[str, Any]) – Other arguments to pass to ray.tune.run().

Raises
  • TypeError – Named configs not string sequences or config updates not mappings.

  • ValueErrorrepeat > 1 but search_alg is not an instance of ray.tune.search.SearchAlgorithm.

Return type

ExperimentAnalysis

Returns

The result of running the parallel experiment with ray.tune.run(). Useful for fetching the configs and results dataframe of all the trials.