Skip to content

Monitor

Bases: Entity, ABC

Source code in PyCloudSim\monitor\__init__.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
class Monitor(Entity, ABC):
    def __init__(
        self,
        label: str,
        sample_period: int | float | Callable[..., int] | Callable[..., float] = 0.1,
    ) -> None:
        """Base class for all monitors

        Args:
            label (str): the short name of the monitor.
            sample_period (int | float | Callable[..., int] | Callable[..., float], optional): the sample period. Defaults to 0.1.
        """
        super().__init__(label=label, create_at=0)

        if callable(sample_period):
            self._sample_period = sample_period()
        else:
            self._sample_period = sample_period

    def on_creation(self):
        @self.continuous_event(
            at=simulation.now,
            interval=self._sample_period,
            duration=inf,
            label=f"{self.label} Observer",
        )
        def _observe():
            self.on_observation()

    def on_termination(self):
        return super().on_termination()

    def on_destruction(self):
        return super().on_destruction()

    @abstractmethod
    def on_observation(self, *arg, **kwargs):
        """The method to be called at each observation/sample."""
        pass

    @property
    def sample_period(self):
        """Return the sample period of the monitor."""
        return self._sample_period

sample_period property

Return the sample period of the monitor.

__init__(label, sample_period=0.1)

Base class for all monitors

Parameters:

Name Type Description Default
label str

the short name of the monitor.

required
sample_period int | float | Callable[..., int] | Callable[..., float]

the sample period. Defaults to 0.1.

0.1
Source code in PyCloudSim\monitor\__init__.py
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
def __init__(
    self,
    label: str,
    sample_period: int | float | Callable[..., int] | Callable[..., float] = 0.1,
) -> None:
    """Base class for all monitors

    Args:
        label (str): the short name of the monitor.
        sample_period (int | float | Callable[..., int] | Callable[..., float], optional): the sample period. Defaults to 0.1.
    """
    super().__init__(label=label, create_at=0)

    if callable(sample_period):
        self._sample_period = sample_period()
    else:
        self._sample_period = sample_period

on_observation(*arg, **kwargs) abstractmethod

The method to be called at each observation/sample.

Source code in PyCloudSim\monitor\__init__.py
47
48
49
50
@abstractmethod
def on_observation(self, *arg, **kwargs):
    """The method to be called at each observation/sample."""
    pass