Class - Plan#

class openfl.federated.plan.plan.Plan[source]#

Bases: object

A class used to represent a Federated Learning plan.

This class provides methods to manage and manipulate federated learning plans.

config#

Dictionary containing patched plan definition.

Type:

dict

authorized_cols#

Authorized collaborator list.

Type:

list

cols_data_paths#

Collaborator data paths dictionary.

Type:

dict

collaborator_#

Collaborator object.

Type:

Collaborator

aggregator_#

Aggregator object.

Type:

Aggregator

assigner_#

Assigner object.

Type:

Assigner

loader_#

Data loader object.

Type:

DataLoader

runner_#

Task runner object.

Type:

TaskRunner

server_#

gRPC server object.

Type:

AggregatorGRPCServer

client_#

gRPC client object.

Type:

AggregatorGRPCClient

pipe_#

Compression pipeline object.

Type:

CompressionPipeline

straggler_policy_#

Straggler handling policy.

Type:

StragglerPolicy

hash_#

Hash of the instance.

Type:

str

name_#

Name of the instance.

Type:

str

serializer_#

Serializer plugin.

Type:

SerializerPlugin

__init__()[source]#

Initializes the Plan object.

Methods

__init__()

Initializes the Plan object.

build(template, settings, **override)

Create an instance of a openfl Component or Federated DataLoader/TaskRunner.

dump(yaml_path, config[, freeze])

Dump the plan config to YAML file.

get_aggregator([tensor_dict])

Get federation aggregator.

get_assigner()

Get the plan task assigner.

get_client(collaborator_name[, ...])

Get gRPC or REST client for the specified collaborator.

get_client_args(collaborator_name[, ...])

get_collaborator(collaborator_name[, ...])

Get collaborator.

get_connector()

Get OpenFL Connector object.

get_data_loader(collaborator_name)

Get data loader for a specific collaborator.

get_server([root_certificate, private_key, ...])

Get gRPC or REST server of the aggregator instance.

get_server_args(root_certificate, ...)

get_straggler_handling_policy()

Get straggler handling policy.

get_task_runner(data_loader)

Get task runner.

get_tasks()

Get federation tasks.

get_tensor_pipe()

Get data tensor pipeline.

import_(template)

Import an instance of a openfl Component or Federated DataLoader/TaskRunner.

load(yaml_path[, default])

Load the plan from YAML file.

parse(plan_config_path[, cols_config_path, ...])

Parse the Federated Learning plan.

resolve()

Resolve the federation settings.

save_model_to_state_file(tensor_dict, ...)

Save model weights to a protobuf state file.

verify()

This function checks for inconsistencies in the plan config, for example, checks if two non-compatible features are enabled at the same time.

Attributes

hash

Generate hash for this instance.

static build(template, settings, **override)[source]#

Create an instance of a openfl Component or Federated DataLoader/TaskRunner.

Parameters:
  • template (str) – Fully qualified class template path.

  • settings (dict) – Keyword arguments to class constructor.

  • override (dict) – Additional settings to override the default ones.

Returns:

A Python object.

Return type:

object

static dump(yaml_path, config, freeze=False)[source]#

Dump the plan config to YAML file.

Parameters:
  • yaml_path (Path) – Path to the YAML file.

  • config (dict) – Plan configuration to be dumped.

  • freeze (bool, optional) – Flag to freeze the plan. Defaults to False.

get_aggregator(tensor_dict=None)[source]#

Get federation aggregator.

This method retrieves the federation aggregator. If the aggregator does not exist, it is built using the configuration settings and the provided tensor dictionary.

Parameters:

tensor_dict (dict, optional) – The initial tensor dictionary to use when building the aggregator. Defaults to None.

Returns:

The federation aggregator.

Return type:

self.aggregator_ (Aggregator)

Raises:

TypeError – If the log_metric_callback is not a callable object or cannot be imported from code.

get_assigner()[source]#

Get the plan task assigner.

get_client(collaborator_name, root_certificate=None, private_key=None, certificate=None)[source]#

Get gRPC or REST client for the specified collaborator.

Parameters:
  • collaborator_name (str) – Name of the collaborator.

  • aggregator_uuid (str) – UUID of the aggregator.

  • federation_uuid (str) – UUID of the federation.

  • root_certificate (str, optional) – Root certificate for the collaborator. Defaults to None.

  • private_key (str, optional) – Private key for the collaborator. Defaults to None.

  • certificate (str, optional) – Certificate for the collaborator. Defaults to None.

Returns:

gRPC or REST client for the collaborator.

Return type:

AggregatorGRPCClient or AggregatorRESTClient

get_collaborator(collaborator_name, root_certificate=None, private_key=None, certificate=None, task_runner=None, client=None)[source]#

Get collaborator.

This method retrieves a collaborator. If the collaborator does not exist, it is built using the configuration settings and the provided parameters.

Parameters:
  • collaborator_name (str) – Name of the collaborator.

  • root_certificate (str, optional) – Root certificate for the collaborator. Defaults to None.

  • private_key (str, optional) – Private key for the collaborator. Defaults to None.

  • certificate (str, optional) – Certificate for the collaborator. Defaults to None.

  • task_runner (TaskRunner, optional) – Task runner for the collaborator. Defaults to None.

  • client (Client, optional) – Client for the collaborator. Defaults to None.

Returns:

The collaborator instance.

Return type:

self.collaborator_ (Collaborator)

get_connector()[source]#

Get OpenFL Connector object.

get_data_loader(collaborator_name)[source]#

Get data loader for a specific collaborator.

Parameters:

collaborator_name (str) – Name of the collaborator.

Returns:

Data loader for the specified collaborator.

Return type:

DataLoader

get_server(root_certificate=None, private_key=None, certificate=None, **kwargs)[source]#

Get gRPC or REST server of the aggregator instance.

Parameters:
  • root_certificate (str, optional) – Root certificate for the server. Defaults to None.

  • private_key (str, optional) – Private key for the server. Defaults to None.

  • certificate (str, optional) – Certificate for the server. Defaults to None.

  • **kwargs – Additional keyword arguments.

Returns:

returns either gRPC or REST server of the aggregator instance.

Return type:

Aggregator Server

get_straggler_handling_policy()[source]#

Get straggler handling policy.

get_task_runner(data_loader)[source]#

Get task runner.

Parameters:

data_loader (DataLoader) – Data loader for the tasks.

Returns:

Task runner for the tasks.

Return type:

TaskRunner

get_tasks()[source]#

Get federation tasks.

get_tensor_pipe()[source]#

Get data tensor pipeline.

property hash[source]#

Generate hash for this instance.

static import_(template)[source]#

Import an instance of a openfl Component or Federated DataLoader/TaskRunner.

Parameters:

template (str) – Fully qualified object path.

Returns:

A Python object.

Return type:

object

static load(yaml_path, default=None)[source]#

Load the plan from YAML file.

Parameters:
  • yaml_path (Path) – Path to the YAML file.

  • default (dict, optional) – Default plan configuration. Defaults to {}.

Returns:

Plan configuration loaded from the YAML file.

Return type:

dict

static parse(plan_config_path, cols_config_path=None, data_config_path=None, gandlf_config_path=None, resolve=True)[source]#

Parse the Federated Learning plan.

Parameters:
  • plan_config_path (Path) – The filepath to the Federated Learning plan.

  • cols_config_path (Path, optional) – The filepath to the Federation collaborator list. Defaults to None.

  • data_config_path (Path, optional) – The filepath to the Federation collaborator data configuration. Defaults to None.

  • gandlf_config_path (Path, optional) – The filepath to a yaml file that overrides the configuration. Defaults to None.

  • resolve (bool, optional) – Flag to resolve the plan settings. Defaults to True.

Returns:

A Federated Learning plan object.

Return type:

Plan

resolve()[source]#

Resolve the federation settings.

save_model_to_state_file(tensor_dict, round_number, output_path)[source]#

Save model weights to a protobuf state file.

This method serializes the model weights into a protobuf format and saves them to a file. The serialization is done using the tensor pipe to ensure proper compression and formatting.

Parameters:
  • tensor_dict (dict) – Dictionary containing model weights and their corresponding tensors.

  • round_number (int) – The current federation round number.

  • output_path (str) – Path where the serialized model state will be saved.

Raises:

Exception – If there is an error during model proto creation or saving to file.

verify()[source]#

This function checks for inconsistencies in the plan config, for example, checks if two non-compatible features are enabled at the same time.