p2pfl.communication.protocols.memory.memory_communication_protocol moduleΒΆ
In-memory communication protocol.
- class p2pfl.communication.protocols.memory.memory_communication_protocol.InMemoryCommunicationProtocol(addr=None, commands=None)[source]ΒΆ
Bases:
CommunicationProtocol
In-memory communication protocol.
- Parameters:
addr (
Optional
[str
]) β Address of the node.commands (
Optional
[List
[Command
]]) β Commands to add to the communication protocol.
Todo
Remove this copy-paste code and use a in-memory wrapper for the grpc communication protocol.
- broadcast(msg, node_list=None)[source]ΒΆ
Broadcast a message to all neighbors.
- Parameters:
msg (
Dict
[str
,Union
[str
,int
,bytes
,List
[str
]]]) β The message to broadcast.node_list (
Optional
[List
[str
]]) β Optional node list.
- Return type:
None
- build_msg(cmd, args=None, round=None)[source]ΒΆ
Build a message.
- Parameters:
cmd (
str
) β The message.args (
Optional
[List
[str
]]) β The arguments.round (
Optional
[int
]) β The round.
- Return type:
Any
- build_weights(cmd, round, serialized_model, contributors=None, weight=1)[source]ΒΆ
Build weights.
- Parameters:
cmd (
str
) β The command.round (
int
) β The round.serialized_model (
bytes
) β The serialized model.contributors (
Optional
[List
[str
]]) β The model contributors.weight (
int
) β The weight of the model (amount of samples used).
- Return type:
Any
- connect(addr, non_direct=False)[source]ΒΆ
Connect to a neighbor.
- Parameters:
addr (
str
) β The address to connect to.non_direct (
bool
) β The non direct flag.
- Return type:
bool
- disconnect(nei, disconnect_msg=True)[source]ΒΆ
Disconnect from a neighbor.
- Parameters:
nei (
str
) β The neighbor to disconnect from.disconnect_msg (
bool
) β The disconnect message flag.
- Return type:
None
- get_neighbors(only_direct=False)[source]ΒΆ
Get the neighbors.
- Parameters:
only_direct (
bool
) β The only direct flag.- Return type:
Dict
[str
,Any
]
- gossip_weights(early_stopping_fn, get_candidates_fn, status_fn, model_fn, period=None, create_connection=False)[source]ΒΆ
Gossip model weights.
- Parameters:
early_stopping_fn (
Callable
[[],bool
]) β The early stopping function.get_candidates_fn (
Callable
[[],List
[str
]]) β The get candidates function.status_fn (
Callable
[[],Any
]) β The status function.model_fn (
Callable
[[str
],Any
]) β The model function.period (
Optional
[float
]) β The period.create_connection (
bool
) β The create connection flag.
- Return type:
None
- send(nei, msg, raise_error=False, remove_on_error=True)[source]ΒΆ
Send a message to a neighbor.
- Parameters:
nei (
str
) β The neighbor to send the message.msg (
Dict
[str
,Union
[str
,int
,bytes
,List
[str
]]]) β The message to senraise_error (
bool
) β If raise error.remove_on_error (
bool
) β If remove on error.d.
- Return type:
None