Skip to content

Information Functions

Protocol

InformationFunction

Bases: Protocol

Source code in gyozas/informations/__init__.py
@runtime_checkable
class InformationFunction(Protocol):
    def reset(self, model: Model) -> None: ...
    def extract(self, model: Model, done: bool) -> Any: ...

Empty

Empty

Information function that returns no additional information.

Source code in gyozas/informations/empty.py
class Empty:
    """Information function that returns no additional information."""

    def reset(self, model: Model) -> None:
        pass

    def extract(self, model: Model, done: bool) -> None:
        pass

TimeSinceLastStep

TimeSinceLastStep

Information function that returns the wall-clock time delta since the last step.

Source code in gyozas/informations/time_since_last_step.py
class TimeSinceLastStep:
    """Information function that returns the wall-clock time delta since the last step."""

    def __init__(self) -> None:
        self.previous_timestamp = time.monotonic()

    def reset(self, model: Model) -> None:
        self.previous_timestamp = time.monotonic()

    def extract(self, model: Model, done: bool) -> float:
        current_timestamp = time.monotonic()
        delta = current_timestamp - self.previous_timestamp
        self.previous_timestamp = current_timestamp
        return delta