Skip to content

Commit

Permalink
Merge branch 'master' into multi_dimensional_action
Browse files Browse the repository at this point in the history
  • Loading branch information
javiarrobas committed Sep 27, 2024
2 parents 2b20646 + 9335d8c commit fbd0661
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 49 deletions.
33 changes: 20 additions & 13 deletions .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
name: CI of BOPTEST-Gym using GitHub Actions
on: [push]
on:
push:
pull_request:
branches:
- main
types: [opened, synchronize, reopened]
jobs:
test-local:
runs-on: ubuntu-latest
Expand All @@ -11,10 +16,12 @@ jobs:
uses: actions/checkout@v3
- name: Pull boptestgym image from registry
run: make pull-boptestgym
- run: echo "The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
- name: List of files in the repository
run: |
ls ${{ github.workspace }}
- name: Pull boptest_base image from registry
run: make pull-boptestbase
- name: Install Docker Compose
run: |
sudo apt-get update
sudo apt-get install -y docker-compose
- name: Test local version
run: make test-local-in-container
test-vectorized:
Expand All @@ -27,10 +34,12 @@ jobs:
uses: actions/checkout@v3
- name: Pull boptestgym image from registry
run: make pull-boptestgym
- run: echo "The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
- name: List of files in the repository
run: |
ls ${{ github.workspace }}
- name: Pull boptest_base image from registry
run: make pull-boptestbase
- name: Install Docker Compose
run: |
sudo apt-get update
sudo apt-get install -y docker-compose
- name: Test vectorized environment
run: make test-vectorized-in-container
test-service:
Expand All @@ -43,10 +52,8 @@ jobs:
uses: actions/checkout@v3
- name: Pull boptestgym image from registry
run: make pull-boptestgym
- run: echo "The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
- name: List of files in the repository
run: |
ls ${{ github.workspace }}
- name: Pull boptest_base image from registry
run: make pull-boptestbase
- name: Test service version
run: make test-service-in-container

21 changes: 13 additions & 8 deletions boptestGymEnv.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ def __init__(self,
observations = {'reaTZon_y':(280.,310.)},
reward = ['reward'],
max_episode_length = 3*3600,
random_start_time = False,
excluding_periods = None,
regressive_period = None,
predictive_period = None,
start_time = None,
start_time = 0,
warmup_period = 0,
scenario = {'electricity_price':'constant'},
step_period = 900,
Expand Down Expand Up @@ -78,13 +79,15 @@ def __init__(self,
buffer of data in case the algorithm is going to use pretraining
max_episode_length: integer
Maximum duration of each episode in seconds
random_start_time: boolean
Set to True if desired to use a random start time for each episode
excluding_periods: list of tuples
List where each element is a tuple indicating the start and
end time of the periods that should not overlap with any
episode used for training. Example:
excluding_periods = [(31*24*3600, 31*24*3600+14*24*3600),
(304*24*3600, 304*24*3600+14*24*3600)]
This is only used when `start_time=None`
This is only used when `random_start_time=True`
regressive_period: integer, default is None
Number of seconds for the regressive horizon. The observations
will be extended for each of the measurement variables indicated
Expand Down Expand Up @@ -112,8 +115,8 @@ def __init__(self,
ambient temperature.
start_time: integer
Initial fixed episode time in seconds from beginning of the
year for each episode. For random start time, set
`start_time=None`
year for each episode. Use in combination with
`random_start_time=False`
warmup_period: integer
Desired simulation period to initialize each episode
scenario: dictionary
Expand All @@ -134,6 +137,7 @@ def __init__(self,
self.actions = actions
self.observations = list(observations.keys())
self.max_episode_length = max_episode_length
self.random_start_time = random_start_time
self.excluding_periods = excluding_periods
self.start_time = start_time
self.warmup_period = warmup_period
Expand Down Expand Up @@ -366,6 +370,7 @@ def get_summary(self):
summary['GYM ENVIRONMENT INFORMATION']['Measurement variables used in observation space'] = pformat(self.measurement_vars)
summary['GYM ENVIRONMENT INFORMATION']['Predictive variables used in observation space'] = pformat(self.predictive_vars)
summary['GYM ENVIRONMENT INFORMATION']['Sampling time (seconds)'] = pformat(self.step_period)
summary['GYM ENVIRONMENT INFORMATION']['Random start time'] = pformat(self.random_start_time)
summary['GYM ENVIRONMENT INFORMATION']['Excluding periods (seconds from the beginning of the year)'] = pformat(self.excluding_periods)
summary['GYM ENVIRONMENT INFORMATION']['Warmup period for each episode (seconds)'] = pformat(self.warmup_period)
summary['GYM ENVIRONMENT INFORMATION']['Maximum episode length (seconds)'] = pformat(self.max_episode_length)
Expand Down Expand Up @@ -415,7 +420,7 @@ def reset(self, seed=None, options=None):
Method to reset the environment. The associated building model is
initialized by running the baseline controller for a
`self.warmup_period` of time right before `self.start_time`.
If `self.start_time` is None, a random time is assigned
If `self.random_start_time` is True, a random time is assigned
to `self.start_time` such that there are not episodes that overlap
with the indicated `self.excluding_periods`. This is useful to
define testing periods that should not use data from training.
Expand Down Expand Up @@ -460,10 +465,10 @@ def find_start_time():
# This point is reached only when a good starting point is found
return start_time

# Assign random start_time if start_time is None
if not self.start_time:
# Assign random start_time if it is None
if self.random_start_time:
self.start_time = find_start_time()

# Initialize the building simulation
res = requests.put('{0}/initialize'.format(self.url),
json={'start_time':int(self.start_time),
Expand Down
73 changes: 45 additions & 28 deletions testing/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,91 +2,108 @@
ROOT ?= $(shell dirname \
$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))))

# Local image name and home
IMG_NAME=boptestgym
IMG_HOME=/home/developer/boptestgym
# Local image name, home directory, and remote registry for BOPTEST-Gym
IMG_NAME_BOPTESTGYM=boptestgym
IMG_HOME_BOPTESTGYM=/home/developer/boptestgym
IMG_REGI_BOPTESTGYM=javierarroyo/boptestgym

# Name of remote registry image
IMG_REGI=javierarroyo/boptestgym
# Local image name and remote registry for the BOPTEST test case
IMG_NAME_BOPTESTBASE=boptest_base
IMG_REGI_BOPTESTBASE=javierarroyo/boptest_base

# BOPTEST commit used for the tests
BOPTEST_COMMIT=78665506a620fc07bc2a8f301661aef3dd6c88c2

# Define current BOPTEST-Gym version (should be even with BOPTEST version defined in commit above)
VERSION = 0.6.0
VERSION = 0.6.0-dev

build-boptestgym:
docker build -f ${ROOT}/testing/Dockerfile \
--progress=plain --rm -t ${IMG_NAME} .
--progress=plain --rm -t ${IMG_NAME_BOPTESTGYM} .

build-boptestgym-no-cache:
docker build -f ${ROOT}/testing/Dockerfile \
--progress=plain --no-cache --rm -t ${IMG_NAME} .

--progress=plain --no-cache --rm -t ${IMG_NAME_BOPTESTGYM} .

# Build the generic BOPTEST base image without mounting any test case
build-boptestbase:
make download-boptest
cd project1-boptest-${BOPTEST_COMMIT} && \
docker compose build

run-boptestgym:
docker run \
--name ${IMG_NAME} \
--name ${IMG_NAME_BOPTESTGYM} \
--detach=false \
--network=host \
--rm \
--user $(id -u):$(id -g) \
-v ${ROOT}:${IMG_HOME}:rw \
-w ${IMG_HOME}/testing \
-v ${ROOT}:${IMG_HOME_BOPTESTGYM}:rw \
-w ${IMG_HOME_BOPTESTGYM}/testing \
-it \
${IMG_NAME}
${IMG_NAME_BOPTESTGYM}

run-boptestgym-detached:
docker run \
--name ${IMG_NAME} \
--name ${IMG_NAME_BOPTESTGYM} \
--detach=true \
--network=host \
--rm \
--user $(id -u):$(id -g) \
-v ${ROOT}:${IMG_HOME}:rw \
-w ${IMG_HOME}/testing \
-v ${ROOT}:${IMG_HOME_BOPTESTGYM}:rw \
-w ${IMG_HOME_BOPTESTGYM}/testing \
-it \
${IMG_NAME}
${IMG_NAME_BOPTESTGYM}

stop-boptestgym:
docker stop ${IMG_NAME}
docker stop ${IMG_NAME_BOPTESTGYM}

exec-boptestgym:
docker exec \
-i \
${IMG_NAME} \
${IMG_NAME_BOPTESTGYM} \
/bin/bash -c "${ARGS} && exit"

push-boptestgym:
# requires `docker login` first
docker tag ${IMG_NAME} ${IMG_REGI}:${VERSION}
docker push ${IMG_REGI}:${VERSION}
docker tag ${IMG_NAME_BOPTESTGYM} ${IMG_REGI_BOPTESTGYM}:${VERSION}
docker push ${IMG_REGI_BOPTESTGYM}:${VERSION}

pull-boptestgym:
docker pull ${IMG_REGI}:${VERSION}
docker tag ${IMG_REGI}:${VERSION} ${IMG_NAME}
docker pull ${IMG_REGI_BOPTESTGYM}:${VERSION}
docker tag ${IMG_REGI_BOPTESTGYM}:${VERSION} ${IMG_NAME_BOPTESTGYM}

push-boptestbase:
# requires `docker login` first
docker tag ${IMG_NAME_BOPTESTBASE} ${IMG_REGI_BOPTESTBASE}:${VERSION}
docker push ${IMG_REGI_BOPTESTBASE}:${VERSION}

pull-boptestbase:
docker pull ${IMG_REGI_BOPTESTBASE}:${VERSION}
docker tag ${IMG_REGI_BOPTESTBASE}:${VERSION} ${IMG_NAME_BOPTESTBASE}

make download-boptest:
download-boptest:
curl -L -o boptest.zip https://github.com/ibpsa/project1-boptest/archive/${BOPTEST_COMMIT}.zip
unzip -o -q boptest.zip

run-boptest-case:
make download-boptest
cd project1-boptest-${BOPTEST_COMMIT} && \
TESTCASE=bestest_hydronic_heat_pump docker-compose up -d --quiet-pull
TESTCASE=bestest_hydronic_heat_pump docker compose up -d

run-boptest-case-no-cache:
make download-boptest
cd project1-boptest-${BOPTEST_COMMIT} && \
TESTCASE=bestest_hydronic_heat_pump docker-compose up -d --force-recreate --build
TESTCASE=bestest_hydronic_heat_pump docker compose up -d --force-recreate --build

run-boptest-vectorized:
make download-boptest && \
cd .. && python3 generateDockerComposeYml.py testing/project1-boptest-${BOPTEST_COMMIT} && \
cd testing/project1-boptest-${BOPTEST_COMMIT} && \
TESTCASE=bestest_hydronic_heat_pump docker-compose up -d --quiet-pull
TESTCASE=bestest_hydronic_heat_pump docker compose up -d

stop-boptest-case:
cd project1-boptest-${BOPTEST_COMMIT} && docker-compose down
cd project1-boptest-${BOPTEST_COMMIT} && docker compose down

cleanup-boptest:
rm boptest.zip
Expand Down

0 comments on commit fbd0661

Please sign in to comment.