fedn.network.clients package

The FEDn client package is responsible for executing the federated learning tasks, including ML model training and validation. It’s the acting gRPC client for the federated network. The client first connacts the centralized controller to receive fedn.network.combiner.Combiner assingment. The client then connects to the combiner and sends requests to the combiner to receive model updates and send model updates.

Submodules

fedn.network.clients.client module

class fedn.network.clients.client.Client(config)[source]

Bases: object

FEDn Client. Service running on client/datanodes in a federation, recieving and handling model update and model validation requests.

Parameters:

config (dict) – A configuration dictionary containing connection information for the discovery service (controller) and settings governing e.g. client-combiner assignment behavior.

assign()[source]

Contacts the controller and asks for combiner assignment.

Returns:

A configuration dictionary containing connection information for combiner.

Return type:

dict

connect(combiner_config)[source]

Connect to combiner.

Parameters:

combiner_config (dict) – connection information for the combiner.

disconnect()[source]

Disconnect from the combiner.

get_model_from_combiner(id, timeout=20)[source]

Fetch a model from the assigned combiner. Downloads the model update object via a gRPC streaming channel.

Parameters:

id (str) – The id of the model update object.

Returns:

The model update object.

Return type:

BytesIO

process_request()[source]

Process training and validation tasks.

run()[source]

Run the client.

send_model_to_combiner(model, id)[source]

Send a model update to the assigned combiner. Uploads the model updated object via a gRPC streaming channel, Upload.

Parameters:
  • model (BytesIO) – The model update object.

  • id (str) – The id of the model update object.

Returns:

The model update object.

Return type:

BytesIO

send_status(msg, log_level=0, type=None, request=None, sesssion_id: str | None = None)[source]

Send status message.

Parameters:
  • msg (str) – The message to send.

  • log_level (fedn.Status.INFO, fedn.Status.WARNING, fedn.Status.ERROR) – The log level of the message.

  • type (str) – The type of the message.

  • request (fedn.Request) – The request message.

untar_package(package_runtime)[source]
class fedn.network.clients.client.GrpcAuth(key)[source]

Bases: AuthMetadataPlugin

fedn.network.clients.connect module

class fedn.network.clients.connect.ConnectorClient(host, port, token, name, remote_package, force_ssl=False, verify=False, combiner=None, id=None)[source]

Bases: object

Connector for assigning client to a combiner in the FEDn network.

Parameters:
  • host (str) – host of discovery service

  • port (int) – port of discovery service

  • token (str) – token for authentication

  • name (str) – name of client

  • remote_package (bool) – True if remote package is used, False if local

  • force_ssl (bool) – True if https is used, False if http

  • verify (bool) – True if certificate is verified, False if not

  • combiner (str) – name of preferred combiner

  • id – id of client

assign()[source]

Connect client to FEDn network discovery service, ask for combiner assignment.

Returns:

Tuple with assingment status, combiner connection information if sucessful, else None.

Return type:

tuple(fedn.network.clients.connect.Status, str)

refresh_token()[source]

Refresh client token.

Returns:

Tuple with assingment status, combiner connection information if sucessful, else None.

Return type:

tuple(fedn.network.clients.connect.Status, str)

class fedn.network.clients.connect.Status(value)[source]

Bases: Enum

Enum for representing the status of a client assignment.

Assigned = 1
TryAgain = 2
UnAuthorized = 3
UnMatchedConfig = 4
Unassigned = 0

fedn.network.clients.package module

class fedn.network.clients.package.PackageRuntime(package_path)[source]

Bases: object

PackageRuntime is used to download, validate and unpack compute packages.

Parameters:
  • package_path (str) – path to compute package

  • package_dir (str) – directory to unpack compute package

dispatcher(run_path)[source]

Dispatch the compute package

Parameters:

run_path (str) – path to dispatch the compute package

Returns:

Dispatcher object

Return type:

fedn.utils.dispatcher.Dispatcher

download(host, port, token, force_ssl=False, secure=False, name=None)[source]

Download compute package from controller

Parameters:
  • host – host of controller

  • port – port of controller

  • token – token for authentication

  • name – name of package

Returns:

True if download was successful, None otherwise

Return type:

bool

unpack()[source]

Unpack the compute package

Returns:

True if unpacking was successful, False otherwise

Return type:

bool

validate(expected_checksum)[source]

Validate the package against the checksum provided by the controller

Parameters:

expected_checksum – checksum provided by the controller

Returns:

True if checksums match, False otherwise

Return type:

bool

fedn.network.clients.state module

class fedn.network.clients.state.ClientState(value)[source]

Bases: Enum

Enum for representing the state of a client.

idle = 1
training = 2
validating = 3
fedn.network.clients.state.ClientStateToString(state)[source]

Convert a ClientState to a string representation.

Parameters:

state (fedn.network.clients.state.ClientState) – the state to convert

Returns:

string representation of the state

Return type:

str

fedn.network.clients.test_client module

class fedn.network.clients.test_client.TestClient(methodName='runTest')[source]

Bases: TestCase

Test the Client class.

setUp()[source]

Hook method for setting up the test fixture before exercising it.

test_add_grpc_metadata()[source]

Test the _add_grpc_metadata method.