Skip to content

Client

Table of Contents

client.client_state

Client state class

ClientState Objects

class ClientState()

Utility class for handling client state

get

def get(attr) -> Union[str, int, float]

Get attribute from state

Arguments:

  • attr: Attribute to get

Returns:

Value of attribute

get_all

def get_all() -> Dict

Get all attributes from state

Returns:

Dictionary of all attributes

client.client_output

Utility class for handling client output

ClientOutput Objects

class ClientOutput()

set

def set(key: Union[str, int], value: Any)

Set output key to values

Arguments:

  • key: String or integer key
  • value: Value to set

get

def get(key: Union[str, int]) -> Any

Get output value for key

Arguments:

  • key: String or integer key

Returns:

Value for key

write

def write()

Write output

client.client_fn

Wrapper to allow Ray to create clients

ClientFunction Objects

class ClientFunction()

Class used to create clients

client_fn

def client_fn(cid: str) -> Client

Function used to create clients

Arguments:

  • cid: The client id

Returns:

Instance of the client class

client.client

Client class for the federated learning framework

Client Objects

class Client(fl.client.NumPyClient)

fit

def fit(parameters: List[ndarray],
        config: flwr.common.FitIns) -> Tuple[List[ndarray], int, Dict]

Fit the model, write output and return parameters and metrics

Arguments:

  • parameters: The current parameters of the global model
  • config: Configuration for this fit

Returns:

The parameters of the global model, the number of samples used and the metrics

evaluate

def evaluate(parameters, config)

Evaluate the model

Arguments:

  • parameters: model parameters
  • config: configuration for this evaluation

Returns:

loss, number of samples and metrics

get_properties

def get_properties(config=None) -> Dict

Return properties of the current client

Arguments:

  • config: Config for getting the properties

client.helpers

Helper functions for the client Specifically, this file contains the following functions: - get_parameters: Returns the parameters of a model as a list of numpy arrays - set_parameters: Sets the parameters of a model from a list of numpy arrays

get_parameters

def get_parameters(net) -> List[np.ndarray]

Returns the parameters of a model as a list of numpy arrays

Arguments:

  • net: The model

Returns:

The parameters of the model as a list of numpy arrays

set_parameters

def set_parameters(net, parameters: List[np.ndarray])

Sets the parameters of a model from a list of numpy arrays

Arguments:

  • net: The model
  • parameters: The parameters of the model as a list of numpy arrays

Returns:

None