コード例 #1
0
    def bufferize(worker: AbstractWorker, plan: "Plan") -> PlanPB:
        """
        This function takes the attributes of a Plan and saves them in a Protobuf message
        Args:
            worker (AbstractWorker): the worker doing the serialization
            plan (Plan): a Plan object
        Returns:
            PlanPB: a Protobuf message holding the unique attributes of the Plan object
        """
        if not plan.is_built:
            raise RuntimeError(
                "A Plan needs to be built before being serialized.")

        protobuf_plan = PlanPB()

        sy.serde.protobuf.proto.set_protobuf_id(protobuf_plan.id, plan.id)

        protobuf_plan.role.CopyFrom(
            sy.serde.protobuf.serde._bufferize(worker, plan.role))

        protobuf_plan.include_state = plan.include_state
        protobuf_plan.name = plan.name
        protobuf_plan.tags.extend(plan.tags)

        if protobuf_plan.description:
            protobuf_plan.description = plan.description

        if plan.torchscript:
            protobuf_plan.torchscript = plan.torchscript.save_to_buffer()

        return protobuf_plan
コード例 #2
0
    def bufferize(worker: AbstractWorker, plan: "Plan") -> PlanPB:
        """
        This function takes the attributes of a Plan and saves them in a Protobuf message
        Args:
            worker (AbstractWorker): the worker doing the serialization
            plan (Plan): a Plan object
        Returns:
            PlanPB: a Protobuf message holding the unique attributes of the Plan object
        """
        protobuf_plan = PlanPB()

        sy.serde.protobuf.proto.set_protobuf_id(protobuf_plan.id, plan.id)

        protobuf_plan.role.CopyFrom(
            sy.serde.protobuf.serde._bufferize(worker, plan.role))

        protobuf_plan.include_state = plan.include_state
        protobuf_plan.is_built = plan.is_built
        protobuf_plan.name = plan.name
        protobuf_plan.tags.extend(plan.tags)

        if protobuf_plan.description:
            protobuf_plan.description = plan.description

        return protobuf_plan
コード例 #3
0
 def get_plan(self, worker_id: str, request_key: str, plan_id: int,
              receive_operations_as: str) -> Union[PlanTorchscript, Plan]:
     params = {
         "worker_id": worker_id,
         "request_key": request_key,
         "plan_id": plan_id,
         "receive_operations_as": receive_operations_as,
     }
     serialized_plan = self._send_http_req("GET", "/model-centric/get-plan",
                                           params)
     if receive_operations_as == ModelCentricFLWorker.PLAN_TYPE_TORCHSCRIPT:
         # TODO migrate to syft-core protobufs
         pb = PlanTorchscriptPB()
         pb.ParseFromString(serialized_plan)
         return PlanTorchscript._proto2object(pb)
     else:
         return self._unserialize(serialized_plan, PlanPB)
コード例 #4
0
    def bufferize(worker: AbstractWorker, plan: "Plan") -> PlanPB:
        """
        This function takes the attributes of a Plan and saves them in a Protobuf message
        Args:
            worker (AbstractWorker): the worker doing the serialization
            plan (Plan): a Plan object
        Returns:
            PlanPB: a Protobuf message holding the unique attributes of the Plan object

        """
        protobuf_plan = PlanPB()

        sy.serde.protobuf.proto.set_protobuf_id(protobuf_plan.id, plan.id)

        protobuf_actions = [
            sy.serde.protobuf.serde._bufferize(worker, action)
            for action in plan.actions
        ]
        protobuf_plan.actions.extend(protobuf_actions)

        protobuf_plan.state.CopyFrom(
            sy.serde.protobuf.serde._bufferize(worker, plan.state))

        protobuf_plan.include_state = plan.include_state
        protobuf_plan.is_built = plan.is_built
        protobuf_plan.name = plan.name
        protobuf_plan.tags.extend(plan.tags)

        if protobuf_plan.description:
            protobuf_plan.description = plan.description

        if type(plan.placeholders) == type(dict()):
            placeholders = plan.placeholders.values()
        else:
            placeholders = plan.placeholders

        protobuf_placeholders = [
            sy.serde.protobuf.serde._bufferize(worker, placeholder)
            for placeholder in placeholders
        ]
        protobuf_plan.placeholders.extend(protobuf_placeholders)

        return protobuf_plan
コード例 #5
0
    def get_plan(
        grid_address: str,
        worker_id: int,
        request_key: str,
        plan_id: int,
        plan_type: str,
    ) -> TypeUnion[PlanTorchscript, Plan]:
        req = requests.get((
            f"http://{grid_address}/model-centric/get-plan?worker_id={worker_id}&"
            f"request_key={request_key}&plan_id={plan_id}&receive_operations_as={plan_type}"
        ))

        if plan_type == "torchscript":
            pb = PlanTorchscriptPB()
            pb.ParseFromString(req.content)
            return PlanTorchscript._proto2object(pb)
        else:
            pb = PlanPB()
            pb.ParseFromString(req.content)
            return deserialize(pb)
コード例 #6
0
 def deserialize_plan(bin: bin) -> "sy.Plan":
     """Deserialize a Plan."""
     pb = PlanPB()
     pb.ParseFromString(bin)
     plan = protobuf.serde._unbufferize(worker, pb)
     return plan