p2pfl.settings module

Module to define constants for the p2pfl system.

class p2pfl.settings.General(SEED=None, GRPC_TIMEOUT=10.0, LOG_LEVEL='INFO', LOG_DIR='logs', MAX_LOG_RUNS=10, DISABLE_RAY=False, RESOURCE_MONITOR_PERIOD=10)[source]

Bases: object

General system settings.

DISABLE_RAY: bool = False

Disable Ray for local testing.

GRPC_TIMEOUT: float = 10.0

Maximum time (seconds) to wait for a gRPC request.

LOG_DIR: str = 'logs'

Directory to save logs.

LOG_LEVEL: str = 'INFO'

Log level for the system.

MAX_LOG_RUNS: int = 10

Maximum number of run log files to keep.

RESOURCE_MONITOR_PERIOD: int = 10

Period (seconds) to send resource monitor information.

SEED: Optional[int] = None

Seed for random number generation.

class p2pfl.settings.Gossip(PERIOD=0.1, TTL=10, MESSAGES_PER_PERIOD=100, AMOUNT_LAST_MESSAGES_SAVED=100, MODELS_PERIOD=1, MODELS_PER_ROUND=2, EXIT_ON_X_EQUAL_ROUNDS=10)[source]

Bases: object

Gossip protocol settings.

AMOUNT_LAST_MESSAGES_SAVED: int = 100

Number of last messages saved in the gossip protocol (avoid multiple message processing).

EXIT_ON_X_EQUAL_ROUNDS: int = 10

Amount of equal rounds to exit gossiping. Careful, a low value can cause an early stop of gossiping.

MESSAGES_PER_PERIOD: int = 100

Number of messages to send in each gossip period.

MODELS_PERIOD: int = 1

Period of gossiping models (times by second).

MODELS_PER_ROUND: int = 2

Amount of equal rounds to exit gossiping. Careful, a low value can cause an early stop of gossiping.

PERIOD: float = 0.1

Period (seconds) for the gossip protocol.

TTL: int = 10

Time to live (TTL) for a message in the gossip protocol.

class p2pfl.settings.Heartbeat(PERIOD=2.0, TIMEOUT=5.0, WAIT_CONVERGENCE=2.0, EXCLUDE_BEAT_LOGS=True)[source]

Bases: object

Heartbeat settings.

EXCLUDE_BEAT_LOGS: bool = True

Exclude heartbeat logs.

PERIOD: float = 2.0

Period (seconds) to send heartbeats.

TIMEOUT: float = 5.0

Timeout (seconds) for a node to be considered dead.

WAIT_CONVERGENCE: float = 2.0

Time (seconds) to wait for the heartbeats to converge before a learning round starts.

class p2pfl.settings.SSL(USE_SSL=True, BASE_DIR='/home/runner/work/p2pfl/p2pfl/p2pfl', CA_CRT='/home/runner/work/p2pfl/p2pfl/p2pfl/certificates/ca.crt', SERVER_CRT='/home/runner/work/p2pfl/p2pfl/p2pfl/certificates/server.crt', CLIENT_CRT='/home/runner/work/p2pfl/p2pfl/p2pfl/certificates/client.crt', SERVER_KEY='/home/runner/work/p2pfl/p2pfl/p2pfl/certificates/server.key', CLIENT_KEY='/home/runner/work/p2pfl/p2pfl/p2pfl/certificates/client.key')[source]

Bases: object

SSL certificate settings.

BASE_DIR: str = '/home/runner/work/p2pfl/p2pfl/p2pfl'
CA_CRT: str = '/home/runner/work/p2pfl/p2pfl/p2pfl/certificates/ca.crt'

CA certificate.

CLIENT_CRT: str = '/home/runner/work/p2pfl/p2pfl/p2pfl/certificates/client.crt'

Client certificate.

CLIENT_KEY: str = '/home/runner/work/p2pfl/p2pfl/p2pfl/certificates/client.key'

Client private key.

SERVER_CRT: str = '/home/runner/work/p2pfl/p2pfl/p2pfl/certificates/server.crt'

Server certificate.

SERVER_KEY: str = '/home/runner/work/p2pfl/p2pfl/p2pfl/certificates/server.key'

Server private key.

USE_SSL: bool = True

Use SSL on experiments.

class p2pfl.settings.Settings(*args, **kwargs)[source]

Bases: object

Class to define global settings for the p2pfl system.

general = General(SEED=None, GRPC_TIMEOUT=10.0, LOG_LEVEL='INFO', LOG_DIR='logs', MAX_LOG_RUNS=10, DISABLE_RAY=False, RESOURCE_MONITOR_PERIOD=10)

General settings.

gossip = Gossip(PERIOD=0.1, TTL=10, MESSAGES_PER_PERIOD=100, AMOUNT_LAST_MESSAGES_SAVED=100, MODELS_PERIOD=1, MODELS_PER_ROUND=2, EXIT_ON_X_EQUAL_ROUNDS=10)

Gossip protocol settings.

heartbeat = Heartbeat(PERIOD=2.0, TIMEOUT=5.0, WAIT_CONVERGENCE=2.0, EXCLUDE_BEAT_LOGS=True)

Heartbeat settings.

classmethod set_from_dict(settings_dict)[source]

Update settings from a dictionary.

The dictionary should be nested, with the first level keys corresponding to the nested setting classes (e.g., “General”, “Heartbeat”) and the second level keys corresponding to the setting attributes within those classes (e.g., “GRPC_TIMEOUT”, “HEARTBEAT_PERIOD”).

Parameters:

settings_dict (dict[str, dict[str, Any]]) – Dictionary with the settings to update.

ssl = SSL(USE_SSL=True, BASE_DIR='/home/runner/work/p2pfl/p2pfl/p2pfl', CA_CRT='/home/runner/work/p2pfl/p2pfl/p2pfl/certificates/ca.crt', SERVER_CRT='/home/runner/work/p2pfl/p2pfl/p2pfl/certificates/server.crt', CLIENT_CRT='/home/runner/work/p2pfl/p2pfl/p2pfl/certificates/client.crt', SERVER_KEY='/home/runner/work/p2pfl/p2pfl/p2pfl/certificates/server.key', CLIENT_KEY='/home/runner/work/p2pfl/p2pfl/p2pfl/certificates/client.key')

SSL certificate settings.

training = Training(VOTE_TIMEOUT=60, AGGREGATION_TIMEOUT=300, DEFAULT_BATCH_SIZE=128)

Training process settings.

class p2pfl.settings.Training(VOTE_TIMEOUT=60, AGGREGATION_TIMEOUT=300, DEFAULT_BATCH_SIZE=128)[source]

Bases: object

Training process settings.

AGGREGATION_TIMEOUT: int = 300

Timeout (seconds) for a node to wait for other models. Timeout starts when the first model is added.

DEFAULT_BATCH_SIZE: int = 128

Default batch size for training.

VOTE_TIMEOUT: int = 60

Timeout (seconds) for a node to wait for a vote.