Beispiel #1
0
 def simplify(worker: AbstractWorker, action: "Action") -> tuple:
     """
     This function takes the attributes of a CommunicationAction and saves them in a tuple
     Args:
         worker (AbstractWorker): a reference to the worker doing the serialization
         action (CommunicationAction): a CommunicationAction
     Returns:
         tuple: a tuple holding the unique attributes of the CommunicationAction
     Examples:
         data = simplify(worker, action)
     """
     return Action.simplify(worker, action)
Beispiel #2
0
    def translate_action(self, action: Action, to_framework: str) -> Action:
        """Uses threepio to perform command level translation given a specific action"""
        threepio = Threepio(self.plan.base_framework, to_framework, None)
        function_name = action.name.split(".")[-1]
        args = action.args if action.target is None else (action.target,
                                                          *action.args)
        cmd = threepio.translate(Command(function_name, args, action.kwargs))

        new_action = action.copy()
        new_action.name = ".".join(cmd.attrs)
        new_action.args = tuple(cmd.args)
        new_action.kwargs = cmd.kwargs
        new_action.target = None
        return new_action
Beispiel #3
0
    def bufferize(worker: AbstractWorker,
                  communication: "ComputationAction") -> "ComputationActionPB":
        """
        This function takes the attributes of a ComputationAction and saves them in Protobuf
        Args:
            worker (AbstractWorker): a reference to the worker doing the serialization
            communication (ComputationAction): a ComputationAction
        Returns:
            protobuf_obj: a Protobuf message holding the unique attributes of the communication
        Examples:
            data = bufferize(sy.local_worker, communication)
        """
        protobuf_action = ComputationActionPB()

        return Action.bufferize(worker, communication, protobuf_action)
Beispiel #4
0
    def detail(worker: AbstractWorker, action_tuple: tuple) -> "Action":
        """
        This function takes the simplified tuple version of this message and converts
        it into a CommunicationAction. 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.
            communication_tuple (Tuple): the raw information being detailed.
        Returns:
            communication (CommunicationAction): a CommunicationAction.
        Examples:
            communication = detail(sy.local_worker, communication_tuple)
        """
        attrs = Action.detail(worker, action_tuple)

        return CommunicationAction(*attrs)
Beispiel #5
0
    def unbufferize(
            worker: AbstractWorker,
            protobuf_obj: "CommunicationActionPB") -> "CommunicationAction":
        """
        This function takes the Protobuf version of this message and converts
        it into an Action. 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 (CommunicationActionPB): the Protobuf message

        Returns:
            obj (CommunicationAction): a CommunicationAction

        Examples:
            message = unbufferize(sy.local_worker, protobuf_msg)
        """
        attrs = Action.unbufferize(worker, protobuf_obj)

        return CommunicationAction(*attrs)