fedn.network.controller package

The controller package is responsible for orchestrating the federated learning process. It’s acts as a gRPC client and sends round config tasks to the fedn.network.combiner.Combiner.

Submodules

fedn.network.controller.control module

exception fedn.network.controller.control.CombinersNotDoneException(message)[source]

Bases: Exception

Exception class for when model is None

class fedn.network.controller.control.Control(statestore)[source]

Bases: ControlBase

Controller, implementing the overall global training, validation and inference logic.

Parameters:

statestore (class: fedn.network.statestorebase.StateStorageBase) – A StateStorage instance.

infer_instruct(config)[source]

Main entrypoint for executing the inference compute plan.

: param config: configuration for the inference round

inference_round(config)[source]

Execute an inference round.

: param config: configuration for the inference round

inference_session(config: RoundConfig) None[source]

Execute a new inference session.

Parameters:

config (InferenceConfig) – The round config.

Returns:

None

reduce(combiners)[source]

Combine updated models from Combiner nodes into one global model.

: param combiners: dict of combiner names(key) and model IDs(value) to reduce : type combiners: dict

round(session_config: RoundConfig, round_id: str)[source]

Execute one global round.

: param session_config: The session config. : type session_config: dict : param round_id: The round id. : type round_id: str

session(config: RoundConfig) None[source]
Execute a new training session. A session consists of one

or several global rounds. All rounds in the same session have the same round_config.

Parameters:

config (dict) – The session config.

start_session(session_id: str, rounds: int) None[source]
exception fedn.network.controller.control.MisconfiguredStorageBackend(message)[source]

Bases: Exception

Exception class for when storage backend is misconfigured.

Parameters:

message (str) – The exception message.

exception fedn.network.controller.control.NoModelException(message)[source]

Bases: Exception

Exception class for when model is None

Parameters:

message (str) – The exception message.

exception fedn.network.controller.control.UnsupportedStorageBackend(message)[source]

Bases: Exception

Exception class for when storage backend is not supported. Passes

fedn.network.controller.controlbase module

class fedn.network.controller.controlbase.ControlBase(statestore)[source]

Bases: ABC

Base class and interface for a global controller.

Override this class to implement a global training strategy (control).

Parameters:

statestore (fedn.network.statestore.statestorebase.StateStoreBase) – The statestore object.

commit(model_id, model=None, session_id=None)[source]

Commit a model to the global model trail. The model commited becomes the lastest consensus model.

Parameters:
  • model_id (str (uuid)) – Unique identifier for the model to commit.

  • model (BytesIO) – The model object to commit

  • session_id (str) – Unique identifier for the session

create_round(round_data)[source]

Initialize a new round in backend db.

create_session(config: RoundConfig, status: str = 'Initialized') None[source]

Initialize a new session in backend db.

evaluate_round_participation_policy(clients_required: int, nr_active_clients: int) bool[source]

Evaluate policy for combiner round-participation. A combiner participates if it is responsive and reports enough active clients to participate in the round.

evaluate_round_start_policy(combiners: list)[source]

Check if the policy to start a round is met.

Parameters:

combiners (list) – A list of combiners

Returns:

True if the round policy is mer, otherwise False

Return type:

bool

evaluate_round_validity_policy(round)[source]

Check if the round is valid.

At the end of the round, before committing a model to the global model trail, we check if the round validity policy has been met. This can involve e.g. asserting that a certain number of combiners have reported in an updated model, or that criteria on model performance have been met.

Parameters:

round – The round object

Rtype round:

dict

Returns:

True if the policy is met, otherwise False

Return type:

bool

get_combiner(name)[source]
get_compute_package(compute_package='')[source]
Parameters:

compute_package

Returns:

get_compute_package_name()[source]
Returns:

get_events()[source]
Returns:

get_helper()[source]

Get a helper instance from global config.

Returns:

Helper instance.

Return type:

fedn.utils.plugins.helperbase.HelperBase

get_latest_round()[source]
get_latest_round_id()[source]
get_model_info()[source]
Returns:

get_participating_combiners(combiner_round_config)[source]

Assemble a list of combiners able to participate in a round as descibed by combiner_round_config.

get_state()[source]

Get the current state of the controller.

Returns:

The current state.

Return type:

fedn.network.state.ReducerState

idle()[source]

Check if the controller is idle.

Returns:

True if idle, False otherwise.

Return type:

bool

abstract reduce(combiners)[source]
request_model_updates(combiners)[source]

Ask Combiner server to produce a model update.

Parameters:

combiners (tuple (combiner, combiner_round_config)) – A list of combiners

abstract round(config, round_number)[source]
abstract session(config)[source]
set_compute_package(filename, path)[source]

Persist the configuration for the compute package.

set_round_config(round_id, round_config: RoundConfig)[source]

Upate round in backend db.

Parameters:
  • round_id (str) – The round unique identifier

  • round_config (dict) – The round configuration

set_round_data(round_id, round_data)[source]

Set round data.

Parameters:
  • round_id (str) – The round unique identifier

  • round_data – The status

set_round_status(round_id, status)[source]

Set the round round stats.

Parameters:
  • round_id (str) – The round unique identifier

  • status (str) – The status

set_session_status(session_id, status)[source]

Set the round round stats.

Parameters:
  • round_id (str) – The round unique identifier

  • status (str) – The status

state()[source]

Get the current state of the controller.

Returns:

The state

Rype:

str

exception fedn.network.controller.controlbase.MisconfiguredHelper[source]

Bases: Exception

exception fedn.network.controller.controlbase.MisconfiguredStorageBackend[source]

Bases: Exception

exception fedn.network.controller.controlbase.UnsupportedStorageBackend[source]

Bases: Exception