Skip to content

Commit

Permalink
reorg edge packages
Browse files Browse the repository at this point in the history
  • Loading branch information
yanchengnv committed Feb 21, 2025
1 parent f66e76c commit 063dc93
Show file tree
Hide file tree
Showing 15 changed files with 91 additions and 20 deletions.
2 changes: 0 additions & 2 deletions nvflare/apis/event_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,3 @@ class EventType(object):

TASK_RESULT_RECEIVED = "_task_result_received"
TASK_ASSIGNMENT_SENT = "_task_assignment_sent"
EDGE_REQUEST_RECEIVED = "_edge_request_received"
EDGE_JOB_REQUEST_RECEIVED = "_edge_job_request_received"
13 changes: 13 additions & 0 deletions nvflare/edge/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) 2025, NVIDIA CORPORATION. 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.
13 changes: 13 additions & 0 deletions nvflare/edge/aggregators/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) 2025, NVIDIA CORPORATION. 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.
5 changes: 5 additions & 0 deletions nvflare/apis/edge_def.py → nvflare/edge/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,8 @@ class EdgeContextKey:
EDGE_CAPABILITIES = "__edge_capabilities__"
REQUEST_FROM_EDGE = "__request_from_edge__"
REPLY_TO_EDGE = "__reply_to_edge__"


class EventType:
EDGE_REQUEST_RECEIVED = "_edge_request_received"
EDGE_JOB_REQUEST_RECEIVED = "_edge_job_request_received"
13 changes: 13 additions & 0 deletions nvflare/edge/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) 2025, NVIDIA CORPORATION. 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.
File renamed without changes.
13 changes: 13 additions & 0 deletions nvflare/edge/executors/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) 2025, NVIDIA CORPORATION. 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.
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

from nvflare.apis.fl_context import FLContext
from nvflare.apis.shareable import ReturnCode, Shareable, make_reply
from nvflare.app_common.executors.ete import EdgeTaskExecutor
from nvflare.edge.executors.ete import EdgeTaskExecutor


class EdgeSurvey(EdgeTaskExecutor):
class EdgeSurveyExecutor(EdgeTaskExecutor):
"""This executor is for test purpose only. It is to be used as the "learner" for the
HierarchicalAggregationManager.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
from abc import abstractmethod
from typing import Any

from nvflare.apis.event_type import EventType
from nvflare.apis.executor import Executor
from nvflare.apis.fl_constant import FLContextKey
from nvflare.apis.fl_context import FLContext
from nvflare.apis.shareable import ReturnCode, Shareable, make_reply
from nvflare.apis.signal import Signal
from nvflare.edge.constants import EventType as EdgeEventType
from nvflare.fuel.f3.message import Message as CellMessage
from nvflare.security.logging import secure_format_exception

Expand All @@ -35,7 +35,7 @@ def __init__(self):
Executor.__init__(self)
self.current_task = None

self.register_event_handler(EventType.EDGE_REQUEST_RECEIVED, self._handle_edge_request)
self.register_event_handler(EdgeEventType.EDGE_REQUEST_RECEIVED, self._handle_edge_request)

@abstractmethod
def process_edge_request(self, request: Any, fl_ctx: FLContext) -> Any:
Expand Down
5 changes: 2 additions & 3 deletions nvflare/lighter/tree_prov.py → nvflare/edge/tree_prov.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@

import argparse

from nvflare.lighter.entity import Participant, ParticipantType, Project
from nvflare.lighter.impl.cert import CertBuilder
from nvflare.lighter.impl.signature import SignatureBuilder
from nvflare.lighter.impl.static_file import StaticFileBuilder
from nvflare.lighter.impl.workspace import WorkspaceBuilder

from .entity import Participant, ParticipantType, Project
from .provisioner import Provisioner
from nvflare.lighter.provisioner import Provisioner


def _new_participant(name: str, ptype: str, props: dict) -> Participant:
Expand Down
13 changes: 13 additions & 0 deletions nvflare/edge/widgets/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) 2025, NVIDIA CORPORATION. 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.
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
import threading
from random import randrange

from nvflare.apis.edge_def import EdgeContextKey, EdgeProtoKey
from nvflare.apis.edge_def import Status as EdgeStatus
from nvflare.apis.event_type import EventType
from nvflare.apis.fl_constant import FLContextKey
from nvflare.apis.fl_context import FLContext
from nvflare.apis.job_def import JobMetaKey
from nvflare.edge.constants import EdgeContextKey, EdgeProtoKey
from nvflare.edge.constants import EventType as EdgeEventType
from nvflare.edge.constants import Status as EdgeStatus
from nvflare.fuel.f3.cellnet.defs import CellChannel, MessageHeaderKey
from nvflare.fuel.f3.cellnet.utils import new_cell_message
from nvflare.fuel.f3.message import Message as CellMessage
Expand All @@ -46,11 +47,11 @@ def __init__(self, request_timeout: float = 2.0):
self._handle_job_done,
)
self.register_event_handler(
EventType.EDGE_JOB_REQUEST_RECEIVED,
EdgeEventType.EDGE_JOB_REQUEST_RECEIVED,
self._handle_edge_job_request,
)
self.register_event_handler(
EventType.EDGE_REQUEST_RECEIVED,
EdgeEventType.EDGE_REQUEST_RECEIVED,
self._handle_edge_request,
)
self.logger.info("EdgeTaskDispatcher created!")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
import time
import uuid

from nvflare.apis.edge_def import EdgeContextKey, EdgeProtoKey, Status
from nvflare.apis.event_type import EventType
from nvflare.apis.fl_context import FLContext
from nvflare.apis.signal import Signal
from nvflare.edge.constants import EdgeContextKey, EdgeProtoKey
from nvflare.edge.constants import EventType as EdgeEventType
from nvflare.edge.constants import Status
from nvflare.widgets.widget import Widget


Expand Down Expand Up @@ -63,7 +65,7 @@ def _generate_tasks(self):
assert isinstance(fl_ctx, FLContext)
if not self.job_id:
fl_ctx.set_prop(EdgeContextKey.EDGE_CAPABILITIES, caps, private=True, sticky=False)
self.fire_event(EventType.EDGE_JOB_REQUEST_RECEIVED, fl_ctx)
self.fire_event(EdgeEventType.EDGE_JOB_REQUEST_RECEIVED, fl_ctx)
result = fl_ctx.get_prop(EdgeContextKey.REPLY_TO_EDGE)
if result:
assert isinstance(result, dict)
Expand All @@ -73,15 +75,15 @@ def _generate_tasks(self):
if job_id:
self.job_id = job_id
else:
self.logger.error(f"no result from ETD for event {EventType.EDGE_JOB_REQUEST_RECEIVED}")
self.logger.error(f"no result from ETD for event {EdgeEventType.EDGE_JOB_REQUEST_RECEIVED}")
else:
task = self._make_task()
fl_ctx.set_prop(EdgeContextKey.JOB_ID, self.job_id, sticky=False, private=True)
fl_ctx.set_prop(EdgeContextKey.REQUEST_FROM_EDGE, task, sticky=False, private=True)
self.fire_event(EventType.EDGE_REQUEST_RECEIVED, fl_ctx)
self.fire_event(EdgeEventType.EDGE_REQUEST_RECEIVED, fl_ctx)
result = fl_ctx.get_prop(EdgeContextKey.REPLY_TO_EDGE)
if not result:
self.logger.error(f"no result from ETD for event {EventType.EDGE_REQUEST_RECEIVED}")
self.logger.error(f"no result from ETD for event {EdgeEventType.EDGE_REQUEST_RECEIVED}")
else:
status = result[EdgeProtoKey.STATUS]
edge_reply = result[EdgeProtoKey.DATA]
Expand Down
5 changes: 3 additions & 2 deletions nvflare/private/fed/client/client_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import threading
import time

from nvflare.apis.edge_def import Status as EdgeStatus
from nvflare.apis.event_type import EventType
from nvflare.apis.executor import Executor
from nvflare.apis.fl_component import FLComponent
Expand All @@ -27,6 +26,8 @@
from nvflare.apis.utils.fl_context_utils import add_job_audit_event
from nvflare.apis.utils.reliable_message import ReliableMessage
from nvflare.apis.utils.task_utils import apply_filters
from nvflare.edge.constants import EventType as EdgeEventType
from nvflare.edge.constants import Status as EdgeStatus
from nvflare.fuel.f3.cellnet.defs import CellChannel
from nvflare.fuel.f3.cellnet.fqcn import FQCN
from nvflare.fuel.f3.cellnet.utils import make_reply as make_cell_reply
Expand Down Expand Up @@ -174,7 +175,7 @@ def _receive_edge_request(self, request: CellMessage):
try:
# place the cell message into fl_ctx in case it's needed by process_edge_request.
fl_ctx.set_prop(FLContextKey.CELL_MESSAGE, request, private=True, sticky=False)
self.engine.fire_event(EventType.EDGE_REQUEST_RECEIVED, fl_ctx)
self.engine.fire_event(EdgeEventType.EDGE_REQUEST_RECEIVED, fl_ctx)
exception = fl_ctx.get_prop(FLContextKey.EXCEPTIONS)
if exception:
return make_cell_reply(EdgeStatus.PROCESS_EXCEPTION)
Expand Down

0 comments on commit 063dc93

Please sign in to comment.