def send_command(self, recipient, message, return_ids=None): """ Send a command through a message to a recipient worker :param recipient: :param message: :return: """ if return_ids is None: return_ids = [int(10e10 * random.random())] message = (message, return_ids) try: _ = self.send_msg(MSGTYPE.CMD, message, location=recipient) except ResponseSignatureError as e: return_ids = e.ids_generated responses = [] for return_id in return_ids: response = sy.PointerTensor( location=recipient, id_at_location=return_id, owner=self, id=int(10e10 * random.random()), ) responses.append(response) if len(return_ids) == 1: return responses[0] return responses
def attr(self, attr_name): attr_ptr = syft.PointerTensor( id=self.id, owner=self.owner, location=self.location, id_at_location=self.id_at_location, point_to_attr=self._create_attr_name_string(attr_name), ).wrap() self.__setattr__(attr_name, attr_ptr) return attr_ptr
def _get_plan_output(self, result_ids, return_ptr=False): responses = [] for return_id in result_ids: response = sy.PointerTensor( location=self.owner, id_at_location=return_id, owner=self, id=sy.ID_PROVIDER.pop() ) responses.append(response if return_ptr else response.get()) if len(responses) == 1: return responses[0] return responses
def attr(self, attr_name): if self.point_to_attr is not None: point_to_attr = "{}.{}".format(self.point_to_attr, attr_name) else: point_to_attr = attr_name attr_ptr = syft.PointerTensor( id=self.id, owner=self.owner, location=self.location, id_at_location=self.id_at_location, point_to_attr=point_to_attr, ).wrap() self.__setattr__(attr_name, attr_ptr) return attr_ptr
def send_command( self, recipient: "BaseWorker", message: str, return_ids: str = None ) -> Union[List["pointers.PointerTensor"], "pointers.PointerTensor"]: """ Sends a command through a message to a recipient worker. Args: recipient: A recipient worker. message: A string representing the message being sent. return_ids: A list of strings indicating the ids of the tensors that should be returned as response to the command execution. Returns: A list of PointerTensors or a single PointerTensor if just one response is expected. """ if return_ids is None: return_ids = [sy.ID_PROVIDER.pop()] message = (message, return_ids) try: ret_val = self.send_msg(codes.MSGTYPE.CMD, message, location=recipient) except ResponseSignatureError as e: ret_val = None return_ids = e.ids_generated if ret_val is None or type(ret_val) == bytes: responses = [] for return_id in return_ids: response = sy.PointerTensor( location=recipient, id_at_location=return_id, owner=self, id=sy.ID_PROVIDER.pop(), ) responses.append(response) if len(return_ids) == 1: responses = responses[0] else: responses = ret_val return responses
def send_command(self, recipient: "BaseWorker", message: str, return_ids: str = None ) -> Union[List[PointerTensor], PointerTensor]: """ Sends a command through a message to a recipient worker. Args: recipient: A recipient worker. message: A string representing the message being sent. return_ids: A list of strings indicating the ids of the tensors that should be returned as response to the command execution. Returns: A list of PointerTensors or a single PointerTensor if just one response is expected. """ if return_ids is None: return_ids = [int(10e10 * random.random())] message = (message, return_ids) try: _ = self.send_msg(MSGTYPE.CMD, message, location=recipient) except ResponseSignatureError as e: return_ids = e.ids_generated responses = [] for return_id in return_ids: response = sy.PointerTensor( location=recipient, id_at_location=return_id, owner=self, id=int(10e10 * random.random()), ) responses.append(response) if len(return_ids) == 1: return responses[0] return responses