nvflare.fuel.utils.fobs.decomposer module

class DataClassDecomposer(data_type: Type[T])[source]

Bases: Decomposer

Generic decomposers for data classes, which must meet following requirements:

  1. All class members must be serializable. The type of member must be one of the types supported by MessagePack or a decomposer is registered for the type.

  2. The __new__ method only takes one argument which is the class type.

  3. The __init__ method has no side effects. It can only change the states of the object. The side effects include creating files, initializing loggers, modifying global variables.

decompose(target: T, manager: DatumManager | None = None) Any[source]

Decompose the target into types supported by msgpack or classes with decomposers registered.

Msgpack supports primitives, bytes, memoryview, lists, dicts.

Parameters:
  • target – The instance to be serialized

  • manager – Datum manager to store externalized datum

Returns:

The decomposed serializable objects

recompose(data: dict, manager: DatumManager | None = None) T[source]

Reconstruct the object from decomposed components.

Parameters:
  • data – The decomposed component

  • manager – Datum manager to internalize datum

Returns:

The reconstructed object

supported_type() Type[T][source]

Returns the type/class supported by this decomposer.

Returns:

The class (not instance) of supported type

class Decomposer[source]

Bases: ABC

Abstract base class for decomposers.

Every class to be serialized by FOBS must register a decomposer which is a concrete subclass of this class.

abstract decompose(target: T, manager: DatumManager | None = None) Any[source]

Decompose the target into types supported by msgpack or classes with decomposers registered.

Msgpack supports primitives, bytes, memoryview, lists, dicts.

Parameters:
  • target – The instance to be serialized

  • manager – Datum manager to store externalized datum

Returns:

The decomposed serializable objects

abstract recompose(data: Any, manager: DatumManager | None = None) T[source]

Reconstruct the object from decomposed components.

Parameters:
  • data – The decomposed component

  • manager – Datum manager to internalize datum

Returns:

The reconstructed object

abstract supported_type() Type[T][source]

Returns the type/class supported by this decomposer.

Returns:

The class (not instance) of supported type

class DictDecomposer(dict_type: Type[dict])[source]

Bases: Decomposer

Generic decomposer for subclasses of dict like Shareable

decompose(target: dict, manager: DatumManager | None = None) Any[source]

Decompose the target into types supported by msgpack or classes with decomposers registered.

Msgpack supports primitives, bytes, memoryview, lists, dicts.

Parameters:
  • target – The instance to be serialized

  • manager – Datum manager to store externalized datum

Returns:

The decomposed serializable objects

recompose(data: dict, manager: DatumManager | None = None) dict[source]

Reconstruct the object from decomposed components.

Parameters:
  • data – The decomposed component

  • manager – Datum manager to internalize datum

Returns:

The reconstructed object

supported_type()[source]

Returns the type/class supported by this decomposer.

Returns:

The class (not instance) of supported type

class EnumTypeDecomposer(data_type: Type[Enum])[source]

Bases: Decomposer

Generic decomposers for enum types.

decompose(target: Enum, manager: DatumManager | None = None) Any[source]

Decompose the target into types supported by msgpack or classes with decomposers registered.

Msgpack supports primitives, bytes, memoryview, lists, dicts.

Parameters:
  • target – The instance to be serialized

  • manager – Datum manager to store externalized datum

Returns:

The decomposed serializable objects

recompose(data: Any, manager: DatumManager | None = None) Enum[source]

Reconstruct the object from decomposed components.

Parameters:
  • data – The decomposed component

  • manager – Datum manager to internalize datum

Returns:

The reconstructed object

supported_type() Type[Enum][source]

Returns the type/class supported by this decomposer.

Returns:

The class (not instance) of supported type

class Externalizer(manager: DatumManager)[source]

Bases: object

This class is used to help creating ‘decompose’ method of decomposers of arbitrary classes.

externalize(target: Any)[source]

Recursively go through object tree (dict or list) and externalize leaf nodes.

class Internalizer(manager: DatumManager)[source]

Bases: object

This class is used to help creating ‘recompose’ method of decomposers of arbitrary classes.

internalize(target) Any[source]

Recursively go through object tree (dict or list) and internalize leaf nodes.

restore_position(manager: DatumManager, datum: Datum, position)[source]

This function is used for restoring object state at the specified position.

Parameters:
  • manager – the datum manager

  • datum – the datum that contains the value of the original object at the position.

  • position – the position to be restored

Returns: None