From 3b5df2a0a7ad3d03b6e78e107cd18510db9ed24d Mon Sep 17 00:00:00 2001 From: Javier Date: Thu, 25 Jan 2024 10:10:05 +0000 Subject: [PATCH] Split `FlowerContext` into `Message` and `Context` (#2851) --- src/py/flwr/common/context.py | 38 +++++++++++++++++++ .../common/{flowercontext.py => message.py} | 25 +++--------- 2 files changed, 44 insertions(+), 19 deletions(-) create mode 100644 src/py/flwr/common/context.py rename src/py/flwr/common/{flowercontext.py => message.py} (63%) diff --git a/src/py/flwr/common/context.py b/src/py/flwr/common/context.py new file mode 100644 index 000000000000..ad859d4c8407 --- /dev/null +++ b/src/py/flwr/common/context.py @@ -0,0 +1,38 @@ +# 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. +# ============================================================================== +"""Context.""" + + +from dataclasses import dataclass + +from .recordset import RecordSet + + +@dataclass +class Context: + """State of your run. + + Parameters + ---------- + state : RecordSet + Holds records added by the entity in a given run and that will stay local. + This means that the data it holds will never leave the system it's running from. + This can be used as an intermediate storage or scratchpad when + executing middleware layers. It can also be used as a memory to access + at different points during the lifecycle of this entity (e.g. across + multiple rounds) + """ + + state: RecordSet diff --git a/src/py/flwr/common/flowercontext.py b/src/py/flwr/common/message.py similarity index 63% rename from src/py/flwr/common/flowercontext.py rename to src/py/flwr/common/message.py index 6e26d93bfe9a..f693d8e27bc3 100644 --- a/src/py/flwr/common/flowercontext.py +++ b/src/py/flwr/common/message.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # ============================================================================== -"""FlowerContext and Metadata.""" +"""Message.""" from dataclasses import dataclass @@ -48,30 +48,17 @@ class Metadata: @dataclass -class FlowerContext: +class Message: """State of your application from the viewpoint of the entity using it. Parameters ---------- - in_message : RecordSet - Holds records sent by another entity (e.g. sent by the server-side - logic to a client, or vice-versa) - out_message : RecordSet - Holds records added by the current entity. This `RecordSet` will - be sent out (e.g. back to the server-side for aggregation of - parameter, or to the client to perform a certain task) - local : RecordSet - Holds record added by the current entity and that will stay local. - This means that the data it holds will never leave the system it's running from. - This can be used as an intermediate storage or scratchpad when - executing middleware layers. It can also be used as a memory to access - at different points during the lifecycle of this entity (e.g. across - multiple rounds) metadata : Metadata A dataclass including information about the task to be executed. + message : RecordSet + Holds records either sent by another entity (e.g. sent by the server-side + logic to a client, or vice-versa) or that will be sent to it. """ - in_message: RecordSet - out_message: RecordSet - local: RecordSet metadata: Metadata + message: RecordSet