Skip to content

Commit eae5ce2

Browse files
authored
Merge pull request #41 from rdnfn/dev/general
v0.4.1
2 parents 27fdc4f + 74c08e8 commit eae5ce2

26 files changed

+258
-140
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,5 +117,5 @@ wandb/
117117
docs/generated/
118118

119119
#beobench
120-
beobench_results/
120+
beobench_results*
121121
notebooks/archive

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/psf/black
3-
rev: 21.9b0
3+
rev: 22.3.0
44
hooks:
55
- id: black
66
language_version: python3.9

HISTORY.rst

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

5+
0.4.1 (2022-03-30)
6+
------------------
7+
8+
* 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)
10+
* Fix: add gym to extended package requirements
11+
12+
513
0.4.0 (2022-03-28)
614
------------------
715

MANIFEST.in

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ include README.rst
66
include PYPI_README.rst
77

88
recursive-include tests *
9-
recursive-exclude * __pycache__
10-
recursive-exclude * *.py[co]
119

1210
recursive-include beobench/experiment/definitions *
11+
recursive-exclude beobench/experiment/definitions/archive/ *
1312

1413
recursive-exclude docs *.rst conf.py Makefile make.bat *.jpg *.png *.gif
14+
recursive-exclude * __pycache__
15+
recursive-exclude * *.py[co]

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.0"
5+
__version__ = "0.4.1"
66

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

beobench/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def cli():
4444
)
4545
@click.option(
4646
"--local-dir",
47-
default="./beobench_results/ray_results",
47+
default="./beobench_results",
4848
help="Local directory to write results to.",
4949
type=click.Path(exists=False, file_okay=False, dir_okay=True),
5050
)

beobench/data/configs/rewex01.yaml

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,38 @@
22
# Run with the command
33
# beobench run -c beobench/experiment/definitions/rewex01.yaml -d . --use-gpu --docker-shm-size 28gb
44

5+
# Some of the descriptions of RLlib config values are taken from
6+
# https://docs.ray.io/en/latest/rllib/rllib-training.html
7+
58
# agent config
69
agent:
710
origin: rllib # either path to agent script or name of agent library (rllib)
811
config: # given to ray.tune.run() as arguments (since rllib set before)
912
run_or_experiment: PPO
1013
stop:
11-
timesteps_total: 400000
14+
timesteps_total: 35040
1215
config:
13-
lr: 0.005
16+
lr: 0.0005
1417
model:
1518
fcnet_activation: relu
1619
fcnet_hiddens: [256,256,256,256]
1720
post_fcnet_activation: tanh
1821
batch_mode: complete_episodes
1922
gamma: 0.999
20-
horizon: 1000
21-
metrics_smoothing_episodes: 5
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
2237
framework: torch
2338
log_level: "WARNING"
2439
num_workers: 1 # this is required for energym to work (can fail silently otherwise)

beobench/data/configs/rewex01_test01.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# REWEX Experiment 01
22
# Run with the command
3-
# beobench run -c beobench/data/configs/rewex01_test01.yaml -d . --use-gpu --docker-shm-size 28gb
3+
# beobench run -c beobench/data/configs/rewex01_test01.yaml -d .[extended] --use-gpu --docker-shm-size 28gb
44

55
# agent config
66
agent:
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
# agent config
6+
agent:
7+
origin: beobench/data/agents/random_agent.py # either path to agent script or name of agent library (rllib)
8+
# environment config
9+
env:
10+
name: MixedUseFanFCU-v0
11+
gym: energym
12+
config:
13+
days: 365
14+
energym_environment: MixedUseFanFCU-v0
15+
gym_kwargs:
16+
max_episode_length: 35040
17+
normalize: true
18+
step_period: 15
19+
weather: GRC_A_Athens

beobench/experiment/containers.py

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import subprocess
44
import os
5+
import pathlib
6+
import shutil
57

68
# To enable compatiblity with Python<=3.6 (e.g. for sinergym dockerfile)
79
try:
@@ -16,8 +18,9 @@
1618
def build_experiment_container(
1719
build_context: str,
1820
use_no_cache: bool = False,
19-
version="latest",
20-
enable_rllib=False,
21+
local_dir: pathlib.Path = None,
22+
version: str = "latest",
23+
enable_rllib: bool = False,
2124
) -> None:
2225
"""Build experiment container from beobench/integrations/boptest/Dockerfile.
2326
@@ -27,26 +30,49 @@ def build_experiment_container(
2730
of existing beobench integration (e.g. `boptest`). See the official docs
2831
https://docs.docker.com/engine/reference/commandline/build/ for more info.
2932
use_no_cache (bool, optional): wether to use cache in build. Defaults to False.
33+
version (str, optional): version to add to container tag. Defaults to "latest".
34+
enable_rllib (bool, optional): whether to install rllib. Defaults to False.
3035
"""
3136

3237
# Flags are shared between gym image build and gym_and_beobench image build
3338
flags = []
39+
40+
# Using buildx to enable platform-specific builds
41+
build_commands = ["docker", "buildx", "build"]
42+
43+
# On arm64 machines force experiment containers to be amd64
44+
# This is only useful for development purposes.
45+
# (example: M1 macbooks)
46+
if os.uname().machine in ["arm64", "aarch64"]:
47+
flags += ["--platform", "linux/amd64"]
48+
3449
if use_no_cache:
3550
flags.append("--no-cache")
3651

52+
# pylint: disable=invalid-name
3753
AVAILABLE_INTEGRATIONS = [
3854
"boptest",
3955
"sinergym",
4056
"energym",
41-
] # pylint: disable=invalid-name
57+
]
4258

4359
if build_context in AVAILABLE_INTEGRATIONS:
4460
image_name = f"beobench_{build_context}"
4561
integration_name = build_context
46-
build_context = (
47-
f"https://github.com/rdnfn/"
48-
f"beobench_contrib.git#main:gyms/{build_context}"
62+
63+
# TODO: remove tmp git dir once buildkit version in docker cli updated
64+
tmp_git_dir = (local_dir / "tmp" / "beobench_contrib").absolute()
65+
subprocess.check_call(
66+
[
67+
"git",
68+
"clone",
69+
"https://github.com/rdnfn/beobench_contrib.git",
70+
tmp_git_dir,
71+
]
4972
)
73+
74+
build_context = str(tmp_git_dir / "gyms" / integration_name)
75+
5076
print(
5177
(
5278
f"Recognised integration named {integration_name}: using build"
@@ -64,17 +90,14 @@ def build_experiment_container(
6490

6591
# Part 1: build base experiment image
6692
args = [
67-
"docker",
68-
"build",
93+
*build_commands,
6994
"-t",
7095
base_image_tag,
71-
"-f",
72-
"Dockerfile", # change to non-default name
7396
*flags,
7497
build_context,
7598
]
7699
env = os.environ.copy()
77-
env["DOCKER_BUILDKIT"] = "0"
100+
print("Running command: " + " ".join(args))
78101
subprocess.check_call(
79102
args,
80103
env=env, # this enables accessing dockerfile in subdir
@@ -92,14 +115,13 @@ def build_experiment_container(
92115
# Which extras to install beobench container
93116
# e.g. using pip install beobench[extras]
94117
if enable_rllib:
95-
beobench_extras = '"extended,rllib"'
118+
beobench_extras = "extended,rllib"
96119
else:
97120
beobench_extras = "extended"
98121
# Load dockerfile into pipe
99122
with subprocess.Popen(["cat", complete_dockerfile], stdout=subprocess.PIPE) as proc:
100123
beobench_build_args = [
101-
"docker",
102-
"build",
124+
*build_commands,
103125
"-t",
104126
complete_image_tag,
105127
"-f",
@@ -118,6 +140,8 @@ def build_experiment_container(
118140
env=env, # this enables accessing dockerfile in subdir
119141
)
120142

143+
# TODO: remove tmp git dir once buildkit version in docker cli updated
144+
shutil.rmtree(tmp_git_dir)
121145
print("Experiment gym image build finished.")
122146

123147
return complete_image_tag

0 commit comments

Comments
 (0)