# Copyright (c) 2021, 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 ABC, abstractmethod
from .ctx import ProvisionContext
from .entity import Project
[docs]
class Builder(ABC):
"""Abstract base class for FL startup kit builders.
A Builder is responsible for generating configuration or content
used during federated learning provisioning. Builders participate in
a three-phase lifecycle:
1. `initialize(project, ctx)` – Prepare any resources or context needed for the build.
2. `build(project, ctx)` – Perform the core build logic, modifying the context.
3. `finalize(project, ctx)` – Clean up, validate, or finalize build outputs.
All builders registered in a provision workflow are executed in sequence.
The `finalize` phase is executed **in reverse order** from the other phases. This
allows builders to finalize or clean up in a specific sequence when multiple builders
are involved.
"""
[docs]
def initialize(self, project: Project, ctx: ProvisionContext):
"""Prepare the builder with any necessary pre-processing.
Args:
project (Project): The project to be provisioned.
ctx (ProvisionContext): Context shared across builders.
"""
pass
[docs]
def build(self, project: Project, ctx: ProvisionContext):
"""Execute the main build logic for this builder.
Args:
project (Project): The project to be provisioned.
ctx (ProvisionContext): Context shared across builders.
"""
pass
[docs]
def finalize(self, project: Project, ctx: ProvisionContext):
"""Finalize the build process and perform any cleanup.
Args:
project (Project): The project to be provisioned.
ctx (ProvisionContext): Context shared across builders.
"""
pass
[docs]
class Packager(ABC):
"""Packager is responsible for packaging the generated startup kits for each participant after the kits have
been generated by the builders.
The packager, if specified, is called as the last step of the provision process.
"""
[docs]
@abstractmethod
def package(self, project: Project, ctx: ProvisionContext):
"""Package the generated startup kits for release.
Args:
project: the project being provisioned
ctx: the provision context object
Returns: None
"""
pass