Skip to content

Commit c92068e

Browse files
authored
Merge pull request #81 from rdnfn/dev/general
v0.5.1
2 parents c51e9a6 + 7efe3e6 commit c92068e

18 files changed

+147
-51
lines changed

CITATION.cff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ message: >-
99
If you use this software, please cite it using the
1010
metadata from this file.
1111
type: software
12-
version: 0.5.0
12+
version: 0.5.1
1313
url: https://github.com/rdnfn/beobench
1414
authors:
1515
- given-names: Arduin

HISTORY.rst

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,22 @@
22
History
33
=======
44

5+
0.5.1 (2022-06-28)
6+
------------------
7+
8+
* Features:
9+
10+
* Add pretty logging based on loguru package. Now all Beobench output is clearly marked as such.
11+
12+
* Improvements
13+
14+
* Enable adding wrapper without setting config.
15+
* Add ``demo.yaml`` simple example config.
16+
17+
* Fixes
18+
19+
* Update Sinergym integration to latest Sinergym version.
20+
521
0.5.0 (2022-05-26)
622
------------------
723

@@ -11,15 +27,16 @@ History
1127
* Support for automatically running multiple samples/trials of same experiment via ``num_samples`` config parameter.
1228
* Configs named `.beobench.yml` will be automatically parsed when Beobench is run in directory containing such a config. This allows users to set e.g. wandb API keys without referring to the config in every Beobench command call.
1329
* Configs from experiments now specify the Beobench version used. When trying to rerun an experiment this version will be checked, and an error thrown if there is a mismatch between installed and requested version.
14-
* Add improved high-level API for getting started. This uses the CLI arguments ``--method``, ``--gym`` and ``--env``. Example usage: ``beobench run --method ppo --gym sinergym --env Eplus-5Zone-hot-continuous-v1``.
30+
* Add improved high-level API for getting started. This uses the CLI arguments ``--method``, ``--gym`` and ``--env``. Example usage: ``beobench run --method ppo --gym sinergym --env Eplus-5Zone-hot-continuous-v1`` (#55).
1531

1632
* Improvements
1733

18-
* Add ``CITATION.cff`` file to citing software easier.
34+
* Add ``CITATION.cff`` file to make citing software easier.
1935
* By default, docker builds of experiment images are now skipped if an image with tag corresponding to installed Beobench version already exists.
20-
* Remove outdated guides and add yaml configuration description from docs.
36+
* Remove outdated guides and add yaml configuration description from docs (#38, #76, #78).
2137
* Add support for logging multidimensional actions to wandb.
2238
* Add support for logging summary metrics on every env reset to wandb.
39+
* Energym config now uses ``name`` argument like other integrations (#34).
2340

2441
* Fixes
2542

beobench/__init__.py

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

33
__author__ = """Beobench authors"""
44
__email__ = "-"
5-
__version__ = "0.5.0"
5+
__version__ = "0.5.1"
66

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

beobench/beobench_contrib

beobench/data/configs/default.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,4 @@ general:
109109
# experiment once.
110110
num_samples: 1
111111
# Beobench version
112-
version: 0.5.0
112+
version: 0.5.1

beobench/data/configs/demo.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
agent:
2+
origin: random_action
3+
config:
4+
stop:
5+
timesteps_total: 10
6+
env:
7+
gym: sinergym
8+
config:
9+
name: Eplus-5Zone-hot-continuous-v1
10+
wrappers:
11+
- origin: general
12+
class: WandbLogger
13+
general:
14+
wandb_entity: beobench
15+
wandb_project: demo
16+
# wandb_api_key: HIDDEN

beobench/experiment/config_parser.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import sys
99
import random
1010
import os
11+
from beobench.logging import logger
1112

1213
import beobench
1314
import beobench.utils
@@ -138,7 +139,7 @@ def get_user() -> dict:
138139
"""
139140

140141
if os.path.isfile(USER_CONFIG_PATH):
141-
print(f"Beobench: recognised user config at '{USER_CONFIG_PATH}'.")
142+
logger.info(f"Recognised user config at '{USER_CONFIG_PATH}'.")
142143
user_config = parse(USER_CONFIG_PATH)
143144
else:
144145
user_config = {}

beobench/experiment/containers.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import subprocess
55
import os
66
import docker
7+
from loguru import logger
78

89
import beobench
910
from beobench.constants import AVAILABLE_INTEGRATIONS
@@ -74,7 +75,7 @@ def build_experiment_container(
7475
)
7576
package_build_context = True
7677

77-
print(f"Beobench: recognised integration named {gym_name}.")
78+
logger.info(f"Recognised integration named {gym_name}.")
7879
else:
7980
# get alphanumeric name from context
8081
context_name = "".join(e for e in build_context if e.isalnum())
@@ -88,15 +89,14 @@ def build_experiment_container(
8889

8990
# skip build if image already exists.
9091
if not force_build and check_image_exists(stage2_image_tag):
91-
print(f"Beobench: existing image found ({stage2_image_tag}). Skipping build.")
92+
logger.info(f"Existing image found ({stage2_image_tag}). Skipping build.")
9293
return stage2_image_tag
9394

94-
print(
95-
f"Beobench: image not found ({stage2_image_tag}) or forced",
96-
"rebuild. Building image.",
95+
logger.warning(
96+
f"Image not found ({stage2_image_tag}) or forced rebuild. Building image.",
9797
)
9898

99-
print(f"Building experiment base image `{stage0_image_tag}`...")
99+
logger.info(f"Building experiment base image `{stage0_image_tag}`...")
100100

101101
with contextlib.ExitStack() as stack:
102102
# if using build context from beobench package, get (potentially temp.) build
@@ -114,7 +114,7 @@ def build_experiment_container(
114114
build_context,
115115
]
116116
env = os.environ.copy()
117-
print("Running command: " + " ".join(stage0_build_args))
117+
logger.info("Running command: " + " ".join(stage0_build_args))
118118
subprocess.check_call(
119119
stage0_build_args,
120120
env=env, # this enables accessing dockerfile in subdir
@@ -146,7 +146,7 @@ def build_experiment_container(
146146
with subprocess.Popen(
147147
["cat", stage1_dockerfile], stdout=subprocess.PIPE
148148
) as proc:
149-
print("Running command: " + " ".join(stage1_build_args))
149+
logger.info("Running command: " + " ".join(stage1_build_args))
150150
subprocess.check_call(
151151
stage1_build_args,
152152
stdin=proc.stdout,
@@ -191,14 +191,14 @@ def build_experiment_container(
191191
with subprocess.Popen(
192192
["cat", stage2_dockerfile], stdout=subprocess.PIPE
193193
) as proc:
194-
print("Running command: " + " ".join(stage2_build_args))
194+
logger.info("Running command: " + " ".join(stage2_build_args))
195195
subprocess.check_call(
196196
stage2_build_args,
197197
stdin=proc.stdout,
198198
env=env, # this enables accessing dockerfile in subdir
199199
)
200200

201-
print("Experiment gym image build finished.")
201+
logger.info("Experiment gym image build finished.")
202202

203203
return stage2_image_tag
204204

@@ -213,10 +213,10 @@ def create_docker_network(network_name: str) -> None:
213213
network_name (str): name of docker network.
214214
"""
215215

216-
print("Creating docker network ...")
216+
logger.info("Creating docker network ...")
217217
try:
218218
args = ["docker", "network", "create", network_name]
219219
subprocess.check_call(args)
220-
print("Docker network created.")
220+
logger.info("Docker network created.")
221221
except subprocess.CalledProcessError:
222-
print("No new network created. Network may already exist.")
222+
logger.info("No new network created. Network may already exist.")

beobench/experiment/provider.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ def create_env(env_config: dict = None) -> object:
3939

4040
for wrapper_dict in config["wrappers"]:
4141
wrapper = _get_wrapper(wrapper_dict)
42-
env = wrapper(env, **wrapper_dict["config"])
42+
if "config" in wrapper_dict.keys():
43+
wrapper_config = wrapper_dict["config"]
44+
else:
45+
wrapper_config = {}
46+
env = wrapper(env, **wrapper_config)
4347

4448
return env
4549

beobench/experiment/scheduler.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@
2323
import beobench.experiment.containers
2424
import beobench.experiment.config_parser
2525
import beobench.utils
26+
import beobench.logging
27+
from beobench.logging import logger
2628
from beobench.constants import CONTAINER_DATA_DIR, CONTAINER_RO_DIR, AVAILABLE_AGENTS
2729

30+
beobench.logging.setup()
31+
2832

2933
def run(
3034
config: Union[str, dict, pathlib.Path, list] = None,
@@ -94,7 +98,7 @@ def run(
9498
num_samples (int, optional): number of experiment samples to run. This defaults
9599
to a single sample, i.e. just running the experiment once.
96100
"""
97-
print("Beobench: starting experiment run ...")
101+
logger.info("Starting experiment run ...")
98102
# parsing relevant kwargs and adding them to config
99103
kwarg_config = _create_config_from_kwargs(
100104
local_dir=local_dir,
@@ -134,9 +138,9 @@ def run(
134138
for i in range(1, num_samples + 1):
135139
# TODO: enable checking whether something is run in container
136140
# and do not print the statement below if inside experiment container.
137-
print(
141+
logger.info(
138142
(
139-
f"Beobench: running experiment in container with environment "
143+
f"Running experiment in container with environment "
140144
f"{config['env']['name']}"
141145
f" and agent from {config['agent']['origin']}. Sample {i} of"
142146
f" {num_samples}."
@@ -152,6 +156,8 @@ def run(
152156
# Execute experiment
153157
# (this is usually reached from inside an experiment container)
154158

159+
logger.info("Running agent script.")
160+
155161
container_ro_dir_abs = CONTAINER_RO_DIR.absolute()
156162
args = [
157163
"python",
@@ -301,9 +307,10 @@ def _build_and_run_in_container(config: dict) -> None:
301307
arg_str = " ".join(args)
302308
if wandb_api_key:
303309
arg_str = arg_str.replace(wandb_api_key, "<API_KEY_HIDDEN>")
304-
print(f"Executing docker command: {arg_str}")
310+
logger.info(f"Executing docker command: {arg_str}")
305311

306-
subprocess.check_call(args)
312+
# subprocess.check_call(args)
313+
beobench.utils.run_command(args, process_name="container")
307314

308315

309316
def _create_config_from_kwargs(**kwargs) -> dict:

0 commit comments

Comments
 (0)