Skip to content

Commit a18bf3f

Browse files
committedJun 5, 2023
black formatter
1 parent 764b263 commit a18bf3f

File tree

6 files changed

+38
-26
lines changed

6 files changed

+38
-26
lines changed
 

‎nrel/hive/initialization/initialize_simulation_with_sampling.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,6 @@ def _add_row_unsafe(
187187

188188
# add all stations to the simulation once we know they are complete
189189
stations = DictOps.iterate_vals(stations_builder)
190-
sim_with_stations = simulation_state_ops.add_entities(
191-
simulation_state, stations
192-
)
190+
sim_with_stations = simulation_state_ops.add_entities(simulation_state, stations)
193191

194192
return sim_with_stations

‎nrel/hive/state/simulation_state/simulation_state.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,14 @@ def get_request_ids(self) -> Tuple[RequestId, ...]:
9090
def get_stations(
9191
self,
9292
filter_function: Optional[Callable[[Station], bool]] = None,
93-
sort_key: Optional[Callable] = None
93+
sort_key: Optional[Callable] = None,
9494
) -> Tuple[Station, ...]:
9595
return DictOps.iterate_sim_coll(self.stations, filter_function, sort_key)
9696

9797
def get_bases(
9898
self,
9999
filter_function: Optional[Callable[[Base], bool]] = None,
100-
sort_key: Optional[Callable] = None
100+
sort_key: Optional[Callable] = None,
101101
) -> Tuple[Base, ...]:
102102
return DictOps.iterate_sim_coll(self.bases, filter_function, sort_key)
103103

‎nrel/hive/state/simulation_state/update/step_simulation_ops.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def _sort_by_vehicle_state(vs: Tuple[Vehicle, ...]) -> Tuple[Vehicle, ...]:
101101
lambda v: isinstance(v.vehicle_state, ChargeQueueing), vs
102102
)
103103

104-
# sort queueing vehicles by enqueue time followed by id as a
104+
# sort queueing vehicles by enqueue time followed by id as a
105105
# deterministic tie-breaker via their VehicleId
106106
sorted_charge_queueing_vehicles = tuple(
107107
sorted(

‎nrel/hive/util/dict_ops.py

+33-16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
from __future__ import annotations
22

3-
from typing import Any, Callable, Iterator, List, NamedTuple, Tuple, Optional, TypeVar, FrozenSet, TYPE_CHECKING, Hashable, Union
3+
from typing import (
4+
Any,
5+
Callable,
6+
Iterator,
7+
List,
8+
NamedTuple,
9+
Tuple,
10+
Optional,
11+
TypeVar,
12+
FrozenSet,
13+
TYPE_CHECKING,
14+
Hashable,
15+
Union,
16+
)
417

518
import h3
619
import immutables
@@ -11,7 +24,6 @@
1124
from _typeshed import SupportsRichComparison
1225

1326

14-
1527
class EntityUpdateResult(NamedTuple):
1628
entities: Optional[immutables.Map[EntityId, Entity]] = None
1729
locations: Optional[immutables.Map[GeoId, FrozenSet[EntityId]]] = None
@@ -23,9 +35,11 @@ class DictOps:
2335
V = TypeVar("V")
2436

2537
@classmethod
26-
def iterate_vals(cls, xs: immutables.Map[K, V], key: Optional[Callable[[V], SupportsRichComparison]]=None) -> Tuple[V, ...]:
38+
def iterate_vals(
39+
cls, xs: immutables.Map[K, V], key: Optional[Callable[[V], SupportsRichComparison]] = None
40+
) -> Tuple[V, ...]:
2741
"""
28-
helper function for iterating on Maps in HIVE which sorts values by key unless a key function
42+
helper function for iterating on Maps in HIVE which sorts values by key unless a key function
2943
is provided. for all stateful Map collections that are being iterated on in HIVE, we need
3044
to sort them _somehow_ to guarantee deterministic runs.
3145
@@ -34,7 +48,7 @@ def iterate_vals(cls, xs: immutables.Map[K, V], key: Optional[Callable[[V], Supp
3448
3549
:param xs: collection to iterate values of
3650
:type xs: immutables.Map[K, V]
37-
:return: values of xs, sorted by key
51+
:return: values of xs, sorted by key
3852
:rtype: Tuple[V, ...]
3953
"""
4054
# forcing ignore here after numerous attempts to set the bounds for K
@@ -47,17 +61,21 @@ def iterate_vals(cls, xs: immutables.Map[K, V], key: Optional[Callable[[V], Supp
4761
else:
4862
vs = sorted(xs.values(), key=key) # type: ignore
4963
return vs
50-
64+
5165
@classmethod
52-
def iterate_items(cls, xs: immutables.Map[K, V], key: Optional[Callable[[Tuple[K, V]], SupportsRichComparison]]=None) -> List[Tuple[K, V]]:
66+
def iterate_items(
67+
cls,
68+
xs: immutables.Map[K, V],
69+
key: Optional[Callable[[Tuple[K, V]], SupportsRichComparison]] = None,
70+
) -> List[Tuple[K, V]]:
5371
"""
54-
helper function for iterating on Maps in HIVE which sorts values by key unless a key function
72+
helper function for iterating on Maps in HIVE which sorts values by key unless a key function
5573
is provided. for all stateful Map collections that are being iterated on in HIVE, we need
5674
to sort them _somehow_ to guarantee deterministic runs.
5775
5876
:param xs: collection to iterate values of
5977
:type xs: immutables.Map[K, V]
60-
:return: values of xs, sorted by key
78+
:return: values of xs, sorted by key
6179
:rtype: Tuple[V, ...]
6280
"""
6381
# forcing ignore here after numerous attempts to set the bounds for K
@@ -71,10 +89,10 @@ def iterate_items(cls, xs: immutables.Map[K, V], key: Optional[Callable[[Tuple[K
7189

7290
@classmethod
7391
def iterate_sim_coll(
74-
cls,
75-
collection: immutables.Map[K, V],
76-
filter_function: Optional[Callable[[V], bool]] = None,
77-
sort_key: Optional[Callable] = None
92+
cls,
93+
collection: immutables.Map[K, V],
94+
filter_function: Optional[Callable[[V], bool]] = None,
95+
sort_key: Optional[Callable] = None,
7896
) -> Tuple[V, ...]:
7997
"""
8098
helper to iterate through a collection on the SimulationState with optional
@@ -89,14 +107,13 @@ def iterate_sim_coll(
89107
:return: _description_
90108
:rtype: Tuple[V, ...]
91109
"""
92-
93-
vals = DictOps.iterate_vals(collection, sort_key)
110+
111+
vals = DictOps.iterate_vals(collection, sort_key)
94112
if filter_function:
95113
return tuple(filter(filter_function, vals))
96114
else:
97115
return vals
98116

99-
100117
@classmethod
101118
def add_to_dict(cls, xs: immutables.Map[K, V], obj_id: K, obj: V) -> immutables.Map[K, V]:
102119
"""

‎tests/test_run_cosim.py

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010

1111
class TestRunCosim(TestCase):
12-
1312
def test_load_and_run_denver(self):
1413
# read scenario
1514
sim = mock_sim()

‎tests/test_simulationstate.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -632,9 +632,7 @@ def test_get_bases(self):
632632
)
633633
)
634634

635-
sorted_bases = sim.get_bases(
636-
sort_key=lambda b: -b.total_stalls
637-
)
635+
sorted_bases = sim.get_bases(sort_key=lambda b: -b.total_stalls)
638636

639637
self.assertEqual(sorted_bases[0].id, "b2", "base 2 has the most stalls")
640638

0 commit comments

Comments
 (0)
Please sign in to comment.