def bufferize(worker: AbstractWorker, action: "ComputationAction") -> "ComputationActionPB": """ This function takes the attributes of a Action and saves them in Protobuf Args: worker (AbstractWorker): a reference to the worker doing the serialization action (Action): an Action Returns: protobuf_obj: a Protobuf message holding the unique attributes of the message Examples: data = bufferize(message) """ protobuf_op = ComputationActionPB() protobuf_op.command = action.name protobuf_target = None if isinstance(action.target, sy.generic.pointers.pointer_tensor.PointerTensor): protobuf_target = protobuf_op.target_pointer elif isinstance(action.target, sy.execution.placeholder_id.PlaceholderId): protobuf_target = protobuf_op.target_placeholder_id elif isinstance(action.target, (int, str)): sy.serde.protobuf.proto.set_protobuf_id(protobuf_op.target_id, action.target) elif action.target is not None: protobuf_target = protobuf_op.target_tensor if protobuf_target is not None: protobuf_target.CopyFrom( sy.serde.protobuf.serde._bufferize(worker, action.target)) if action.args: protobuf_op.args.extend( sy.serde.protobuf.serde.bufferize_args(worker, action.args)) if action.kwargs: for key, value in action.kwargs.items(): protobuf_op.kwargs.get_or_create(key).CopyFrom( sy.serde.protobuf.serde.bufferize_arg(worker, value)) if action.return_ids is not None: if not isinstance(action.return_ids, (list, tuple)): return_ids = (action.return_ids, ) else: return_ids = action.return_ids for return_id in return_ids: if isinstance(return_id, PlaceholderId): # NOTE to know when we have a PlaceholderId, we store it # in return_placeholder_ids and not in return_ids protobuf_op.return_placeholder_ids.append( sy.serde.protobuf.serde._bufferize(worker, return_id)) else: sy.serde.protobuf.proto.set_protobuf_id( protobuf_op.return_ids.add(), return_id) return protobuf_op
def bufferize(worker: AbstractWorker, action: "ComputationAction") -> "ComputationActionPB": """ This function takes the attributes of a Action and saves them in Protobuf Args: worker (AbstractWorker): a reference to the worker doing the serialization action (Action): an Action Returns: protobuf_obj: a Protobuf message holding the unique attributes of the message Examples: data = bufferize(message) """ protobuf_op = ComputationActionPB() protobuf_op.command = action.name if type(action.target ) == sy.generic.pointers.pointer_tensor.PointerTensor: protobuf_owner = protobuf_op.target_pointer elif (type(action.target) == sy.frameworks.torch.tensors.interpreters. placeholder.PlaceHolder): protobuf_owner = protobuf_op.target_placeholder else: protobuf_owner = protobuf_op.target_tensor if action.target is not None: protobuf_owner.CopyFrom( sy.serde.protobuf.serde._bufferize(worker, action.target)) if action.args: protobuf_op.args.extend( ComputationAction._bufferize_args(worker, action.args)) if action.kwargs: for key, value in action.kwargs.items(): protobuf_op.kwargs.get_or_create(key).CopyFrom( ComputationAction._bufferize_arg(worker, value)) if action.return_ids is not None: if type(action.return_ids) == PlaceHolder: return_ids = list((action.return_ids, )) else: return_ids = action.return_ids for return_id in return_ids: if type(return_id) == PlaceHolder: protobuf_op.return_placeholders.extend([ sy.serde.protobuf.serde._bufferize(worker, return_id) ]) else: sy.serde.protobuf.proto.set_protobuf_id( protobuf_op.return_ids.add(), return_id) return protobuf_op
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)