nvflare.app_opt.p2p.executors.consensus module

class ConsensusExecutor(initial_value: float | None = None)[source]

Bases: SyncAlgorithmExecutor

An executor that implements a consensus algorithm in a peer-to-peer (P2P) setup.

This executor extends the SyncAlgorithmExecutor to implement a simple consensus algorithm. The client starts with an initial value and iteratively exchanges values with its neighbors. At each iteration, the client updates its current value based on its own value and the weighted sum of its neighbors’ values. The process continues for a specified number of iterations, and the history of values is saved at the end of the run.

The number of iterations must be provided by the controller when asing to run the algorithm. It can be set in the extra parameters of the controller’s config with the “iterations” key.

Parameters:

initial_value (float, optional) – The initial value for the consensus algorithm. If not provided, a random value between 0 and 1 is used.

current_value

The current value of the client in the consensus algorithm.

Type:

float

value_history

A list storing the history of values over iterations.

Type:

list[float]

Init FLComponent.

The FLComponent is the base class of all FL Components. (executors, controllers, responders, filters, aggregators, and widgets are all FLComponents)

FLComponents have the capability to handle and fire events and contain various methods for logging.

run_algorithm(fl_ctx, shareable, abort_signal)[source]

Abstract method to execute the main P2P algorithm.

Subclasses must implement this method to define the algorithm logic.