예제 #1
0
파일: hook_args.py 프로젝트: wddan1/PySyft
def register_tensor(tensor: FrameworkTensorType,
                    owner: AbstractWorker,
                    response_ids: List = list()):
    """
    Registers a tensor.

    Args:
        tensor: A tensor.
        owner: The owner that makes the registration.
        response_ids: List of ids where the tensor should be stored
            and each id is pop out when needed.
    """
    # This method often leads to re-registration of tensors
    # hence creating two copies of the same info. The older tensor
    # is left hanging and is never deleted. De-Registering the original
    # tensor (if-exists) before registration addresses this problem.
    owner.de_register_obj(
        tensor)  # Doesn't raise Exceptions if absent on owner
    tensor.owner = owner
    try:
        tensor.id = response_ids.pop(-1)
    except IndexError:
        raise exceptions.ResponseSignatureError

    owner.register_obj(tensor)
예제 #2
0
파일: state.py 프로젝트: znbdata/PySyft
    def unbufferize(worker: AbstractWorker,
                    protobuf_state: StatePB) -> "State":
        """
        Reconstruct the plan's state from the state elements and supposed
        ids.
        """
        state_placeholders = protobuf_state.placeholders
        state_elements = protobuf_state.tensors

        state_placeholders = [
            sy.serde.protobuf.serde._unbufferize(worker, placeholder)
            for placeholder in protobuf_state.placeholders
        ]

        state_elements = []
        for protobuf_tensor in protobuf_state.tensors:
            tensor = getattr(protobuf_tensor,
                             protobuf_tensor.WhichOneof("tensor"))
            state_elements.append(
                sy.serde.protobuf.serde._unbufferize(worker, tensor))

        for state_element in state_elements:
            worker.register_obj(state_element, obj_id=state_element.id)

        for state_placeholder, state_element in zip(state_placeholders,
                                                    state_elements):
            state_placeholder.instantiate(state_element)

        state = State(state_placeholders)
        return state
예제 #3
0
파일: protocol.py 프로젝트: ganesan5/PySyft
    def detail(worker: AbstractWorker, protocol_tuple: tuple) -> "Protocol":
        """This function reconstructs a Protocol object given its attributes in the form of a tuple.
        Args:
            worker: the worker doing the deserialization
            protocol_tuple: a tuple holding the attributes of the Protocol
        Returns:
            protocol: a Protocol object
        """

        id, tags, description, plans_reference, workers_resolved = map(
            lambda o: sy.serde._detail(worker, o), protocol_tuple
        )

        plans = []
        for owner_id, plan_id in plans_reference:
            if workers_resolved:
                plan_owner = worker.get_worker(owner_id, fail_hard=True)
                plan_pointer = worker.request_search(plan_id, location=plan_owner)[0]
                worker.register_obj(plan_pointer)
                plans.append((plan_owner, plan_pointer))
            else:
                try:
                    plan_owner = worker.get_worker(owner_id, fail_hard=True)
                    plan_pointer = worker.request_search(plan_id, location=plan_owner)[0]
                    plan = plan_pointer.get()
                except WorkerNotFoundException:
                    plan = worker.get_obj(plan_id)
                plans.append((worker.id, plan))

        protocol = sy.Protocol(plans=plans, id=id, owner=worker, tags=tags, description=description)

        return protocol
예제 #4
0
파일: state.py 프로젝트: hobbit19/PySyft
    def detail(worker: AbstractWorker, state_tuple: tuple) -> "State":
        """
        Reconstruct the plan's state from the state elements and supposed
        ids.
        """
        state_ids, state_elements = state_tuple
        state_ids = sy.serde.msgpack.serde._detail(worker, state_ids)
        state_elements = sy.serde.msgpack.serde._detail(worker, state_elements)

        for state_id, state_element in zip(state_ids, state_elements):
            worker.register_obj(state_element, obj_id=state_id)

        state = State(owner=worker, plan=None, state_ids=state_ids)
        return state
예제 #5
0
    def detail(worker: AbstractWorker, state_tuple: tuple) -> "State":
        """
        Reconstruct the plan's state from the state elements and supposed
        ids.
        """
        state_placeholders, state_elements = state_tuple

        state_placeholders = sy.serde.msgpack.serde._detail(worker, state_placeholders)
        state_elements = sy.serde.msgpack.serde._detail(worker, state_elements)

        for state_element in state_elements:
            worker.register_obj(state_element, obj_id=state_element.id)

        for state_placeholder, state_element in zip(state_placeholders, state_elements):
            state_placeholder.instantiate(state_element)

        state = State(state_placeholders)
        return state
예제 #6
0
def register_tensor(
    tensor: FrameworkTensorType, owner: AbstractWorker, response_ids: List = list()
):
    """
    Registers a tensor.

    Args:
        tensor: A tensor.
        owner: The owner that makes the registration.
        response_ids: List of ids where the tensor should be stored
            and each id is pop out when needed.
    """
    tensor.owner = owner
    try:
        tensor.id = response_ids.pop(-1)
    except IndexError:
        raise exceptions.ResponseSignatureError

    owner.register_obj(tensor)