Skip to content

Commit

Permalink
Merge pull request #20 from rdnfn/dev/general
Browse files Browse the repository at this point in the history
Add support for sinergym and other fixes
  • Loading branch information
rdnfn authored Feb 3, 2022
2 parents 65be3cc + 337b4ff commit ccedce5
Show file tree
Hide file tree
Showing 17 changed files with 146 additions and 391 deletions.
8 changes: 0 additions & 8 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@ RUN pip3 --disable-pip-version-check --no-cache-dir install -r /tmp/pip-tmp/requ
-r /tmp/pip-tmp/boptest_requirements.txt \
&& rm -rf /tmp/pip-tmp

# Install beobench problem set libraries
ENV MAIN_PYTHONPATH = "${PYTHONPATH}"
ENV PYTHONPATH "${PYTHONPATH}:/tmp"
COPY beobench/installer.py beobench/constants.py /tmp/beobench/
RUN python /tmp/beobench/installer.py \
&& rm -rf /tmp/beobench
ENV PYTHONPATH = "${MAIN_PYTHONPATH}"

# Install nvidia container runtime
RUN wget -O tmp/nvidia-container-toolkit.deb https://nvidia.github.io/libnvidia-container/stable/debian10/amd64/nvidia-container-toolkit_1.7.0-1_amd64.deb \
&& wget -O tmp/nvidia-container-tools.deb https://nvidia.github.io/libnvidia-container/stable/debian10/amd64/libnvidia-container-tools_1.7.0-1_amd64.deb \
Expand Down
7 changes: 4 additions & 3 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
"workspaceFolder": "/workspace",
// "workspaceMount": "source=remote-workspace,target=/workspace,type=volume",
// ADAPT: the mount must be adapted to cloned repo location
"workspaceMount": "source=/home/rdnfn-docker/main/repos/github/beobench/,target=/workspace,type=bind,consistency=cached",
"workspaceMount": "source=/home/rdnfn-docker/main/repos/github/beobench/,target=/workspace/beobench/,type=bind,consistency=cached",
// ADAPT: the mount must be adapted to the gitconfig location on the remote machine
"mounts": [
"source=/home/rdnfn-docker/.gitconfig,target=/.gitconfig,type=bind,consistency=cached"
"source=/home/rdnfn-docker/.gitconfig,target=/root/.gitconfig,type=bind,consistency=cached",
"source=/home/rdnfn-docker/main/repos/github/beobench_contrib,target=/workspace/beobench_contrib/,type=bind,consistency=cached"
],
"postCreateCommand": "pwd && pip install -e .",
"postCreateCommand": "cd ./beobench && pip install -e .",
// Set *default* container specific settings.json values on container create.
"settings": {
"python.defaultInterpreterPath": "/usr/local/bin/python",
Expand Down
28 changes: 21 additions & 7 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,26 @@ To run a subset of tests::
Deploying
---------

A reminder for the maintainers on how to deploy.
Make sure all your changes are committed (including an entry in HISTORY.rst).
Then run::
A reminder for the maintainers on how to deploy. Follow this checklist (inspired by `this checklist <https://gist.github.com/audreyfeldroy/5990987>`_ and `this packaging tutorial <https://packaging.python.org/en/latest/tutorials/packaging-projects/>`_):

$ bump2version patch # possible: major / minor / patch
$ git push
$ git push --tags
1. Update ``HISTORY.rst`` and commit with message like "aux: add changelog for upcoming release 0.1.0"
2. Run

Travis will then deploy to PyPI if tests pass.
.. code-block:: console
bump2version patch # possible: major / minor / patch
3. Push commits
4. Build the package

.. code-block:: console
python3 -m build
5. Upload the package (this will ask for password/token from pypi.org)

.. code-block:: console
twine upload dist/*
6. Add release tag on github
7 changes: 7 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
History
=======

0.2.1 (2022-02-03)
------------------

* Add integration with sinergym
* Move gym integrations to separate beobench_contrib repo
* Make usage of GPUs in containers optional

0.2.0 (2022-01-18)
------------------

Expand Down
4 changes: 2 additions & 2 deletions PYPI_README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ Features

*Some of the features are work in progress*

**Main features**
Main features

- *RL algorithm collection:* what's the best RL method for your BEO problem? Building on `Ray RLlib <https://github.com/ray-project/ray/tree/master/rllib>`_, beobench provides a large collection of pre-configured RL algorithm experiments that can be easily applied to your new BEO problem.
- *Problem collection:* beobench provides ready-to-use docker containers for popular BEO gym-type problem libraries. By enforcing a strict OpenAI ``gym.Env`` it makes testing your method on different libraries easy.

**Additional features**
Additional features

- *Experiment logging:* log experiment results in a reproducible and shareable manner via `Weights and Biases`_.
- *Hyperparameter tuning:* easily tune hyperparameters using the extensive `Ray Tune Search API <https://docs.ray.io/en/master/tune/index.html>`_.
Expand Down
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ Features

*Some of the features are work in progress*

**Main features**
Main features

- *RL algorithm collection:* what's the best RL method for your BEO problem? Building on `Ray RLlib <https://github.com/ray-project/ray/tree/master/rllib>`_, beobench provides a large collection of pre-configured RL algorithm experiments that can be easily applied to your new BEO problem.
- *Problem collection:* beobench provides ready-to-use docker containers for popular BEO gym-type problem libraries. By enforcing a strict OpenAI ``gym.Env`` it makes testing your method on different libraries easy.

**Additional features**
Additional features

- *Experiment logging:* log experiment results in a reproducible and shareable manner via `Weights and Biases`_.
- *Hyperparameter tuning:* easily tune hyperparameters using the extensive `Ray Tune Search API <https://docs.ray.io/en/master/tune/index.html>`_.
Expand All @@ -61,7 +61,7 @@ Run your first beobench experiment in three steps:
.. code-block:: console
pip install beobench
3. Finally, start your first experiment using:

.. code-block:: console
Expand Down
2 changes: 1 addition & 1 deletion beobench/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

__author__ = """rdnfn"""
__email__ = "-"
__version__ = "0.2.0"
__version__ = "0.2.1"

from beobench.utils import restart
4 changes: 2 additions & 2 deletions beobench/experiment/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ def build_experiment_container(
if use_no_cache:
flags.append("--no-cache")

AVAILABLE_INTEGRATIONS = ["boptest"] # pylint: disable=invalid-name
AVAILABLE_INTEGRATIONS = ["boptest","sinergym"] # pylint: disable=invalid-name

if build_context in AVAILABLE_INTEGRATIONS:
docker_tag = f"beobench_{build_context}:latest"
integration_name = build_context
build_context = (
f"https://github.com/rdnfn/"
f"beobench.git#master:beobench/integrations/{build_context}"
f"beobench_contrib.git#main:gyms/{build_context}"
)
print(
(
Expand Down
1 change: 0 additions & 1 deletion beobench/experiment/definitions/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
"framework": "torch",
"log_level": "WARNING",
"num_workers": 8, # 1 for silent mode, can at least be 6
"num_gpus": 1,
"seed": ray.tune.randint(0, 10000000),
},
"log_to_file": True,
Expand Down
42 changes: 42 additions & 0 deletions beobench/experiment/definitions/experiment_003_sinergym.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""An experiment to test sinergym integration."""

import ray.tune
from beobench.experiment.definitions.default import problem, method, rllib_setup


problem = {
"name": "sinergym_test_problem",
"description": ("Control problem corresponding to " "created by sinergym env ''."),
"problem_library": "sinergym",
"rllib_experiment_config": {
"config": {
"env": "sinergym-Eplus-5Zone-hot-continuous-v1",
"env_config": {
"name": "Eplus-5Zone-hot-continuous-v1",
"normalize": True,
},
"gamma": 0.999,
"output": "/root/ray_results/debug/",
"output_compress_columns": [],
"soft_horizon": False,
"no_done_at_end": False,
"horizon": 10000,
},
"stop": {"timesteps_total": 400000},
},
}

rllib_setup = {
"rllib_experiment_config": {
"config": {
# Utilities settings
"framework": "torch",
"log_level": "WARNING",
"num_workers": 8, # 1 for silent mode, can at least be 6
"num_gpus": 1,
"seed": ray.tune.randint(0, 10000000),
},
"log_to_file": True,
"checkpoint_freq": 10000,
},
}
73 changes: 62 additions & 11 deletions beobench/experiment/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def run(
wandb_project: str = "",
wandb_entity: str = "",
wandb_api_key: str = "",
use_gpu: bool = False,
docker_shm_size: str = "2gb",
no_additional_container: bool = False,
use_no_cache: bool = False,
) -> None:
Expand All @@ -39,6 +41,10 @@ def run(
"initial_experiments".
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.
docker_shm_size(str, optional): size of the shared memory available to the
container. Defaults to '2gb'."
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.
Expand All @@ -59,6 +65,16 @@ def run(
experiment_def = importlib.util.module_from_spec(spec)
spec.loader.exec_module(experiment_def)

# check if all attributes present and replace with default if not
if not hasattr(experiment_def, "problem"):
experiment_def.problem = beobench.experiment.definitions.default.problem
if not hasattr(experiment_def, "method"):
experiment_def.method = beobench.experiment.definitions.default.method
if not hasattr(experiment_def, "rllib_setup"):
experiment_def.rllib_setup = (
beobench.experiment.definitions.default.rllib_setup
)

if no_additional_container:

# Add wandb callback if sufficient information
Expand All @@ -71,11 +87,17 @@ def run(
)
else:
callbacks = []

# change RLlib setup if GPU used
rllib_setup = experiment_def.rllib_setup
if use_gpu:
rllib_setup["rllib_experiment_config"]["config"]["num_gpus"] = 1

# run experiment in ray tune
run_in_tune(
problem_def=experiment_def.problem,
method_def=experiment_def.method,
rllib_setup=experiment_def.rllib_setup,
rllib_setup=rllib_setup,
rllib_callbacks=callbacks,
)
else:
Expand All @@ -91,7 +113,6 @@ def run(
build_context=experiment_def.problem["problem_library"],
use_no_cache=use_no_cache,
)
beobench.experiment.containers.create_docker_network("beobench-net")

# define docker arguments/options/flags
unique_id = uuid.uuid4().hex[:6]
Expand All @@ -106,6 +127,28 @@ def run(
f"{exp_file_abs}:{exp_file_on_docker}:ro",
]

# enable docker-from-docker access only for built-in boptest integration.
if experiment_def.problem["problem_library"] == "boptest":

# Create docker network (only useful if starting other containers)
beobench.experiment.containers.create_docker_network("beobench-net")

docker_flags += [
# enable access to docker-from-docker
"-v",
"/var/run/docker.sock:/var/run/docker.sock",
# network allows access to BOPTEST API in other containers
"--network",
"beobench-net",
]

# enabling GPU access in docker container
if use_gpu:
docker_flags += [
# add all available GPUs
"--gpus=all",
]

# define flags for beobench scheduler call inside experiment container
beobench_flags = []
if experiment_file:
Expand All @@ -114,6 +157,8 @@ def run(
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
Expand All @@ -124,21 +169,13 @@ def run(
args = [
"docker",
"run",
# the mounted socket allows access to docker
"-v",
"/var/run/docker.sock:/var/run/docker.sock",
# mount experiment data dir
"-v",
f"{local_dir_abs}:/root/ray_results",
# automatically remove container when stopped/exited
"--rm",
# network allows access to BOPTEST API in other containers
"--network",
"beobench-net",
# add more memory
"--shm-size=20.48gb",
# add available GPUs,
"--gpus=all",
f"--shm-size={docker_shm_size}",
"--name",
container_name,
*docker_flags,
Expand Down Expand Up @@ -183,6 +220,16 @@ def run(
default="",
help="Weights and biases API key.",
)
@click.option(
"--use-gpu",
is_flag=True,
help="Whether to use GPUs from the host system in experiment container.",
)
@click.option(
"--docker-shm-size",
default="2gb",
help="Size of shared memory available to experiment container.",
)
@click.option(
"--no-additional-container",
is_flag=True,
Expand All @@ -199,6 +246,8 @@ def run_command(
wandb_project: str,
wandb_entity: str,
wandb_api_key: str,
use_gpu: bool,
docker_shm_size: str,
no_additional_container: bool,
use_no_cache: bool,
) -> None:
Expand All @@ -216,6 +265,8 @@ def run_command(
wandb_project=wandb_project,
wandb_entity=wandb_entity,
wandb_api_key=wandb_api_key,
use_gpu=use_gpu,
docker_shm_size=docker_shm_size,
no_additional_container=no_additional_container,
use_no_cache=use_no_cache,
)
Expand Down
1 change: 0 additions & 1 deletion beobench/integrations/__init__.py

This file was deleted.

24 changes: 0 additions & 24 deletions beobench/integrations/boptest/Dockerfile

This file was deleted.

Loading

0 comments on commit ccedce5

Please sign in to comment.