Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pip-dep/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ phe~=1.4.0
Pillow~=6.2.2
requests~=2.22.0
scipy~=1.4.1
syft-proto~=0.2.3.a1
syft-proto~=0.2.4.a1
tblib~=1.6.0
torchvision~=0.5.0
torch~=1.4.0
tornado==4.5.3
websocket_client~=0.57.0
websockets~=8.1.0
tornado==4.5.3
6 changes: 3 additions & 3 deletions syft/generic/pointers/pointer_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from syft.generic.frameworks.types import FrameworkTensor
from syft.generic.tensor import AbstractTensor
from syft.generic.pointers.object_pointer import ObjectPointer
from syft.messaging.message import CommandMessage
from syft.messaging.message import TensorCommandMessage
from syft.workers.abstract import AbstractWorker

from syft_proto.generic.pointers.v1.pointer_tensor_pb2 import PointerTensor as PointerTensorPB
Expand Down Expand Up @@ -263,7 +263,7 @@ def create_pointer(

def move(self, destination):
kwargs = {"inplace": True, "create_pointer": False}
message = CommandMessage.communication(
message = TensorCommandMessage.communication(
self.id_at_location, self.location.id, [destination.id], kwargs
)
self.owner.send_msg(message=message, location=self.location)
Expand All @@ -279,7 +279,7 @@ def remote_send(self, destination):
C will hold a pointer to a pointer on A which points to the tensor on B.
"""
kwargs = {"inplace": True}
message = CommandMessage.communication(
message = TensorCommandMessage.communication(
self.id_at_location, self.location.id, [destination.id], kwargs
)
self.owner.send_msg(message=message, location=self.location)
Expand Down
62 changes: 33 additions & 29 deletions syft/messaging/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from syft.frameworks.torch.tensors.interpreters.placeholder import PlaceHolder

from syft_proto.messaging.v1.message_pb2 import ObjectMessage as ObjectMessagePB
from syft_proto.messaging.v1.message_pb2 import CommandMessage as CommandMessagePB
from syft_proto.messaging.v1.message_pb2 import TensorCommandMessage as CommandMessagePB


class Message(ABC):
Expand Down Expand Up @@ -52,7 +52,7 @@ def __repr__(self):
return self.__str__()


class CommandMessage(Message):
class TensorCommandMessage(Message):
"""All syft actions use this message type

In Syft, an action is when one worker wishes to tell another worker to do something with
Expand Down Expand Up @@ -104,27 +104,27 @@ def __str__(self):

@staticmethod
def computation(name, target, args_, kwargs_, return_ids):
""" Helper function to build a CommandMessage containing a ComputationAction
""" Helper function to build a TensorCommandMessage containing a ComputationAction
directly from the action arguments.
"""
action = ComputationAction(name, target, args_, kwargs_, return_ids)
return CommandMessage(action)
return TensorCommandMessage(action)

@staticmethod
def communication(obj_id, source, destinations, kwargs):
""" Helper function to build a CommandMessage containing a CommunicationAction
""" Helper function to build a TensorCommandMessage containing a CommunicationAction
directly from the action arguments.
"""
action = CommunicationAction(obj_id, source, destinations, kwargs)
return CommandMessage(action)
return TensorCommandMessage(action)

@staticmethod
def simplify(worker: AbstractWorker, ptr: "CommandMessage") -> tuple:
def simplify(worker: AbstractWorker, ptr: "TensorCommandMessage") -> tuple:
"""
This function takes the attributes of a CommandMessage and saves them in a tuple
This function takes the attributes of a TensorCommandMessage and saves them in a tuple
Args:
worker (AbstractWorker): a reference to the worker doing the serialization
ptr (CommandMessage): a Message
ptr (TensorCommandMessage): a Message
Returns:
tuple: a tuple holding the unique attributes of the message
Examples:
Expand All @@ -133,33 +133,35 @@ def simplify(worker: AbstractWorker, ptr: "CommandMessage") -> tuple:
return (sy.serde.msgpack.serde._simplify(worker, ptr.action),)

@staticmethod
def detail(worker: AbstractWorker, msg_tuple: tuple) -> "CommandMessage":
def detail(worker: AbstractWorker, msg_tuple: tuple) -> "TensorCommandMessage":
"""
This function takes the simplified tuple version of this message and converts
it into a CommandMessage. The simplify() method runs the inverse of this method.
it into a TensorCommandMessage. The simplify() method runs the inverse of this method.

Args:
worker (AbstractWorker): a reference to the worker necessary for detailing. Read
syft/serde/serde.py for more information on why this is necessary.
msg_tuple (Tuple): the raw information being detailed.
Returns:
ptr (CommandMessage): an CommandMessage.
ptr (TensorCommandMessage): an TensorCommandMessage.
Examples:
message = detail(sy.local_worker, msg_tuple)
"""
simplified_action = msg_tuple[0]

detailed_action = sy.serde.msgpack.serde._detail(worker, simplified_action)

return CommandMessage(detailed_action)
return TensorCommandMessage(detailed_action)

@staticmethod
def bufferize(worker: AbstractWorker, action_message: "CommandMessage") -> "CommandMessagePB":
def bufferize(
worker: AbstractWorker, action_message: "TensorCommandMessage"
) -> "CommandMessagePB":
"""
This function takes the attributes of a CommandMessage and saves them in Protobuf
This function takes the attributes of a TensorCommandMessage and saves them in Protobuf
Args:
worker (AbstractWorker): a reference to the worker doing the serialization
action_message (CommandMessage): an CommandMessage
action_message (TensorCommandMessage): an TensorCommandMessage
Returns:
protobuf_obj: a Protobuf message holding the unique attributes of the message
Examples:
Expand All @@ -177,25 +179,27 @@ def bufferize(worker: AbstractWorker, action_message: "CommandMessage") -> "Comm
return protobuf_action_msg

@staticmethod
def unbufferize(worker: AbstractWorker, protobuf_obj: "CommandMessagePB") -> "CommandMessage":
def unbufferize(
worker: AbstractWorker, protobuf_obj: "CommandMessagePB"
) -> "TensorCommandMessage":
"""
This function takes the Protobuf version of this message and converts
it into an CommandMessage. The bufferize() method runs the inverse of this method.
it into an TensorCommandMessage. The bufferize() method runs the inverse of this method.

Args:
worker (AbstractWorker): a reference to the worker necessary for detailing. Read
syft/serde/serde.py for more information on why this is necessary.
protobuf_obj (CommandMessagePB): the Protobuf message

Returns:
obj (CommandMessage): an CommandMessage
obj (TensorCommandMessage): an TensorCommandMessage

Examples:
message = unbufferize(sy.local_worker, protobuf_msg)
"""
action = getattr(protobuf_obj, protobuf_obj.WhichOneof("action"))
detailed_action = sy.serde.protobuf.serde._unbufferize(worker, action)
return CommandMessage(detailed_action)
return TensorCommandMessage(detailed_action)


class ObjectMessage(Message):
Expand Down Expand Up @@ -607,14 +611,14 @@ def detail(worker: AbstractWorker, msg_tuple: tuple) -> "PlanCommandMessage":
)


class ExecuteWorkerFunctionMessage(Message):
class WorkerCommandMessage(Message):
"""Message used to execute a function of the remote worker."""

# TODO: add more efficient detailer and simplifier custom for this type
# https://github.com/OpenMined/PySyft/issues/2512

def __init__(self, command_name: str, message: tuple):
"""Initialize a ExecuteWorkerFunctionMessage.
"""Initialize a WorkerCommandMessage.

Args:
command_name (str): name used to identify the command.
Expand All @@ -638,13 +642,13 @@ def contents(self):
return (self.command_name, self.message)

@staticmethod
def simplify(worker: AbstractWorker, ptr: "ExecuteWorkerFunctionMessage") -> tuple:
def simplify(worker: AbstractWorker, ptr: "WorkerCommandMessage") -> tuple:
"""
This function takes the attributes of a ExecuteWorkerFunctionMessage and saves them in a tuple
This function takes the attributes of a WorkerCommandMessage and saves them in a tuple

Args:
worker (AbstractWorker): a reference to the worker doing the serialization
ptr (ExecuteWorkerFunctionMessage): a Message
ptr (WorkerCommandMessage): a Message

Returns:
tuple: a tuple holding the unique attributes of the message
Expand All @@ -655,20 +659,20 @@ def simplify(worker: AbstractWorker, ptr: "ExecuteWorkerFunctionMessage") -> tup
)

@staticmethod
def detail(worker: AbstractWorker, msg_tuple: tuple) -> "ExecuteWorkerFunctionMessage":
def detail(worker: AbstractWorker, msg_tuple: tuple) -> "WorkerCommandMessage":
"""
This function takes the simplified tuple version of this message and converts
it into a ExecuteWorkerFunctionMessage. The simplify() method runs the inverse of this method.
it into a WorkerCommandMessage. The simplify() method runs the inverse of this method.

Args:
worker (AbstractWorker): a reference to the worker necessary for detailing. Read
syft/serde/serde.py for more information on why this is necessary.
msg_tuple (Tuple): the raw information being detailed.
Returns:
ptr (ExecuteWorkerFunctionMessage): a ExecuteWorkerFunctionMessage.
ptr (WorkerCommandMessage): a WorkerCommandMessage.
"""
command_name, message = msg_tuple
return ExecuteWorkerFunctionMessage(
return WorkerCommandMessage(
sy.serde.msgpack.serde._detail(worker, command_name),
sy.serde.msgpack.serde._detail(worker, message),
)
8 changes: 4 additions & 4 deletions syft/serde/msgpack/serde.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@
from syft.execution.computation import ComputationAction
from syft.execution.communication import CommunicationAction
from syft.execution.protocol import Protocol
from syft.messaging.message import CommandMessage
from syft.messaging.message import TensorCommandMessage
from syft.messaging.message import ObjectMessage
from syft.messaging.message import ObjectRequestMessage
from syft.messaging.message import IsNoneMessage
from syft.messaging.message import GetShapeMessage
from syft.messaging.message import ForceObjectDeleteMessage
from syft.messaging.message import SearchMessage
from syft.messaging.message import PlanCommandMessage
from syft.messaging.message import ExecuteWorkerFunctionMessage
from syft.messaging.message import WorkerCommandMessage
from syft.serde import compression
from syft.serde.msgpack.native_serde import MAP_NATIVE_SIMPLIFIERS_AND_DETAILERS
from syft.workers.abstract import AbstractWorker
Expand Down Expand Up @@ -124,18 +124,18 @@
TrainConfig,
BaseWorker,
AutogradTensor,
CommandMessage,
TensorCommandMessage,
ObjectMessage,
ObjectRequestMessage,
IsNoneMessage,
GetShapeMessage,
ForceObjectDeleteMessage,
SearchMessage,
PlanCommandMessage,
WorkerCommandMessage,
GradFunc,
String,
BaseDataset,
ExecuteWorkerFunctionMessage,
]

# If an object implements its own force_simplify and force_detail functions it should be stored in this list
Expand Down
6 changes: 3 additions & 3 deletions syft/serde/protobuf/proto.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from syft.frameworks.torch.tensors.interpreters.additive_shared import AdditiveSharingTensor
from syft.frameworks.torch.tensors.interpreters.placeholder import PlaceHolder
from syft.generic.pointers.pointer_tensor import PointerTensor
from syft.messaging.message import CommandMessage
from syft.messaging.message import TensorCommandMessage
from syft.messaging.message import ObjectMessage

from google.protobuf.empty_pb2 import Empty
Expand All @@ -35,7 +35,7 @@
)
from syft_proto.generic.pointers.v1.pointer_tensor_pb2 import PointerTensor as PointerTensorPB
from syft_proto.messaging.v1.message_pb2 import ObjectMessage as ObjectMessagePB
from syft_proto.messaging.v1.message_pb2 import CommandMessage as CommandMessagePB
from syft_proto.messaging.v1.message_pb2 import TensorCommandMessage as CommandMessagePB
from syft_proto.types.syft.v1.id_pb2 import Id as IdPB
from syft_proto.types.torch.v1.device_pb2 import Device as DevicePB
from syft_proto.types.torch.v1.parameter_pb2 import Parameter as ParameterPB
Expand All @@ -59,7 +59,7 @@
# Syft types
AdditiveSharingTensor: AdditiveSharingTensorPB,
ObjectMessage: ObjectMessagePB,
CommandMessage: CommandMessagePB,
TensorCommandMessage: CommandMessagePB,
CommunicationAction: CommunicationActionPB,
ComputationAction: ComputationActionPB,
PlaceHolder: PlaceholderPB,
Expand Down
6 changes: 3 additions & 3 deletions syft/serde/protobuf/serde.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from syft.frameworks.torch.tensors.interpreters.placeholder import PlaceHolder
from syft.generic.pointers.pointer_tensor import PointerTensor
from syft.messaging.message import ObjectMessage
from syft.messaging.message import CommandMessage
from syft.messaging.message import TensorCommandMessage
from syft.execution.plan import Plan
from syft.execution.protocol import Protocol
from syft.execution.state import State
Expand Down Expand Up @@ -44,7 +44,7 @@
AdditiveSharingTensor,
ObjectMessage,
ComputationAction,
CommandMessage,
TensorCommandMessage,
CommunicationAction,
PlaceHolder,
Plan,
Expand Down Expand Up @@ -241,7 +241,7 @@ def serialize(
msg_wrapper.contents_empty_msg.CopyFrom(protobuf_obj)
elif obj_type == ObjectMessage:
msg_wrapper.contents_object_msg.CopyFrom(protobuf_obj)
elif obj_type == CommandMessage:
elif obj_type == TensorCommandMessage:
msg_wrapper.contents_action_msg.CopyFrom(protobuf_obj)

# 2) Serialize
Expand Down
Loading