From 6c9b371b3bac498718d58f1fbe1cf4caef81ad04 Mon Sep 17 00:00:00 2001 From: Costa Huang Date: Fri, 16 Apr 2021 12:27:08 -0400 Subject: [PATCH] add reproduce utility script --- cleanrl/utils/reproduce.py | 43 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 cleanrl/utils/reproduce.py diff --git a/cleanrl/utils/reproduce.py b/cleanrl/utils/reproduce.py new file mode 100644 index 000000000..4974e87ef --- /dev/null +++ b/cleanrl/utils/reproduce.py @@ -0,0 +1,43 @@ +import argparse +import json +import requests +from distutils.util import strtobool + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description='CleanRL Plots') + # Common arguments + parser.add_argument('--run', type=str, default="cleanrl/cleanrl.benchmark/runs/thq5rgnz", + help='the name of wandb project (e.g. cleanrl/cleanrl)') + parser.add_argument('--remove-entity', type=lambda x:bool(strtobool(x)), default=True, nargs='?', const=True, + help='if toggled, the wandb-entity will be removed') + args = parser.parse_args() + uri = args.run.replace("/runs", "") + + requirements_txt_url = f"https://api.wandb.ai/files/{uri}/requirements.txt" + metadata_url = f"https://api.wandb.ai/files/{uri}/wandb-metadata.json" + metadata = requests.get(url=metadata_url).json() + + if args.remove_entity: + a = [] + wandb_entity_idx = None + for i in range(len(metadata["args"])): + if metadata["args"][i] == "--wandb-entity": + wandb_entity_idx = i + continue + if wandb_entity_idx and i == wandb_entity_idx+1: + continue + a += [metadata["args"][i]] + else: + a = metadata["args"] + + program = ["python"] + [metadata["program"]] + a + + + print(f""" +# run the following +python3 -m venv venv +source venv/bin/activate +pip install -r {requirements_txt_url} +curl -OL https://api.wandb.ai/files/{uri}/code/{metadata["codePath"]} +{" ".join(program)} +""") \ No newline at end of file