Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(framework) Wrap SimulationIo stub with RetryInvoker #4649

Merged
merged 6 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/py/flwr/common/retry_invoker.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from flwr.common.typing import RunNotRunningException
from flwr.proto.clientappio_pb2_grpc import ClientAppIoStub
from flwr.proto.serverappio_pb2_grpc import ServerAppIoStub
from flwr.proto.simulationio_pb2_grpc import SimulationIoStub


def exponential(
Expand Down Expand Up @@ -365,7 +366,8 @@ def _should_giveup_fn(e: Exception) -> bool:


def _wrap_stub(
stub: Union[ServerAppIoStub, ClientAppIoStub], retry_invoker: RetryInvoker
stub: Union[ServerAppIoStub, ClientAppIoStub, SimulationIoStub],
retry_invoker: RetryInvoker,
) -> None:
"""Wrap a gRPC stub with a retry invoker."""

Expand Down
3 changes: 3 additions & 0 deletions src/py/flwr/simulation/simulationio_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from flwr.common.constant import SIMULATIONIO_API_DEFAULT_CLIENT_ADDRESS
from flwr.common.grpc import create_channel
from flwr.common.logger import log
from flwr.common.retry_invoker import _make_simple_grpc_retry_invoker, _wrap_stub
from flwr.proto.simulationio_pb2_grpc import SimulationIoStub # pylint: disable=E0611


Expand All @@ -48,6 +49,7 @@ def __init__( # pylint: disable=too-many-arguments
self._cert = root_certificates
self._grpc_stub: Optional[SimulationIoStub] = None
self._channel: Optional[grpc.Channel] = None
self._retry_invoker = _make_simple_grpc_retry_invoker()

@property
def _is_connected(self) -> bool:
Expand All @@ -72,6 +74,7 @@ def _connect(self) -> None:
root_certificates=self._cert,
)
self._grpc_stub = SimulationIoStub(self._channel)
_wrap_stub(self._grpc_stub, self._retry_invoker)
log(DEBUG, "[SimulationIO] Connected to %s", self._addr)

def _disconnect(self) -> None:
Expand Down