Client¶
This page documents the client-side components of ICOS-FL, particularly the classes and functions defined in icos_fl.client.client.
Client Components¶
- class icos_fl.client.client.IcosClient(client_id, client_state, model, trainloader, valloader, local_epochs, metric)¶
Client implementation for ICOS FL with time series prediction.
This client trains an LSTM model for time series prediction in a federated learning setting. It handles local model training, evaluation, and parameter management as part of the federated learning process.
- Parameters:
client_id (Union[int, str]) – Unique identifier for this client
client_state (RecordSet) – RecordSet to maintain state across rounds
model (LSTMModel) – The LSTM model to train
trainloader (torch.utils.data.DataLoader) – DataLoader for training data
valloader (torch.utils.data.DataLoader) – DataLoader for validation data
local_epochs (int) – Number of local training epochs per FL round
metric (str) – Name of the metric being predicted
- get_parameters(config)¶
Get model parameters as a list of NumPy arrays.
- Parameters:
config (Dict[str, Any]) – Configuration parameters
- Returns:
List of model parameter arrays
- Return type:
List[NDArrays]
- set_parameters(parameters)¶
Set model parameters from a list of NumPy arrays.
- Parameters:
parameters (List[NDArrays]) – List of model parameter arrays
- fit(parameters, config)¶
Train the model on the local dataset.
- evaluate(parameters, config)¶
Evaluate the model on the local validation dataset.
- icos_fl.client.client.client_fn(context)¶
Create and return a Flower client instance.
This function is used by the ClientApp to create a client instance for each node in the federated learning system. It extracts configuration from the context, initializes the model, and prepares data loaders for training and evaluation.
- Parameters:
context (Context) – Flower client context with configuration and node info
- Returns:
Instantiated NumPyClient
- Return type:
NumPyClient
ClientApp Definition¶
- icos_fl.client.client.app¶
The Flower ClientApp instance used for federated learning.
This is the main entry point for the client-side federated learning process. It uses the
client_fnfunction to create client instances.- Type:
ClientApp
Client Workflow¶
The client workflow in ICOS-FL follows these steps:
Initialization: The client is initialized with a model, data loaders, and configuration
Data Fetching: The client fetches local system metrics data from DataClay
Model Parameter Exchange: The client receives the global model parameters
Local Training: The client trains the model on local data for a specified number of epochs
Local Evaluation: The client evaluates the model on a validation set
Parameter Update: The client sends the updated parameters back to the server
Example Usage¶
# Run the client with Flower CLI
$ flwr run . remote-deployment
# Or programmatically
from icos_fl.client.client import app
app.start(server_address="127.0.0.1:9092")