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

Introduce base Backend #2994

Merged
merged 29 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
4c83a5e
init
jafermarq Feb 21, 2024
a85db40
base backend
jafermarq Feb 21, 2024
b770312
update
jafermarq Feb 21, 2024
b9c6455
update docstrings
jafermarq Feb 21, 2024
cd48539
minor fixes
jafermarq Feb 21, 2024
2791163
updates
jafermarq Feb 22, 2024
4ca33ec
backend-config should contain value types
jafermarq Feb 22, 2024
1b6564a
fix
jafermarq Feb 22, 2024
bad8727
w/ previous
jafermarq Feb 22, 2024
a68172f
fix
jafermarq Feb 22, 2024
e2b072e
Merge branch 'vce-flee-api' into vce-fleet-api-backends
jafermarq Feb 22, 2024
6881866
fix for json.loads
jafermarq Feb 22, 2024
935e333
keep backend-config as json string
jafermarq Feb 22, 2024
704d667
merged
jafermarq Feb 22, 2024
17e3089
Merge branch 'main' into vce-flee-api
danieljanes Feb 22, 2024
0e02b05
moved import
jafermarq Feb 22, 2024
b77e4e8
Merge branch 'vce-flee-api' into vce-fleet-api-backends
jafermarq Feb 22, 2024
fd67f22
Apply suggestions from code review
jafermarq Feb 22, 2024
cf004d8
renamed vars; exporting
jafermarq Feb 22, 2024
f10a6ca
Merge branch 'vce-flee-api' into vce-fleet-api-backends
jafermarq Feb 22, 2024
d097bcd
Merge branch 'main' into vce-fleet-api-backends
jafermarq Feb 22, 2024
2ccf612
Merge branch 'main' into vce-fleet-api-backends
jafermarq Feb 22, 2024
f5488eb
Merge branch 'main' into vce-fleet-api-backends
jafermarq Feb 23, 2024
5401cff
Update src/py/flwr/server/superlink/fleet/vce/backend/__init__.py
danieljanes Feb 23, 2024
c4a659b
Update src/py/flwr/server/superlink/fleet/vce/backend/backend.py
danieljanes Feb 23, 2024
8b70316
Update src/py/flwr/server/superlink/fleet/vce/backend/backend.py
danieljanes Feb 23, 2024
277af9d
Update src/py/flwr/server/superlink/fleet/vce/backend/backend.py
danieljanes Feb 23, 2024
8ab5e68
Merge branch 'main' into vce-fleet-api-backends
danieljanes Feb 23, 2024
1ac487e
format
jafermarq Feb 23, 2024
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
22 changes: 22 additions & 0 deletions src/py/flwr/server/superlink/fleet/vce/backend/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2024 Flower Labs GmbH. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Simulation Engine Backends."""

from .backend import Backend, BackendConfig

__all__ = [
"Backend",
"BackendConfig",
]
60 changes: 60 additions & 0 deletions src/py/flwr/server/superlink/fleet/vce/backend/backend.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Copyright 2024 Flower Labs GmbH. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Generic Backend class for Fleet API using the Simulation Engine."""


from abc import ABC, abstractmethod
from typing import Callable, Dict, Tuple

from flwr.client.clientapp import ClientApp
from flwr.common.context import Context
from flwr.common.message import Message
from flwr.common.typing import ConfigsRecordValues

BackendConfig = Dict[str, Dict[str, ConfigsRecordValues]]


class Backend(ABC):
"""Abstract base class for a Simulation Engine Backend."""

@abstractmethod
async def build(self) -> None:
"""Build backend asynchronously.

Different components need to be in place before workers in a backend are ready
to accept jobs. When this method finishes executing, the backend should be fully
ready to run jobs.
"""

@property
def num_workers(self) -> int:
"""Return number of workers in the backend.

This is the number of TaskIns that can be processed concurrently.
"""
return 0

@abstractmethod
def is_worker_idle(self) -> bool:
"""Report whether a backend worker is idle and can therefore run a ClientApp."""

@abstractmethod
async def process_message(
self,
app: Callable[[], ClientApp],
message: Message,
context: Context,
) -> Tuple[Message, Context]:
"""Submit a job to the backend."""