Skip to content

Commit 1daa34a

Browse files
authored
Merge pull request #56 from rdnfn/dev/general
v0.4.2
2 parents eae5ce2 + 95cd78a commit 1daa34a

23 files changed

+379
-149
lines changed

.devcontainer/devcontainer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@
4545
"editor.formatOnSave": true,
4646
"editor.rulers": [
4747
88
48-
]
48+
],
49+
"python.terminal.activateEnvInCurrentTerminal": true,
50+
"esbonio.server.enabled": false,
51+
"esbonio.sphinx.confDir": "${workspaceFolder}/docs"
4952
},
5053
// Add the IDs of extensions you want installed when the container is created.
5154
"extensions": [

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,5 @@ docs/generated/
118118

119119
#beobench
120120
beobench_results*
121-
notebooks/archive
121+
notebooks/archive
122+
*beo.yaml

.readthedocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ version: 2
99
build:
1010
os: ubuntu-20.04
1111
tools:
12-
python: "3.7"
12+
python: "3.9"
1313

1414
# Build documentation in the docs/ directory with Sphinx
1515
sphinx:

CONTRIBUTING.rst

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,31 @@ Ready to contribute? Here's how to set up `beobench` for local development.
8282

8383
5. Submit a pull request through the GitHub website.
8484

85-
Pull Request Guidelines
86-
-----------------------
85+
Guidelines
86+
----------
87+
88+
Commit messages
89+
~~~~~~~~~~~~~~~
90+
91+
When committing to the Beobench repo, please try to follow `this style
92+
guide by Udacity <https://udacity.github.io/git-styleguide/>`_ for the
93+
commit messages with the following adaptions:
94+
95+
1. Replace the ``chore:`` type with ``aux:``.
96+
2. Use a ``exp:`` type for commits relating to experiment data (e.g. experiment config files).
97+
98+
99+
Pull Requests
100+
~~~~~~~~~~~~~
87101

88102
Before you submit a pull request, check that it meets these guidelines:
89103

90104
1. The pull request should include tests.
91105
2. If the pull request adds functionality, the docs should be updated. Put
92106
your new functionality into a function with a docstring, and add the
93107
feature to the list in README.rst.
108+
109+
94110
.. 3. The pull request should work for Python 3.6, 3.7, 3.8 and 3.9.
95111
96112
.. Check https://travis-ci.com/rdnfn/beobench/pull_requests
@@ -104,6 +120,15 @@ To run a subset of tests::
104120

105121
$ python -m unittest tests.test_beobench
106122

123+
124+
Resources
125+
---------
126+
127+
Documentation and cheatsheets for reStructuredText (``.rst`` files):
128+
129+
* https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html
130+
* https://bashtage.github.io/sphinx-material/rst-cheatsheet/rst-cheatsheet.html
131+
107132
Deploying
108133
---------
109134

HISTORY.rst

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,35 @@
22
History
33
=======
44

5+
0.4.2 (2022-04-04)
6+
------------------
7+
8+
* Feature: defining all relevant options/kwargs of CLI an API is now supported
9+
yaml files (#54)
10+
* Feature: allow multiple configs to be given to both CLI
11+
(giving multiple ``-c`` options) and Python API (as a list) (#51)
12+
* Fix: adapted Energym env reset() method to avoid triggering
13+
long warm-up times with additional simulation runs (#43)
14+
* Fix: enable container build even if prior build failed midway
15+
and left artifacts
16+
517
0.4.1 (2022-03-30)
618
------------------
719

820
* Feature: enable package extras to be given in development mode
9-
* Feature: add support for arm64/aarch64-based development by forcing experiment containers to run as amd64 containers on those systems (#32)
21+
* Feature: add support for arm64/aarch64-based development by forcing
22+
experiment containers to run as amd64 containers on those systems (#32)
1023
* Fix: add gym to extended package requirements
1124

1225

1326
0.4.0 (2022-03-28)
1427
------------------
1528

16-
* Make dependencies that are only used inside experiment/gym containers optional (for all dependencies install via ``pip install beobench[extended]``)
17-
* Add two part experiment image build process so that there is shared beobench installation dockerfile
29+
* Make dependencies that are only used inside experiment/gym
30+
containers optional
31+
(for all dependencies install via ``pip install beobench[extended]``)
32+
* Add two part experiment image build process so that there is shared beobench
33+
installation dockerfile
1834
* Add support for yaml config files (!)
1935
* Overhaul of documentation, including new envs page and new theme
2036
* Enable RLlib free experiment containers when not required
@@ -25,7 +41,8 @@ History
2541
0.3.0 (2022-02-14)
2642
------------------
2743

28-
* Add complete redesign of CLI: main command changed from ``python -m beobench.experiment.scheduler`` to ``beobench run``.
44+
* Add complete redesign of CLI: main command changed from
45+
``python -m beobench.experiment.scheduler`` to ``beobench run``.
2946
* Add support for energym environments
3047
* Add support for MLflow experiment tracking
3148
* Add support for custom agents
@@ -41,7 +58,8 @@ History
4158
0.2.0 (2022-01-18)
4259
------------------
4360

44-
* Enable adding custom environments to beobench with *docker build context*-based syntax
61+
* Enable adding custom environments to beobench with
62+
*docker build context*-based syntax
4563
* Save experiment results on host machine
4664
* Major improvements to documentation
4765
* Remove unnecessary wandb arguments in main CLI

beobench/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
__author__ = """rdnfn"""
44
__email__ = "-"
5-
__version__ = "0.4.1"
5+
__version__ = "0.4.2"
66

77
from beobench.utils import restart
88
from beobench.experiment.scheduler import run

beobench/cli.py

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""Command line interface for beobench."""
22

33
import click
4-
import ast
54

65
import beobench.experiment.scheduler
76
import beobench.utils
@@ -19,48 +18,37 @@ def cli():
1918
default=None,
2019
help="Json or filepath with yaml that defines beobench experiment configuration.",
2120
type=str,
22-
)
23-
@click.option(
24-
"--experiment-file",
25-
default=None,
26-
help="File that defines beobench experiment.",
27-
type=click.Path(exists=True, file_okay=True, dir_okay=False),
28-
)
29-
@click.option(
30-
"--agent-file",
31-
default=None,
32-
help="File that defines custom agent.",
33-
type=click.Path(exists=True, file_okay=True, dir_okay=False),
21+
multiple=True,
3422
)
3523
@click.option(
3624
"--method",
37-
default="",
25+
default=None,
3826
help="Name of RL method to use in experiment.",
3927
)
4028
@click.option(
4129
"--env",
42-
default="",
30+
default=None,
4331
help="Name of RL environment to use in experiment.",
4432
)
4533
@click.option(
4634
"--local-dir",
47-
default="./beobench_results",
35+
default=None,
4836
help="Local directory to write results to.",
4937
type=click.Path(exists=False, file_okay=False, dir_okay=True),
5038
)
5139
@click.option(
5240
"--wandb-project",
53-
default="",
41+
default=None,
5442
help="Weights and biases project name to log runs to.",
5543
)
5644
@click.option(
5745
"--wandb-entity",
58-
default="",
46+
default=None,
5947
help="Weights and biases entity name to log runs under.",
6048
)
6149
@click.option(
6250
"--wandb-api-key",
63-
default="",
51+
default=None,
6452
help="Weights and biases API key.",
6553
)
6654
@click.option(
@@ -75,7 +63,7 @@ def cli():
7563
)
7664
@click.option(
7765
"--docker-shm-size",
78-
default="2gb",
66+
default=None,
7967
help="Size of shared memory available to experiment container.",
8068
)
8169
@click.option(
@@ -96,8 +84,6 @@ def cli():
9684
)
9785
def run(
9886
config: str,
99-
experiment_file: str,
100-
agent_file: str,
10187
method: str,
10288
env: str,
10389
local_dir: str,
@@ -121,14 +107,8 @@ def run(
121107
#
122108
# See https://stackoverflow.com/a/40094408.
123109

124-
# Parse config str to dict if
125-
if config and config[0] == "{":
126-
config = ast.literal_eval(config)
127-
128110
beobench.experiment.scheduler.run(
129-
config=config,
130-
experiment_file=experiment_file,
131-
agent_file=agent_file,
111+
config=list(config),
132112
method=method,
133113
env=env,
134114
local_dir=local_dir,

beobench/data/configs/rewex02.yaml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# REWEX Experiment 02
2+
# Run with the command
3+
# beobench run -c beobench/data/configs/rewex01_test02.yaml -d .[extended] --use-gpu --docker-shm-size 28gb
4+
5+
# Some of the descriptions of RLlib config values are taken from
6+
# https://docs.ray.io/en/latest/rllib/rllib-training.html
7+
8+
# agent config
9+
agent:
10+
origin: rllib # either path to agent script or name of agent library (rllib)
11+
config: # given to ray.tune.run() as arguments (since rllib set before)
12+
run_or_experiment: PPO
13+
stop:
14+
timesteps_total: 35040
15+
config:
16+
lr: 0.0005
17+
model:
18+
fcnet_activation: relu
19+
fcnet_hiddens: [256,256,256,256]
20+
post_fcnet_activation: tanh
21+
batch_mode: complete_episodes
22+
gamma: 0.999
23+
# Number of steps after which the episode is forced to terminate. Defaults
24+
# to `env.spec.max_episode_steps` (if present) for Gym envs.
25+
horizon: 96
26+
# Calculate rewards but don't reset the environment when the horizon is
27+
# hit. This allows value estimation and RNN state to span across logical
28+
# episodes denoted by horizon. This only has an effect if horizon != inf.
29+
soft_horizon: True
30+
# Number of timesteps collected for each SGD round. This defines the size
31+
# of each SGD epoch.
32+
train_batch_size: 94 # single day of 15min steps
33+
# Total SGD batch size across all devices for SGD. This defines the
34+
# minibatch size within each epoch.
35+
sgd_minibatch_size: 24
36+
metrics_smoothing_episodes: 1
37+
framework: torch
38+
log_level: "WARNING"
39+
num_workers: 1 # this is required for energym to work (can fail silently otherwise)
40+
num_gpus: 1
41+
# environment config
42+
env:
43+
name: MixedUseFanFCU-v0
44+
gym: energym
45+
config:
46+
days: 365
47+
energym_environment: MixedUseFanFCU-v0
48+
gym_kwargs:
49+
max_episode_length: 35040
50+
normalize: true
51+
step_period: 15
52+
weather: GRC_A_Athens

beobench/data/sweeps/sweep01.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
program: beobench
2+
method: grid
3+
command:
4+
- ${program}
5+
- run
6+
- ${args}
7+
parameters:
8+
config:
9+
value:
10+
- ./beobench/data/configs/rewex01.yaml
11+
- ./wandb.beo.yaml
12+
dev-path:
13+
value: .

beobench/experiment/config_parser.py

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,64 @@
33
from typing import Union
44
import pathlib
55
import yaml
6+
import ast
7+
import sys
68

7-
# To enable compatiblity with Python<=3.6 (e.g. for sinergym dockerfile)
8-
try:
9+
import beobench.utils
10+
11+
# To enable compatiblity with Python<=3.8 (e.g. for sinergym dockerfile)
12+
if sys.version_info[1] >= 9:
913
import importlib.resources
10-
except ImportError:
14+
else:
1115
import importlib_resources
1216
import importlib
1317

1418
importlib.resources = importlib_resources
1519

1620

17-
def parse(config: Union[str, pathlib.Path]) -> dict:
18-
"""Parse experiment config from yaml file to dict.
21+
def parse(config: Union[dict, str, pathlib.Path, list]) -> dict:
22+
"""Parse experiment config to dict.
1923
2024
Args:
21-
config (Union[str, pathlib.Path]): path of yaml file
25+
config (Union[dict, str, pathlib.Path, list]): path of yaml file
2226
2327
Returns:
2428
dict: config in dictionary
2529
"""
26-
27-
# load config dict if path given
28-
if isinstance(config, (str, pathlib.Path)):
29-
# make sure config is a real path
30-
if isinstance(config, str):
31-
config = pathlib.Path(config)
30+
if isinstance(config, list):
31+
# get list of config dicts
32+
parsed_configs = []
33+
for single_config in config:
34+
parsed_configs.append(parse(single_config))
35+
36+
# merge config dicts
37+
parsed_config = {}
38+
for conf in parsed_configs:
39+
parsed_config = beobench.utils.merge_dicts(parsed_config, conf)
40+
41+
elif isinstance(config, pathlib.Path):
42+
# load config yaml to dict if path given
3243
with open(config, "r", encoding="utf-8") as config_file:
33-
config_dict = yaml.safe_load(config_file)
44+
parsed_config = yaml.safe_load(config_file)
45+
46+
elif isinstance(config, str):
47+
if config[0] in ["{", "["]:
48+
# if json str or list
49+
parsed_config = parse(ast.literal_eval(config))
50+
else:
51+
# make sure config is a real path
52+
config_path = pathlib.Path(config)
53+
parsed_config = parse(config_path)
54+
55+
elif isinstance(config, dict):
56+
parsed_config = config
57+
3458
else:
35-
config_dict = config
59+
raise ValueError(
60+
f"Config not one of allowed types (dict, str, pathlib.Path, list): {config}"
61+
)
3662

37-
return config_dict
63+
return parsed_config
3864

3965

4066
def create_rllib_config(config: dict) -> dict:

0 commit comments

Comments
 (0)