Skip to content

Commit 0a8addf

Browse files
authored
Pre-submit Checks: Google-specific (#51)
Update files to make pre-submit checks pass, so we can merge the code into Google. Addresses all remaining Google-specific linting checks, except for "g-bad-todo" and "g-bad-import-order".
1 parent b5952ea commit 0a8addf

16 files changed

+90
-34
lines changed

smart_control/reinforcement_learning/observers/rendering_observer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ class RenderingObserver(Observer):
4444
def __init__(
4545
self,
4646
render_interval_steps: int = 10,
47-
env=None, # TODO: do we want to use `Optional[environment.Environment] = None` here?
48-
render_fn: Optional[Callable] = None, # pylint: disable=g-bare-generic # TODO: use more specific type hint if possible
49-
plot_fn: Optional[Callable] = None, # pylint: disable=g-bare-generic # TODO: use more specific type hint if possible
47+
env=None, # consider: `Optional[environment.Environment] = None`
48+
render_fn: Optional[Callable] = None, # pylint: disable=g-bare-generic
49+
plot_fn: Optional[Callable] = None, # pylint: disable=g-bare-generic
5050
clear_output_before_render: bool = True,
5151
time_zone: str = DEFAULT_TIME_ZONE,
5252
save_path: str = RENDERS_PATH,

smart_control/reinforcement_learning/utils/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
# Path to the root directory of the project:
3333
ROOT_DIR = os.path.join(os.path.dirname(__file__), "..", "..", "..")
3434
# fmt: off
35-
#pylint: disable=line-too-long
35+
# pylint: disable=line-too-long
3636
DATA_PATH = os.path.join(ROOT_DIR, "smart_control", "configs", "resources", "sb1")
3737
CONFIG_PATH = os.path.join(ROOT_DIR, "smart_control", "configs", "resources", "sb1", "train_sim_configs")
3838
METRICS_PATH = os.path.join(ROOT_DIR, "smart_control", "reinforcement_learning", "experiment_results", "metrics")

smart_control/reward/base_setpoint_energy_carbon_reward.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,18 @@ def compute_reward(
5555
def _sum_zone_productivities(
5656
self, energy_reward_info: smart_control_reward_pb2.RewardInfo
5757
) -> Tuple[float, float]:
58+
"""Calculates cumulative productivity and total occupancy across all zones.
59+
60+
Args:
61+
energy_reward_info: A RewardInfo object containing zone-specific
62+
information, including setpoint temperatures, zone air temperatures, and
63+
average occupancies.
64+
65+
Returns:
66+
A tuple containing:
67+
- The cumulative productivity across all zones (float).
68+
- The total average occupancy across all zones (float).
69+
"""
5870
time_interval_sec = self._get_delta_time_sec(energy_reward_info)
5971
cumulative_productivity = 0.0
6072
total_occupancy = 0.0
@@ -63,12 +75,8 @@ def _sum_zone_productivities(
6375
occupancy = energy_reward_info.zone_reward_infos[zid].average_occupancy
6476
total_occupancy += occupancy
6577
cumulative_productivity += self._get_zone_productivity_reward(
66-
energy_reward_info.zone_reward_infos[
67-
zid
68-
].heating_setpoint_temperature,
69-
energy_reward_info.zone_reward_infos[
70-
zid
71-
].cooling_setpoint_temperature,
78+
energy_reward_info.zone_reward_infos[zid].heating_setpoint_temperature, # pylint:disable=line-too-long
79+
energy_reward_info.zone_reward_infos[zid].cooling_setpoint_temperature, # pylint:disable=line-too-long
7280
energy_reward_info.zone_reward_infos[zid].zone_air_temperature,
7381
time_interval_sec,
7482
occupancy,

smart_control/reward/base_setpoint_energy_carbon_reward_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ class TestEnergyCost(BaseEnergyCost):
153153
154154
Used for testing purposes.
155155
156-
TODO: https://github.com/google/sbsim/issues/49 - consider refactoring with similar classes in:
156+
TODO: https://github.com/google/sbsim/issues/49 - refactor identical classes:
157157
smart_control/reward/setpoint_energy_carbon_regret_test.py
158158
smart_control/reward/setpoint_energy_carbon_reward_test.py
159159
@@ -163,7 +163,7 @@ class TestEnergyCost(BaseEnergyCost):
163163
def __init__(self, usd_per_kwh: float, kg_per_kwh: float):
164164
# Energy price in USD/Watt second (fixed schedule)
165165
# To convert denominator units hours to seconds, divide by 3600.0, and to
166-
# convert kW to W, divide by 1000. This leaves us with an enegy price
166+
# convert kW to W, divide by 1000. This leaves us with an energy price
167167
# in USD /W /s and carbon rate of kg /W /s.
168168
self._energy_price = usd_per_kwh / 3600.0 / 1000.0
169169
self._carbon_rate = kg_per_kwh / 3600.0 / 1000.0

smart_control/reward/setpoint_energy_carbon_regret_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,15 +301,15 @@ class TestEnergyCost(BaseEnergyCost):
301301
302302
Used for testing purposes.
303303
304-
TODO: https://github.com/google/sbsim/issues/49 - consider refactoring with similar classes in:
304+
TODO: https://github.com/google/sbsim/issues/49 - refactor identical classes:
305305
smart_control/reward/base_setpoint_energy_carbon_reward_test.py
306306
smart_control/reward/setpoint_energy_carbon_reward_test.py
307307
"""
308308

309309
def __init__(self, usd_per_kwh: float, kg_per_kwh: float):
310310
# Energy price in USD/Watt second (fixed schedule)
311311
# To convert denominator units hours to seconds, divide by 3600.0, and to
312-
# convert kW to W, divide by 1000. This leaves us with an enegy price
312+
# convert kW to W, divide by 1000. This leaves us with an energy price
313313
# in USD /W /s and carbon rate of kg /W /s.
314314
self._energy_price = usd_per_kwh / 3600.0 / 1000.0
315315
self._carbon_rate = kg_per_kwh / 3600.0 / 1000.0

smart_control/reward/setpoint_energy_carbon_reward_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,15 +235,15 @@ class TestEnergyCost(BaseEnergyCost):
235235
236236
Used for testing purposes.
237237
238-
TODO: https://github.com/google/sbsim/issues/49 - consider refactoring with similar classes in:
238+
TODO: https://github.com/google/sbsim/issues/49 - refactor identical classes:
239239
smart_control/reward/base_setpoint_energy_carbon_reward_test.py
240240
smart_control/reward/setpoint_energy_carbon_regret_test.py
241241
"""
242242

243243
def __init__(self, usd_per_kwh: float, kg_per_kwh: float):
244244
# Energy price in USD/Watt second (fixed schedule)
245245
# To convert denominator units hours to seconds, divide by 3600.0, and to
246-
# convert kW to W, divide by 1000. This leaves us with an enegy price
246+
# convert kW to W, divide by 1000. This leaves us with an energy price
247247
# in USD /W /s and carbon rate of kg /W /s.
248248
self._energy_price = usd_per_kwh / 3600.0 / 1000.0
249249
self._carbon_rate = kg_per_kwh / 3600.0 / 1000.0

smart_control/simulator/base_convection_simulator.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,8 @@ def apply_convection(
3636
"""Applies convection to the temperature array in place.
3737
3838
Splits up rooms via room_dict.
39+
40+
Args:
41+
room_dict: A dictionary mapping of room coordinates.
42+
temp: An array of temperatures.
3943
"""

smart_control/simulator/building.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ def apply_thermal_power_zone(
599599
600600
The thermal power [W] is applied to zones `zone_x` and `zone_y`.
601601
602-
Args:
602+
Args:
603603
zone_coordinates: Tuple containing x and y coordinates for zone.
604604
power: Watts to apply to zone.
605605
"""
@@ -625,9 +625,10 @@ class FloorPlanBasedBuilding(BaseSimulatorBuilding):
625625
width and length of each room.
626626
building_shape: 2-Tuple representing the number of rooms in the width and
627627
length of the building.
628+
floor_plan: an np.ndarray representing the building's floor plan.
628629
temp: The current temp in K of each control volume.
629630
conductivity: Thermal conductivity in of each control volume W/m/K.
630-
heat_capacity: Thermal heat cpacity of each control volume in J/kg/K.
631+
heat_capacity: Thermal heat capacity of each control volume in J/kg/K.
631632
density: Material density in kg/m3 of each control volume.
632633
input_q: Heat energy applied (sign indicates heating/cooling) at the CV in W
633634
(J/s).
@@ -871,7 +872,7 @@ def get_zone_temp_stats(self, zone_name: str) -> Tuple[float, float, float]: #
871872
return np.min(temps), np.max(temps), np.mean(temps)
872873

873874
def get_zone_average_temps(self) -> Dict[str, Any]:
874-
"""Returns a dict of zone average temps,
875+
"""Returns a dict of zone average temps.
875876
876877
The dict is formatted as: {`zone_coordinates`: `temp`}.
877878
"""

smart_control/simulator/randomized_arrival_departure_occupancy_test.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from smart_control.simulator import randomized_arrival_departure_occupancy
2424

2525
# fmt: off
26-
#pylint: disable=bad-continuation
26+
# pylint: disable=bad-continuation
2727
_EXPECTED_ZONE_OCCUPANCIES_PACIFIC = [
2828
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
2929
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
@@ -89,8 +89,9 @@
8989
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
9090
1, 1, 1, 1, 1, 1,
9191
]
92-
#pylint: disable=bad-continuation
93-
#fmt: off
92+
# pylint: disable=bad-continuation
93+
# fmt: off
94+
9495

9596
class RandomizedArrivalDepartureOccupancyTest(parameterized.TestCase):
9697

smart_control/simulator/simulator.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,9 @@ def _get_zone_reward_infos(
492492
"""Returns a map of messages with zone data.
493493
494494
This data is used to compute the instantaneous reward.
495+
496+
Args:
497+
occupancy_function: An occupancy function.
495498
"""
496499
zone_reward_infos = {}
497500
for (

smart_control/simulator/simulator_flexible_floor_plan.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,9 @@ def _get_zone_reward_infos(
228228
"""Returns a map of messages with zone data.
229229
230230
This data is used to compute the instantaneous reward.
231+
232+
Args:
233+
occupancy_function: An occupancy function.
231234
"""
232235
zone_reward_infos = {}
233236
for (

smart_control/simulator/stochastic_convection_simulator.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ def apply_convection(
6868
"""Applies convection to the temperature array given.
6969
7070
Splits up rooms via room_dict.
71+
72+
Args:
73+
room_dict: A dictionary mapping of room coordinates.
74+
temp: An array of temperatures.
7175
"""
7276
p = self._p
7377
distance = self._distance

smart_control/simulator/stochastic_occupancy.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,20 @@ def _occupant_departed(self, timestamp: pd.Timestamp) -> bool:
159159
return departed
160160

161161
def peek(self, current_time: pd.Timestamp) -> OccupancyStateEnum:
162+
"""Checks the current occupancy state based on the provided timestamp.
163+
164+
This method determines the occupancy state (AWAY or WORK) based on
165+
the current time, considering workdays, arrival/departure times,
166+
and a lunch break.
167+
168+
Args:
169+
current_time: The current timestamp to evaluate.
170+
171+
Returns:
172+
The current `OccupancyStateEnum` (AWAY or WORK).
173+
"""
162174
local_timestamp = self._to_local_time(current_time)
163-
# print(f"Inside peek: current_time={current_time}")
164-
local_time = (
165-
local_timestamp.time()
166-
) # Extracts time as a datetime.time object
175+
local_time = local_timestamp.time() # a datetime.time object
167176
if debug_print:
168177
print(
169178
f"Peek called: current_time={current_time},"

smart_control/simulator/tf_simulator.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def _cv_corner_type(cv_neighbors: Sequence[tuple[int, int]]) -> CVType:
219219
corner=CVCornerOrientationType.BOTTOM_RIGHT
220220
)
221221
raise ValueError(
222-
f"wasn't able to determine which corner the CV {(i,j)} is."
222+
f"Wasn't able to determine which corner the CV {(i, j)} is."
223223
)
224224

225225
def _cv_type_edge_factory(
@@ -242,7 +242,7 @@ def _cv_edge_type(cv_neighbors: Sequence[tuple[int, int]]) -> CVType:
242242
return edge(CVEdgeOrientationType.LEFT)
243243
if set([(i - 1, j), (i, j - 1), (i + 1, j)]) == set(cv_neighbors):
244244
return edge(CVEdgeOrientationType.RIGHT)
245-
raise ValueError(f"wasn't able to determine which edge the CV {(i,j)} is.")
245+
raise ValueError(f"Wasn't able to determine which edge the CV {(i, j)} is.")
246246

247247
i, j = coords
248248

@@ -260,7 +260,7 @@ def _cv_edge_type(cv_neighbors: Sequence[tuple[int, int]]) -> CVType:
260260
return CVType(position=CVPositionType.INTERIOR)
261261
case _:
262262
raise ValueError(
263-
f"wasn't able to determine which CV type the CV {(i,j)} is."
263+
f"Wasn't able to determine which CV type the CV {(i, j)} is."
264264
)
265265

266266

smart_control/utils/plot_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919
import os
2020
import pathlib
2121

22+
from matplotlib import cm
2223
from matplotlib import patches
23-
import matplotlib.cm as cm
2424
import matplotlib.dates as mdates
2525
import matplotlib.pyplot as plt
2626
from matplotlib.ticker import MaxNLocator
2727
import numpy as np
2828
import pandas as pd
2929

30-
K_TO_C = 273.0 # TODO: consider importing and using `int(KELVIN_TO_CELSIUS)` constant here (see https://github.com/google/sbsim/issues/25)
30+
K_TO_C = 273.0 # TODO: https://github.com/google/sbsim/issues/25 - consider importing and using `int(KELVIN_TO_CELSIUS)` constant here # pylint:disable=line-too-long
3131

3232

3333
def get_temp_colors(min_k, max_k):

smart_control/utils/regression_building_utils.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,12 @@ def get_action_tuples(
216216
) -> Set[Tuple[str, str, str]]:
217217
"""Returns the tuples from ActionResponse.
218218
219-
The tuples are formatted as (_ACTION_PREFIX, device_id, setpoint).
219+
Args:
220+
action_response: The ActionResponse from which to extract action tuples.
221+
222+
Returns:
223+
A set of tuples, where each tuple is in the format
224+
(`_ACTION_PREFIX`, `device_id`, `setpoint`).
220225
"""
221226
action_tuples = set()
222227
for request in action_response.request.single_action_requests:
@@ -433,7 +438,13 @@ def get_device_action_tuples(
433438
) -> Sequence[Tuple[str, str, str]]:
434439
"""Converts DeviceInfos into action tuples.
435440
436-
The tuples are formatted as (_ACTION_PREFIX, device, setpoint).
441+
Args:
442+
devices: A sequence of DeviceInfo objects.
443+
444+
Returns:
445+
A sequence of tuples, where each tuple is in the format
446+
(`_ACTION_PREFIX`, `device_id`, `setpoint`).
447+
437448
"""
438449
device_action_tuples = []
439450
for device_info in devices:
@@ -745,9 +756,21 @@ def get_zone_reward_infos(
745756
zone_infos: Sequence[smart_control_building_pb2.ZoneInfo],
746757
device_infos: Sequence[smart_control_building_pb2.DeviceInfo],
747758
) -> Mapping[str, smart_control_reward_pb2.RewardInfo.ZoneRewardInfo]:
748-
"""Returns a mapping of messages with zone data.
759+
"""Get zone reward information.
749760
750761
This is used to compute the instantaneous reward.
762+
763+
Args:
764+
current_timestamp: The current timestamp.
765+
step_interval: The time duration of a single step.
766+
current_observation_mapping: A mapping for the current observation.
767+
occupancy_function: An occupancy function.
768+
setpoint_schedule: A setpoint schedule.
769+
zone_infos: A sequence of ZoneInfo objects.
770+
device_infos: A sequence of DeviceInfo objects.
771+
772+
Returns:
773+
A mapping of messages with zone data.
751774
"""
752775
zone_reward_infos = {}
753776
zone_device_mapping = {

0 commit comments

Comments
 (0)