Skip to content

Commit

Permalink
Updating NamedEntity and Monitoring resources to assist data gathering.
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesArruda committed Dec 19, 2024
1 parent 5f995c9 commit 11c3d67
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
20 changes: 12 additions & 8 deletions src/upstage_des/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,18 +342,22 @@ def __init_subclass__(
cls,
entity_groups: Iterable[str] | str | None = None,
add_to_entity_groups: bool = True,
skip_classname: bool = False,
) -> None:
if not add_to_entity_groups:
return
if entity_groups is None:
entity_groups = [cls.__name__]
else:
if isinstance(entity_groups, str):
entity_groups = [entity_groups]
entity_groups = list(entity_groups) + [cls.__name__]

entity_group = [cls.__name__] if entity_groups is None else entity_groups
entity_group = list(set(entity_group))
entity_groups = [] if entity_groups is None else entity_groups

if isinstance(entity_groups, str):
entity_groups = [entity_groups]

entity_groups = list(entity_groups)

if cls.__name__ not in entity_groups and not skip_classname:
entity_groups.append(cls.__name__)

entity_group = list(set(entity_groups))
old_init = cls.__init__

@wraps(old_init)
Expand Down
1 change: 1 addition & 0 deletions src/upstage_des/data_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Utilities for gathering all recorded simulation data."""
24 changes: 18 additions & 6 deletions src/upstage_des/resources/monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from simpy.resources.container import ContainerGet, ContainerPut
from simpy.resources.store import FilterStoreGet, StoreGet, StorePut

from upstage_des.base import NamedUpstageEntity

from .container import ContinuousContainer
from .reserve import ReserveContainer
from .sorted import SortedFilterStore, _SortedFilterStoreGet
Expand All @@ -27,7 +29,9 @@
RECORDER_FUNC = Callable[[list[Any]], int]


class SelfMonitoringStore(Store):
class SelfMonitoringStore(
Store, NamedUpstageEntity, entity_groups=["_monitored"], skip_classname=True
):
"""A self-monitoring version of the SimPy Store."""

def __init__(
Expand Down Expand Up @@ -76,7 +80,9 @@ def _do_get(self, event: StoreGet) -> None:
self._record("get")


class SelfMonitoringFilterStore(FilterStore):
class SelfMonitoringFilterStore(
FilterStore, NamedUpstageEntity, entity_groups=["_monitored"], skip_classname=True
):
"""A self-monitoring version of the SimPy FilterStore."""

def __init__(
Expand Down Expand Up @@ -125,7 +131,9 @@ def _do_get(self, event: FilterStoreGet) -> None: # type: ignore[override]
self._record("get")


class SelfMonitoringContainer(Container):
class SelfMonitoringContainer(
Container, NamedUpstageEntity, entity_groups=["_monitored"], skip_classname=True
):
"""A self-monitoring version of the SimPy Container."""

def __init__(self, env: Environment, capacity: float = float("inf"), init: float = 0.0) -> None:
Expand Down Expand Up @@ -163,7 +171,9 @@ def _do_get(self, event: ContainerGet) -> None:
self._record()


class SelfMonitoringContinuousContainer(ContinuousContainer):
class SelfMonitoringContinuousContainer(
ContinuousContainer, NamedUpstageEntity, entity_groups=["_monitored"], skip_classname=True
):
"""A self-monitoring version of the Continuous Container."""

def __init__(
Expand Down Expand Up @@ -202,7 +212,7 @@ def _set_level(self) -> float:
return amt


class SelfMonitoringSortedFilterStore(SortedFilterStore, SelfMonitoringStore):
class SelfMonitoringSortedFilterStore(SortedFilterStore, SelfMonitoringStore, skip_classname=True):
"""A self-monitoring version of the SortedFilterStore."""

def _do_get(self, event: _SortedFilterStoreGet) -> bool: # type: ignore [override]
Expand All @@ -212,7 +222,9 @@ def _do_get(self, event: _SortedFilterStoreGet) -> bool: # type: ignore [overri
return ans


class SelfMonitoringReserveContainer(ReserveContainer):
class SelfMonitoringReserveContainer(
ReserveContainer, NamedUpstageEntity, entity_groups=["_monitored"], skip_classname=True
):
"""A self-monitoring version of the ReserveContainer."""

def __init__(self, env: Environment, capacity: float = float("inf"), init: float = 0.0) -> None:
Expand Down

0 comments on commit 11c3d67

Please sign in to comment.