Skip to content

fl_server_ai.notification.training

Modules:

Name Description
finished
model_test
round_start
start
swag
training

Classes:

Name Description
TrainingFinishedNotification

Notification that a training has finished.

TrainingModelTestNotification

Notification for the start of a model test round.

TrainingNotification

Abstract base class for training notifications.

TrainingRoundStartNotification

Notification for the start of a training round.

TrainingSWAGRoundStartNotification

Notification for the start of a SWAG training round.

TrainingStartNotification

Class representing a notification for the start of a training.

Attributes

__all__ module-attribute

__all__ = ['TrainingModelTestNotification', 'TrainingNotification', 'TrainingFinishedNotification', 'TrainingStartNotification', 'TrainingSWAGRoundStartNotification', 'TrainingRoundStartNotification']

Classes

TrainingFinishedNotification dataclass

Bases: TrainingNotification['TrainingFinishedNotification.Body']


              flowchart TD
              fl_server_ai.notification.training.TrainingFinishedNotification[TrainingFinishedNotification]
              fl_server_ai.notification.training.training.TrainingNotification[TrainingNotification]
              fl_server_ai.notification.notification.Notification[Notification]
              fl_server_ai.notification.serializable.Serializable[Serializable]

                              fl_server_ai.notification.training.training.TrainingNotification --> fl_server_ai.notification.training.TrainingFinishedNotification
                                fl_server_ai.notification.notification.Notification --> fl_server_ai.notification.training.training.TrainingNotification
                                fl_server_ai.notification.serializable.Serializable --> fl_server_ai.notification.notification.Notification
                




              click fl_server_ai.notification.training.TrainingFinishedNotification href "" "fl_server_ai.notification.training.TrainingFinishedNotification"
              click fl_server_ai.notification.training.training.TrainingNotification href "" "fl_server_ai.notification.training.training.TrainingNotification"
              click fl_server_ai.notification.notification.Notification href "" "fl_server_ai.notification.notification.Notification"
              click fl_server_ai.notification.serializable.Serializable href "" "fl_server_ai.notification.serializable.Serializable"
            

Notification that a training has finished.

Classes:

Name Description
Body

Inner class representing the body of the notification.

Methods:

Name Description
from_training

Create a TrainingFinishedNotification instance from a training object.

Attributes:

Name Type Description
type NotificationType

The type of the notification.

Source code in fl_server_ai/notification/training/finished.py
class TrainingFinishedNotification(TrainingNotification["TrainingFinishedNotification.Body"]):
    """
    Notification that a training has finished.
    """

    type: NotificationType = NotificationType.TRAINING_FINISHED
    """The type of the notification."""

    @dataclass
    class Body(Serializable):
        """
        Inner class representing the body of the notification.
        """
        global_model_uuid: UUID
        """The UUID of the global model."""

    @classmethod
    def from_training(cls, training: TrainingDB):
        """
        Create a `TrainingFinishedNotification` instance from a training object.

        Args:
            training (TrainingDB): The training object to create the notification from.

        Returns:
            TrainingFinishedNotification: The created notification.
        """
        receivers = list(training.participants.all())
        if not receivers.__contains__(training.actor):
            receivers.append(training.actor)
        return cls(
            receivers=receivers,
            body=cls.Body(
                global_model_uuid=training.model.id
            ),
            training_uuid=training.id
        )

Attributes

type class-attribute instance-attribute

The type of the notification.

Classes

Body dataclass

Bases: Serializable


              flowchart TD
              fl_server_ai.notification.training.TrainingFinishedNotification.Body[Body]
              fl_server_ai.notification.serializable.Serializable[Serializable]

                              fl_server_ai.notification.serializable.Serializable --> fl_server_ai.notification.training.TrainingFinishedNotification.Body
                


              click fl_server_ai.notification.training.TrainingFinishedNotification.Body href "" "fl_server_ai.notification.training.TrainingFinishedNotification.Body"
              click fl_server_ai.notification.serializable.Serializable href "" "fl_server_ai.notification.serializable.Serializable"
            

Inner class representing the body of the notification.

Methods:

Name Description
__init__

Attributes:

Name Type Description
global_model_uuid UUID

The UUID of the global model.

Source code in fl_server_ai/notification/training/finished.py
@dataclass
class Body(Serializable):
    """
    Inner class representing the body of the notification.
    """
    global_model_uuid: UUID
    """The UUID of the global model."""
Attributes
global_model_uuid instance-attribute
global_model_uuid: UUID

The UUID of the global model.

Functions
__init__
__init__(global_model_uuid: UUID) -> None

Functions

from_training classmethod
from_training(training: Training)

Create a TrainingFinishedNotification instance from a training object.

Parameters:

Name Type Description Default
training
Training

The training object to create the notification from.

required

Returns:

Name Type Description
TrainingFinishedNotification

The created notification.

Source code in fl_server_ai/notification/training/finished.py
@classmethod
def from_training(cls, training: TrainingDB):
    """
    Create a `TrainingFinishedNotification` instance from a training object.

    Args:
        training (TrainingDB): The training object to create the notification from.

    Returns:
        TrainingFinishedNotification: The created notification.
    """
    receivers = list(training.participants.all())
    if not receivers.__contains__(training.actor):
        receivers.append(training.actor)
    return cls(
        receivers=receivers,
        body=cls.Body(
            global_model_uuid=training.model.id
        ),
        training_uuid=training.id
    )

TrainingModelTestNotification dataclass

Bases: TrainingRoundStartNotification


              flowchart TD
              fl_server_ai.notification.training.TrainingModelTestNotification[TrainingModelTestNotification]
              fl_server_ai.notification.training.round_start.TrainingRoundStartNotification[TrainingRoundStartNotification]
              fl_server_ai.notification.training.training.TrainingNotification[TrainingNotification]
              fl_server_ai.notification.notification.Notification[Notification]
              fl_server_ai.notification.serializable.Serializable[Serializable]

                              fl_server_ai.notification.training.round_start.TrainingRoundStartNotification --> fl_server_ai.notification.training.TrainingModelTestNotification
                                fl_server_ai.notification.training.training.TrainingNotification --> fl_server_ai.notification.training.round_start.TrainingRoundStartNotification
                                fl_server_ai.notification.notification.Notification --> fl_server_ai.notification.training.training.TrainingNotification
                                fl_server_ai.notification.serializable.Serializable --> fl_server_ai.notification.notification.Notification
                





              click fl_server_ai.notification.training.TrainingModelTestNotification href "" "fl_server_ai.notification.training.TrainingModelTestNotification"
              click fl_server_ai.notification.training.round_start.TrainingRoundStartNotification href "" "fl_server_ai.notification.training.round_start.TrainingRoundStartNotification"
              click fl_server_ai.notification.training.training.TrainingNotification href "" "fl_server_ai.notification.training.training.TrainingNotification"
              click fl_server_ai.notification.notification.Notification href "" "fl_server_ai.notification.notification.Notification"
              click fl_server_ai.notification.serializable.Serializable href "" "fl_server_ai.notification.serializable.Serializable"
            

Notification for the start of a model test round.

Attributes:

Name Type Description
type NotificationType

The type of the notification.

Source code in fl_server_ai/notification/training/model_test.py
class TrainingModelTestNotification(TrainingRoundStartNotification):
    """
    Notification for the start of a model test round.
    """

    type: NotificationType = NotificationType.MODEL_TEST_ROUND
    """The type of the notification."""

Attributes

type class-attribute instance-attribute

The type of the notification.

TrainingNotification dataclass

Bases: Generic[TBody], Notification[TBody]


              flowchart TD
              fl_server_ai.notification.training.TrainingNotification[TrainingNotification]
              fl_server_ai.notification.notification.Notification[Notification]
              fl_server_ai.notification.serializable.Serializable[Serializable]

                              fl_server_ai.notification.notification.Notification --> fl_server_ai.notification.training.TrainingNotification
                                fl_server_ai.notification.serializable.Serializable --> fl_server_ai.notification.notification.Notification
                



              click fl_server_ai.notification.training.TrainingNotification href "" "fl_server_ai.notification.training.TrainingNotification"
              click fl_server_ai.notification.notification.Notification href "" "fl_server_ai.notification.notification.Notification"
              click fl_server_ai.notification.serializable.Serializable href "" "fl_server_ai.notification.serializable.Serializable"
            

Abstract base class for training notifications.

Methods:

Name Description
__init__
serialize

Attributes:

Name Type Description
training_uuid UUID

The UUID of the training.

Source code in fl_server_ai/notification/training/training.py
@dataclass
class TrainingNotification(Generic[TBody], Notification[TBody]):
    """
    Abstract base class for training notifications.
    """

    training_uuid: UUID
    """The UUID of the training."""

    def serialize(self) -> dict[str, Any]:
        data = super().serialize()
        data["training_uuid"] = str(self.training_uuid)
        return data

Attributes

training_uuid instance-attribute
training_uuid: UUID

The UUID of the training.

Functions

__init__
__init__(receivers: list[NotificationReceiver], body: TBody, training_uuid: UUID) -> None
serialize
serialize() -> dict[str, Any]
Source code in fl_server_ai/notification/training/training.py
def serialize(self) -> dict[str, Any]:
    data = super().serialize()
    data["training_uuid"] = str(self.training_uuid)
    return data

TrainingRoundStartNotification dataclass

Bases: TrainingNotification['TrainingRoundStartNotification.Body']


              flowchart TD
              fl_server_ai.notification.training.TrainingRoundStartNotification[TrainingRoundStartNotification]
              fl_server_ai.notification.training.training.TrainingNotification[TrainingNotification]
              fl_server_ai.notification.notification.Notification[Notification]
              fl_server_ai.notification.serializable.Serializable[Serializable]

                              fl_server_ai.notification.training.training.TrainingNotification --> fl_server_ai.notification.training.TrainingRoundStartNotification
                                fl_server_ai.notification.notification.Notification --> fl_server_ai.notification.training.training.TrainingNotification
                                fl_server_ai.notification.serializable.Serializable --> fl_server_ai.notification.notification.Notification
                




              click fl_server_ai.notification.training.TrainingRoundStartNotification href "" "fl_server_ai.notification.training.TrainingRoundStartNotification"
              click fl_server_ai.notification.training.training.TrainingNotification href "" "fl_server_ai.notification.training.training.TrainingNotification"
              click fl_server_ai.notification.notification.Notification href "" "fl_server_ai.notification.notification.Notification"
              click fl_server_ai.notification.serializable.Serializable href "" "fl_server_ai.notification.serializable.Serializable"
            

Notification for the start of a training round.

Classes:

Name Description
Body

Inner class representing the body of the notification.

Methods:

Name Description
from_training

Create a TrainingRoundStartNotification instance from a training object.

Attributes:

Name Type Description
callback_error Signature | None
callback_success Signature | None
type NotificationType

The type of the notification.

Source code in fl_server_ai/notification/training/round_start.py
class TrainingRoundStartNotification(TrainingNotification["TrainingRoundStartNotification.Body"]):
    """
    Notification for the start of a training round.
    """

    type: NotificationType = NotificationType.UPDATE_ROUND_START
    """The type of the notification."""

    @property
    def callback_success(self) -> Optional[Signature]:
        return training_notification_callback_success.s(training_uuid=self.training_uuid)

    @property
    def callback_error(self) -> Optional[Signature]:
        return training_notification_callback_failure.s(training_uuid=self.training_uuid)

    @dataclass
    class Body(Serializable):
        """
        Inner class representing the body of the notification.
        """
        round: int
        """The round number."""
        global_model_uuid: UUID
        """The UUID of the global model."""

    @classmethod
    def from_training(cls, training: TrainingDB):
        """
        Create a `TrainingRoundStartNotification` instance from a training object.

        Args:
            training (TrainingDB): The training object to create the notification from.

        Returns:
            TrainingRoundStartNotification: The created notification.
        """
        return cls(
            receivers=training.participants.all(),
            body=cls.Body(
                round=training.model.round,
                global_model_uuid=training.model.id
            ),
            training_uuid=training.id
        )

Attributes

callback_error property
callback_error: Signature | None
callback_success property
callback_success: Signature | None
type class-attribute instance-attribute

The type of the notification.

Classes

Body dataclass

Bases: Serializable


              flowchart TD
              fl_server_ai.notification.training.TrainingRoundStartNotification.Body[Body]
              fl_server_ai.notification.serializable.Serializable[Serializable]

                              fl_server_ai.notification.serializable.Serializable --> fl_server_ai.notification.training.TrainingRoundStartNotification.Body
                


              click fl_server_ai.notification.training.TrainingRoundStartNotification.Body href "" "fl_server_ai.notification.training.TrainingRoundStartNotification.Body"
              click fl_server_ai.notification.serializable.Serializable href "" "fl_server_ai.notification.serializable.Serializable"
            

Inner class representing the body of the notification.

Methods:

Name Description
__init__

Attributes:

Name Type Description
global_model_uuid UUID

The UUID of the global model.

round int

The round number.

Source code in fl_server_ai/notification/training/round_start.py
@dataclass
class Body(Serializable):
    """
    Inner class representing the body of the notification.
    """
    round: int
    """The round number."""
    global_model_uuid: UUID
    """The UUID of the global model."""
Attributes
global_model_uuid instance-attribute
global_model_uuid: UUID

The UUID of the global model.

round instance-attribute
round: int

The round number.

Functions
__init__
__init__(round: int, global_model_uuid: UUID) -> None

Functions

from_training classmethod
from_training(training: Training)

Create a TrainingRoundStartNotification instance from a training object.

Parameters:

Name Type Description Default
training
Training

The training object to create the notification from.

required

Returns:

Name Type Description
TrainingRoundStartNotification

The created notification.

Source code in fl_server_ai/notification/training/round_start.py
@classmethod
def from_training(cls, training: TrainingDB):
    """
    Create a `TrainingRoundStartNotification` instance from a training object.

    Args:
        training (TrainingDB): The training object to create the notification from.

    Returns:
        TrainingRoundStartNotification: The created notification.
    """
    return cls(
        receivers=training.participants.all(),
        body=cls.Body(
            round=training.model.round,
            global_model_uuid=training.model.id
        ),
        training_uuid=training.id
    )

TrainingSWAGRoundStartNotification dataclass

Bases: TrainingRoundStartNotification


              flowchart TD
              fl_server_ai.notification.training.TrainingSWAGRoundStartNotification[TrainingSWAGRoundStartNotification]
              fl_server_ai.notification.training.round_start.TrainingRoundStartNotification[TrainingRoundStartNotification]
              fl_server_ai.notification.training.training.TrainingNotification[TrainingNotification]
              fl_server_ai.notification.notification.Notification[Notification]
              fl_server_ai.notification.serializable.Serializable[Serializable]

                              fl_server_ai.notification.training.round_start.TrainingRoundStartNotification --> fl_server_ai.notification.training.TrainingSWAGRoundStartNotification
                                fl_server_ai.notification.training.training.TrainingNotification --> fl_server_ai.notification.training.round_start.TrainingRoundStartNotification
                                fl_server_ai.notification.notification.Notification --> fl_server_ai.notification.training.training.TrainingNotification
                                fl_server_ai.notification.serializable.Serializable --> fl_server_ai.notification.notification.Notification
                





              click fl_server_ai.notification.training.TrainingSWAGRoundStartNotification href "" "fl_server_ai.notification.training.TrainingSWAGRoundStartNotification"
              click fl_server_ai.notification.training.round_start.TrainingRoundStartNotification href "" "fl_server_ai.notification.training.round_start.TrainingRoundStartNotification"
              click fl_server_ai.notification.training.training.TrainingNotification href "" "fl_server_ai.notification.training.training.TrainingNotification"
              click fl_server_ai.notification.notification.Notification href "" "fl_server_ai.notification.notification.Notification"
              click fl_server_ai.notification.serializable.Serializable href "" "fl_server_ai.notification.serializable.Serializable"
            

Notification for the start of a SWAG training round.

Attributes:

Name Type Description
type NotificationType

The type of the notification.

Source code in fl_server_ai/notification/training/swag.py
class TrainingSWAGRoundStartNotification(TrainingRoundStartNotification):
    """
    Notification for the start of a SWAG training round.
    """

    type: NotificationType = NotificationType.SWAG_ROUND_START
    """The type of the notification."""

Attributes

type class-attribute instance-attribute

The type of the notification.

TrainingStartNotification dataclass

Bases: TrainingNotification['TrainingStartNotification.Body']


              flowchart TD
              fl_server_ai.notification.training.TrainingStartNotification[TrainingStartNotification]
              fl_server_ai.notification.training.training.TrainingNotification[TrainingNotification]
              fl_server_ai.notification.notification.Notification[Notification]
              fl_server_ai.notification.serializable.Serializable[Serializable]

                              fl_server_ai.notification.training.training.TrainingNotification --> fl_server_ai.notification.training.TrainingStartNotification
                                fl_server_ai.notification.notification.Notification --> fl_server_ai.notification.training.training.TrainingNotification
                                fl_server_ai.notification.serializable.Serializable --> fl_server_ai.notification.notification.Notification
                




              click fl_server_ai.notification.training.TrainingStartNotification href "" "fl_server_ai.notification.training.TrainingStartNotification"
              click fl_server_ai.notification.training.training.TrainingNotification href "" "fl_server_ai.notification.training.training.TrainingNotification"
              click fl_server_ai.notification.notification.Notification href "" "fl_server_ai.notification.notification.Notification"
              click fl_server_ai.notification.serializable.Serializable href "" "fl_server_ai.notification.serializable.Serializable"
            

Class representing a notification for the start of a training.

Classes:

Name Description
Body

Inner class representing the body of the notification.

Methods:

Name Description
from_training

Create a TrainingStartNotification instance from a training object.

Attributes:

Name Type Description
type NotificationType

The type of the notification.

Source code in fl_server_ai/notification/training/start.py
class TrainingStartNotification(TrainingNotification["TrainingStartNotification.Body"]):
    """
    Class representing a notification for the start of a training.
    """

    type: NotificationType = NotificationType.TRAINING_START
    """The type of the notification."""

    @dataclass
    class Body(Serializable):
        """
        Inner class representing the body of the notification.
        """
        global_model_uuid: UUID
        """The UUID of the global model."""

    @classmethod
    def from_training(cls, training: TrainingDB):
        """
        Create a `TrainingStartNotification` instance from a training object.

        Args:
            training (TrainingDB): The training object to create the notification from.

        Returns:
            TrainingStartNotification: The created notification.
        """
        return cls(
            receivers=training.participants.all(),
            body=cls.Body(
                global_model_uuid=training.model.id
            ),
            training_uuid=training.id
        )

Attributes

type class-attribute instance-attribute

The type of the notification.

Classes

Body dataclass

Bases: Serializable


              flowchart TD
              fl_server_ai.notification.training.TrainingStartNotification.Body[Body]
              fl_server_ai.notification.serializable.Serializable[Serializable]

                              fl_server_ai.notification.serializable.Serializable --> fl_server_ai.notification.training.TrainingStartNotification.Body
                


              click fl_server_ai.notification.training.TrainingStartNotification.Body href "" "fl_server_ai.notification.training.TrainingStartNotification.Body"
              click fl_server_ai.notification.serializable.Serializable href "" "fl_server_ai.notification.serializable.Serializable"
            

Inner class representing the body of the notification.

Methods:

Name Description
__init__

Attributes:

Name Type Description
global_model_uuid UUID

The UUID of the global model.

Source code in fl_server_ai/notification/training/start.py
@dataclass
class Body(Serializable):
    """
    Inner class representing the body of the notification.
    """
    global_model_uuid: UUID
    """The UUID of the global model."""
Attributes
global_model_uuid instance-attribute
global_model_uuid: UUID

The UUID of the global model.

Functions
__init__
__init__(global_model_uuid: UUID) -> None

Functions

from_training classmethod
from_training(training: Training)

Create a TrainingStartNotification instance from a training object.

Parameters:

Name Type Description Default
training
Training

The training object to create the notification from.

required

Returns:

Name Type Description
TrainingStartNotification

The created notification.

Source code in fl_server_ai/notification/training/start.py
@classmethod
def from_training(cls, training: TrainingDB):
    """
    Create a `TrainingStartNotification` instance from a training object.

    Args:
        training (TrainingDB): The training object to create the notification from.

    Returns:
        TrainingStartNotification: The created notification.
    """
    return cls(
        receivers=training.participants.all(),
        body=cls.Body(
            global_model_uuid=training.model.id
        ),
        training_uuid=training.id
    )