コード例 #1
0
ファイル: serde.py プロジェクト: yashk2000/PySyft
    def update(self):
        if not self.stale_state:
            return self

        # If an object implements its own simplify and detail functions it should be stored
        # in this list
        # NOTE: serialization constants for these objects need to be defined in `proto.json` file
        # in https://github.com/OpenMined/proto

        self._OBJ_SIMPLIFIER_AND_DETAILERS = list(get_msgpack_subclasses(SyftSerializable))

        # Maps a type to a tuple containing its simplifier and detailer function
        # NOTE: serialization constants for these objects need to be defined in `proto.json` file
        # in https://github.com/OpenMined/proto

        self._MAP_TO_SIMPLFIERS_AND_DETAILERS = OrderedDict(
            list(MAP_NATIVE_SIMPLIFIERS_AND_DETAILERS.items())
            + list(MAP_TORCH_SIMPLIFIERS_AND_DETAILERS.items())
            + list(MAP_TF_SIMPLIFIERS_AND_DETAILERS.items())
        )

        self._OBJ_FORCE_FULL_SIMPLIFIER_AND_DETAILERS = [VirtualWorker]
        self._EXCEPTION_SIMPLIFIER_AND_DETAILERS = [
            GetNotPermittedError,
            ResponseSignatureError,
            EmptyCryptoPrimitiveStoreError,
        ]

        self.stale_state = False

        def _add_simplifier_and_detailer(curr_type, simplifier, detailer, forced=False):
            type_info = proto_type_info(curr_type)
            if forced:
                self._forced_full_simplifiers[curr_type] = (type_info.forced_code, simplifier)
                self._detailers[type_info.forced_code] = detailer
            else:
                self._simplifiers[curr_type] = (type_info.code, simplifier)
                self._detailers[type_info.code] = detailer

        # Register native and torch types
        for curr_type, (simplifier, detailer) in self._MAP_TO_SIMPLFIERS_AND_DETAILERS.items():
            _add_simplifier_and_detailer(curr_type, simplifier, detailer)

        # # Register syft objects with custom simplify and detail methods
        for syft_type in (
            self._OBJ_SIMPLIFIER_AND_DETAILERS + self._EXCEPTION_SIMPLIFIER_AND_DETAILERS
        ):
            simplifier, detailer = syft_type.simplify, syft_type.detail
            _add_simplifier_and_detailer(syft_type, simplifier, detailer)
        #
        # # Register syft objects with custom force_simplify and force_detail methods
        for syft_type in self._OBJ_FORCE_FULL_SIMPLIFIER_AND_DETAILERS:
            force_simplifier, force_detailer = syft_type.force_simplify, syft_type.force_detail
            _add_simplifier_and_detailer(syft_type, force_simplifier, force_detailer, forced=True)
        return self
コード例 #2
0
ファイル: serde.py プロジェクト: hobbit19/PySyft
else:
    MAP_TORCH_SIMPLIFIERS_AND_DETAILERS = {}

if dependency_check.tensorflow_available:
    from syft_tensorflow.serde import MAP_TF_SIMPLIFIERS_AND_DETAILERS
else:
    MAP_TF_SIMPLIFIERS_AND_DETAILERS = {}

from syft.serde.msgpack.proto import proto_type_info

# Maps a type to a tuple containing its simplifier and detailer function
# NOTE: serialization constants for these objects need to be defined in `proto.json` file
# in https://github.com/OpenMined/proto
MAP_TO_SIMPLIFIERS_AND_DETAILERS = OrderedDict(
    list(MAP_NATIVE_SIMPLIFIERS_AND_DETAILERS.items()) +
    list(MAP_TORCH_SIMPLIFIERS_AND_DETAILERS.items()) +
    list(MAP_TF_SIMPLIFIERS_AND_DETAILERS.items()))

# If an object implements its own simplify and detail functions it should be stored in this list
# NOTE: serialization constants for these objects need to be defined in `proto.json` file
# in https://github.com/OpenMined/proto
OBJ_SIMPLIFIER_AND_DETAILERS = [
    AdditiveSharingTensor,
    FixedPrecisionTensor,
    PrivateTensor,
    CRTPrecisionTensor,
    LoggingTensor,
    MultiPointerTensor,
    PromiseTensor,
    ObjectPointer,
    Plan,