Definition of messages exchanged by the researcher and the nodes
Attributes
Classes
ApprovalReply dataclass
ApprovalReply(researcher_id, training_plan_id, message, node_id, status, command, success, *, protocol_version=str(__messaging_protocol_version__), request_id=None)
Bases: RequestReply
, RequiresProtocolVersion
Describes the TrainingPlan approval reply (acknoledge) from node to researcher.
Attributes:
Name | Type | Description |
---|---|---|
researcher_id | str | Id of the researcher that will receive the reply |
training_plan_id | str | None | Unique training plan identifier, can be none in case of success false. |
message | str | currently unused (empty string) |
node_id | str | Node id that replys the request |
status | int | status code for the request (obsolete, always 0) |
command | str | Reply command string |
success | bool | Request was successfully sumbitted to node (not yet approved) |
Raises:
Type | Description |
---|---|
FedbiomedMessageError | triggered if message's fields validation failed |
Attributes
command instance-attribute
command
message instance-attribute
message
node_id instance-attribute
node_id
researcher_id instance-attribute
researcher_id
status instance-attribute
status
success instance-attribute
success
training_plan_id instance-attribute
training_plan_id
ApprovalRequest dataclass
ApprovalRequest(researcher_id, description, training_plan, command, *, protocol_version=str(__messaging_protocol_version__), request_id=None)
Bases: RequestReply
, RequiresProtocolVersion
Describes the TrainingPlan approval request from researcher to node.
Attributes:
Name | Type | Description |
---|---|---|
researcher_id | str | id of the researcher that sends the request |
description | str | description of the training plan |
training_plan | str | The training plan that is going to be checked for approval |
command | str | request command string |
Raises:
Type | Description |
---|---|
FedbiomedMessageError | triggered if message's fields validation failed |
Attributes
command instance-attribute
command
description instance-attribute
description
researcher_id instance-attribute
researcher_id
training_plan instance-attribute
training_plan
ErrorMessage dataclass
ErrorMessage(researcher_id, node_id, errnum, extra_msg, command, *, protocol_version=str(__messaging_protocol_version__), request_id=None)
Bases: RequestReply
, RequiresProtocolVersion
Describes an error message sent by the node.
Attributes:
Name | Type | Description |
---|---|---|
researcher_id | str | ID of the researcher that receives the error message |
node_id | str | ID of the node that sends error message |
errnum | str | Error ID/Number |
extra_msg | str | Additional message regarding the error |
command | str | Reply command string |
Raises:
Type | Description |
---|---|
FedbiomedMessageError | triggered if message's fields validation failed |
Attributes
command instance-attribute
command
errnum instance-attribute
errnum
extra_msg instance-attribute
extra_msg
node_id instance-attribute
node_id
researcher_id instance-attribute
researcher_id
FeedbackMessage dataclass
FeedbackMessage(researcher_id=None, log=None, scalar=None, *, protocol_version=str(__messaging_protocol_version__))
Bases: ProtoSerializableMessage
, RequiresProtocolVersion
Attributes
log class-attribute
instance-attribute
log = None
researcher_id class-attribute
instance-attribute
researcher_id = None
scalar class-attribute
instance-attribute
scalar = None
InnerMessage dataclass
InnerMessage(*, node_id, dest_node_id)
Bases: Message
Parent class of messages sent from node to node.
Node to node messages are sent as inner message (payload) of an overlay message
Attributes:
Name | Type | Description |
---|---|---|
node_id | str | Id of the source node sending the mess |
dest_node_id | str | Id of the destination node of the overlay message |
Attributes
dest_node_id instance-attribute
dest_node_id
node_id instance-attribute
node_id
InnerRequestReply dataclass
InnerRequestReply(*, node_id, dest_node_id, request_id=None)
Bases: InnerMessage
Common attribute for Request and Reply Inner Message.
Attributes:
Name | Type | Description |
---|---|---|
request_id | Optional[str] | unique ID for this request-reply |
Attributes
request_id class-attribute
instance-attribute
request_id = None
KeyReply dataclass
KeyReply(public_key, secagg_id, command, *, protocol_version=str(__messaging_protocol_version__), node_id, dest_node_id, request_id=None)
Bases: InnerRequestReply
, RequiresProtocolVersion
Message for continuing an exchange for creating crypto key material.
Currently only Diffie-Hellman key exchange is supported
Attributes:
Name | Type | Description |
---|---|---|
public_key | bytes | public key of replying node |
secagg_id | str | unique ID of this secagg context element |
command | str | Command string |
Raises:
Type | Description |
---|---|
FedbiomedMessageError | triggered if message's fields validation failed |
Attributes
command instance-attribute
command
public_key instance-attribute
public_key
secagg_id instance-attribute
secagg_id
KeyRequest dataclass
KeyRequest(secagg_id, command, *, protocol_version=str(__messaging_protocol_version__), node_id, dest_node_id, request_id=None)
Bases: InnerRequestReply
, RequiresProtocolVersion
Message for starting a new exchange for creating crypto key material.
Currently only Diffie-Hellman key exchange is supported
Attributes:
Name | Type | Description |
---|---|---|
secagg_id | str | unique ID of this secagg context element |
command | str | Command string |
Raises:
Type | Description |
---|---|
FedbiomedMessageError | triggered if message's fields validation failed |
Attributes
command instance-attribute
command
secagg_id instance-attribute
secagg_id
ListReply dataclass
ListReply(researcher_id, success, databases, node_id, count, command, *, protocol_version=str(__messaging_protocol_version__), request_id=None)
Bases: RequestReply
, RequiresProtocolVersion
This class describes a list reply message sent by the node that includes list of datasets. It is a reply for ListRequest message from the researcher.
Attributes:
Name | Type | Description |
---|---|---|
researcher_id | str | Id of the researcher that sends the request |
succes | str | True if the node process the request as expected, false if any exception occurs |
databases | list | List of datasets |
node_id | str | Node id that replys the request |
count | int | Number of datasets |
command | str | Reply command string |
Raises:
Type | Description |
---|---|
FedbiomedMessageError | triggered if message's fields validation failed |
Attributes
command instance-attribute
command
count instance-attribute
count
databases instance-attribute
databases
node_id instance-attribute
node_id
researcher_id instance-attribute
researcher_id
success instance-attribute
success
ListRequest dataclass
ListRequest(researcher_id, command, *, protocol_version=str(__messaging_protocol_version__), request_id=None)
Bases: RequestReply
, RequiresProtocolVersion
Describes a list request message sent by the researcher to nodes in order to list datasets belonging to each node.
Attributes:
Name | Type | Description |
---|---|---|
researcher_id | str | Id of the researcher that sends the request |
command | str | Request command string |
Raises:
Type | Description |
---|---|
FedbiomedMessageError | triggered if message's fields validation failed |
Attributes
command instance-attribute
command
researcher_id instance-attribute
researcher_id
Log dataclass
Log(node_id, level, msg)
Bases: ProtoSerializableMessage
Describes the message type for log coming from node to researcher
Attributes
level instance-attribute
level
msg instance-attribute
msg
node_id instance-attribute
node_id
Message
Bases: object
Base class for all fedbiomed messages providing all methods to access the messages
The subclasses of this class will be pure data containers (no provided functions)
Functions
from_proto classmethod
from_proto(proto)
Converts given protobuf to python Dict
Source code in fedbiomed/common/message.py
@classmethod
def from_proto(
cls,
proto: ProtobufMessage
) -> Dict[str, Any]:
"""Converts given protobuf to python Dict"""
dict_ = {}
one_ofs = proto.DESCRIPTOR.oneofs_by_name
for field in proto.DESCRIPTOR.fields:
one_of_field = False
for one_of, _ in one_ofs.items():
if field.name == proto.WhichOneof(one_of):
one_of_field = True
# If the field is oneof and options are in message type
if one_of_field and field.type == FieldDescriptor.TYPE_MESSAGE:
field_ = cls.__dataclass_fields__[field.name]
args = get_args(field_.type)
# Make sure oneof message is typed as Optional
if not args:
raise FedbiomedMessageError(
f"Please make sure the field '{field_.name}' in dataclass '{cls.__name__}' "
"is typed as Optional[<dataclass>]. The field that are typed as `oneof` "
"in proto file should be typed as Optional in python dataclass"
)
if not hasattr(args[0], "__PROTO_TYPE__"):
raise FedbiomedMessageError(f"Dataclass {args[0]} should have attribute '__PROTO_TYPE__'")
dict_.update(
{field.name: args[0].from_proto(getattr(proto, field.name))}
)
# Detects the types that are declared as `optional`
# NOTE: In proto3 all fields are labeled as `LABEL_OPTIONAL` by default.
# However, if the field is labeled as `optional` explicitly, it will have
# presence, otherwise, `has_presence` returns False
elif field.has_presence and field.label == FieldDescriptor.LABEL_OPTIONAL:
# If proto has the field it means that the value is not None
if proto.HasField(field.name):
dict_.update({field.name: getattr(proto, field.name)})
elif field.label == FieldDescriptor.LABEL_REPEATED:
if field.type == FieldDescriptor.TYPE_MESSAGE:
dict_.update({field.name: dict(getattr(proto, field.name))})
else:
dict_.update({field.name: list(getattr(proto, field.name))})
else:
dict_.update({field.name: getattr(proto, field.name)})
return cls(**dict_)
get_dict
get_dict()
Returns pairs (Message class attributes name, attributes values) into a dictionary
Returns:
Type | Description |
---|---|
Dict[str, Any] | Message as dictionary |
Source code in fedbiomed/common/message.py
def get_dict(self) -> Dict[str, Any]:
"""Returns pairs (Message class attributes name, attributes values) into a dictionary
Returns:
Message as dictionary
"""
return self.__dict__
get_param
get_param(param)
Get the value of a given param
Parameters:
Name | Type | Description | Default |
---|---|---|---|
param | str | name of the param | required |
Source code in fedbiomed/common/message.py
def get_param(self, param: str):
"""Get the value of a given param
Args:
param: name of the param
"""
return getattr(self, param)
to_proto
to_proto()
Converts recursively python dataclass to gRPC proto
Source code in fedbiomed/common/message.py
def to_proto(self):
"""Converts recursively python dataclass to gRPC proto"""
proto_dict = {}
for key, _ in self.__dataclass_fields__.items():
param = self.get_param(key)
if hasattr(param, '__PROTO_TYPE__'):
proto_dict.update({key: self.get_param(key).to_proto()})
else:
proto_dict.update({key: self.get_param(key)})
return self.__PROTO_TYPE__(**proto_dict)
MessageFactory
Pack message contents into the appropriate Message class.
Functions
format_incoming_message classmethod
format_incoming_message(params)
Format a dictionary representing an incoming message into the appropriate Message class.
Packs the input into the appropriate Message class representing an incoming message. The type of Message class is inferred from the command
key in the input dictionary. This function also validates:
- the legacy of the message
- the structure of the received message
Attributes:
Name | Type | Description |
---|---|---|
params | the dictionary of key-value pairs extracted from the received message. |
Raises:
Type | Description |
---|---|
FedbiomedMessageError | if 'command' field is not present in |
FedbiomedMessageError | if the component is not allowed to receive the message |
Returns:
Type | Description |
---|---|
Message | The received message formatted as an instance of the appropriate Message class |
Source code in fedbiomed/common/message.py
@classmethod
def format_incoming_message(cls, params: Dict[str, Any]) -> Message:
"""Format a dictionary representing an incoming message into the appropriate Message class.
Packs the input into the appropriate Message class representing an incoming message.
The type of Message class is inferred from the `command` key in the input dictionary.
This function also validates:
- the legacy of the message
- the structure of the received message
Attributes:
params: the dictionary of key-value pairs extracted from the received message.
Raises:
FedbiomedMessageError: if 'command' field is not present in `params`
FedbiomedMessageError: if the component is not allowed to receive the message
Returns:
The received message formatted as an instance of the appropriate Message class
"""
MessageFactory._raise_for_missing_command(params)
message_type = params['command']
MessageFactory._validate_message_type_or_raise(message_type, cls.INCOMING_MESSAGE_TYPE_TO_CLASS_MAP)
raise_for_version_compatibility(
params['protocol_version'],
__messaging_protocol_version__
)
return cls.INCOMING_MESSAGE_TYPE_TO_CLASS_MAP[message_type](**params)
format_outgoing_message classmethod
format_outgoing_message(params)
Format a dictionary representing an outgoing message into the appropriate Message class.
Packs the input into the appropriate Message class representing an outbound message. The type of Message class is inferred from the command
key in the input dictionary. This function also validates:
- the legacy of the message
- the structure of the received message
Attributes:
Name | Type | Description |
---|---|---|
params | the dictionary of key-value pairs to be packed into the outgoing message. |
Raises:
Type | Description |
---|---|
FedbiomedMessageError | if 'command' field is not present in |
FedbiomedMessageError | if the component is not allowed to send the message |
Returns:
Type | Description |
---|---|
Message | The outbound message formatted as an instance of the appropriate Message class |
Source code in fedbiomed/common/message.py
@classmethod
def format_outgoing_message(cls, params: Dict[str, Any]) -> Message:
"""Format a dictionary representing an outgoing message into the appropriate Message class.
Packs the input into the appropriate Message class representing an outbound message.
The type of Message class is inferred from the `command` key in the input dictionary.
This function also validates:
- the legacy of the message
- the structure of the received message
Attributes:
params: the dictionary of key-value pairs to be packed into the outgoing message.
Raises:
FedbiomedMessageError: if 'command' field is not present in `params`
FedbiomedMessageError: if the component is not allowed to send the message
Returns:
The outbound message formatted as an instance of the appropriate Message class
"""
MessageFactory._raise_for_missing_command(params)
message_type = params['command']
MessageFactory._validate_message_type_or_raise(message_type, cls.OUTGOING_MESSAGE_TYPE_TO_CLASS_MAP)
params['protocol_version'] = str(__messaging_protocol_version__) # inject procotol version only in outgoing msg
return cls.OUTGOING_MESSAGE_TYPE_TO_CLASS_MAP[message_type](**params)
NodeMessages
Bases: MessageFactory
Specializes MessageFactory for Node side messages Node <=> Researcher
Node send replies and receive requests.
Attributes
INCOMING_MESSAGE_TYPE_TO_CLASS_MAP class-attribute
instance-attribute
INCOMING_MESSAGE_TYPE_TO_CLASS_MAP = {'train': TrainRequest, 'search': SearchRequest, 'ping': PingRequest, 'list': ListRequest, 'training-plan-status': TrainingPlanStatusRequest, 'approval': ApprovalRequest, 'secagg': SecaggRequest, 'secagg-delete': SecaggDeleteRequest, 'overlay': OverlayMessage}
OUTGOING_MESSAGE_TYPE_TO_CLASS_MAP class-attribute
instance-attribute
OUTGOING_MESSAGE_TYPE_TO_CLASS_MAP = {'train': TrainReply, 'search': SearchReply, 'pong': PingReply, 'error': ErrorMessage, 'add_scalar': Scalar, 'list': ListReply, 'training-plan-status': TrainingPlanStatusReply, 'approval': ApprovalReply, 'secagg': SecaggReply, 'secagg-delete': SecaggDeleteReply, 'overlay': OverlayMessage}
NodeToNodeMessages
Bases: MessageFactory
Specializes MessageFactory for message from Node to Node
Attributes
INCOMING_MESSAGE_TYPE_TO_CLASS_MAP class-attribute
instance-attribute
INCOMING_MESSAGE_TYPE_TO_CLASS_MAP = {'key-request': KeyRequest, 'key-reply': KeyReply}
OUTGOING_MESSAGE_TYPE_TO_CLASS_MAP class-attribute
instance-attribute
OUTGOING_MESSAGE_TYPE_TO_CLASS_MAP = INCOMING_MESSAGE_TYPE_TO_CLASS_MAP
OverlayMessage dataclass
OverlayMessage(*, protocol_version=str(__messaging_protocol_version__), researcher_id, node_id, dest_node_id, overlay, command)
Bases: Message
, RequiresProtocolVersion
Message for handling overlay trafic.
Same message used from source node to researcher, and from researcher to destination node.
Attributes:
Name | Type | Description |
---|---|---|
researcher_id | str | Id of the researcher relaying the overlay message |
node_id | str | Id of the source node of the overlay message |
dest_node_id | str | Id of the destination node of the overlay message |
overlay | list | payload of the message to be forwarded unchanged to the destination node |
command | str | Command string |
Raises:
Type | Description |
---|---|
FedbiomedMessageError | triggered if message's fields validation failed |
Attributes
command instance-attribute
command
dest_node_id instance-attribute
dest_node_id
node_id instance-attribute
node_id
overlay instance-attribute
overlay
researcher_id instance-attribute
researcher_id
PingReply dataclass
PingReply(researcher_id, node_id, success, command, *, protocol_version=str(__messaging_protocol_version__), request_id=None)
Bases: RequestReply
, RequiresProtocolVersion
This class describes a ping message sent by the node.
Attributes:
Name | Type | Description |
---|---|---|
researcher_id | str | Id of the researcher that will receive the reply |
node_id | str | Node id that replys the request |
succes | str | True if the node process the request as expected, false if any exception occurs |
command | str | Reply command string |
Raises:
Type | Description |
---|---|
FedbiomedMessageError | triggered if message's fields validation failed |
Attributes
command instance-attribute
command
node_id instance-attribute
node_id
researcher_id instance-attribute
researcher_id
success instance-attribute
success
PingRequest dataclass
PingRequest(researcher_id, command, *, protocol_version=str(__messaging_protocol_version__), request_id=None)
Bases: RequestReply
, RequiresProtocolVersion
Describes a ping message sent by the researcher
Attributes:
Name | Type | Description |
---|---|---|
researcher_id | str | Id of the researcher that send ping request |
command | str | Request command string |
Raises:
Type | Description |
---|---|
FedbiomedMessageError | triggered if message's fields validation failed |
Attributes
command instance-attribute
command
researcher_id instance-attribute
researcher_id
RequestReply dataclass
RequestReply(*, request_id=None)
Bases: Message
Common attribute for Request and Reply Message.
Attributes:
Name | Type | Description |
---|---|---|
request_id | Optional[str] | unique ID for this request-reply |
Attributes
request_id class-attribute
instance-attribute
request_id = None
RequiresProtocolVersion dataclass
RequiresProtocolVersion(*, protocol_version=str(__messaging_protocol_version__))
Mixin class for messages that must be endowed with a version field.
Attributes:
Name | Type | Description |
---|---|---|
protocol_version | str | version of the messaging protocol used |
Attributes
protocol_version class-attribute
instance-attribute
protocol_version = str(__messaging_protocol_version__)
ResearcherMessages
Bases: MessageFactory
Specializes MessageFactory for Researcher.
Researchers send requests and receive replies.
Attributes
INCOMING_MESSAGE_TYPE_TO_CLASS_MAP class-attribute
instance-attribute
INCOMING_MESSAGE_TYPE_TO_CLASS_MAP = {'train': TrainReply, 'search': SearchReply, 'pong': PingReply, 'error': ErrorMessage, 'list': ListReply, 'add_scalar': Scalar, 'training-plan-status': TrainingPlanStatusReply, 'approval': ApprovalReply, 'secagg': SecaggReply, 'secagg-delete': SecaggDeleteReply, 'overlay': OverlayMessage}
OUTGOING_MESSAGE_TYPE_TO_CLASS_MAP class-attribute
instance-attribute
OUTGOING_MESSAGE_TYPE_TO_CLASS_MAP = {'train': TrainRequest, 'search': SearchRequest, 'ping': PingRequest, 'list': ListRequest, 'training-plan-status': TrainingPlanStatusRequest, 'approval': ApprovalRequest, 'secagg': SecaggRequest, 'secagg-delete': SecaggDeleteRequest, 'overlay': OverlayMessage}
Scalar dataclass
Scalar(node_id, experiment_id, train, test, test_on_local_updates, test_on_global_updates, metric, total_samples, batch_samples, num_batches, iteration, epoch=None, num_samples_trained=None)
Bases: ProtoSerializableMessage
Describes a add_scalar message sent by the node.
Attributes:
Name | Type | Description |
---|---|---|
researcher_id | ID of the researcher that receives the reply | |
experiment_id | str | ID of the experiment that is sent by researcher |
train | bool | Declares whether scalar value is for training |
test | bool | Declares whether scalar value is for validation |
test_on_local_updates | bool | Declares whether validation is performed over locally updated parameters |
test_on_global_updates | bool | Declares whether validation is performed over aggregated parameters |
metric | dict | Evaluation metroc |
epoch | Optional[int] | Scalar is received at |
total_samples | int | Number of all samples in dataset |
batch_samples | int | Number of samples in batch |
num_batches | int | Number of batches in single epoch |
iteration | int | Scalar is received at |
Raises:
Type | Description |
---|---|
FedbiomedMessageError | triggered if message's fields validation failed |
Attributes
batch_samples instance-attribute
batch_samples
epoch class-attribute
instance-attribute
epoch = None
experiment_id instance-attribute
experiment_id
iteration instance-attribute
iteration
metric instance-attribute
metric
node_id instance-attribute
node_id
num_batches instance-attribute
num_batches
num_samples_trained class-attribute
instance-attribute
num_samples_trained = None
test instance-attribute
test
test_on_global_updates instance-attribute
test_on_global_updates
test_on_local_updates instance-attribute
test_on_local_updates
total_samples instance-attribute
total_samples
train instance-attribute
train
SearchReply dataclass
SearchReply(researcher_id, success, databases, node_id, count, command, *, protocol_version=str(__messaging_protocol_version__), request_id=None)
Bases: RequestReply
, RequiresProtocolVersion
Describes a search message sent by the node
Attributes:
Name | Type | Description |
---|---|---|
researcher_id | str | Id of the researcher that sends the request |
succes | str | True if the node process the request as expected, false if any exception occurs |
databases | list | List of datasets |
node_id | str | Node id that replys the request |
count | int | Number of datasets |
command | str | Reply command string |
Raises:
Type | Description |
---|---|
FedbiomedMessageError | triggered if message's fields validation failed |
Attributes
command instance-attribute
command
count instance-attribute
count
databases instance-attribute
databases
node_id instance-attribute
node_id
researcher_id instance-attribute
researcher_id
success instance-attribute
success
SearchRequest dataclass
SearchRequest(researcher_id, tags, command, *, protocol_version=str(__messaging_protocol_version__), request_id=None)
Bases: RequestReply
, RequiresProtocolVersion
Describes a search message sent by the researcher.
Attributes:
Name | Type | Description |
---|---|---|
researcher_id | str | ID of the researcher that sends the request |
tags | list | Tags for search request |
command | str | Request command string |
Raises:
Type | Description |
---|---|
FedbiomedMessageError | triggered if message's fields validation failed |
Attributes
command instance-attribute
command
researcher_id instance-attribute
researcher_id
tags instance-attribute
tags
SecaggDeleteReply dataclass
SecaggDeleteReply(researcher_id, secagg_id, success, node_id, msg, command, *, protocol_version=str(__messaging_protocol_version__), request_id=None)
Bases: RequestReply
, RequiresProtocolVersion
Describes a secagg context element delete reply message sent by the node
Attributes:
Name | Type | Description |
---|---|---|
researcher_id | str | ID of the researcher that requests deletion |
secagg_id | str | ID of secagg context element that is sent by researcher |
success | bool | True if the node process the request as expected, false if any exception occurs |
node_id | str | Node id that replies to the request |
msg | str | Custom message |
command | str | Reply command string |
Raises:
Type | Description |
---|---|
FedbiomedMessageError | triggered if message's fields validation failed |
Attributes
command instance-attribute
command
msg instance-attribute
msg
node_id instance-attribute
node_id
researcher_id instance-attribute
researcher_id
secagg_id instance-attribute
secagg_id
success instance-attribute
success
SecaggDeleteRequest dataclass
SecaggDeleteRequest(researcher_id, secagg_id, element, experiment_id, command, *, protocol_version=str(__messaging_protocol_version__), request_id=None)
Bases: RequestReply
, RequiresProtocolVersion
Describes a secagg context element delete request message sent by the researcher
Attributes:
Name | Type | Description |
---|---|---|
researcher_id | str | ID of the researcher that requests deletion |
secagg_id | str | ID of secagg context element that is sent by researcher |
element | int | Type of secagg context element |
experiment_id | Optional[str] | Id of the experiment to which this secagg context element is attached |
command | str | Request command string |
Raises:
Type | Description |
---|---|
FedbiomedMessageError | triggered if message's fields validation failed |
Attributes
command instance-attribute
command
element instance-attribute
element
experiment_id instance-attribute
experiment_id
researcher_id instance-attribute
researcher_id
secagg_id instance-attribute
secagg_id
SecaggReply dataclass
SecaggReply(researcher_id, secagg_id, success, node_id, msg, command, *, protocol_version=str(__messaging_protocol_version__), request_id=None)
Bases: RequestReply
, RequiresProtocolVersion
Describes a secagg context element setup reply message sent by the node
Attributes:
Name | Type | Description |
---|---|---|
researcher_id | str | ID of the researcher that requests setup |
secagg_id | str | ID of secagg context element that is sent by researcher |
success | bool | True if the node process the request as expected, false if any exception occurs |
node_id | str | Node id that replies to the request |
msg | str | Custom message |
command | str | Reply command string |
Raises:
Type | Description |
---|---|
FedbiomedMessageError | triggered if message's fields validation failed |
Attributes
command instance-attribute
command
msg instance-attribute
msg
node_id instance-attribute
node_id
researcher_id instance-attribute
researcher_id
secagg_id instance-attribute
secagg_id
success instance-attribute
success
SecaggRequest dataclass
SecaggRequest(researcher_id, secagg_id, element, experiment_id, parties, command, *, protocol_version=str(__messaging_protocol_version__), request_id=None)
Bases: RequestReply
, RequiresProtocolVersion
Describes a secagg context element setup request message sent by the researcher
Attributes:
Name | Type | Description |
---|---|---|
researcher_id | str | ID of the researcher that requests setup |
secagg_id | str | ID of secagg context element that is sent by researcher |
element | int | Type of secagg context element |
experiment_id | Optional[str] | Id of the experiment to which this secagg context element is attached |
parties | list | List of parties participating to the secagg context element setup |
command | str | Request command string |
Raises:
Type | Description |
---|---|
FedbiomedMessageError | triggered if message's fields validation failed |
Attributes
command instance-attribute
command
element instance-attribute
element
experiment_id instance-attribute
experiment_id
parties instance-attribute
parties
researcher_id instance-attribute
researcher_id
secagg_id instance-attribute
secagg_id
TaskRequest dataclass
TaskRequest(node, *, protocol_version=str(__messaging_protocol_version__))
Bases: ProtoSerializableMessage
, RequiresProtocolVersion
Task request message from node to researcher
Attributes
node instance-attribute
node
TaskResponse dataclass
TaskResponse(size, iteration, bytes_)
Bases: ProtoSerializableMessage
Response for task request
Attributes
bytes_ instance-attribute
bytes_
iteration instance-attribute
iteration
size instance-attribute
size
TaskResult dataclass
TaskResult(size, iteration, bytes_)
Bases: ProtoSerializableMessage
Response for task request
Attributes
bytes_ instance-attribute
bytes_
iteration instance-attribute
iteration
size instance-attribute
size
TrainReply dataclass
TrainReply(researcher_id, experiment_id, success, node_id, dataset_id, timing, msg, command, state_id=None, sample_size=None, encrypted=False, params=None, optimizer_args=None, optim_aux_var=None, encryption_factor=None, *, protocol_version=str(__messaging_protocol_version__), request_id=None)
Bases: RequestReply
, RequiresProtocolVersion
Describes a train message sent by the node.
Attributes:
Name | Type | Description |
---|---|---|
researcher_id | str | Id of the researcher that receives the reply |
experiment_id | str | Id of the experiment that is sent by researcher |
success | bool | True if the node process the request as expected, false if any exception occurs |
node_id | str | Node id that replies the request |
dataset_id | str | id of the dataset that is used for training |
params_url | str | URL of parameters uploaded by node |
timing | dict | Timing statistics |
msg | str | Custom message |
command | str | Reply command string |
Raises:
Type | Description |
---|---|
FedbiomedMessageError | triggered if message's fields validation failed |
Attributes
command instance-attribute
command
dataset_id instance-attribute
dataset_id
encrypted class-attribute
instance-attribute
encrypted = False
encryption_factor class-attribute
instance-attribute
encryption_factor = None
experiment_id instance-attribute
experiment_id
msg instance-attribute
msg
node_id instance-attribute
node_id
optim_aux_var class-attribute
instance-attribute
optim_aux_var = None
optimizer_args class-attribute
instance-attribute
optimizer_args = None
params class-attribute
instance-attribute
params = None
researcher_id instance-attribute
researcher_id
sample_size class-attribute
instance-attribute
sample_size = None
state_id class-attribute
instance-attribute
state_id = None
success instance-attribute
success
timing instance-attribute
timing
TrainRequest dataclass
TrainRequest(researcher_id, experiment_id, state_id, training_args, dataset_id, training, model_args, params, training_plan, training_plan_class, command, round, aggregator_args, aux_vars=None, secagg_arguments=None, *, protocol_version=str(__messaging_protocol_version__), request_id=None)
Bases: RequestReply
, RequiresProtocolVersion
Describes a train message sent by the researcher
Attributes:
Name | Type | Description |
---|---|---|
researcher_id | str | ID of the researcher that requests training |
experiment_id | str | Id of the experiment that is sent by researcher |
state_id | Optional[str] | ID of state associated to this request on node |
training_args | dict | Arguments for training routine |
dataset_id | str | id of the dataset that is used for training |
training | bool | Declares whether training will be performed |
model_args | dict | Arguments to initialize training plan class |
training_plan | str | Source code of training plan |
training_plan_class | str | Class name of the training plan |
command | str | Reply command string |
round | int | number of rounds already executed for this experiment |
aggregator_args | Dict | ?? |
aux_var | Dict | Optimizer auxiliary variables |
secagg_arguments | Optional[Dict] | Arguments for secure aggregation |
Raises:
Type | Description |
---|---|
FedbiomedMessageError | triggered if message's fields validation failed |
Attributes
aggregator_args instance-attribute
aggregator_args
aux_vars class-attribute
instance-attribute
aux_vars = None
command instance-attribute
command
dataset_id instance-attribute
dataset_id
experiment_id instance-attribute
experiment_id
model_args instance-attribute
model_args
params instance-attribute
params
researcher_id instance-attribute
researcher_id
round instance-attribute
round
secagg_arguments class-attribute
instance-attribute
secagg_arguments = None
state_id instance-attribute
state_id
training instance-attribute
training
training_args instance-attribute
training_args
training_plan instance-attribute
training_plan
training_plan_class instance-attribute
training_plan_class
TrainingPlanStatusReply dataclass
TrainingPlanStatusReply(researcher_id, node_id, experiment_id, success, approval_obligation, status, msg, training_plan, command, training_plan_id, *, protocol_version=str(__messaging_protocol_version__), request_id=None)
Bases: RequestReply
, RequiresProtocolVersion
Describes a training plan approve status check message sent by the node
Attributes:
Name | Type | Description |
---|---|---|
researcher_id | str | Id of the researcher that sends the request |
node_id | str | Node id that replies the request |
experiment_id | str | experiment id related to the experiment |
success | bool | True if the node process the request as expected, false if any exception occurs |
approval_obligation | Approval mode for node. True, if training plan approval is enabled/required in the node for training. | |
status | str | a |
msg | str | Message from node based on state of the reply |
training_plan | str | The training plan that has been checked for approval |
command | str | Reply command string |
training_plan_id | Optional[str] | Unique training plan identifier, can be None in case of success false. |
Raises:
Type | Description |
---|---|
FedbiomedMessageError | triggered if message's fields validation failed |
Attributes
approval_obligation instance-attribute
approval_obligation
command instance-attribute
command
experiment_id instance-attribute
experiment_id
msg instance-attribute
msg
node_id instance-attribute
node_id
researcher_id instance-attribute
researcher_id
status instance-attribute
status
success instance-attribute
success
training_plan instance-attribute
training_plan
training_plan_id instance-attribute
training_plan_id
TrainingPlanStatusRequest dataclass
TrainingPlanStatusRequest(researcher_id, experiment_id, training_plan, command, *, protocol_version=str(__messaging_protocol_version__), request_id=None)
Bases: RequestReply
, RequiresProtocolVersion
Describes a training plan approve status check message sent by the researcher.
Attributes:
Name | Type | Description |
---|---|---|
researcher_id | str | Id of the researcher that sends the request |
experiment_id | str | experiment id related to the experiment. |
training_plan_url | str | The training plan that is going to be checked for approval |
command | str | Request command string |
Raises:
Type | Description |
---|---|
FedbiomedMessageError | triggered if message's fields validation failed |
Attributes
command instance-attribute
command
experiment_id instance-attribute
experiment_id
researcher_id instance-attribute
researcher_id
training_plan instance-attribute
training_plan
Functions
catch_dataclass_exception
catch_dataclass_exception(cls)
Encapsulates the init() method of dataclass in order to transform the exceptions sent by the dataclass (TypeError) into our own exception (FedbiomedMessageError)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cls | Callable | Dataclass to validate | required |
Source code in fedbiomed/common/message.py
def catch_dataclass_exception(cls: Callable):
"""Encapsulates the __init__() method of dataclass in order to transform the exceptions sent
by the dataclass (TypeError) into our own exception (FedbiomedMessageError)
Args:
cls: Dataclass to validate
"""
def __cde_init__(self: Any, *args: list, **kwargs: dict):
"""This is the __init__() replacement.
Its purpose is to catch the TypeError created by the __init__
method of the @dataclass decorator and replace this exception by FedbiomedMessageError
Raises:
FedbiomedMessageError if number/type of arguments is wrong
"""
try:
self.__class__.__dict__['__initial_init__'](self, *args, **kwargs)
except TypeError as e:
# this is the error raised by dataclass if number of parameter is wrong
_msg = ErrorNumbers.FB601.value + ": bad number of parameters: " + str(e)
logger.error(_msg)
raise FedbiomedMessageError(_msg)
@functools.wraps(cls)
def wrap(cls: Callable):
""" Wrapper to the class given as parameter
Class wrapping should keep some attributes (__doc__, etc) of the initial class or the API documentation tools
will be mistaken
"""
cls.__initial_init__ = cls.__init__
setattr(cls, "__init__", __cde_init__)
return cls
return wrap(cls)