From 7e8e54e84c63171e748bbf09516fd517e6821ace Mon Sep 17 00:00:00 2001 From: Gustaf Rydholm Date: Sat, 20 Mar 2021 18:09:06 +0100 Subject: Inital commit for refactoring to lightning --- training/prepare_experiments.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 training/prepare_experiments.py (limited to 'training/prepare_experiments.py') diff --git a/training/prepare_experiments.py b/training/prepare_experiments.py new file mode 100644 index 0000000..21997af --- /dev/null +++ b/training/prepare_experiments.py @@ -0,0 +1,34 @@ +"""Run a experiment from a config file.""" +import json + +import click +import yaml + + +def run_experiments(experiments_filename: str) -> None: + """Run experiment from file.""" + with open(experiments_filename, "r") as f: + experiments_config = yaml.safe_load(f) + + num_experiments = len(experiments_config["experiments"]) + for index in range(num_experiments): + experiment_config = experiments_config["experiments"][index] + experiment_config["experiment_group"] = experiments_config["experiment_group"] + cmd = f"poetry run run-experiment --gpu=-1 --save '{json.dumps(experiment_config)}'" + print(cmd) + + +@click.command() +@click.option( + "--experiments_filename", + required=True, + type=str, + help="Filename of Yaml file of experiments to run.", +) +def run_cli(experiments_filename: str) -> None: + """Parse command-line arguments and run experiments from provided file.""" + run_experiments(experiments_filename) + + +if __name__ == "__main__": + run_cli() -- cgit v1.2.3-70-g09d2