Skip to content

unaiverse.clock

What this module does 🟡

Provides a network-synchronized logical clock that maps wall-clock time to discrete cycles, supporting slowed-down execution and server time offset correction.

clock

█████ █████ ██████ █████ █████ █████ █████ ██████████ ███████████ █████████ ██████████ ░░███ ░░███ ░░██████ ░░███ ░░███ ░░███ ░░███ ░░███░░░░░█░░███░░░░░███ ███░░░░░███░░███░░░░░█ ░███ ░███ ░███░███ ░███ ██████ ░███ ░███ ░███ ░███ █ ░ ░███ ░███ ░███ ░░░ ░███ █ ░ ░███ ░███ ░███░░███░███ ░░░░░███ ░███ ░███ ░███ ░██████ ░██████████ ░░█████████ ░██████ ░███ ░███ ░███ ░░██████ ███████ ░███ ░░███ ███ ░███░░█ ░███░░░░░███ ░░░░░░░░███ ░███░░█ ░███ ░███ ░███ ░░█████ ███░░███ ░███ ░░░█████░ ░███ ░ █ ░███ ░███ ███ ░███ ░███ ░ █ ░░████████ █████ ░░█████░░████████ █████ ░░███ ██████████ █████ █████░░█████████ ██████████ ░░░░░░░░ ░░░░░ ░░░░░ ░░░░░░░░ ░░░░░ ░░░ ░░░░░░░░░░ ░░░░░ ░░░░░ ░░░░░░░░░ ░░░░░░░░░░ A Collectionless AI Project (https://collectionless.ai) Registration/Login: https://unaiverse.io Code Repositories: https://github.com/collectionlessai/ Main Developers: Stefano Melacci (Project Leader), Christian Di Maio, Tommaso Guidi

clock module-attribute

clock = Clock()

Clock

Clock()

A lazy-initializing singleton wrapper around _Clock.

Clock acts as a transparent proxy: attribute accesses on a Clock instance are forwarded to the underlying _Clock instance. If no _Clock has been configured yet, one is created automatically on the first attribute access using the current UTC time as the synchronization reference, so callers do not need to call create explicitly.

The module-level clock object is the single shared instance of this class. The rest of the framework imports and uses clock directly rather than instantiating _Clock itself. Providing a single shared clock ensures that all components agree on cycle boundaries and synchronized timestamps.

Initialize the Clock wrapper with no underlying _Clock instance.

The internal __instance slot is set to None. The first attribute access after construction will trigger lazy initialization via __getattr__, creating a _Clock with the current UTC time as the reference unless create or set is called first.

Source code in unaiverse/clock.py
def __init__(self):
    """Initialize the Clock wrapper with no underlying ``_Clock`` instance.

    The internal ``__instance`` slot is set to ``None``. The first attribute access
    after construction will trigger lazy initialization via ``__getattr__``, creating
    a ``_Clock`` with the current UTC time as the reference unless ``create`` or
    ``set`` is called first.
    """
    self.__instance = None

set

set(existing_clock)

Attach an already-constructed _Clock instance to this wrapper.

Replaces whatever _Clock (if any) is currently held by this wrapper. All subsequent attribute accesses will be forwarded to existing_clock. This is useful when a _Clock has been created externally (for example, with a specific synchronization timestamp) and needs to be shared via the module-level clock singleton.

Parameters:

Name Type Description Default
existing_clock

A _Clock instance to use as the underlying implementation.

required
Source code in unaiverse/clock.py
def set(self, existing_clock):
    """Attach an already-constructed ``_Clock`` instance to this wrapper.

    Replaces whatever ``_Clock`` (if any) is currently held by this wrapper. All
    subsequent attribute accesses will be forwarded to ``existing_clock``. This is
    useful when a ``_Clock`` has been created externally (for example, with a
    specific synchronization timestamp) and needs to be shared via the module-level
    ``clock`` singleton.

    Args:
        existing_clock: A ``_Clock`` instance to use as the underlying implementation.
    """
    self.__instance = existing_clock

create

create(*args, **kwargs)

Create and attach a new _Clock instance, replacing any existing one.

All positional and keyword arguments are forwarded verbatim to the _Clock constructor. After this call, the new instance becomes the target of all subsequent attribute accesses via __getattr__. See _Clock.__init__ for the full parameter documentation.

Parameters:

Name Type Description Default
*args

Positional arguments forwarded to _Clock.__init__.

()
**kwargs

Keyword arguments forwarded to _Clock.__init__.

{}

Raises:

Type Description
ValueError

Propagated from _Clock.__init__ if the initial synchronized time cannot be obtained from any available source.

Source code in unaiverse/clock.py
def create(self, *args, **kwargs):
    """Create and attach a new ``_Clock`` instance, replacing any existing one.

    All positional and keyword arguments are forwarded verbatim to the ``_Clock``
    constructor. After this call, the new instance becomes the target of all
    subsequent attribute accesses via ``__getattr__``. See ``_Clock.__init__`` for
    the full parameter documentation.

    Args:
        *args: Positional arguments forwarded to ``_Clock.__init__``.
        **kwargs: Keyword arguments forwarded to ``_Clock.__init__``.

    Raises:
        ValueError: Propagated from ``_Clock.__init__`` if the initial synchronized
            time cannot be obtained from any available source.
    """
    self.__instance = _Clock(*args, **kwargs)