Serialization
The serialization module provides utilities for handling Numba objects and other problematic types during pickling.
Serialize Base
_SerializeBase()
Mixin class providing serialization utilities for objects with Numba dependencies. Handles conversion of problematic objects to serializable formats during pickling and reconstruction during unpickling.
- class hiten.algorithms.types.serialization._SerializeBase[source]
Bases:
object
Mixin class providing serialization utilities for objects with Numba dependencies.
This class provides methods to handle serialization of objects that may contain Numba-compiled functions, typed containers, or other objects that cannot be pickled directly. It converts problematic objects to serializable formats during pickling and handles reconstruction during unpickling.
The main methods are: - _make_serializable(): Converts objects to pickle-safe formats - __getstate__(): Handles object state serialization - __setstate__(): Handles object state deserialization
Notes
This class is designed to be used as a mixin with other base classes. It handles the common case where objects contain Numba-typed containers (like numba.typed.List) that cannot be pickled directly due to internal _nrt_python._MemInfo objects.
Examples
>>> class MyClass(_SerializeBase): ... def __init__(self): ... from numba.typed import List ... self.data = List() ... self.data.append([1, 2, 3]) >>> >>> obj = MyClass() >>> # This will now work without pickling errors >>> import pickle >>> pickled = pickle.dumps(obj) >>> restored = pickle.loads(pickled)
- __getstate__()[source]
Get state for pickling, handling Numba objects properly.
This method creates a dictionary containing the object’s state that can be safely pickled. It processes all attributes through _make_serializable() to handle Numba objects and other problematic types.