Definition of messages exchanged by the researcher and the nodes
Attributes
Classes
AdditiveSSSetupReply dataclass
AdditiveSSSetupReply(*, protocol_version=str(__messaging_protocol_version__), request_id=None, researcher_id, secagg_id, success, node_id, msg, share)
Bases: SecaggReply
Message that instantiated on the node side to reply secagg setup request from researcher
Attributes
share instance-attribute
share
AdditiveSSSetupRequest dataclass
AdditiveSSSetupRequest(*, protocol_version=str(__messaging_protocol_version__), request_id=None, researcher_id, secagg_id, element, experiment_id, parties)
AdditiveSSharingReply dataclass
AdditiveSSharingReply(secagg_id, share, *, protocol_version=str(__messaging_protocol_version__), node_id, dest_node_id, request_id=None)
Bases: InnerRequestReply
, RequiresProtocolVersion
Attributes
secagg_id instance-attribute
secagg_id
share instance-attribute
share
AdditiveSSharingRequest dataclass
AdditiveSSharingRequest(secagg_id, *, protocol_version=str(__messaging_protocol_version__), node_id, dest_node_id, request_id=None)
Bases: InnerRequestReply
, RequiresProtocolVersion
Attributes
secagg_id instance-attribute
secagg_id
ApprovalReply dataclass
ApprovalReply(researcher_id, training_plan_id, message, node_id, status, 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) |
success | bool | Request was successfully sumbitted to node (not yet approved) |
Raises:
Type | Description |
---|---|
FedbiomedMessageError | triggered if message's fields validation failed |
Attributes
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, *, 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 |
Raises:
Type | Description |
---|---|
FedbiomedMessageError | triggered if message's fields validation failed |
Attributes
description instance-attribute
description
researcher_id instance-attribute
researcher_id
training_plan instance-attribute
training_plan
ChannelSetupReply dataclass
ChannelSetupReply(public_key, *, protocol_version=str(__messaging_protocol_version__), node_id, dest_node_id, request_id=None)
Bases: InnerRequestReply
, RequiresProtocolVersion
Message for reply peer node key for securing a n2n channel.
Attributes:
Name | Type | Description |
---|---|---|
public_key | bytes | public key of replying node |
Raises:
Type | Description |
---|---|
FedbiomedMessageError | triggered if message's fields validation failed |
Attributes
public_key instance-attribute
public_key
ChannelSetupRequest dataclass
ChannelSetupRequest(*, protocol_version=str(__messaging_protocol_version__), node_id, dest_node_id, request_id=None)
Bases: InnerRequestReply
, RequiresProtocolVersion
Message for requesting peer node key for securing a n2n channel.
Raises:
Type | Description |
---|---|
FedbiomedMessageError | triggered if message's fields validation failed |
ErrorMessage dataclass
ErrorMessage(*, protocol_version=str(__messaging_protocol_version__), request_id=None, researcher_id, node_id, extra_msg, errnum=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 | Optional[str] | Error ID/Number |
extra_msg | str | Additional message regarding the error |
Raises:
Type | Description |
---|---|
FedbiomedMessageError | triggered if message's fields validation failed |
Attributes
errnum class-attribute
instance-attribute
errnum = None
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, *, 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 |
Raises:
Type | Description |
---|---|
FedbiomedMessageError | triggered if message's fields validation failed |
Attributes
public_key instance-attribute
public_key
secagg_id instance-attribute
secagg_id
KeyRequest dataclass
KeyRequest(secagg_id, *, 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 |
Raises:
Type | Description |
---|---|
FedbiomedMessageError | triggered if message's fields validation failed |
Attributes
secagg_id instance-attribute
secagg_id
ListReply dataclass
ListReply(researcher_id, success, databases, node_id, count, *, 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 |
Raises:
Type | Description |
---|---|
FedbiomedMessageError | triggered if message's fields validation failed |
Attributes
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, *, 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 |
Raises:
Type | Description |
---|---|
FedbiomedMessageError | triggered if message's fields validation failed |
Attributes
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
Base class for all fedbiomed messages providing all methods to access the messages
The subclass of this class will be pure data containers (no provided functions)
Functions
from_dict staticmethod
from_dict(obj)
De-serializes the message
Source code in fedbiomed/common/message.py
@staticmethod
def from_dict(obj: Dict):
"""De-serializes the message"""
message = {**obj}
if (
"__type_message__" not in message
or not isinstance(message["__type_message__"], dict)
or not all(
x_ in message["__type_message__"].keys() for x_ in ["class", "module"]
)
):
raise FedbiomedValueError(
"Message does not include valid '__type_message__' entry."
)
type_ = message["__type_message__"]
cls_ = import_object("fedbiomed.common.message", type_["class"])
if not inspect.isclass(cls_) or not issubclass(cls_, Message):
raise FedbiomedMessageError(
"Given object class is not subclass of 'Message'"
)
raise_for_version_compatibility(
message["protocol_version"], __messaging_protocol_version__
)
message.pop("__type_message__")
return cls_(**message)
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, None)
to_dict
to_dict()
Serializes the message
Returns:
Type | Description |
---|---|
Dict | Serializes data class into a dict |
Source code in fedbiomed/common/message.py
def to_dict(self) -> Dict:
"""Serializes the message
Returns:
Serializes data class into a dict
"""
class_ = type(self).__name__
module_ = type(self).__module__
return {
**self.get_dict(),
"__type_message__": {"module": module_, "class": class_},
}
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)
OverlayMessage dataclass
OverlayMessage(*, protocol_version=str(__messaging_protocol_version__), researcher_id, node_id, dest_node_id, overlay, setup, salt, nonce)
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 | bytes | payload of the message to be forwarded unchanged to the destination node |
setup | bool | True if this is a channel setup message, False if this is an application layer message |
salt | bytes | value used for salting the key derivation for this message |
nonce | bytes | value used for noncing the encryption for this message |
Raises:
Type | Description |
---|---|
FedbiomedMessageError | triggered if message's fields validation failed |
Attributes
dest_node_id instance-attribute
dest_node_id
node_id instance-attribute
node_id
nonce instance-attribute
nonce
overlay instance-attribute
overlay
researcher_id instance-attribute
researcher_id
salt instance-attribute
salt
setup instance-attribute
setup
PingReply dataclass
PingReply(researcher_id, node_id, *, 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 |
Raises:
Type | Description |
---|---|
FedbiomedMessageError | triggered if message's fields validation failed |
Attributes
node_id instance-attribute
node_id
researcher_id instance-attribute
researcher_id
PingRequest dataclass
PingRequest(researcher_id, *, 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 |
Raises:
Type | Description |
---|---|
FedbiomedMessageError | triggered if message's fields validation failed |
Attributes
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__)
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, databases, node_id, count, *, 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 |
Raises:
Type | Description |
---|---|
FedbiomedMessageError | triggered if message's fields validation failed |
Attributes
count instance-attribute
count
databases instance-attribute
databases
node_id instance-attribute
node_id
researcher_id instance-attribute
researcher_id
SearchRequest dataclass
SearchRequest(researcher_id, tags, *, 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 |
Raises:
Type | Description |
---|---|
FedbiomedMessageError | triggered if message's fields validation failed |
Attributes
researcher_id instance-attribute
researcher_id
tags instance-attribute
tags
SecaggDeleteReply dataclass
SecaggDeleteReply(*, protocol_version=str(__messaging_protocol_version__), request_id=None, researcher_id, secagg_id, success, node_id, msg=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 | Optional[str] | Custom message |
Raises:
Type | Description |
---|---|
FedbiomedMessageError | triggered if message's fields validation failed |
Attributes
msg class-attribute
instance-attribute
msg = None
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, *, 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 |
Raises:
Type | Description |
---|---|
FedbiomedMessageError | triggered if message's fields validation failed |
Attributes
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(*, protocol_version=str(__messaging_protocol_version__), request_id=None, researcher_id, secagg_id, success, node_id, msg)
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 |
Raises:
Type | Description |
---|---|
FedbiomedMessageError | triggered if message's fields validation failed |
Attributes
msg class-attribute
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(*, protocol_version=str(__messaging_protocol_version__), request_id=None, researcher_id, secagg_id, element, experiment_id, parties)
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 | 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 |
Raises:
Type | Description |
---|---|
FedbiomedMessageError | triggered if message's fields validation failed |
Attributes
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, 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 |
Raises:
Type | Description |
---|---|
FedbiomedMessageError | triggered if message's fields validation failed |
Attributes
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, 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 |
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
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, 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 |
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
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, *, 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 |
Raises:
Type | Description |
---|---|
FedbiomedMessageError | triggered if message's fields validation failed |
Attributes
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) from e
@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)