示例#1
0
    def unbufferize(worker: AbstractWorker,
                    protobuf_placeholder: PlaceholderPB) -> "PlaceHolder":
        """
            This function reconstructs a PlaceHolder given it's attributes in form of a Protobuf message.
            Args:
                worker: the worker doing the deserialization
                protobuf_placeholder: a Protobuf message holding the attributes of the PlaceHolder
            Returns:
                PlaceHolder: a PlaceHolder
            """

        tensor_id = syft.serde.protobuf.proto.get_protobuf_id(
            protobuf_placeholder.id)
        tags = set(protobuf_placeholder.tags)

        description = None
        if bool(protobuf_placeholder.description):
            description = protobuf_placeholder.description

        if not hasattr(worker, "_tmp_placeholders"):
            worker._tmp_placeholders = {}

        if tensor_id not in worker._tmp_placeholders:
            tensor = PlaceHolder(owner=worker,
                                 id=tensor_id,
                                 tags=tags,
                                 description=description)
            worker._tmp_placeholders[tensor_id] = tensor

        return worker._tmp_placeholders[tensor_id]
示例#2
0
    def detail(worker: AbstractWorker, tensor_tuple: tuple) -> "PlaceHolder":
        """
            This function reconstructs a PlaceHolder given it's attributes in form of a tuple.
            Args:
                worker: the worker doing the deserialization
                tensor_tuple: a tuple holding the attributes of the PlaceHolder
            Returns:
                PlaceHolder: a PlaceHolder
            """

        tensor_id, tags, description = tensor_tuple

        tensor_id = syft.serde.msgpack.serde._detail(worker, tensor_id)
        tags = syft.serde.msgpack.serde._detail(worker, tags)
        description = syft.serde.msgpack.serde._detail(worker, description)

        if not hasattr(worker, "_tmp_placeholders"):
            worker._tmp_placeholders = {}

        if tensor_id not in worker._tmp_placeholders:
            tensor = PlaceHolder(owner=worker,
                                 id=tensor_id,
                                 tags=tags,
                                 description=description)
            worker._tmp_placeholders[tensor_id] = tensor

        return worker._tmp_placeholders[tensor_id]
示例#3
0
文件: plan.py 项目: youben11/PySyft
    def unbufferize(worker: AbstractWorker, protobuf_plan: PlanPB) -> "Plan":
        """This function reconstructs a Plan object given its attributes in the form of a Protobuf message
        Args:
            worker: the worker doing the deserialization
            protobuf_plan: a Protobuf message holding the attributes of the Plan
        Returns:
            plan: a Plan object
        """

        worker._tmp_placeholders = {}
        id = sy.serde.protobuf.proto.get_protobuf_id(protobuf_plan.id)

        operations = []
        for operation in protobuf_plan.operations:
            op_msg = OperationMessagePB()
            op_msg.operation.CopyFrom(operation)
            operations.append(op_msg)

        operations = [
            sy.serde.protobuf.serde._unbufferize(worker, operation)
            for operation in operations
        ]
        state = sy.serde.protobuf.serde._unbufferize(worker,
                                                     protobuf_plan.state)

        placeholders = [
            sy.serde.protobuf.serde._unbufferize(worker, placeholder)
            for placeholder in protobuf_plan.placeholders
        ]
        placeholders = dict([(placeholder.id, placeholder)
                             for placeholder in placeholders])

        plan = sy.Plan(
            include_state=protobuf_plan.include_state,
            is_built=protobuf_plan.is_built,
            operations=operations,
            placeholders=placeholders,
            id=id,
            owner=worker,
        )
        del worker._tmp_placeholders

        plan.state = state
        state.plan = plan

        plan.name = protobuf_plan.name
        if protobuf_plan.tags:
            plan.tags = set(protobuf_plan.tags)
        if protobuf_plan.description:
            plan.description = protobuf_plan.description

        return plan
示例#4
0
    def detail(worker: AbstractWorker, plan_tuple: tuple) -> "Plan":
        """This function reconstructs a Plan object given its attributes in the form of a tuple.
        Args:
            worker: the worker doing the deserialization
            plan_tuple: a tuple holding the attributes of the Plan
        Returns:
            plan: a Plan object
        """

        (
            id,
            actions,
            state,
            include_state,
            is_built,
            name,
            tags,
            description,
            placeholders,
        ) = plan_tuple

        worker._tmp_placeholders = {}
        id = sy.serde.msgpack.serde._detail(worker, id)
        actions = sy.serde.msgpack.serde._detail(worker, actions)
        state = sy.serde.msgpack.serde._detail(worker, state)
        placeholders = sy.serde.msgpack.serde._detail(worker, placeholders)

        plan = sy.Plan(
            include_state=include_state,
            is_built=is_built,
            actions=actions,
            placeholders=placeholders,
            id=id,
            owner=worker,
        )
        del worker._tmp_placeholders

        plan.state = state
        state.plan = plan

        plan.name = sy.serde.msgpack.serde._detail(worker, name)
        plan.tags = sy.serde.msgpack.serde._detail(worker, tags)
        plan.description = sy.serde.msgpack.serde._detail(worker, description)

        return plan