xain_fl.config package

This package provides the logic for reading and validating the various configuration options exposed by the CLI and the toml config file.

xain_fl.config.get_cmd_parameters()

Parse the command arguments

Returns

the parsed command arguments

Return type

Namespace

class xain_fl.config.Config(ai, storage, server, logging, metrics)

Bases: object

The coordinator configuration.

Configuration is split in three sections: Config.ai for items directly related to the FL protocol, Config.server for the server infrastructure, and Config.storage for storage related items.

The configuration is usually loaded from a dictionary the Config attributes map to the dictionary keys.

Parameters
  • ai (NamedTuple) – the configuration corresponding to the [ai] section of the toml config file

  • storage (NamedTuple) – the configuration corresponding to the [storage] section of the toml config fil

  • server (NamedTuple) – the configuration corresponding to the [server] section of the toml config file

  • logging (NamedTuple) – the configuration corresponding to the [logging] section of the toml config file

  • metrics (NamedTuple) – the configuration corresponding to the [metrics] section of the toml config file

Example

Here is a valid configuration:

# This section correspond to the `Config.server` attribute
[server]

# Address to listen on for incoming gRPC connections
host = "[::]"
# Port to listen on for incoming gRPC connections
port = 50051


# This section corresponds to the `Config.ai` attribute
[ai]

# Number of global rounds the model is going to be trained for. This
# must be a positive integer.
rounds = 1

# Number of local epochs per round
epochs = 1

# Minimum number of participants to be selected for a round.
min_participants = 1

# Fraction of total clients that participate in a training round. This
# must be a float between 0 and 1.
fraction_participants = 1.0

# This section corresponds to the `Config.storage` attribute
[storage]

# URL to the storage service to use
endpoint = "http://localhost:9000"

# Name of the bucket for storing the models
bucket = "weights"

# AWS secret access to use to authenticate to the storage service
secret_access_key = "my-secret"

# AWS access key ID to use to authenticate to the storage service
access_key_id = "my-key-id"

This config file can be loaded and used as follows:

from xain_fl.config import Config

config = Config.load("example_config.toml")

assert config.server.host == "[::]"
assert config.server.port == 50051

assert config.ai.rounds == 1
assert config.ai.epochs == 1
assert config.ai.min_participants == 1
assert config.ai.fraction_participants == 1.0

assert config.storage.endpoint == "http://localhost:9000"
assert config.storage.global_weights_bucket == "global_weights"
assert config.storage.local_weights_bucket == "local_weights"
assert config.storage.secret_access_key == "my-access-key"
assert config.storage.access_key_id == "my-key"
classmethod from_unchecked_dict(dictionary)

Check if the given dictionary contains a valid configuration, and if so, create a Config instance from it.

Parameters

dictionary (Mapping[str, Any]) – a dictionary containing the configuration

Return type

~T

classmethod from_valid_dict(dictionary)

Create a Config instance for the given dictionary, assuming it contains a valid configuration

Parameters

dictionary (Mapping[str, Any]) – a dictionary containing the configuration

Return type

~T

classmethod load(path)

Read the config file from the given path, check that it contains a valid configuration, and return the corresponding Config instance.

Parameters

path (str) – path to a configuration file

Return type

~T

class xain_fl.config.AiConfig

Bases: tuple

FL configuration: number of participant to each training round, etc.

property epochs

Alias for field number 1

property fraction_participants

Alias for field number 3

property min_participants

Alias for field number 2

property rounds

Alias for field number 0

class xain_fl.config.LoggingConfig

Bases: tuple

Logging related configuration: log level, colors, etc.

property console

Alias for field number 1

property level

Alias for field number 0

property third_party

Alias for field number 2

class xain_fl.config.StorageConfig

Bases: tuple

Storage related configuration: storage endpoints and credentials, etc.

property access_key_id

Alias for field number 3

property bucket

Alias for field number 1

property endpoint

Alias for field number 0

property secret_access_key

Alias for field number 2

class xain_fl.config.ServerConfig

Bases: tuple

The server configuration: TLS, addresses for incoming connections, etc.

property grpc_options

Alias for field number 2

property heartbeat_time

Alias for field number 4

property heartbeat_timeout

Alias for field number 5

property host

Alias for field number 0

property port

Alias for field number 1

property thread_pool_workers

Alias for field number 3

class xain_fl.config.MetricsConfig

Bases: tuple

Metrics related configuration: InfluxDB host, InfluxDB port, etc.

property db_name

Alias for field number 5

property enable

Alias for field number 0

property host

Alias for field number 1

property password

Alias for field number 4

property port

Alias for field number 2

property user

Alias for field number 3

exception xain_fl.config.InvalidConfig

Bases: ValueError

Exception raised upon trying to load an invalid configuration

Submodules

xain_fl.config.cli module

This module provides helpers for parsing the CLI arguments.

xain_fl.config.cli.get_cmd_parameters()

Parse the command arguments

Returns

the parsed command arguments

Return type

Namespace

xain_fl.config.schema module

This module provides helpers for reading and validating the TOML configuration.

class xain_fl.config.schema.AiConfig

Bases: tuple

FL configuration: number of participant to each training round, etc.

property epochs

Alias for field number 1

property fraction_participants

Alias for field number 3

property min_participants

Alias for field number 2

property rounds

Alias for field number 0

class xain_fl.config.schema.Config(ai, storage, server, logging, metrics)

Bases: object

The coordinator configuration.

Configuration is split in three sections: Config.ai for items directly related to the FL protocol, Config.server for the server infrastructure, and Config.storage for storage related items.

The configuration is usually loaded from a dictionary the Config attributes map to the dictionary keys.

Parameters
  • ai (NamedTuple) – the configuration corresponding to the [ai] section of the toml config file

  • storage (NamedTuple) – the configuration corresponding to the [storage] section of the toml config fil

  • server (NamedTuple) – the configuration corresponding to the [server] section of the toml config file

  • logging (NamedTuple) – the configuration corresponding to the [logging] section of the toml config file

  • metrics (NamedTuple) – the configuration corresponding to the [metrics] section of the toml config file

Example

Here is a valid configuration:

# This section correspond to the `Config.server` attribute
[server]

# Address to listen on for incoming gRPC connections
host = "[::]"
# Port to listen on for incoming gRPC connections
port = 50051


# This section corresponds to the `Config.ai` attribute
[ai]

# Number of global rounds the model is going to be trained for. This
# must be a positive integer.
rounds = 1

# Number of local epochs per round
epochs = 1

# Minimum number of participants to be selected for a round.
min_participants = 1

# Fraction of total clients that participate in a training round. This
# must be a float between 0 and 1.
fraction_participants = 1.0

# This section corresponds to the `Config.storage` attribute
[storage]

# URL to the storage service to use
endpoint = "http://localhost:9000"

# Name of the bucket for storing the models
bucket = "weights"

# AWS secret access to use to authenticate to the storage service
secret_access_key = "my-secret"

# AWS access key ID to use to authenticate to the storage service
access_key_id = "my-key-id"

This config file can be loaded and used as follows:

from xain_fl.config import Config

config = Config.load("example_config.toml")

assert config.server.host == "[::]"
assert config.server.port == 50051

assert config.ai.rounds == 1
assert config.ai.epochs == 1
assert config.ai.min_participants == 1
assert config.ai.fraction_participants == 1.0

assert config.storage.endpoint == "http://localhost:9000"
assert config.storage.global_weights_bucket == "global_weights"
assert config.storage.local_weights_bucket == "local_weights"
assert config.storage.secret_access_key == "my-access-key"
assert config.storage.access_key_id == "my-key"
classmethod from_unchecked_dict(dictionary)

Check if the given dictionary contains a valid configuration, and if so, create a Config instance from it.

Parameters

dictionary (Mapping[str, Any]) – a dictionary containing the configuration

Return type

~T

classmethod from_valid_dict(dictionary)

Create a Config instance for the given dictionary, assuming it contains a valid configuration

Parameters

dictionary (Mapping[str, Any]) – a dictionary containing the configuration

Return type

~T

classmethod load(path)

Read the config file from the given path, check that it contains a valid configuration, and return the corresponding Config instance.

Parameters

path (str) – path to a configuration file

Return type

~T

exception xain_fl.config.schema.InvalidConfig

Bases: ValueError

Exception raised upon trying to load an invalid configuration

class xain_fl.config.schema.LoggingConfig

Bases: tuple

Logging related configuration: log level, colors, etc.

property console

Alias for field number 1

property level

Alias for field number 0

property third_party

Alias for field number 2

class xain_fl.config.schema.MetricsConfig

Bases: tuple

Metrics related configuration: InfluxDB host, InfluxDB port, etc.

property db_name

Alias for field number 5

property enable

Alias for field number 0

property host

Alias for field number 1

property password

Alias for field number 4

property port

Alias for field number 2

property user

Alias for field number 3

class xain_fl.config.schema.ServerConfig

Bases: tuple

The server configuration: TLS, addresses for incoming connections, etc.

property grpc_options

Alias for field number 2

property heartbeat_time

Alias for field number 4

property heartbeat_timeout

Alias for field number 5

property host

Alias for field number 0

property port

Alias for field number 1

property thread_pool_workers

Alias for field number 3

class xain_fl.config.schema.StorageConfig

Bases: tuple

Storage related configuration: storage endpoints and credentials, etc.

property access_key_id

Alias for field number 3

property bucket

Alias for field number 1

property endpoint

Alias for field number 0

property secret_access_key

Alias for field number 2

xain_fl.config.schema.create_class_from_schema(class_name, schema)

Create a class named class_name from the given schema, where the attributes of the new class are the schema’s keys.

Parameters
  • class_name (str) – name of the class to create

  • schema (Schema) – schema from which to create the class

Return type

Any

Returns

A new class where attributes are the given schema’s keys

xain_fl.config.schema.error(key, description)

Return an error message for the given configuration item and description of the expected value type.

Parameters
  • key (str) – key of the configuration item

  • description (str) – description of the expected type of value for this configuration item

Return type

str

xain_fl.config.schema.hostname_or_ip_address(key, expected_value='a valid domain name or IP address')

Return a hostname or IP address validator for the given configuration item.

Parameters
  • key (str) – key of the configuration item

  • expected_value (str) – description of the expected type of value for this configuration item

Return type

Schema

xain_fl.config.schema.is_valid_hostname(value)

Return whether the given string is a valid hostname

Parameters

value (str) – string to check

Return type

bool

Returns

True if the given value is a valid hostname, False otherwise

xain_fl.config.schema.is_valid_ip_address(value)

Return whether the given string is a valid IP address

Parameters

value (str) – string to check

Return type

bool

Returns

True if the given value is a valid IP address, False otherwise

xain_fl.config.schema.log_level(key)

Return a validator for logging levels

Parameters

key (str) – key of the configuration item

Return type

Schema

xain_fl.config.schema.non_negative_integer(key, expected_value='a positive integer')

Return a non-negative integer validator for the given configuration item.

Parameters
  • key (str) – key of the configuration item

  • expected_value (str) – description of the expected type of value for this configuration item

Return type

Schema

xain_fl.config.schema.positive_integer(key, expected_value='a strictly positive integer')

Return a validator for strictly positive integers for the given configuration item.

Parameters
  • key (str) – key of the configuration item

  • expected_value (str) – description of the expected type of value for this configuration item

Return type

Schema

xain_fl.config.schema.url(key, expected_value='a valid URL')

Return a URL validator for the given configuration item.

Parameters
  • key (str) – key of the configuration item

  • expected_value (str) – description of the expected type of value for this configuration item

Return type

Schema