From 8e31bf7eb6e7a1e132e1f5fff0f48da124982590 Mon Sep 17 00:00:00 2001 From: rdnfn <75615911+rdnfn@users.noreply.github.com> Date: Thu, 31 Mar 2022 17:27:11 +0000 Subject: [PATCH 01/52] aux: move settings to devcontainer --- .devcontainer/devcontainer.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index a25e0a81..d733294f 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -45,7 +45,10 @@ "editor.formatOnSave": true, "editor.rulers": [ 88 - ] + ], + "python.terminal.activateEnvInCurrentTerminal": true, + "esbonio.server.enabled": false, + "esbonio.sphinx.confDir": "${workspaceFolder}/docs" }, // Add the IDs of extensions you want installed when the container is created. "extensions": [ From e0f1a8aa34d093ff4db27303edb59ff6c3d4d945 Mon Sep 17 00:00:00 2001 From: rdnfn <75615911+rdnfn@users.noreply.github.com> Date: Thu, 31 Mar 2022 17:42:21 +0000 Subject: [PATCH 02/52] aux: add rst linters to dev requirements --- requirements/dev_requirements.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/requirements/dev_requirements.txt b/requirements/dev_requirements.txt index 61976f21..13abc6a9 100644 --- a/requirements/dev_requirements.txt +++ b/requirements/dev_requirements.txt @@ -26,4 +26,8 @@ jupyterlab # wandb # Convex solver tools (OPTIONAL) -# cvxpy \ No newline at end of file +# cvxpy + +# for rst development (used by vscode) +doc8 +rstcheck \ No newline at end of file From bcb9e47e2112a9503a1ea7b595dcca1124e1d127 Mon Sep 17 00:00:00 2001 From: rdnfn <75615911+rdnfn@users.noreply.github.com> Date: Fri, 1 Apr 2022 09:53:02 +0000 Subject: [PATCH 03/52] aux: add fix to history --- HISTORY.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/HISTORY.rst b/HISTORY.rst index 8b2e9cf7..83e1a15f 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -2,6 +2,11 @@ History ======= +0.4.2 (2022-04-00) +------------------ + +* Fix: adapted Energym env reset() method to avoid triggering long warm-up times with additional simulation runs + 0.4.1 (2022-03-30) ------------------ From 2e5f2905a273788d142a98419c5438cf8bfaa8fd Mon Sep 17 00:00:00 2001 From: rdnfn <75615911+rdnfn@users.noreply.github.com> Date: Fri, 1 Apr 2022 13:43:45 +0000 Subject: [PATCH 04/52] feat: add support for list of configs This adds support for multiple config cli options as well as giving the python API a list of configs. --- beobench/cli.py | 8 ++--- beobench/experiment/config_parser.py | 50 +++++++++++++++++++++------- beobench/experiment/scheduler.py | 14 ++++---- 3 files changed, 48 insertions(+), 24 deletions(-) diff --git a/beobench/cli.py b/beobench/cli.py index 622a68b7..e79d894b 100644 --- a/beobench/cli.py +++ b/beobench/cli.py @@ -1,7 +1,6 @@ """Command line interface for beobench.""" import click -import ast import beobench.experiment.scheduler import beobench.utils @@ -19,6 +18,7 @@ def cli(): default=None, help="Json or filepath with yaml that defines beobench experiment configuration.", type=str, + multiple=True, ) @click.option( "--experiment-file", @@ -121,12 +121,8 @@ def run( # # See https://stackoverflow.com/a/40094408. - # Parse config str to dict if - if config and config[0] == "{": - config = ast.literal_eval(config) - beobench.experiment.scheduler.run( - config=config, + config=list(config), experiment_file=experiment_file, agent_file=agent_file, method=method, diff --git a/beobench/experiment/config_parser.py b/beobench/experiment/config_parser.py index a5abc600..32488dc4 100644 --- a/beobench/experiment/config_parser.py +++ b/beobench/experiment/config_parser.py @@ -3,6 +3,9 @@ from typing import Union import pathlib import yaml +import ast + +import beobench.utils # To enable compatiblity with Python<=3.6 (e.g. for sinergym dockerfile) try: @@ -14,27 +17,50 @@ importlib.resources = importlib_resources -def parse(config: Union[str, pathlib.Path]) -> dict: - """Parse experiment config from yaml file to dict. +def parse(config: Union[dict, str, pathlib.Path, list]) -> dict: + """Parse experiment config to dict. Args: - config (Union[str, pathlib.Path]): path of yaml file + config (Union[dict, str, pathlib.Path, list]): path of yaml file Returns: dict: config in dictionary """ - - # load config dict if path given - if isinstance(config, (str, pathlib.Path)): - # make sure config is a real path - if isinstance(config, str): - config = pathlib.Path(config) + if isinstance(config, list): + # get list of config dicts + parsed_configs = [] + for single_config in config: + parsed_configs.append(parse(single_config)) + + # merge config dicts + parsed_config = {} + for conf in parsed_configs: + parsed_config = beobench.utils.merge_dicts(parsed_config, conf) + + elif isinstance(config, pathlib.Path): + # load config yaml to dict if path given with open(config, "r", encoding="utf-8") as config_file: - config_dict = yaml.safe_load(config_file) + parsed_config = yaml.safe_load(config_file) + + elif isinstance(config, str): + if config[0] == "{": + # if json str + parsed_config = ast.literal_eval(config) + else: + # make sure config is a real path + config_path = pathlib.Path(config) + parsed_config = parse(config_path) + + elif isinstance(config, dict): + parsed_config = config + else: - config_dict = config + raise ValueError( + f"Config not one of allowed types (dict, str, pathlib.Path, list): {config}" + ) - return config_dict + print("Parsed config:", parsed_config) + return parsed_config def create_rllib_config(config: dict) -> dict: diff --git a/beobench/experiment/scheduler.py b/beobench/experiment/scheduler.py index 7304a29f..4e736d36 100644 --- a/beobench/experiment/scheduler.py +++ b/beobench/experiment/scheduler.py @@ -21,7 +21,7 @@ def run( - config: Union[str, dict] = None, + config: Union[str, dict, pathlib.Path, list] = None, experiment_file: str = None, agent_file: str = None, method: str = None, @@ -43,8 +43,9 @@ def run( interface. Args: - config (str or dict, optional): experiment configuration. This can either be - a dictionary or a path to a yaml file. + config (str, dict, pathlib.Path or list, optional): experiment configuration. + This can either be a dictionary, or a path (str or pathlib) to a yaml file, + or a json str, or a list combining any number of the prior config types. experiment_file (str, optional): File that defines experiment. Defaults to None. DEPRECATED. agent_file (str, optional): File that defines custom agent. This script is @@ -78,10 +79,11 @@ def run( # pylint: disable=unused-argument # get config dict from config argument - if config: - config = beobench.experiment.config_parser.parse(config) - else: + if not config: config = beobench.experiment.config_parser.get_default() + else: + config = beobench.experiment.config_parser.parse(config) + # Create a definition of experiment from inputs if experiment_file is not None: warnings.warn( From f4d5807ac22370d630cbd94aa8ea25f0105bc10b Mon Sep 17 00:00:00 2001 From: rdnfn <75615911+rdnfn@users.noreply.github.com> Date: Fri, 1 Apr 2022 13:50:32 +0000 Subject: [PATCH 05/52] docs: add new feature to history and fix too long lines in history --- HISTORY.rst | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 83e1a15f..962b5eb3 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -5,21 +5,28 @@ History 0.4.2 (2022-04-00) ------------------ -* Fix: adapted Energym env reset() method to avoid triggering long warm-up times with additional simulation runs +* Feature: allow multiple configs to be given to both CLI + (giving multiple ``-c`` options) and Python API (as a list). +* Fix: adapted Energym env reset() method to avoid triggering + long warm-up times with additional simulation runs 0.4.1 (2022-03-30) ------------------ * Feature: enable package extras to be given in development mode -* Feature: add support for arm64/aarch64-based development by forcing experiment containers to run as amd64 containers on those systems (#32) +* Feature: add support for arm64/aarch64-based development by forcing + experiment containers to run as amd64 containers on those systems (#32) * Fix: add gym to extended package requirements 0.4.0 (2022-03-28) ------------------ -* Make dependencies that are only used inside experiment/gym containers optional (for all dependencies install via ``pip install beobench[extended]``) -* Add two part experiment image build process so that there is shared beobench installation dockerfile +* Make dependencies that are only used inside experiment/gym + containers optional + (for all dependencies install via ``pip install beobench[extended]``) +* Add two part experiment image build process so that there is shared beobench + installation dockerfile * Add support for yaml config files (!) * Overhaul of documentation, including new envs page and new theme * Enable RLlib free experiment containers when not required @@ -30,7 +37,8 @@ History 0.3.0 (2022-02-14) ------------------ -* Add complete redesign of CLI: main command changed from ``python -m beobench.experiment.scheduler`` to ``beobench run``. +* Add complete redesign of CLI: main command changed from + ``python -m beobench.experiment.scheduler`` to ``beobench run``. * Add support for energym environments * Add support for MLflow experiment tracking * Add support for custom agents @@ -46,7 +54,8 @@ History 0.2.0 (2022-01-18) ------------------ -* Enable adding custom environments to beobench with *docker build context*-based syntax +* Enable adding custom environments to beobench with + *docker build context*-based syntax * Save experiment results on host machine * Major improvements to documentation * Remove unnecessary wandb arguments in main CLI From 356459f598b7139ade015ad235bc5301b1920d61 Mon Sep 17 00:00:00 2001 From: rdnfn <75615911+rdnfn@users.noreply.github.com> Date: Fri, 1 Apr 2022 13:55:30 +0000 Subject: [PATCH 06/52] docs: add github issues to history --- HISTORY.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 962b5eb3..d77ece33 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -6,9 +6,9 @@ History ------------------ * Feature: allow multiple configs to be given to both CLI - (giving multiple ``-c`` options) and Python API (as a list). + (giving multiple ``-c`` options) and Python API (as a list) (#51) * Fix: adapted Energym env reset() method to avoid triggering - long warm-up times with additional simulation runs + long warm-up times with additional simulation runs (#43) 0.4.1 (2022-03-30) ------------------ From 7ae8415f6c28744ecf6b4307a9a92ccef45d5ff2 Mon Sep 17 00:00:00 2001 From: rdnfn <75615911+rdnfn@users.noreply.github.com> Date: Fri, 1 Apr 2022 14:20:21 +0000 Subject: [PATCH 07/52] docs: fix doc8 warning in installation guide --- docs/guides/installation.rst | 15 ++++++++++++--- docs/guides/installation_linux.rst | 17 ++++++++++++++--- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/docs/guides/installation.rst b/docs/guides/installation.rst index 7d38c300..c0df8d89 100644 --- a/docs/guides/installation.rst +++ b/docs/guides/installation.rst @@ -1,6 +1,9 @@ .. highlight:: shell +.. toctree:: + :hidden: + installation_linux .. _sec-installation: @@ -18,7 +21,8 @@ Recommended method pip install beobench -Look at the :doc:`getting started guide ` to run your first beobench experiment. +Look at the :doc:`getting started guide ` +to run your first beobench experiment. .. admonition:: OS support @@ -27,7 +31,10 @@ Look at the :doc:`getting started guide ` to run your first beo Directly from GitHub ^^^^^^^^^^^^^^^^^^^^ -If you would like to get the truly latest (but not necessarily stable) version of beobench, you can replace the `pip install` command above with the following command: +If you would like to get the truly latest (but +not necessarily stable) version of beobench, +you can replace the `pip install` command above +with the following command: .. code-block:: console @@ -39,4 +46,6 @@ This will install the latest version directly from the master branch on GitHub. Development environment ^^^^^^^^^^^^^^^^^^^^^^^ -If you would like to contribute to beobench, use :doc:`this guide ` to set up the full development environment. \ No newline at end of file +If you would like to contribute to beobench, +use :doc:`this guide ` to set up the +full development environment. diff --git a/docs/guides/installation_linux.rst b/docs/guides/installation_linux.rst index 405ccc27..b950ff6d 100644 --- a/docs/guides/installation_linux.rst +++ b/docs/guides/installation_linux.rst @@ -1,7 +1,18 @@ Additional installation steps on Linux ----------------------------------------- -Docker behaves differently depending on your OS. In Linux, many docker commands require additional privileges that can be granted by adding ``sudo`` in front of the command. Beobench relies on docker for most of its functionality. Therefore, there are two options to get beobench to work on a Linux system: +Docker behaves differently depending on your OS. In Linux, +many docker commands require additional privileges that can +be granted by adding ``sudo`` in front of the command. +Beobench relies on docker for most of its functionality. +Therefore, there are two options to get beobench to work +on a Linux system: -1. Always use ``sudo`` in front of beobench commands to grant the relevant privileges required for docker (note that this has not been tested) -2. *Recommended:* follow the official post-installation steps to `manage docker as a non-root user `_ to enable running docker without ``sudo``. As the linked documentation points out, this carries a certain security risk. \ No newline at end of file +1. Always use ``sudo`` in front of beobench commands to grant + the relevant privileges required for docker (note that this + has not been tested) +2. *Recommended:* follow the official post-installation steps + to `manage docker as a non-root user + `_ to enable running docker + without ``sudo``. As the linked documentation points out, + this carries a certain security risk. From 8dc5ff6bbe9709d6aee2cf7e76efc0401b3de2d2 Mon Sep 17 00:00:00 2001 From: rdnfn <75615911+rdnfn@users.noreply.github.com> Date: Fri, 1 Apr 2022 15:21:55 +0000 Subject: [PATCH 08/52] docs: add rst resources to contributing guide --- CONTRIBUTING.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index de2da604..3e989fa1 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -104,6 +104,15 @@ To run a subset of tests:: $ python -m unittest tests.test_beobench + +Resources +--------- + +Documentation and cheatsheets for reStructuredText (``..rst``): + +* https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html +* https://bashtage.github.io/sphinx-material/rst-cheatsheet/rst-cheatsheet.html + Deploying --------- From 97e51218d8d05ca5c720a0f9008de5d431dc86ab Mon Sep 17 00:00:00 2001 From: rdnfn <75615911+rdnfn@users.noreply.github.com> Date: Fri, 1 Apr 2022 15:26:18 +0000 Subject: [PATCH 09/52] fix: enable container build even if prior build failed midway --- beobench/experiment/containers.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/beobench/experiment/containers.py b/beobench/experiment/containers.py index 1b410b30..7ab2a33c 100644 --- a/beobench/experiment/containers.py +++ b/beobench/experiment/containers.py @@ -62,6 +62,12 @@ def build_experiment_container( # TODO: remove tmp git dir once buildkit version in docker cli updated tmp_git_dir = (local_dir / "tmp" / "beobench_contrib").absolute() + + try: + shutil.rmtree(tmp_git_dir) + except FileNotFoundError: + pass + subprocess.check_call( [ "git", From a9cc63999f0c083bd341d4af7f281afe15974798 Mon Sep 17 00:00:00 2001 From: rdnfn <75615911+rdnfn@users.noreply.github.com> Date: Fri, 1 Apr 2022 15:27:18 +0000 Subject: [PATCH 10/52] aux: add fix to history --- HISTORY.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/HISTORY.rst b/HISTORY.rst index d77ece33..de1ab399 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -9,6 +9,8 @@ History (giving multiple ``-c`` options) and Python API (as a list) (#51) * Fix: adapted Energym env reset() method to avoid triggering long warm-up times with additional simulation runs (#43) +* Fix: enable container build even if prior build failed midway + and left artifacts 0.4.1 (2022-03-30) ------------------ From a7ed61ac41f9543f3cd9408d8dbe01a2f5c9d3d6 Mon Sep 17 00:00:00 2001 From: rdnfn <75615911+rdnfn@users.noreply.github.com> Date: Fri, 1 Apr 2022 15:31:56 +0000 Subject: [PATCH 11/52] fix: prevent multiple config print outputs --- beobench/experiment/config_parser.py | 1 - beobench/experiment/scheduler.py | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/beobench/experiment/config_parser.py b/beobench/experiment/config_parser.py index 32488dc4..99b96d2d 100644 --- a/beobench/experiment/config_parser.py +++ b/beobench/experiment/config_parser.py @@ -59,7 +59,6 @@ def parse(config: Union[dict, str, pathlib.Path, list]) -> dict: f"Config not one of allowed types (dict, str, pathlib.Path, list): {config}" ) - print("Parsed config:", parsed_config) return parsed_config diff --git a/beobench/experiment/scheduler.py b/beobench/experiment/scheduler.py index 4e736d36..9e232273 100644 --- a/beobench/experiment/scheduler.py +++ b/beobench/experiment/scheduler.py @@ -84,6 +84,8 @@ def run( else: config = beobench.experiment.config_parser.parse(config) + print("Beobench config used:", config) + # Create a definition of experiment from inputs if experiment_file is not None: warnings.warn( From fd83dac4879d87b58b6ffa85cc46e63a71dbca14 Mon Sep 17 00:00:00 2001 From: rdnfn <75615911+rdnfn@users.noreply.github.com> Date: Fri, 1 Apr 2022 15:49:31 +0000 Subject: [PATCH 12/52] exp: add example wandb sweep to data --- beobench/data/sweeps/sweep01.yaml | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 beobench/data/sweeps/sweep01.yaml diff --git a/beobench/data/sweeps/sweep01.yaml b/beobench/data/sweeps/sweep01.yaml new file mode 100644 index 00000000..c7a64e44 --- /dev/null +++ b/beobench/data/sweeps/sweep01.yaml @@ -0,0 +1,9 @@ +program: beobench +method: grid +command: +- ${program} +- run +- ${args} +parameters: + config: + values: [./beobench/data/configs/rewex01.yaml] \ No newline at end of file From 6f432f418631dc4f1f4175f07dbb704f4dcf6318 Mon Sep 17 00:00:00 2001 From: rdnfn <75615911+rdnfn@users.noreply.github.com> Date: Fri, 1 Apr 2022 15:49:54 +0000 Subject: [PATCH 13/52] docs: add first draft of hyperparameter tuning guide --- docs/guides.rst | 3 ++- docs/guides/hyperparameter_tuning.rst | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 docs/guides/hyperparameter_tuning.rst diff --git a/docs/guides.rst b/docs/guides.rst index f097f742..23abc896 100644 --- a/docs/guides.rst +++ b/docs/guides.rst @@ -10,4 +10,5 @@ Welcome to beobench's usage guides! guides/getting_started guides/intro_experiment guides/add_env - guides/dev_env \ No newline at end of file + guides/hyperparameter_tuning + guides/dev_env diff --git a/docs/guides/hyperparameter_tuning.rst b/docs/guides/hyperparameter_tuning.rst new file mode 100644 index 00000000..71c0ec1e --- /dev/null +++ b/docs/guides/hyperparameter_tuning.rst @@ -0,0 +1,14 @@ +Hyperparameter Tuning +--------------------- + +There multiple different ways with which hyperparameters +can be tuned in experiments involving Beobench environments. +In this page we illustrate the usage of the `W&B Sweeps API +`_ in combination with Beobench, but there +are other options as well (e.g. `Ray Tune `_). + +W&B Sweeps +^^^^^^^^^^ + +*Under construction.* + From 4600dcb7c7fefb30156efeca3ae37b2d0c8e91bf Mon Sep 17 00:00:00 2001 From: rdnfn <75615911+rdnfn@users.noreply.github.com> Date: Fri, 1 Apr 2022 17:47:50 +0000 Subject: [PATCH 14/52] docs: minor spelling fix --- CONTRIBUTING.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 3e989fa1..5e83d3ec 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -108,7 +108,7 @@ To run a subset of tests:: Resources --------- -Documentation and cheatsheets for reStructuredText (``..rst``): +Documentation and cheatsheets for reStructuredText (``.rst`` files): * https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html * https://bashtage.github.io/sphinx-material/rst-cheatsheet/rst-cheatsheet.html From 6b4015c35aa06c5b31888eea703289e3789c0887 Mon Sep 17 00:00:00 2001 From: rdnfn <75615911+rdnfn@users.noreply.github.com> Date: Mon, 4 Apr 2022 08:56:23 +0000 Subject: [PATCH 15/52] docs: add commit message style guide --- CONTRIBUTING.rst | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 5e83d3ec..8dafeb90 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -82,8 +82,17 @@ Ready to contribute? Here's how to set up `beobench` for local development. 5. Submit a pull request through the GitHub website. +Guidelines +---------- + +Commit messages +^^^^^^^^^^^^^^^ + +When committing to the Beobench repo, please try to follow `this style guide by Udacity ` for the commit messages. + + Pull Request Guidelines ------------------------ +^^^^^^^^^^^^^^^^^^^^^^^ Before you submit a pull request, check that it meets these guidelines: From af478878f3c3476a38e35e0fc70cf460177858a6 Mon Sep 17 00:00:00 2001 From: rdnfn <75615911+rdnfn@users.noreply.github.com> Date: Mon, 4 Apr 2022 08:56:49 +0000 Subject: [PATCH 16/52] docs: fix toctree problems with linux installation --- docs/guides/installation.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/guides/installation.rst b/docs/guides/installation.rst index c0df8d89..74530b4d 100644 --- a/docs/guides/installation.rst +++ b/docs/guides/installation.rst @@ -1,10 +1,5 @@ .. highlight:: shell -.. toctree:: - :hidden: - - installation_linux - .. _sec-installation: @@ -49,3 +44,8 @@ Development environment If you would like to contribute to beobench, use :doc:`this guide ` to set up the full development environment. + +.. toctree:: + :hidden: + + installation_linux From d3dd0183979b8deb47a7146e18850aab30d794a4 Mon Sep 17 00:00:00 2001 From: rdnfn <75615911+rdnfn@users.noreply.github.com> Date: Mon, 4 Apr 2022 08:57:21 +0000 Subject: [PATCH 17/52] docs: rename home page title --- docs/index.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/index.rst b/docs/index.rst index aaffebb3..c70d7309 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -1,4 +1,4 @@ -Home - Beobench Docs +Beobench Docs ============================= .. include:: ../README.rst @@ -10,8 +10,9 @@ Contents .. toctree:: :maxdepth: 2 + :includehidden: - self + Home guides/installation guides envs From 01f9cd9c2c3ba72808f8598030d37ed927450708 Mon Sep 17 00:00:00 2001 From: rdnfn <75615911+rdnfn@users.noreply.github.com> Date: Mon, 4 Apr 2022 09:05:03 +0000 Subject: [PATCH 18/52] refactor: remove deprecated *_file arguments. --- beobench/cli.py | 16 ---------------- beobench/experiment/scheduler.py | 18 ------------------ 2 files changed, 34 deletions(-) diff --git a/beobench/cli.py b/beobench/cli.py index e79d894b..953ea1ed 100644 --- a/beobench/cli.py +++ b/beobench/cli.py @@ -20,18 +20,6 @@ def cli(): type=str, multiple=True, ) -@click.option( - "--experiment-file", - default=None, - help="File that defines beobench experiment.", - type=click.Path(exists=True, file_okay=True, dir_okay=False), -) -@click.option( - "--agent-file", - default=None, - help="File that defines custom agent.", - type=click.Path(exists=True, file_okay=True, dir_okay=False), -) @click.option( "--method", default="", @@ -96,8 +84,6 @@ def cli(): ) def run( config: str, - experiment_file: str, - agent_file: str, method: str, env: str, local_dir: str, @@ -123,8 +109,6 @@ def run( beobench.experiment.scheduler.run( config=list(config), - experiment_file=experiment_file, - agent_file=agent_file, method=method, env=env, local_dir=local_dir, diff --git a/beobench/experiment/scheduler.py b/beobench/experiment/scheduler.py index 9e232273..34eb8b4d 100644 --- a/beobench/experiment/scheduler.py +++ b/beobench/experiment/scheduler.py @@ -22,8 +22,6 @@ def run( config: Union[str, dict, pathlib.Path, list] = None, - experiment_file: str = None, - agent_file: str = None, method: str = None, env: str = None, local_dir: str = "./beobench_results", @@ -46,10 +44,6 @@ def run( config (str, dict, pathlib.Path or list, optional): experiment configuration. This can either be a dictionary, or a path (str or pathlib) to a yaml file, or a json str, or a list combining any number of the prior config types. - experiment_file (str, optional): File that defines experiment. - Defaults to None. DEPRECATED. - agent_file (str, optional): File that defines custom agent. This script is - executed inside the gym container. DEPRECATED, this should be set in config. method (str, optional): RL method to use in experiment. This overwrites any method that is set in experiment file. For example 'PPO'. Defaults to None. env (str, optional): environment to apply method to in experiment. This @@ -86,18 +80,6 @@ def run( print("Beobench config used:", config) - # Create a definition of experiment from inputs - if experiment_file is not None: - warnings.warn( - "The experiment_file argument has been replaced by config", - DeprecationWarning, - ) - if agent_file is not None: - warnings.warn( - "The agent_file argmunet has been replaced by config", - DeprecationWarning, - ) - if config["agent"]["origin"] == "rllib": agent_file = None else: From 09cad48c6afa13646527460061cdfe3c1b6ead5d Mon Sep 17 00:00:00 2001 From: rdnfn <75615911+rdnfn@users.noreply.github.com> Date: Mon, 4 Apr 2022 09:07:04 +0000 Subject: [PATCH 19/52] refactor: remove experiment_file parsing code --- beobench/experiment/scheduler.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/beobench/experiment/scheduler.py b/beobench/experiment/scheduler.py index 34eb8b4d..51287522 100644 --- a/beobench/experiment/scheduler.py +++ b/beobench/experiment/scheduler.py @@ -143,14 +143,6 @@ def run( unique_id = uuid.uuid4().hex[:6] container_name = f"auto_beobench_experiment_{unique_id}" - if experiment_file is not None: - exp_file_abs = experiment_file.absolute() - exp_file_on_docker = f"/tmp/beobench/{experiment_file.name}" - docker_flags += [ - "-v", - f"{exp_file_abs}:{exp_file_on_docker}:ro", - ] - if agent_file is not None: ag_file_abs = agent_file.absolute() ag_file_on_docker = f"/tmp/beobench/{agent_file.name}" From 5b8910f590313632d40a49be84279fd42f77fd9e Mon Sep 17 00:00:00 2001 From: rdnfn <75615911+rdnfn@users.noreply.github.com> Date: Mon, 4 Apr 2022 09:12:19 +0000 Subject: [PATCH 20/52] refactor: add env and method error due to refactoring --- beobench/experiment/scheduler.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/beobench/experiment/scheduler.py b/beobench/experiment/scheduler.py index 51287522..424014fb 100644 --- a/beobench/experiment/scheduler.py +++ b/beobench/experiment/scheduler.py @@ -24,13 +24,13 @@ def run( config: Union[str, dict, pathlib.Path, list] = None, method: str = None, env: str = None, - local_dir: str = "./beobench_results", - wandb_project: str = "", - wandb_entity: str = "", - wandb_api_key: str = "", + local_dir: str = None, + wandb_project: str = None, + wandb_entity: str = None, + wandb_api_key: str = None, mlflow_name: str = None, use_gpu: bool = False, - docker_shm_size: str = "2gb", + docker_shm_size: str = None, no_additional_container: bool = False, use_no_cache: bool = False, dev_path: str = None, @@ -78,6 +78,14 @@ def run( else: config = beobench.experiment.config_parser.parse(config) + if env or method: + raise ValueError( + ( + "This functionality has been deprecated. Directly configure" + " the environment or method in the config argument." + ) + ) + print("Beobench config used:", config) if config["agent"]["origin"] == "rllib": From aabc2b039ba03c696452d15e4c14743c12bd84d2 Mon Sep 17 00:00:00 2001 From: rdnfn <75615911+rdnfn@users.noreply.github.com> Date: Mon, 4 Apr 2022 09:14:06 +0000 Subject: [PATCH 21/52] refactor: remove defaults outside default yaml --- beobench/cli.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/beobench/cli.py b/beobench/cli.py index 953ea1ed..77506738 100644 --- a/beobench/cli.py +++ b/beobench/cli.py @@ -22,33 +22,33 @@ def cli(): ) @click.option( "--method", - default="", + default=None, help="Name of RL method to use in experiment.", ) @click.option( "--env", - default="", + default=None, help="Name of RL environment to use in experiment.", ) @click.option( "--local-dir", - default="./beobench_results", + default=None, help="Local directory to write results to.", type=click.Path(exists=False, file_okay=False, dir_okay=True), ) @click.option( "--wandb-project", - default="", + default=None, help="Weights and biases project name to log runs to.", ) @click.option( "--wandb-entity", - default="", + default=None, help="Weights and biases entity name to log runs under.", ) @click.option( "--wandb-api-key", - default="", + default=None, help="Weights and biases API key.", ) @click.option( @@ -63,7 +63,7 @@ def cli(): ) @click.option( "--docker-shm-size", - default="2gb", + default=None, help="Size of shared memory available to experiment container.", ) @click.option( From 214e66451d622a07448b895bdd19c2107c119839 Mon Sep 17 00:00:00 2001 From: rdnfn <75615911+rdnfn@users.noreply.github.com> Date: Mon, 4 Apr 2022 09:16:21 +0000 Subject: [PATCH 22/52] docs: update scheduler docstring to new defaults --- beobench/experiment/scheduler.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/beobench/experiment/scheduler.py b/beobench/experiment/scheduler.py index 424014fb..0cd2edfc 100644 --- a/beobench/experiment/scheduler.py +++ b/beobench/experiment/scheduler.py @@ -4,7 +4,6 @@ import uuid import subprocess import pathlib -import warnings import yaml from typing import Union @@ -43,28 +42,29 @@ def run( Args: config (str, dict, pathlib.Path or list, optional): experiment configuration. This can either be a dictionary, or a path (str or pathlib) to a yaml file, - or a json str, or a list combining any number of the prior config types. + or a json str, or a list combining any number of the prior config types. If + no config is given, a default config is used. method (str, optional): RL method to use in experiment. This overwrites any method that is set in experiment file. For example 'PPO'. Defaults to None. env (str, optional): environment to apply method to in experiment. This overwrites any env set in experiment file. Defaults to None. local_dir (str, optional): Directory to write experiment files to. This argument is equivalent to the `local_dir` argument in `tune.run()`. Defaults to - `"./beobench_results"`. + None. wandb_project (str, optional): Name of wandb project. Defaults to - "initial_experiments". + None. wandb_entity (str, optional): Name of wandb entity. Defaults to "beobench". wandb_api_key (str, optional): wandb API key. Defaults to None. use_gpu (bool, optional): whether to use GPU from the host system. Defaults to False. - mlflow_name (str, optional): name of MLflow experiment. + mlflow_name (str, optional): name of MLflow experiment. Defaults to None. docker_shm_size(str, optional): size of the shared memory available to the - container. Defaults to '2gb'." + container. Defaults to None." no_additional_container (bool, optional): wether not to start another container to run experiments in. Defaults to False, which means that another container - is started to run experiments in. + is started to run experiments in. Defaults to False. use_no_cache (bool, optional): whether to use cache to build experiment - container. + container. Defaults to False. dev_path (str, optional): file or github path to beobench package. For developement purpose only. This will install a custom beobench version inside the experiment container. By default the latest PyPI version is From 4e0a1c057a26f579d5bfbcfa7689f91a7a2e2f88 Mon Sep 17 00:00:00 2001 From: rdnfn <75615911+rdnfn@users.noreply.github.com> Date: Mon, 4 Apr 2022 09:41:49 +0000 Subject: [PATCH 23/52] feat: add support for adding cli/api args to config --- beobench/experiment/scheduler.py | 61 ++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 18 deletions(-) diff --git a/beobench/experiment/scheduler.py b/beobench/experiment/scheduler.py index 0cd2edfc..0c8d2093 100644 --- a/beobench/experiment/scheduler.py +++ b/beobench/experiment/scheduler.py @@ -30,9 +30,9 @@ def run( mlflow_name: str = None, use_gpu: bool = False, docker_shm_size: str = None, - no_additional_container: bool = False, use_no_cache: bool = False, dev_path: str = None, + no_additional_container: bool = False, ) -> None: """Run experiment. @@ -60,40 +60,52 @@ def run( mlflow_name (str, optional): name of MLflow experiment. Defaults to None. docker_shm_size(str, optional): size of the shared memory available to the container. Defaults to None." - no_additional_container (bool, optional): wether not to start another container - to run experiments in. Defaults to False, which means that another container - is started to run experiments in. Defaults to False. use_no_cache (bool, optional): whether to use cache to build experiment container. Defaults to False. dev_path (str, optional): file or github path to beobench package. For developement purpose only. This will install a custom beobench version inside the experiment container. By default the latest PyPI version is installed. + no_additional_container (bool, optional): wether not to start another container + to run experiments in. Defaults to False, which means that another container + is started to run experiments in. """ - # pylint: disable=unused-argument - - # get config dict from config argument - if not config: + # use fault config if no config given + if config is None: config = beobench.experiment.config_parser.get_default() - else: - config = beobench.experiment.config_parser.parse(config) - - if env or method: - raise ValueError( - ( - "This functionality has been deprecated. Directly configure" - " the environment or method in the config argument." - ) - ) + # parsing some kwargs to config and adding them to config + kwarg_config = _create_config_from_kwargs( + local_dir=local_dir, + wandb_project=wandb_project, + wandb_entity=wandb_entity, + wandb_api_key=wandb_api_key, + mlflow_name=mlflow_name, + use_gpu=use_gpu, + docker_shm_size=docker_shm_size, + use_no_cache=use_no_cache, + dev_path=dev_path, + ) + config = [config, kwarg_config] + + # parse combined config + config = beobench.experiment.config_parser.parse(config) print("Beobench config used:", config) + # select agent script if config["agent"]["origin"] == "rllib": agent_file = None else: agent_file = pathlib.Path(config["agent"]["origin"]) # TODO add parsing of high level API arguments env and agent + if env or method: + raise ValueError( + ( + "This functionality has been deprecated. Directly configure" + " the environment or method in the config argument." + ) + ) if no_additional_container: # Execute experiment @@ -256,3 +268,16 @@ def run( ] print("Executing docker command: ", " ".join(args)) subprocess.check_call(args) + + +def _create_config_from_kwargs(**kwargs) -> dict: + """Create a config dict from kwargs. + + Returns: + dict: config dict with kwargs under general key. + """ + config = {"general": {}} + for key, value in kwargs.items(): + if value: + config["general"][key] = value + return config From 6fce9640b8b6557a059a144f6d04e58830c54611 Mon Sep 17 00:00:00 2001 From: rdnfn <75615911+rdnfn@users.noreply.github.com> Date: Mon, 4 Apr 2022 10:01:18 +0000 Subject: [PATCH 24/52] refactor: draw all variables in scheduler directly from config --- beobench/experiment/scheduler.py | 37 ++++++++++++++++---------------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/beobench/experiment/scheduler.py b/beobench/experiment/scheduler.py index 0c8d2093..94902a0d 100644 --- a/beobench/experiment/scheduler.py +++ b/beobench/experiment/scheduler.py @@ -116,10 +116,10 @@ def run( if config["agent"]["origin"] == "rllib": beobench.integration.rllib.run_in_tune( config, - wandb_entity=wandb_entity, - wandb_project=wandb_project, - mlflow_name=mlflow_name, - use_gpu=use_gpu, + wandb_entity=config["general"]["wandb_entity"], + wandb_project=config["general"]["wandb_project"], + mlflow_name=config["general"]["mlflow_name"], + use_gpu=config["general"]["use_gpu"], ) else: # run custom RL agent @@ -131,13 +131,13 @@ def run( ### part 1: build docker images # Ensure local_dir exists, and create otherwise - local_dir_path = pathlib.Path(local_dir) + local_dir_path = pathlib.Path(config["general"]["local_dir"]) local_dir_path.mkdir(parents=True, exist_ok=True) enable_rllib = config["agent"]["origin"] == "rllib" image_tag = beobench.experiment.containers.build_experiment_container( build_context=config["env"]["gym"], - use_no_cache=use_no_cache, + use_no_cache=config["general"]["use_no_cache"], enable_rllib=enable_rllib, local_dir=local_dir_path, ) @@ -159,10 +159,11 @@ def run( f"{config_path_abs}:/tmp/beobench/config.yaml:ro", ] - # define more docker arguments/options/flags + # setup container name with unique identifier unique_id = uuid.uuid4().hex[:6] container_name = f"auto_beobench_experiment_{unique_id}" + # load agent file (e.g. if RLlib integration not used) if agent_file is not None: ag_file_abs = agent_file.absolute() ag_file_on_docker = f"/tmp/beobench/{agent_file.name}" @@ -187,7 +188,7 @@ def run( ] # enabling GPU access in docker container - if use_gpu: + if config["general"]["use_gpu"]: docker_flags += [ # add all available GPUs "--gpus=all", @@ -196,26 +197,26 @@ def run( # define flags for beobench scheduler call inside experiment container beobench_flags = [] beobench_flags.append(f'--config="{config}"') - if wandb_project: - beobench_flags.append(f"--wandb-project={wandb_project}") - if wandb_entity: - beobench_flags.append(f"--wandb-entity={wandb_entity}") - if use_gpu: - beobench_flags.append("--use-gpu") beobench_flag_str = " ".join(beobench_flags) # if no wandb API key is given try to get it from env - if not wandb_api_key: + if config["general"]["wandb_api_key"] is None: # this will return "" if env var not set wandb_api_key = os.getenv("WANDB_API_KEY", "") + else: + wandb_api_key = config["general"]["wandb_api_key"] - # dev mode where custom beobench is installed directly from github or local path + # Setup dev mode + # In dev mode Beobench is installed directly from github or local path + dev_path = config["general"]["dev_path"] cmd_list_in_container = [""] if dev_path is not None: cmd_list_in_container.append("pip uninstall --yes beobench") if "https" in dev_path: + # clone directly from web adress cmd_list_in_container.append(f"pip install {dev_path}") else: + # use local Beobench repo if "[" in dev_path: dev_paths = dev_path.split("[") if len(dev_paths) > 2: @@ -227,7 +228,7 @@ def run( else: dev_extras = "" - # mount local beobench repo + # mount local Beobench repo dev_path = pathlib.Path(dev_path) dev_abs = dev_path.absolute() dev_path_on_docker = "/tmp/beobench/beobench" @@ -253,7 +254,7 @@ def run( # automatically remove container when stopped/exited "--rm", # add more memory - f"--shm-size={docker_shm_size}", + f"--shm-size={config['general']['docker_shm_size']}", "--name", container_name, *docker_flags, From 4d217f8f20f96cbf0ec66ec01eb20b2b8b75bad7 Mon Sep 17 00:00:00 2001 From: rdnfn <75615911+rdnfn@users.noreply.github.com> Date: Mon, 4 Apr 2022 10:37:13 +0000 Subject: [PATCH 25/52] refactor: make default introduction more usable --- beobench/experiment/scheduler.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/beobench/experiment/scheduler.py b/beobench/experiment/scheduler.py index 94902a0d..4a811350 100644 --- a/beobench/experiment/scheduler.py +++ b/beobench/experiment/scheduler.py @@ -70,11 +70,7 @@ def run( to run experiments in. Defaults to False, which means that another container is started to run experiments in. """ - # use fault config if no config given - if config is None: - config = beobench.experiment.config_parser.get_default() - - # parsing some kwargs to config and adding them to config + # parsing relevant kwargs and adding them to config kwarg_config = _create_config_from_kwargs( local_dir=local_dir, wandb_project=wandb_project, @@ -90,6 +86,14 @@ def run( # parse combined config config = beobench.experiment.config_parser.parse(config) + + # adding any defaults that haven't been set by user given config + default_config = beobench.experiment.config_parser.get_default() + print("default", default_config) + config = beobench.utils.merge_dicts( + a=default_config, b=config, let_b_overrule_a=True + ) + print("Beobench config used:", config) # select agent script From 1fd8edb0258ccae7e8e753ee63193ed5f02f004a Mon Sep 17 00:00:00 2001 From: rdnfn <75615911+rdnfn@users.noreply.github.com> Date: Mon, 4 Apr 2022 10:39:42 +0000 Subject: [PATCH 26/52] feat: add overruling feature to merge dict method in utils --- beobench/utils.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/beobench/utils.py b/beobench/utils.py index acd361e5..7afe5435 100644 --- a/beobench/utils.py +++ b/beobench/utils.py @@ -19,7 +19,13 @@ def check_if_in_notebook() -> bool: return False -def merge_dicts(a: dict, b: dict, path: list = None, mutate_a: bool = False) -> dict: +def merge_dicts( + a: dict, + b: dict, + path: list = None, + mutate_a: bool = False, + let_b_overrule_a=False, +) -> dict: """Merge dictionary b into dictionary a. Adapted from https://stackoverflow.com/a/7205107. @@ -32,6 +38,7 @@ def merge_dicts(a: dict, b: dict, path: list = None, mutate_a: bool = False) -> mutate_a (bool, optional): whether to mutate the dictionary a that is given. Necessary for recursion, no need to use. Defaults to False. + let_b_overrule_a: whether to allow dict b to overrule if they disagree on key. Raises: @@ -51,11 +58,20 @@ def merge_dicts(a: dict, b: dict, path: list = None, mutate_a: bool = False) -> for key in b: if key in a: if isinstance(a[key], dict) and isinstance(b[key], dict): - merge_dicts(a[key], b[key], path + [str(key)], mutate_a=True) + merge_dicts( + a[key], + b[key], + path + [str(key)], + mutate_a=True, + let_b_overrule_a=let_b_overrule_a, + ) elif a[key] == b[key]: pass # same leaf value else: - raise Exception("Conflict at %s" % ".".join(path + [str(key)])) + if not let_b_overrule_a: + raise Exception("Conflict at %s" % ".".join(path + [str(key)])) + else: + a[key] = b[key] else: a[key] = b[key] return a From a2f80404b2f6199d8b8ee600e3b8cf555a32a9e5 Mon Sep 17 00:00:00 2001 From: rdnfn <75615911+rdnfn@users.noreply.github.com> Date: Mon, 4 Apr 2022 10:41:35 +0000 Subject: [PATCH 27/52] feat: add new variables to default yaml --- beobench/experiment/definitions/default.yaml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/beobench/experiment/definitions/default.yaml b/beobench/experiment/definitions/default.yaml index 6de6a702..f96a0ed1 100644 --- a/beobench/experiment/definitions/default.yaml +++ b/beobench/experiment/definitions/default.yaml @@ -28,3 +28,14 @@ env: normalize: true step_period: 15 weather: GRC_A_Athens +# general config +general: + local_dir: ./beobench_results + wandb_project: "" + wandb_entity: "" + wandb_api_key: "" + mlflow_name: null + use_gpu: False + docker_shm_size: 4gb + use_no_cache: False + dev_path: null From 9fb36c678cd780695d4d266a4d4561001b13f36c Mon Sep 17 00:00:00 2001 From: rdnfn <75615911+rdnfn@users.noreply.github.com> Date: Mon, 4 Apr 2022 10:47:09 +0000 Subject: [PATCH 28/52] docs: add new feature to history --- HISTORY.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/HISTORY.rst b/HISTORY.rst index de1ab399..04eb1b41 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -5,6 +5,8 @@ History 0.4.2 (2022-04-00) ------------------ +* Feature: defining all relevant options/kwargs of CLI an API is now supported + yaml files (#54) * Feature: allow multiple configs to be given to both CLI (giving multiple ``-c`` options) and Python API (as a list) (#51) * Fix: adapted Energym env reset() method to avoid triggering From f7cb3de9afc86cd7271604380147bf36685ceea5 Mon Sep 17 00:00:00 2001 From: rdnfn <75615911+rdnfn@users.noreply.github.com> Date: Mon, 4 Apr 2022 11:05:11 +0000 Subject: [PATCH 29/52] docs: update merge dict docstring --- beobench/utils.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/beobench/utils.py b/beobench/utils.py index 7afe5435..58493e0d 100644 --- a/beobench/utils.py +++ b/beobench/utils.py @@ -38,11 +38,12 @@ def merge_dicts( mutate_a (bool, optional): whether to mutate the dictionary a that is given. Necessary for recursion, no need to use. Defaults to False. - let_b_overrule_a: whether to allow dict b to overrule if they disagree on key. + let_b_overrule_a: whether to allow dict b to overrule if they disagree on a + key value. Defaults to False. Raises: - Exception: When dictionaries are inconsistent + Exception: When dictionaries are inconsistent, and not let_b_overrule_a. Returns: dictionary: merged dictionary. From 95d1745b396c8ed50dd88fa4d815f8ce59a94be7 Mon Sep 17 00:00:00 2001 From: rdnfn <75615911+rdnfn@users.noreply.github.com> Date: Mon, 4 Apr 2022 11:28:27 +0000 Subject: [PATCH 30/52] refactor: change location of key usage and avoid not leaking via command --- beobench/experiment/scheduler.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/beobench/experiment/scheduler.py b/beobench/experiment/scheduler.py index 4a811350..dce2c030 100644 --- a/beobench/experiment/scheduler.py +++ b/beobench/experiment/scheduler.py @@ -149,6 +149,16 @@ def run( ### part 2: create args and run command in docker container docker_flags = [] + # if no wandb API key is given try to get it from env + if config["general"]["wandb_api_key"] is None: + # this will return "" if env var not set + wandb_api_key = os.getenv("WANDB_API_KEY", "") + else: + wandb_api_key = config["general"]["wandb_api_key"] + + # We don't want the key to be logged in wandb + del config["general"]["wandb_api_key"] + ### create path to store ray results at ray_path_abs = str((local_dir_path / "ray_results").absolute()) @@ -203,13 +213,6 @@ def run( beobench_flags.append(f'--config="{config}"') beobench_flag_str = " ".join(beobench_flags) - # if no wandb API key is given try to get it from env - if config["general"]["wandb_api_key"] is None: - # this will return "" if env var not set - wandb_api_key = os.getenv("WANDB_API_KEY", "") - else: - wandb_api_key = config["general"]["wandb_api_key"] - # Setup dev mode # In dev mode Beobench is installed directly from github or local path dev_path = config["general"]["dev_path"] From 28d920207d5f8e899f3b058626b0b891bdaabd1e Mon Sep 17 00:00:00 2001 From: rdnfn <75615911+rdnfn@users.noreply.github.com> Date: Mon, 4 Apr 2022 11:50:32 +0000 Subject: [PATCH 31/52] fix: enable use of importlib in python 3.8 --- beobench/experiment/config_parser.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/beobench/experiment/config_parser.py b/beobench/experiment/config_parser.py index 99b96d2d..9ca3cc29 100644 --- a/beobench/experiment/config_parser.py +++ b/beobench/experiment/config_parser.py @@ -4,13 +4,14 @@ import pathlib import yaml import ast +import sys import beobench.utils -# To enable compatiblity with Python<=3.6 (e.g. for sinergym dockerfile) -try: +# To enable compatiblity with Python<=3.8 (e.g. for sinergym dockerfile) +if sys.version_info[1] >= 9: import importlib.resources -except ImportError: +else: import importlib_resources import importlib From 9c15bc7fb220248b7da239886cb263a772879d23 Mon Sep 17 00:00:00 2001 From: rdnfn <75615911+rdnfn@users.noreply.github.com> Date: Mon, 4 Apr 2022 11:51:35 +0000 Subject: [PATCH 32/52] refactor: add more useful error message to merge dict util --- beobench/utils.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/beobench/utils.py b/beobench/utils.py index 58493e0d..0c3f036c 100644 --- a/beobench/utils.py +++ b/beobench/utils.py @@ -70,7 +70,13 @@ def merge_dicts( pass # same leaf value else: if not let_b_overrule_a: - raise Exception("Conflict at %s" % ".".join(path + [str(key)])) + location = ".".join(path + [str(key)]) + raise Exception( + ( + f"Conflict at {location}." + f"a={a[key]} is not the same as b={b[key]}." + ) + ) else: a[key] = b[key] else: From 714549531541da1208b9571ab7b37db2e0ef855f Mon Sep 17 00:00:00 2001 From: rdnfn <75615911+rdnfn@users.noreply.github.com> Date: Mon, 4 Apr 2022 11:55:51 +0000 Subject: [PATCH 33/52] chore: add *.beo.yaml beobench config files to gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 795e60a5..8bb9ebb4 100644 --- a/.gitignore +++ b/.gitignore @@ -118,4 +118,5 @@ docs/generated/ #beobench beobench_results* -notebooks/archive \ No newline at end of file +notebooks/archive +*beo.yaml \ No newline at end of file From b20424f48e3d744899af99226ef427dce1d51a33 Mon Sep 17 00:00:00 2001 From: rdnfn <75615911+rdnfn@users.noreply.github.com> Date: Mon, 4 Apr 2022 11:58:55 +0000 Subject: [PATCH 34/52] fix: change output of run command to avoid showing api key in logs --- beobench/experiment/scheduler.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/beobench/experiment/scheduler.py b/beobench/experiment/scheduler.py index dce2c030..c389da13 100644 --- a/beobench/experiment/scheduler.py +++ b/beobench/experiment/scheduler.py @@ -274,7 +274,10 @@ def run( "--no-additional-container && bash" ), ] - print("Executing docker command: ", " ".join(args)) + print( + "Executing docker command: ", + " ".join(args).replace(wandb_api_key, ""), + ) subprocess.check_call(args) From eb61038e944d5250e81ccb27093f98cfec89938a Mon Sep 17 00:00:00 2001 From: rdnfn <75615911+rdnfn@users.noreply.github.com> Date: Mon, 4 Apr 2022 13:19:15 +0000 Subject: [PATCH 35/52] fix: further improvements to run command output --- beobench/experiment/scheduler.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/beobench/experiment/scheduler.py b/beobench/experiment/scheduler.py index c389da13..aec41cf8 100644 --- a/beobench/experiment/scheduler.py +++ b/beobench/experiment/scheduler.py @@ -11,7 +11,7 @@ try: import beobench.integration.rllib except ImportError: - print("Note: RLlib beobench integration not available.") + pass import beobench.experiment.definitions.utils import beobench.experiment.containers @@ -89,13 +89,10 @@ def run( # adding any defaults that haven't been set by user given config default_config = beobench.experiment.config_parser.get_default() - print("default", default_config) config = beobench.utils.merge_dicts( a=default_config, b=config, let_b_overrule_a=True ) - print("Beobench config used:", config) - # select agent script if config["agent"]["origin"] == "rllib": agent_file = None @@ -274,10 +271,12 @@ def run( "--no-additional-container && bash" ), ] - print( - "Executing docker command: ", - " ".join(args).replace(wandb_api_key, ""), - ) + + arg_str = " ".join(args) + if wandb_api_key: + arg_str.replace(wandb_api_key, "") + print(f"Executing docker command: {arg_str}") + subprocess.check_call(args) From 9f6d0670b391493724a1e41149387c2c86646313 Mon Sep 17 00:00:00 2001 From: rdnfn <75615911+rdnfn@users.noreply.github.com> Date: Mon, 4 Apr 2022 13:32:48 +0000 Subject: [PATCH 36/52] exp: add rewex02.yaml --- beobench/data/configs/rewex02.yaml | 52 ++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 beobench/data/configs/rewex02.yaml diff --git a/beobench/data/configs/rewex02.yaml b/beobench/data/configs/rewex02.yaml new file mode 100644 index 00000000..91d47ea5 --- /dev/null +++ b/beobench/data/configs/rewex02.yaml @@ -0,0 +1,52 @@ +# REWEX Experiment 02 +# Run with the command +# beobench run -c beobench/data/configs/rewex01_test02.yaml -d .[extended] --use-gpu --docker-shm-size 28gb + +# Some of the descriptions of RLlib config values are taken from +# https://docs.ray.io/en/latest/rllib/rllib-training.html + +# agent config +agent: + origin: rllib # either path to agent script or name of agent library (rllib) + config: # given to ray.tune.run() as arguments (since rllib set before) + run_or_experiment: PPO + stop: + timesteps_total: 35040 + config: + lr: 0.0005 + model: + fcnet_activation: relu + fcnet_hiddens: [256,256,256,256] + post_fcnet_activation: tanh + batch_mode: complete_episodes + gamma: 0.999 + # Number of steps after which the episode is forced to terminate. Defaults + # to `env.spec.max_episode_steps` (if present) for Gym envs. + horizon: 96 + # Calculate rewards but don't reset the environment when the horizon is + # hit. This allows value estimation and RNN state to span across logical + # episodes denoted by horizon. This only has an effect if horizon != inf. + soft_horizon: True + # Number of timesteps collected for each SGD round. This defines the size + # of each SGD epoch. + train_batch_size: 94 # single day of 15min steps + # Total SGD batch size across all devices for SGD. This defines the + # minibatch size within each epoch. + sgd_minibatch_size: 24 + metrics_smoothing_episodes: 1 + framework: torch + log_level: "WARNING" + num_workers: 1 # this is required for energym to work (can fail silently otherwise) + num_gpus: 1 +# environment config +env: + name: MixedUseFanFCU-v0 + gym: energym + config: + days: 365 + energym_environment: MixedUseFanFCU-v0 + gym_kwargs: + max_episode_length: 35040 + normalize: true + step_period: 15 + weather: GRC_A_Athens \ No newline at end of file From 555c873dff936eccac73eae36f19218d9d80c578 Mon Sep 17 00:00:00 2001 From: rdnfn <75615911+rdnfn@users.noreply.github.com> Date: Mon, 4 Apr 2022 13:38:16 +0000 Subject: [PATCH 37/52] docs: improve print output of run commmand --- beobench/experiment/scheduler.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/beobench/experiment/scheduler.py b/beobench/experiment/scheduler.py index aec41cf8..05dd47f0 100644 --- a/beobench/experiment/scheduler.py +++ b/beobench/experiment/scheduler.py @@ -4,6 +4,7 @@ import uuid import subprocess import pathlib +from wandb import agent import yaml from typing import Union @@ -70,6 +71,7 @@ def run( to run experiments in. Defaults to False, which means that another container is started to run experiments in. """ + print("Beobench: starting experiment run ...") # parsing relevant kwargs and adding them to config kwarg_config = _create_config_from_kwargs( local_dir=local_dir, @@ -108,6 +110,13 @@ def run( ) ) + print( + ( + f"Beobench: running experiment with environment {config['env']['name']}" + f" and agent from {config['agent']['origin']}." + ) + ) + if no_additional_container: # Execute experiment # (this is usually reached from inside an experiment container) From def31e6638e7eebf0451c2d9b17a76ef466b257f Mon Sep 17 00:00:00 2001 From: rdnfn <75615911+rdnfn@users.noreply.github.com> Date: Mon, 4 Apr 2022 14:30:33 +0000 Subject: [PATCH 38/52] fix: correct error where list str breaks config parser --- beobench/experiment/config_parser.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/beobench/experiment/config_parser.py b/beobench/experiment/config_parser.py index 9ca3cc29..63ad5a0c 100644 --- a/beobench/experiment/config_parser.py +++ b/beobench/experiment/config_parser.py @@ -44,9 +44,9 @@ def parse(config: Union[dict, str, pathlib.Path, list]) -> dict: parsed_config = yaml.safe_load(config_file) elif isinstance(config, str): - if config[0] == "{": - # if json str - parsed_config = ast.literal_eval(config) + if config[0] in ["{", "["]: + # if json str or list + parsed_config = parse(ast.literal_eval(config)) else: # make sure config is a real path config_path = pathlib.Path(config) From bbcb2803f316f01b89c979bd2a0eb78078530aed Mon Sep 17 00:00:00 2001 From: rdnfn <75615911+rdnfn@users.noreply.github.com> Date: Mon, 4 Apr 2022 14:31:12 +0000 Subject: [PATCH 39/52] docs: add additional step to hypterparameter tuning section --- docs/guides/hyperparameter_tuning.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/guides/hyperparameter_tuning.rst b/docs/guides/hyperparameter_tuning.rst index 71c0ec1e..76e0b45a 100644 --- a/docs/guides/hyperparameter_tuning.rst +++ b/docs/guides/hyperparameter_tuning.rst @@ -10,5 +10,9 @@ are other options as well (e.g. `Ray Tune `_). W&B Sweeps ^^^^^^^^^^ +Make sure that the W&B ``wandb`` Python package is installed. Follow the +`official quickstart `_ if it is +not installed yet. + *Under construction.* From ff6aa82ba57e236e20d1cec1394453d7912c4cdf Mon Sep 17 00:00:00 2001 From: rdnfn <75615911+rdnfn@users.noreply.github.com> Date: Mon, 4 Apr 2022 14:31:57 +0000 Subject: [PATCH 40/52] aux: update beobench_contrib --- beobench_contrib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beobench_contrib b/beobench_contrib index 955b0c0e..4c240bb9 160000 --- a/beobench_contrib +++ b/beobench_contrib @@ -1 +1 @@ -Subproject commit 955b0c0e8abf14919167ec7c74ffed0bb9a56fde +Subproject commit 4c240bb9fa7ee100771ae6410c6cbcf2f8dc0a11 From 539b8958a6bd19ae30a6b95e4fea6cb3c6fa2e9d Mon Sep 17 00:00:00 2001 From: rdnfn <75615911+rdnfn@users.noreply.github.com> Date: Mon, 4 Apr 2022 14:34:54 +0000 Subject: [PATCH 41/52] docs: update commit message guidance --- CONTRIBUTING.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 8dafeb90..7a057efe 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -88,7 +88,9 @@ Guidelines Commit messages ^^^^^^^^^^^^^^^ -When committing to the Beobench repo, please try to follow `this style guide by Udacity ` for the commit messages. +When committing to the Beobench repo, please try to follow `this style +guide by Udacity ` for the +commit messages, but replace the ``chore:`` type with ``aux:``. Pull Request Guidelines From 54dd2627f60750cf2466c1449c7705154308d65f Mon Sep 17 00:00:00 2001 From: rdnfn <75615911+rdnfn@users.noreply.github.com> Date: Mon, 4 Apr 2022 14:35:19 +0000 Subject: [PATCH 42/52] exp: update sweep01.yaml --- beobench/data/sweeps/sweep01.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/beobench/data/sweeps/sweep01.yaml b/beobench/data/sweeps/sweep01.yaml index c7a64e44..eb48280b 100644 --- a/beobench/data/sweeps/sweep01.yaml +++ b/beobench/data/sweeps/sweep01.yaml @@ -6,4 +6,8 @@ command: - ${args} parameters: config: - values: [./beobench/data/configs/rewex01.yaml] \ No newline at end of file + value: + - ./beobench/data/configs/rewex01.yaml + - ./wandb.beo.yaml + dev-path: + value: . \ No newline at end of file From ac464805dea81621996efdab27171424d18ca9de Mon Sep 17 00:00:00 2001 From: rdnfn <75615911+rdnfn@users.noreply.github.com> Date: Mon, 4 Apr 2022 14:40:38 +0000 Subject: [PATCH 43/52] docs: update contributing guide --- CONTRIBUTING.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 7a057efe..563025ee 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -90,7 +90,9 @@ Commit messages When committing to the Beobench repo, please try to follow `this style guide by Udacity ` for the -commit messages, but replace the ``chore:`` type with ``aux:``. +commit messages with the following adaptions: +1. Replace the ``chore:`` type with ``aux:``. +2. Use a ``exp:`` type for commits relating to experiment data (e.g. experiment config files). Pull Request Guidelines From 142da0b031c989a272390e48b2a0b3cd4998e0f8 Mon Sep 17 00:00:00 2001 From: rdnfn <75615911+rdnfn@users.noreply.github.com> Date: Mon, 4 Apr 2022 14:44:36 +0000 Subject: [PATCH 44/52] fix: remove accidental wandb import --- beobench/experiment/scheduler.py | 1 - 1 file changed, 1 deletion(-) diff --git a/beobench/experiment/scheduler.py b/beobench/experiment/scheduler.py index 05dd47f0..4cf96e6e 100644 --- a/beobench/experiment/scheduler.py +++ b/beobench/experiment/scheduler.py @@ -4,7 +4,6 @@ import uuid import subprocess import pathlib -from wandb import agent import yaml from typing import Union From 9adebba5971b2d466b8b464716d5b0565612a285 Mon Sep 17 00:00:00 2001 From: rdnfn <75615911+rdnfn@users.noreply.github.com> Date: Mon, 4 Apr 2022 14:47:38 +0000 Subject: [PATCH 45/52] aux: upgrade readthedocs config to Python 3.9 --- .readthedocs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.readthedocs.yml b/.readthedocs.yml index 6252d08b..cf33351a 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -9,7 +9,7 @@ version: 2 build: os: ubuntu-20.04 tools: - python: "3.7" + python: "3.9" # Build documentation in the docs/ directory with Sphinx sphinx: From bb71e781843852e5ea55407397c8d0dc1b7dc445 Mon Sep 17 00:00:00 2001 From: rdnfn <75615911+rdnfn@users.noreply.github.com> Date: Mon, 4 Apr 2022 14:53:03 +0000 Subject: [PATCH 46/52] docs: remove unfinished hyperparameter tuning section --- docs/guides.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/guides.rst b/docs/guides.rst index 23abc896..8d124914 100644 --- a/docs/guides.rst +++ b/docs/guides.rst @@ -10,5 +10,4 @@ Welcome to beobench's usage guides! guides/getting_started guides/intro_experiment guides/add_env - guides/hyperparameter_tuning guides/dev_env From c36df33aee37a8c9bc255a16d2cb2c4116c47d35 Mon Sep 17 00:00:00 2001 From: rdnfn <75615911+rdnfn@users.noreply.github.com> Date: Mon, 4 Apr 2022 14:57:31 +0000 Subject: [PATCH 47/52] docs: add date for v0.4.2 --- HISTORY.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HISTORY.rst b/HISTORY.rst index 04eb1b41..d7204f43 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -2,7 +2,7 @@ History ======= -0.4.2 (2022-04-00) +0.4.2 (2022-04-04) ------------------ * Feature: defining all relevant options/kwargs of CLI an API is now supported From af0a22bad6f4845f830dd18ca9871cac28826cc0 Mon Sep 17 00:00:00 2001 From: rdnfn <75615911+rdnfn@users.noreply.github.com> Date: Mon, 4 Apr 2022 14:58:30 +0000 Subject: [PATCH 48/52] docs: fix link to commit message guide --- CONTRIBUTING.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 563025ee..89cbe21a 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -89,8 +89,9 @@ Commit messages ^^^^^^^^^^^^^^^ When committing to the Beobench repo, please try to follow `this style -guide by Udacity ` for the +guide by Udacity `_ for the commit messages with the following adaptions: + 1. Replace the ``chore:`` type with ``aux:``. 2. Use a ``exp:`` type for commits relating to experiment data (e.g. experiment config files). From a3ce202ed18712b4401ef1fac2726481ff7964eb Mon Sep 17 00:00:00 2001 From: rdnfn <75615911+rdnfn@users.noreply.github.com> Date: Mon, 4 Apr 2022 15:00:54 +0000 Subject: [PATCH 49/52] fix: add newline after list --- CONTRIBUTING.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 89cbe21a..12018c08 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -105,6 +105,8 @@ Before you submit a pull request, check that it meets these guidelines: 2. If the pull request adds functionality, the docs should be updated. Put your new functionality into a function with a docstring, and add the feature to the list in README.rst. + + .. 3. The pull request should work for Python 3.6, 3.7, 3.8 and 3.9. .. Check https://travis-ci.com/rdnfn/beobench/pull_requests From 7113ef92088819756f26a6629abd4715f477fb45 Mon Sep 17 00:00:00 2001 From: rdnfn <75615911+rdnfn@users.noreply.github.com> Date: Mon, 4 Apr 2022 15:02:13 +0000 Subject: [PATCH 50/52] docs: fix problem with heading types --- CONTRIBUTING.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 12018c08..cf52ea6e 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -86,7 +86,7 @@ Guidelines ---------- Commit messages -^^^^^^^^^^^^^^^ +~~~~~~~~~~~~~~~ When committing to the Beobench repo, please try to follow `this style guide by Udacity `_ for the @@ -97,7 +97,7 @@ commit messages with the following adaptions: Pull Request Guidelines -^^^^^^^^^^^^^^^^^^^^^^^ +~~~~~~~~~~~~~~~~~~~~~~~ Before you submit a pull request, check that it meets these guidelines: From f5cdb624bf898f07b3bdfbd2f5f95fb83ac7eb85 Mon Sep 17 00:00:00 2001 From: rdnfn <75615911+rdnfn@users.noreply.github.com> Date: Mon, 4 Apr 2022 15:05:05 +0000 Subject: [PATCH 51/52] docs: minor fix --- CONTRIBUTING.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index cf52ea6e..44979e18 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -96,8 +96,8 @@ commit messages with the following adaptions: 2. Use a ``exp:`` type for commits relating to experiment data (e.g. experiment config files). -Pull Request Guidelines -~~~~~~~~~~~~~~~~~~~~~~~ +Pull Requests +~~~~~~~~~~~~~ Before you submit a pull request, check that it meets these guidelines: From 95cd78a036fc2f4a255949179b38839ec12269b2 Mon Sep 17 00:00:00 2001 From: rdnfn <75615911+rdnfn@users.noreply.github.com> Date: Mon, 4 Apr 2022 15:09:30 +0000 Subject: [PATCH 52/52] =?UTF-8?q?Bump=20version:=200.4.1=20=E2=86=92=200.4?= =?UTF-8?q?.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- beobench/__init__.py | 2 +- setup.cfg | 2 +- setup.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/beobench/__init__.py b/beobench/__init__.py index e930f852..ede46ad8 100644 --- a/beobench/__init__.py +++ b/beobench/__init__.py @@ -2,7 +2,7 @@ __author__ = """rdnfn""" __email__ = "-" -__version__ = "0.4.1" +__version__ = "0.4.2" from beobench.utils import restart from beobench.experiment.scheduler import run diff --git a/setup.cfg b/setup.cfg index eff631de..6d09b3b2 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.4.1 +current_version = 0.4.2 commit = True tag = True diff --git a/setup.py b/setup.py index 6c477c85..8a52fd70 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ with open("HISTORY.rst", encoding="UTF-8") as history_file: history = history_file.read() -version = "0.4.1" # pylint: disable=invalid-name +version = "0.4.2" # pylint: disable=invalid-name requirements = [ "docker",