Skip to content

Commit da325d2

Browse files
committed
Pre-submit Checks: Restore Unused References (#57)
Removing unused References in #32 caused Google tests to fail, so we are fixing the tests by restoring some of the original code that was removed in that PR. Notes: + It was originally thought that because the `HybridActionEnvironment` child class defines its own `_format_action` function that the definition of this function in the parent `Environment` class was unnecessary, because in the parent class this function was a no-op that returned the `action` without formatting it. + However there was also an invocation of the `_format_action` function within the `_step` function of the `Environment` class, and because the `HybridActionEnvironment` class doesn't define its own `_step` function, restoring the invocation in the parent class was necessary to allow the child class to format the actions during each step. + And in order for this invocation in the parent class to be valid we need to also restore the definition of the `_format_action` function within the parent class.
1 parent 0a8addf commit da325d2

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

.github/workflows/build.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ name: Python CI Build
22

33
on:
44
push:
5+
branches:
6+
- master
7+
- main
8+
- copybara_push
59
pull_request:
610
branches:
711
- master

SBSIM_OVERVIEW.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ The `environment` module provides the reinforcement learning environment where t
123123

124124
* `_get_action_spec_and_normalizers(...)`: Defines the action space and normalizers based on the building devices and action configurations.
125125
* `_get_observation_spec(...)`: Defines the observation space based on the building devices and observation configurations.
126+
* `_format_action(action, action_names)`: Reformat actions if necessary (extension point for subclasses).
126127
* `render(mode)`: (Not implemented) Intended for rendering the environment state.
127128
* **Properties**:
128129

smart_control/environment/environment.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,6 +1207,28 @@ def action_spec(self) -> types.NestedArraySpec:
12071207
def observation_spec(self) -> types.NestedArraySpec:
12081208
return self._observation_spec
12091209

1210+
def _format_action(
1211+
self, action: types.NestedArray, action_names: Sequence[str] # pylint: disable=unused-argument
1212+
) -> types.NestedArray:
1213+
"""Enables extension classes to reformat actions into base format.
1214+
1215+
Args:
1216+
action: the action(s) to be formatted.
1217+
action_names: the action names to use for formatting.
1218+
1219+
Returns:
1220+
The formatted action names.
1221+
1222+
NOTE: this function is currently a no-op
1223+
that returns the action without formatting it.
1224+
However invocation of this function from within the `_step` function
1225+
allows child classes to format their actions.
1226+
So it turns out this function is required to stay here, and we are
1227+
allowing the unused argument.
1228+
See: https://github.com/google/sbsim/pull/57
1229+
"""
1230+
return action
1231+
12101232
def _step(self, action: types.NestedArray) -> ts.TimeStep:
12111233
"""Individual time step calculations.
12121234
@@ -1238,6 +1260,9 @@ def _action_strings(
12381260
reward_value = 0.0
12391261
observation = None
12401262

1263+
# Reformat actions if necessary.
1264+
action = self._format_action(action, self._action_names)
1265+
12411266
# Convert the action from normalized to native values.
12421267
action_request = self._create_action_request(action)
12431268

0 commit comments

Comments
 (0)