Exemplo n.º 1
0
def _record_heartbeat(trial_id: int, storage: storages.BaseStorage, stop_event: Event) -> None:
    heartbeat_interval = storage.get_heartbeat_interval()
    assert heartbeat_interval is not None
    while True:
        storage.record_heartbeat(trial_id)
        if stop_event.wait(timeout=heartbeat_interval):
            return
Exemplo n.º 2
0
def is_heartbeat_enabled(storage: BaseStorage) -> bool:
    """Check whether the storage enables the heartbeat.

    Returns:
        :obj:`True` if the storage also inherits :class:`~optuna.storages._heartbeat.BaseHeartbeat`
        and the return value of :meth:`~optuna.storages.BaseStorage.get_heartbeat_interval` is an
        integer, otherwise :obj:`False`.
    """
    return isinstance(
        storage,
        BaseHeartbeat) and storage.get_heartbeat_interval() is not None