p2pfl.management.p2pfl_web_services moduleΒΆ

Communication with P2PFL Web Services (via REST API).

Todo

Implement batch sending.

Todo

Implement get_pending_actions.

Todo

Implement unregister_node.

Todo

Implement get_experiment_id.

class p2pfl.management.p2pfl_web_services.P2pflWebServices(url, key)[source]ΒΆ

Bases: object

Class that manages the communication with the p2pfl-web services.

Parameters:
  • url (str) – The URL of the p2pfl-web services.

  • key (str) – The key to access the services.

get_pending_actions()[source]ΒΆ

Get pending actions from the p2pfl-web services.

register_node(node)[source]ΒΆ

Register a node.

Parameters:

node (str) – The node address.

Return type:

None

send_communication_log(node, timestamp, direction, cmd, source_dest, package_type, package_size, round_num=None, additional_info=None)[source]ΒΆ

Send a communication log to the web services.

Parameters:
  • node (str) – The node address.

  • timestamp (datetime) – The timestamp of the communication.

  • direction (str) – Direction of communication (β€œsent” or β€œreceived”).

  • cmd (str) – The command or message type.

  • source_dest (str) – Source (if receiving) or destination (if sending) node.

  • package_type (str) – Type of package (β€œmessage” or β€œweights”).

  • package_size (int) – Size of the package in bytes (if available).

  • round_num (Optional[int]) – The federated learning round number (if applicable).

  • additional_info (Optional[dict]) – Additional information as a dictionary.

Return type:

None

send_global_metric(exp, round, metric, node, value)[source]ΒΆ

Send a local metric.

Parameters:
  • exp (str) – The experiment.

  • round (int) – The round.

  • metric (str) – The metric.

  • node (str) – The node address.

  • value (float) – The value.

send_local_metric(exp, round, metric, node, value, step)[source]ΒΆ

Send a local metric.

Parameters:
  • exp (str) – The experiment.

  • round (int) – The round.

  • metric (str) – The metric.

  • node (str) – The node address.

  • value (float) – The value.

  • step (int) – The step.

Return type:

None

send_log(time, node, level, message)[source]ΒΆ

Send a log message.

Parameters:
  • time (datetime) – The time of the message.

  • node (str) – The node address.

  • level (int) – The log level.

  • message (str) – The message.

Return type:

None

send_system_metric(node, metric, value, time)[source]ΒΆ

Send a metric.

Parameters:
  • node (str) – The node address.

  • metric (str) – The metric.

  • value (float) – The value.

  • time (datetime) – The time.

unregister_node(node)[source]ΒΆ

Unregister a node.

Parameters:

node (str) – The node address.

Return type:

None

exception p2pfl.management.p2pfl_web_services.P2pflWebServicesError(code, message)[source]ΒΆ

Bases: Exception

P2PFL Web Services Error.

Parameters:
  • code (int) – Error code.

  • message (str) – Error message.