Exemple #1
0
 def __init__(self,
              client_manager: ClientManager,
              strategy: Optional[Strategy] = None) -> None:
     self._client_manager: ClientManager = client_manager
     self.parameters: Parameters = Parameters(tensors=[],
                                              tensor_type="numpy.ndarray")
     self.strategy: Strategy = strategy if strategy is not None else FedAvg(
     )
def test_aggregate_fit_no_failures() -> None:
    """Test evaluate function."""
    # Prepare
    strategy = FaultTolerantFedAvg(min_completion_rate_fit=0.99)
    results: List[Tuple[ClientProxy, FitRes]] = [
        (MagicMock(), FitRes(Parameters(tensors=[], tensor_type=""), 1, 1, 0.1))
    ]
    failures: List[BaseException] = []
    expected: Optional[Weights] = []

    # Execute
    actual = strategy.aggregate_fit(1, results, failures)

    # Assert
    assert actual == expected
Exemple #3
0
def test_fit_clients() -> None:
    """Test fit_clients."""
    # Prepare
    clients: List[ClientProxy] = [
        FailingCLient("0"),
        SuccessClient("1"),
    ]
    arr = np.array([[1, 2], [3, 4], [5, 6]])
    arr_serialized = ndarray_to_bytes(arr)
    ins: FitIns = FitIns(Parameters(tensors=[arr_serialized], tensor_type=""), {})
    client_instructions = [(c, ins) for c in clients]

    # Execute
    results, failures = fit_clients(client_instructions)

    # Assert
    assert len(results) == 1
    assert len(failures) == 1
    assert results[0][1].num_examples == 1
Exemple #4
0
 def fit(self, ins: FitIns) -> FitRes:
     arr = np.array([[1, 2], [3, 4], [5, 6]])
     arr_serialized = ndarray_to_bytes(arr)
     return FitRes(Parameters(tensors=[arr_serialized], tensor_type=""), 1, 1, 12.3)
Exemple #5
0
 def weights_to_parameters(self, weights: Weights) -> Parameters:
     """Convert NumPy weights to parameters object."""
     tensors = [self.ndarray_to_bytes(ndarray) for ndarray in weights]
     return Parameters(tensors=tensors, tensor_type="numpy.nda")