Source code for nvflare.apis.job_launcher_spec

# Copyright (c) 2024, 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.
from abc import abstractmethod

from nvflare.apis.fl_component import FLComponent
from nvflare.apis.fl_constant import FLContextKey
from nvflare.apis.fl_context import FLContext
from nvflare.fuel.common.exit_codes import ProcessExitCode


[docs] class JobReturnCode(ProcessExitCode): SUCCESS = 0 EXECUTION_ERROR = 1 ABORTED = 9 UNKNOWN = 127
[docs] def add_launcher(launcher, fl_ctx: FLContext): job_launcher: list = fl_ctx.get_prop(FLContextKey.JOB_LAUNCHER, []) job_launcher.append(launcher) fl_ctx.set_prop(FLContextKey.JOB_LAUNCHER, job_launcher, private=True, sticky=False)
[docs] class JobHandleSpec:
[docs] @abstractmethod def terminate(self): """To terminate the job run. Returns: the job run return code. """ raise NotImplementedError()
[docs] @abstractmethod def poll(self): """To get the return code of the job run. Returns: return_code """ raise NotImplementedError()
[docs] @abstractmethod def wait(self): """To wait until the job run complete. Returns: returns until the job run complete. """ raise NotImplementedError()
[docs] class JobLauncherSpec(FLComponent):
[docs] @abstractmethod def launch_job(self, job_meta: dict, fl_ctx: FLContext) -> JobHandleSpec: """To launch a job run. Args: job_meta: job meta data fl_ctx: FLContext Returns: boolean to indicates the job launch success or fail. """ raise NotImplementedError()