Skip to content

Commit d76dd5c

Browse files
authored
(v3.8.2) - Initial context for environment fix (#481)
* Fix initial context applied only in first episode * Update Sinergym version from 3.8.1 to 3.8.2 * Fix test error
1 parent bbae3b4 commit d76dd5c

File tree

4 files changed

+15
-13
lines changed

4 files changed

+15
-13
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
package-mode = true
77
name = "sinergym"
88

9-
version = "3.8.1"
9+
version = "3.8.2"
1010
description = "Sinergym provides a Gymnasium-based interface to interact with building simulations. This allows control in simulation time through custom controllers, including reinforcement learning agents"
1111
license = "MIT"
1212

sinergym/envs/eplus_env.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ def __init__(
110110
self.meters = meters
111111
self.actuators = actuators
112112
self.context = context
113-
self.initial_context = initial_context
114113

115114
# ---------------------------------------------------------------------------- #
116115
# Define observation and action variables #
@@ -156,10 +155,6 @@ def __init__(
156155
# Simulator #
157156
# ---------------------------------------------------------------------------- #
158157

159-
# Set initial context if exists
160-
if self.initial_context is not None:
161-
self.update_context(self.initial_context)
162-
163158
# EnergyPlus simulator
164159
self.energyplus_simulator = EnergyPlus(
165160
name=env_name,
@@ -181,6 +176,8 @@ def __init__(
181176
# Weather Variability
182177
if weather_variability:
183178
self.default_options['weather_variability'] = weather_variability
179+
if initial_context:
180+
self.default_options['initial_context'] = initial_context
184181
# ... more reset option implementations here
185182

186183
# ---------------------------------------------------------------------------- #
@@ -240,16 +237,16 @@ def reset(self,
240237
"""
241238

242239
# If global seed was configured, reset seed will not be applied.
243-
if self.seed is None:
240+
if not self.seed:
244241
np.random.seed(seed)
245242

246243
# Apply options if exists, else default options
247-
reset_options = options if options is not None else self.default_options
244+
reset_options = options if options else self.default_options
248245

249246
self.episode += 1
250247
self.timestep = 0
251248

252-
# Stop oold thread of old episode if exists
249+
# Stop old thread of old episode if exists
253250
self.energyplus_simulator.stop()
254251

255252
self.last_obs = dict(
@@ -280,6 +277,10 @@ def reset(self,
280277
f'Saving episode output path in {eplus_working_out_path}.')
281278
self.logger.debug(f'Path: {eplus_working_out_path}')
282279

280+
# Set initial context if exists
281+
if reset_options.get('initial_context'):
282+
self.update_context(reset_options['initial_context'])
283+
283284
self.energyplus_simulator.start(
284285
building_path=eplus_working_building_path,
285286
weather_path=eplus_working_weather_path,
@@ -432,7 +433,7 @@ def update_context(self,
432433
if len(context_values) != len(self.context):
433434
self.logger.warning(
434435
f'Context values must have the same length than context variables specified, and values must be in the same order. The context space is {
435-
self.context}, but values {context_values} were spevified.')
436+
self.context}, but values {context_values} were specified.')
436437

437438
try:
438439
self.context_queue.put(context_values, block=False)

sinergym/utils/wrappers.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2036,8 +2036,9 @@ def __init__(self,
20362036
self.delta_context = (-delta_value, delta_value)
20372037
self.step_frequency_range = step_frequency_range
20382038

2039-
initial_context = self.get_wrapper_attr('initial_context')
2040-
if initial_context is not None:
2039+
initial_context = self.get_wrapper_attr(
2040+
'default_options').get('initial_context')
2041+
if initial_context:
20412042
self.current_context = np.array(
20422043
initial_context, np.float32)
20432044
else:

sinergym/version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.8.1
1+
3.8.2

0 commit comments

Comments
 (0)