Classes¶
JoyeLibertSecureAggregation ¶
JoyeLibertSecureAggregation(active=True, clipping_range=None)
Bases: _SecureAggregation
Secure aggregation controller of researcher component for Joye-Libert.
This class is responsible for;
- setting up the context for Joye-Libert secure aggregation
- Applying secure aggregation after receiving encrypted model parameters from nodes
Attributes:
| Name | Type | Description |
|---|---|---|
_servkey | SecaggServkeyContext | None | Server-key context setup instance. |
Assigns default values for attributes
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
active | bool | True if secure aggregation is activated for the experiment | True |
clipping_range | Union[None, int] | Clipping range that will be used for quantization of model parameters on the node side. The default will be [ | None |
Raises:
| Type | Description |
|---|---|
FedbiomedSecureAggregationError | bad argument type |
Source code in fedbiomed/researcher/secagg/_secure_aggregation.py
def __init__(
self,
active: bool = True,
clipping_range: Union[None, int] = None,
) -> None:
"""Class constructor
Assigns default values for attributes
Args:
active: True if secure aggregation is activated for the experiment
clipping_range: Clipping range that will be used for quantization of model
parameters on the node side. The default will be
[`VEParameters.CLIPPING_RANGE`][fedbiomed.common.constants.VEParameters].
The default value will be automatically set on the node side.
Raises:
FedbiomedSecureAggregationError: bad argument type
"""
super().__init__(active, clipping_range)
self._servkey: SecaggServkeyContext | None = None
self._secagg_crypter: SecaggCrypter = SecaggCrypter()
self._scheme = SecureAggregationSchemes.JOYE_LIBERT
Attributes¶
servkey property ¶
servkey
Gets servkey object
Returns:
| Type | Description |
|---|---|
Union[None, SecaggServkeyContext] | Servkey object, None if servkey is not setup |
Functions¶
aggregate ¶
aggregate(*args, round_, total_sample_size, model_params, encryption_factors=None, num_expected_params=1, **kwargs)
Aggregates given model parameters
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
round_ | int | current training round number | required |
total_sample_size | int | sum of number of samples used by all nodes | required |
model_params | Dict[str, List[int]] | model parameters from the participating nodes | required |
encryption_factors | Dict[str, Union[List[int], None]] | encryption factors from the participating nodes | None |
num_expected_params | int | number of decrypted parameters to decode from the model parameters | 1 |
Returns:
| Type | Description |
|---|---|
List[float] | Aggregated parameters |
Raises:
| Type | Description |
|---|---|
FedbiomedSecureAggregationError | secure aggregation context not properly configured |
Source code in fedbiomed/researcher/secagg/_secure_aggregation.py
def aggregate(
self,
*args,
round_: int,
total_sample_size: int,
model_params: Dict[str, List[int]],
encryption_factors: Dict[str, Union[List[int], None]] = None,
num_expected_params: int = 1,
**kwargs,
) -> List[float]:
"""Aggregates given model parameters
Args:
round_: current training round number
total_sample_size: sum of number of samples used by all nodes
model_params: model parameters from the participating nodes
encryption_factors: encryption factors from the participating nodes
num_expected_params: number of decrypted parameters to decode from the model parameters
Returns:
Aggregated parameters
Raises:
FedbiomedSecureAggregationError: secure aggregation context not properly configured
"""
# Avoid mutable argument by default
if encryption_factors is None:
encryption_factors = {}
if self._servkey is None:
raise FedbiomedSecureAggregationError(
f"{ErrorNumbers.FB417.value}: Can not aggregate parameters, Servkey context is "
f"not configured. Please setup secure aggregation before the aggregation."
)
if not self._servkey.status:
raise FedbiomedSecureAggregationError(
f"{ErrorNumbers.FB417.value}: Can not aggregate parameters, one of Biprime or Servkey context is "
f"not set properly"
)
key = self._servkey.context["server_key"]
biprime = self._servkey.context["biprime"]
num_nodes = len(model_params)
aggregate = functools.partial(
self._secagg_crypter.aggregate,
current_round=round_,
num_nodes=num_nodes,
key=key,
total_sample_size=total_sample_size,
biprime=biprime,
clipping_range=self.clipping_range,
)
return self._aggregate(
model_params,
encryption_factors,
aggregate,
num_expected_params,
)
load_state_breakpoint classmethod ¶
load_state_breakpoint(state)
Create a SecureAggregation object from a saved state
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state | Dict | saved state to restore in the created object | required |
Returns:
| Type | Description |
|---|---|
SecureAggregation | The created |
Source code in fedbiomed/researcher/secagg/_secure_aggregation.py
@classmethod
def load_state_breakpoint(cls, state: Dict) -> "SecureAggregation":
"""Create a `SecureAggregation` object from a saved state
Args:
state: saved state to restore in the created object
Returns:
The created `SecureAggregation` object
"""
if state["attributes"]["_servkey"] is not None:
state["attributes"]["_servkey"] = (
SecaggServkeyContext.load_state_breakpoint(
state=state["attributes"]["_servkey"]
)
)
return super().load_state_breakpoint(state)
save_state_breakpoint ¶
save_state_breakpoint()
Saves state of the secagg
Returns:
| Type | Description |
|---|---|
Dict[str, Any] | The secagg state to be saved |
Source code in fedbiomed/researcher/secagg/_secure_aggregation.py
def save_state_breakpoint(self) -> Dict[str, Any]:
"""Saves state of the secagg
Returns:
The secagg state to be saved
"""
state = super().save_state_breakpoint()
state["attributes"].update(
{
"_servkey": (
self._servkey.save_state_breakpoint()
if self._servkey is not None
else None
),
}
)
return state
setup ¶
setup(parties, experiment_id, researcher_id, force=False, insecure_validation=True)
Setup secure aggregation instruments.
Requires setting parties and experiment_id if they are not set in previous secagg setups. It is possible to execute without any argument if SecureAggregation has already parties and experiment_id defined. This feature provides researcher execute secagg.setup() if any connection issu#e
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parties | List[str] | Parties that participates secure aggregation | required |
experiment_id | str | The id of the experiment | required |
researcher_id | str | ID of the researcher that context will be created for. | required |
force | bool | Forces secagg setup even context is already existing | False |
insecure_validation | bool | True if the insecure mechanism for validation secagg data coherence is enabled | True |
Returns:
| Type | Description |
|---|---|
bool | Status of setup |
Raises FedbiomedSecureAggregationError: Invalid argument type
Source code in fedbiomed/researcher/secagg/_secure_aggregation.py
def setup(
self,
parties: List[str],
experiment_id: str,
researcher_id: str,
force: bool = False,
insecure_validation: bool = True,
) -> bool:
"""Setup secure aggregation instruments.
Requires setting `parties` and `experiment_id` if they are not set in previous secagg
setups. It is possible to execute without any argument if SecureAggregation
has already `parties` and `experiment_id` defined. This feature provides researcher
execute `secagg.setup()` if any connection issu#e
Args:
parties: Parties that participates secure aggregation
experiment_id: The id of the experiment
researcher_id: ID of the researcher that context will be created for.
force: Forces secagg setup even context is already existing
insecure_validation: True if the insecure mechanism for validation secagg data
coherence is enabled
Returns:
Status of setup
Raises
FedbiomedSecureAggregationError: Invalid argument type
"""
super().setup(parties, experiment_id, researcher_id, force, insecure_validation)
self._servkey = cast(SecaggServkeyContext, self._servkey)
if not self._servkey.status or force:
self._servkey.setup()
return True
train_arguments ¶
train_arguments()
Gets train arguments for secagg train request
Returns:
| Type | Description |
|---|---|
Dict | Arguments that are going to be attached to the experiment. |
Source code in fedbiomed/researcher/secagg/_secure_aggregation.py
def train_arguments(self) -> Dict:
"""Gets train arguments for secagg train request
Returns:
Arguments that are going to be attached to the experiment.
"""
arguments = super().train_arguments()
arguments.update(
{
"secagg_servkey_id": (
self._servkey.secagg_id if self._servkey is not None else None
),
}
)
return arguments
LomSecureAggregation ¶
LomSecureAggregation(active=True, clipping_range=None)
Bases: _SecureAggregation
Secure aggregation controller of researcher component for Low Overhead Masking.
This class is responsible for;
- setting up the context for LOM secure aggregation
- Applying secure aggregation after receiving encrypted model parameters from nodes
Attributes:
| Name | Type | Description |
|---|---|---|
_dh | SecaggDHContext | None | Diffie Hellman keypairs per node context setup instance. |
Assigns default values for attributes
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
active | bool | True if secure aggregation is activated for the experiment | True |
clipping_range | Union[None, int] | Clipping range that will be used for quantization of model parameters on the node side. The default will be [ | None |
Raises:
| Type | Description |
|---|---|
FedbiomedSecureAggregationError | bad argument type |
Source code in fedbiomed/researcher/secagg/_secure_aggregation.py
def __init__(
self,
active: bool = True,
clipping_range: Union[None, int] = None,
) -> None:
"""Class constructor
Assigns default values for attributes
Args:
active: True if secure aggregation is activated for the experiment
clipping_range: Clipping range that will be used for quantization of model
parameters on the node side. The default will be
[`VEParameters.CLIPPING_RANGE`][fedbiomed.common.constants.VEParameters].
The default value will be automatically set on the node side.
Raises:
FedbiomedSecureAggregationError: bad argument type
"""
super().__init__(active, clipping_range)
self._dh: SecaggDHContext | None = None
self._secagg_crypter = SecaggLomCrypter()
self._scheme = SecureAggregationSchemes.LOM
Attributes¶
dh property ¶
dh
Gets Diffie Hellman keypairs object
Returns:
| Type | Description |
|---|---|
Union[None, SecaggDHContext] | DH object, None if DH is not setup |
Functions¶
aggregate ¶
aggregate(*args, model_params, total_sample_size, encryption_factors=None, **kwargs)
Aggregates given model parameters
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
total_sample_size | int | sum of number of samples used by all nodes | required |
model_params | Dict[str, List[int]] | model parameters from the participating nodes | required |
encryption_factors | Dict[str, Union[List[int], None]] | encryption factors from the participating nodes | None |
Returns:
| Type | Description |
|---|---|
List[float] | Aggregated parameters |
Raises:
| Type | Description |
|---|---|
FedbiomedSecureAggregationError | secure aggregation context not properly configured |
Source code in fedbiomed/researcher/secagg/_secure_aggregation.py
def aggregate(
self,
*args,
model_params: Dict[str, List[int]],
total_sample_size: int,
encryption_factors: Dict[str, Union[List[int], None]] = None,
**kwargs,
) -> List[float]:
"""Aggregates given model parameters
Args:
total_sample_size: sum of number of samples used by all nodes
model_params: model parameters from the participating nodes
encryption_factors: encryption factors from the participating nodes
Returns:
Aggregated parameters
Raises:
FedbiomedSecureAggregationError: secure aggregation context not properly configured
"""
# Avoid mutable argument by default
if encryption_factors is None:
encryption_factors = {}
if self._dh is None:
raise FedbiomedSecureAggregationError(
f"{ErrorNumbers.FB417.value}: Can not aggregate parameters, Diffie "
"Hellman context is not configured. Please setup secure aggregation "
"before the aggregation."
)
if not self._dh.status:
raise FedbiomedSecureAggregationError(
f"{ErrorNumbers.FB417.value}: Can not aggregate parameters, Diffie "
"Hellman context is not set properly"
)
aggregate = functools.partial(
self._secagg_crypter.aggregate,
total_sample_size=total_sample_size,
clipping_range=self.clipping_range,
)
return self._aggregate(
model_params,
encryption_factors,
aggregate,
)
load_state_breakpoint classmethod ¶
load_state_breakpoint(state)
Create a SecureAggregation object from a saved state
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state | Dict | saved state to restore in the created object | required |
Returns:
| Type | Description |
|---|---|
SecureAggregation | The created |
Source code in fedbiomed/researcher/secagg/_secure_aggregation.py
@classmethod
def load_state_breakpoint(cls, state: Dict) -> "SecureAggregation":
"""Create a `SecureAggregation` object from a saved state
Args:
state: saved state to restore in the created object
Returns:
The created `SecureAggregation` object
"""
if state["attributes"]["_dh"] is not None:
state["attributes"]["_dh"] = SecaggDHContext.load_state_breakpoint(
state=state["attributes"]["_dh"]
)
return super().load_state_breakpoint(state)
save_state_breakpoint ¶
save_state_breakpoint()
Saves state of the secagg
Returns:
| Type | Description |
|---|---|
Dict[str, Any] | The secagg state to be saved |
Source code in fedbiomed/researcher/secagg/_secure_aggregation.py
def save_state_breakpoint(self) -> Dict[str, Any]:
"""Saves state of the secagg
Returns:
The secagg state to be saved
"""
state = super().save_state_breakpoint()
state["attributes"].update(
{
"_dh": (
self._dh.save_state_breakpoint() if self._dh is not None else None
),
}
)
return state
setup ¶
setup(parties, experiment_id, researcher_id, force=False, insecure_validation=True)
Setup secure aggregation instruments.
Requires setting parties and experiment_id if they are not set in previous secagg setups. It is possible to execute without any argument if SecureAggregation has already parties and experiment_id defined. This feature provides researcher execute secagg.setup() if any connection issue
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parties | List[str] | Parties that participates secure aggregation | required |
experiment_id | str | The id of the experiment | required |
researcher_id | str | ID of the researcher that executes secagg setup. | required |
force | bool | Forces secagg setup even if context is already existing | False |
insecure_validation | bool | True if the insecure mechanism for validation secagg data coherence is enabled | True |
Returns:
| Type | Description |
|---|---|
bool | Status of setup |
Raises FedbiomedSecureAggregationError: Invalid argument type
Source code in fedbiomed/researcher/secagg/_secure_aggregation.py
def setup(
self,
parties: List[str],
experiment_id: str,
researcher_id: str,
force: bool = False,
insecure_validation: bool = True,
) -> bool:
"""Setup secure aggregation instruments.
Requires setting `parties` and `experiment_id` if they are not set in previous secagg
setups. It is possible to execute without any argument if SecureAggregation
has already `parties` and `experiment_id` defined. This feature provides researcher
execute `secagg.setup()` if any connection issue
Args:
parties: Parties that participates secure aggregation
experiment_id: The id of the experiment
researcher_id: ID of the researcher that executes secagg setup.
force: Forces secagg setup even if context is already existing
insecure_validation: True if the insecure mechanism for validation secagg data
coherence is enabled
Returns:
Status of setup
Raises
FedbiomedSecureAggregationError: Invalid argument type
"""
parties = list(filter(lambda x: x != researcher_id, parties))
super().setup(parties, experiment_id, researcher_id, force, insecure_validation)
self._dh = cast(SecaggDHContext, self._dh)
if not self._dh.status or force:
self._dh.setup()
return self._dh.status
train_arguments ¶
train_arguments()
Gets train arguments for secagg train request
Returns:
| Type | Description |
|---|---|
Dict | Arguments that are going to be attached to the experiment. |
Source code in fedbiomed/researcher/secagg/_secure_aggregation.py
def train_arguments(self) -> Dict:
"""Gets train arguments for secagg train request
Returns:
Arguments that are going to be attached to the experiment.
"""
arguments = super().train_arguments()
arguments.update(
{
"secagg_dh_id": self._dh.secagg_id if self._dh is not None else None,
}
)
return arguments
SecaggContext ¶
SecaggContext(researcher_id, parties, experiment_id, secagg_id=None)
Bases: ABC
Handles a Secure Aggregation context element on the researcher side.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
researcher_id | str | ID of the researcher that context will be created for. | required |
parties | List[str] | list of parties participating in the secagg context element setup, named by their unique id ( | required |
experiment_id | str | ID of the experiment to which this secagg context element is attached. | required |
secagg_id | Union[str, None] | optional secagg context element ID to use for this element. Default is None, which means a unique element ID will be generated. | None |
Raises:
| Type | Description |
|---|---|
FedbiomedSecaggError | bad argument type or value |
Source code in fedbiomed/researcher/secagg/_secagg_context.py
@abstractmethod
def __init__(
self,
researcher_id: str,
parties: List[str],
experiment_id: str,
secagg_id: Union[str, None] = None,
):
"""Constructor of the class.
Args:
researcher_id: ID of the researcher that context will be created for.
parties: list of parties participating in the secagg context element setup, named
by their unique id (`node_id`, `researcher_id`).
There must be at least 3 parties, and the first party is this researcher
experiment_id: ID of the experiment to which this secagg context element is attached.
secagg_id: optional secagg context element ID to use for this element.
Default is None, which means a unique element ID will be generated.
Raises:
FedbiomedSecaggError: bad argument type or value
"""
self._v = Validator()
self._v.register(
"nonempty_str_or_none", self._check_secagg_id_type, override=True
)
try:
self._v.validate(secagg_id, "nonempty_str_or_none")
except ValidatorError as e:
raise FedbiomedSecaggError(
f"{ErrorNumbers.FB415.value}: bad parameter "
"`secagg_id` must be a None or non-empty string: {e}"
) from e
try:
self._v.validate(parties, list)
for p in parties:
self._v.validate(p, str)
except ValidatorError as e:
raise FedbiomedSecaggError(
f"{ErrorNumbers.FB415.value}: bad parameter "
f"`parties` must be a list of strings: {e}"
) from e
self._researcher_id = researcher_id
self._db = config.vars["DB"]
self._secagg_id = (
secagg_id if secagg_id is not None else "secagg_" + str(uuid.uuid4())
)
self._parties = parties
self._requests = Requests(config)
self._status = False
self._context = None
self._experiment_id = experiment_id
self._element: SecaggElementTypes
# to be set in subclasses
self._secagg_manager: Optional[BaseSecaggManager] = None
Attributes¶
context property ¶
context
Getter for secagg context element content
Returns:
| Type | Description |
|---|---|
Union[dict, None] | secagg context element, or |
experiment_id property ¶
experiment_id
Getter for secagg context element experiment_id
Returns:
| Type | Description |
|---|---|
str | secagg context element experiment_id |
parties property ¶
parties
Getter for secagg parties
Returns:
| Type | Description |
|---|---|
str | Parties that participates secure aggregation |
secagg_id property ¶
secagg_id
Getter for secagg context element ID
Returns:
| Type | Description |
|---|---|
str | secagg context element unique ID |
status property ¶
status
Getter for secagg context element status
Returns:
| Type | Description |
|---|---|
bool |
|
Functions¶
delete ¶
delete()
Delete secagg context element on defined parties.
Returns:
| Type | Description |
|---|---|
bool | True if secagg context element could be deleted for all parties, False if at least one of the parties could not delete context element. |
Source code in fedbiomed/researcher/secagg/_secagg_context.py
def delete(self) -> bool:
"""Delete secagg context element on defined parties.
Returns:
True if secagg context element could be deleted for all parties, False if at least
one of the parties could not delete context element.
"""
self._status = False
self._context = None
request = self._REQUEST_DELETE(
researcher_id=self._researcher_id,
secagg_id=self._secagg_id,
element=self._element.value,
experiment_id=self._experiment_id,
)
_ = self._launch_request(request)
status = self._secagg_manager.remove(self._secagg_id, self.experiment_id)
if status:
logger.debug(
f"Context element successfully deleted for researcher_id='{self._researcher_id}' "
f"secagg_id='{self._secagg_id}'"
)
else:
logger.error(
f"{ErrorNumbers.FB415.value}: No such context element secagg_id={self._secagg_id} "
f"on researcher researcher_id='{self._researcher_id}'"
)
return True
load_state_breakpoint staticmethod ¶
load_state_breakpoint(state)
Method for loading secagg state from breakpoint state
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state | Dict[str, Any] | The state that will be loaded | required |
Source code in fedbiomed/researcher/secagg/_secagg_context.py
@staticmethod
def load_state_breakpoint(state: Dict[str, Any]) -> "SecaggContext":
"""
Method for loading secagg state from breakpoint state
Args:
state: The state that will be loaded
"""
# Get class
cls = getattr(importlib.import_module(state["module"]), state["class"])
secagg = cls(**state["arguments"])
for key, value in state["attributes"].items():
setattr(secagg, key, value)
return secagg
save_state_breakpoint ¶
save_state_breakpoint()
Method for saving secagg state for saving breakpoints
Returns:
| Type | Description |
|---|---|
Dict[str, Any] | The state of the secagg |
Source code in fedbiomed/researcher/secagg/_secagg_context.py
def save_state_breakpoint(self) -> Dict[str, Any]:
"""Method for saving secagg state for saving breakpoints
Returns:
The state of the secagg
"""
# `_v` and `_requests` dont need to be savec (properly initiated in constructor)
state = {
"class": type(self).__name__,
"module": self.__module__,
"arguments": {
"secagg_id": self._secagg_id,
"parties": self._parties,
"experiment_id": self._experiment_id,
"researcher_id": self._researcher_id,
},
"attributes": {
"_status": self._status,
"_context": self._context,
},
}
return state
secagg_round abstractmethod ¶
secagg_round(request)
Negotiate secagg context element action with defined parties.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
msg | message sent to the parties during the round | required |
Returns:
| Type | Description |
|---|---|
bool | True if secagg context element action could be done for all parties, False if at least one of the parties could not do the context element action. |
Source code in fedbiomed/researcher/secagg/_secagg_context.py
@abstractmethod
def secagg_round(
self,
request: Message,
) -> bool:
"""Negotiate secagg context element action with defined parties.
Args:
msg: message sent to the parties during the round
Returns:
True if secagg context element action could be done for all parties, False if at least
one of the parties could not do the context element action.
"""
setup ¶
setup()
Setup secagg context element on defined parties.
Returns:
| Type | Description |
|---|---|
Dict | True if secagg context element could be setup for all parties, False if at least one of the parties could not setup context element. |
Source code in fedbiomed/researcher/secagg/_secagg_context.py
def setup(self) -> Dict:
"""Setup secagg context element on defined parties.
Returns:
True if secagg context element could be setup for all parties, False if at least
one of the parties could not setup context element.
"""
context = self._secagg_manager.get(self._secagg_id, self._experiment_id)
if context and matching_parties_servkey(context, self._parties):
logger.info(
f"{ErrorNumbers.FB415.value}: secagg context for {self._secagg_id} exists"
)
self._context = context["context"]
else:
request = self._REQUEST_SETUP(
researcher_id=self._researcher_id,
secagg_id=self._secagg_id,
element=self._element.value,
experiment_id=self._experiment_id,
parties=self._parties,
)
self._context = self.secagg_round(request)
self._status = True
return self._status
SecaggDHContext ¶
SecaggDHContext(researcher_id, parties, experiment_id, secagg_id=None)
Bases: SecaggContext
Handles a Secure Aggregation Diffie Hellman context element on the researcher side.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
researcher_id | str | ID of the researcher that context will be created for. | required |
parties | List[str] | list of parties participating in the secagg context element setup, named by their unique id ( | required |
experiment_id | str | ID of the experiment to which this secagg context element is attached. | required |
secagg_id | Union[str, None] | optional secagg context element ID to use for this element. Default is None, which means a unique element ID will be generated. | None |
Raises:
| Type | Description |
|---|---|
FedbiomedSecaggError | bad argument type or value |
Source code in fedbiomed/researcher/secagg/_secagg_context.py
def __init__(
self,
researcher_id: str,
parties: List[str],
experiment_id: str,
secagg_id: Union[str, None] = None,
):
"""Constructor of the class.
Args:
researcher_id: ID of the researcher that context will be created for.
parties: list of parties participating in the secagg context element setup, named
by their unique id (`node_id`, `researcher_id`).
There must be at least 3 parties, and the first party is this researcher
experiment_id: ID of the experiment to which this secagg context element is attached.
secagg_id: optional secagg context element ID to use for this element.
Default is None, which means a unique element ID will be generated.
Raises:
FedbiomedSecaggError: bad argument type or value
"""
super().__init__(researcher_id, parties, experiment_id, secagg_id)
self._element = SecaggElementTypes.DIFFIE_HELLMAN
self._raise_if_missing_parties(parties)
self._secagg_manager = SecaggDhManager(self._db)
Functions¶
secagg_round ¶
secagg_round(request)
Negotiate secagg context element action with defined parties for DH key exchange.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request | Message | message sent to the parties during the round | required |
Returns:
| Type | Description |
|---|---|
Tuple[dict, dict[str, bool]] | A tuple of - a dict containing the context describing this secagg context element - a dict where key/values are node ids/boolean with success status for secagg on each party |
Source code in fedbiomed/researcher/secagg/_secagg_context.py
def secagg_round(
self,
request: Message,
) -> Tuple[dict, dict[str, bool]]:
"""Negotiate secagg context element action with defined parties for DH key exchange.
Args:
request: message sent to the parties during the round
Returns:
A tuple of
- a dict containing the context describing this secagg context element
- a dict where key/values are node ids/boolean with success status for
secagg on each party
"""
_ = self._launch_request(request)
context = {}
return self._register(context)
SecaggServkeyContext ¶
SecaggServkeyContext(researcher_id, parties, experiment_id, secagg_id=None)
Bases: SecaggContext
Source code in fedbiomed/researcher/secagg/_secagg_context.py
def __init__(
self,
researcher_id,
parties: List[str],
experiment_id: str,
secagg_id: str | None = None,
):
"""Constructs key context class"""
super().__init__(researcher_id, parties, experiment_id, secagg_id)
self._element = SecaggElementTypes.SERVER_KEY
self._raise_if_missing_parties(parties)
self._secagg_manager = SecaggServkeyManager(self._db)
Functions¶
secagg_round ¶
secagg_round(request)
Negotiate secagg context element action with defined parties for secret sharing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request | Message | message sent to the parties during the round | required |
Returns:
| Type | Description |
|---|---|
Tuple[dict, dict[str, bool]] | A tuple of - a dict containing the context describing this secagg context element - a dict where key/values are node ids/boolean with success status for secagg on each party |
Source code in fedbiomed/researcher/secagg/_secagg_context.py
def secagg_round(
self,
request: Message,
) -> Tuple[dict, dict[str, bool]]:
"""Negotiate secagg context element action with defined parties for secret sharing.
Args:
request: message sent to the parties during the round
Returns:
A tuple of
- a dict containing the context describing this secagg context element
- a dict where key/values are node ids/boolean with success status
for secagg on each party
"""
replies = self._launch_request(request)
servkey: int = AdditiveShares(
[AdditiveShare(rep.share) for rep in replies.values()]
).reconstruct()
biprime = get_default_biprime()
context = {"server_key": -servkey, "biprime": biprime}
return self._register(context)
SecureAggregation ¶
SecureAggregation(*args, scheme=SecureAggregationSchemes.LOM, **kwargs)
Interface for different secure aggregation classes
Builds corresponding secure aggregation object/scheme based on given scheme argument
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scheme | SecureAggregationSchemes | Secure aggregation scheme | LOM |
Source code in fedbiomed/researcher/secagg/_secure_aggregation.py
def __init__(
self,
*args,
scheme: SecureAggregationSchemes = SecureAggregationSchemes.LOM,
**kwargs,
) -> None:
"""Constructs secure aggregation class
Builds corresponding secure aggregation object/scheme based
on given scheme argument
Args:
scheme: Secure aggregation scheme
"""
self.__scheme = scheme
match self.__scheme:
case SecureAggregationSchemes.LOM:
self.__secagg = LomSecureAggregation(*args, **kwargs)
case SecureAggregationSchemes.JOYE_LIBERT:
self.__secagg = JoyeLibertSecureAggregation(*args, **kwargs)
case _:
self.__secagg = LomSecureAggregation(*args, **kwargs)
Functions¶
load_state_breakpoint classmethod ¶
load_state_breakpoint(state)
Create a SecureAggregation object from a saved state
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state | Dict | saved state to restore in the created object | required |
Returns:
| Type | Description |
|---|---|
SecureAggregation | The created |
Source code in fedbiomed/researcher/secagg/_secure_aggregation.py
@classmethod
def load_state_breakpoint(cls, state: Dict) -> "SecureAggregation":
"""Create a `SecureAggregation` object from a saved state
Args:
state: saved state to restore in the created object
Returns:
The created `SecureAggregation` object
"""
secagg = cls(scheme=SecureAggregationSchemes(state["arguments"]["scheme"]))
for name, val in state["attributes_states"].items():
_sub_cls = getattr(importlib.import_module(val["module"]), val["class"])
instance = _sub_cls.load_state_breakpoint(val)
setattr(secagg, name, instance)
return secagg
save_state_breakpoint abstractmethod ¶
save_state_breakpoint()
Saves state of the secagg
This methods also save states of __secagg which provides a single entry point for secagg schemes
Returns:
| Type | Description |
|---|---|
Dict[str, Any] | The secagg state to be saved |
Source code in fedbiomed/researcher/secagg/_secure_aggregation.py
@abstractmethod
def save_state_breakpoint(self) -> Dict[str, Any]:
"""Saves state of the secagg
This methods also save states of `__secagg` which provides
a single entry point for secagg schemes
Returns:
The secagg state to be saved
"""
state = {
"class": type(self).__name__,
"module": self.__module__,
"arguments": {
"scheme": self.__scheme.value,
},
"attributes": {},
"attributes_states": {
"_SecureAggregation__secagg": self.__secagg.save_state_breakpoint()
},
}
return state