openfl.federated.plan.plan.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.

logger#

Logger instance for the class.

Type:

Logger

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:

StragglerHandlingPolicy

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.

deserialize_interface_objects()

Deserialize objects for 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 client for the specified collaborator.

get_collaborator(collaborator_name[, ...])

Get collaborator.

get_core_task_runner([data_loader, ...])

Get core task runner.

get_data_loader(collaborator_name)

Get data loader for a specific collaborator.

get_serializer_plugin(**kwargs)

Get serializer plugin.

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

Get gRPC server of the aggregator instance.

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.

initialize_data_loader(data_loader, ...)

Initialize data loader.

interactive_api_get_server(*, tensor_dict, ...)

Get gRPC server of the aggregator instance for interactive API.

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.

restore_object(filename)

Deserialize an object.

Attributes

hash

Generate hash for this instance.

logger

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

deserialize_interface_objects()[source]#

Deserialize objects for TaskRunner.

Returns:

Tuple containing the deserialized objects.

Return type:

tuple

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, aggregator_uuid, federation_uuid, root_certificate=None, private_key=None, certificate=None)[source]#

Get gRPC 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 client for the specified collaborator.

Return type:

AggregatorGRPCClient

get_collaborator(collaborator_name, root_certificate=None, private_key=None, certificate=None, task_runner=None, client=None, shard_descriptor=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.

  • shard_descriptor (ShardDescriptor, optional) – Descriptor of the data shard. Defaults to None.

Returns:

The collaborator instance.

Return type:

self.collaborator_ (Collaborator)

get_core_task_runner(data_loader=None, model_provider=None, task_keeper=None)[source]#

Get core task runner.

Parameters:
  • data_loader (DataLoader, optional) – Data loader for the tasks. Defaults to None.

  • model_provider (ModelProvider, optional) – Provider for the model. Defaults to None.

  • task_keeper (TaskKeeper, optional) – Keeper for the tasks. Defaults to None.

Returns:

Core task runner for the tasks.

Return type:

CoreTaskRunner

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_serializer_plugin(**kwargs)[source]#

Get serializer plugin.

This plugin is used for serialization of interfaces in new interactive API.

Parameters:

**kwargs – Additional keyword arguments.

Returns:

Serializer plugin.

Return type:

SerializerPlugin

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

Get gRPC 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:

gRPC server of the aggregator instance.

Return type:

AggregatorGRPCServer

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

initialize_data_loader(data_loader, shard_descriptor)[source]#

Initialize data loader.

Parameters:
  • data_loader (DataLoader) – Data loader to initialize.

  • shard_descriptor (ShardDescriptor) – Descriptor of the data shard.

Returns:

Initialized data loader.

Return type:

DataLoader

interactive_api_get_server(*, tensor_dict, root_certificate, certificate, private_key, tls)[source]#

Get gRPC server of the aggregator instance for interactive API.

Parameters:
  • tensor_dict (dict) – Dictionary of tensors.

  • root_certificate (str) – Root certificate for the server.

  • certificate (str) – Certificate for the server.

  • private_key (str) – Private key for the server.

  • tls (bool) – Whether to use Transport Layer Security.

Returns:

gRPC server of the aggregator instance.

Return type:

AggregatorGRPCServer

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.

restore_object(filename)[source]#

Deserialize an object.

Parameters:

filename (str) – Name of the file.

Returns:

Deserialized object.

Return type:

object