bartz.npz.serializable¶
- bartz.npz.serializable(cls)[source]¶
Register a dataclass to allow its instances in npz archives.
Use it as a class decorator, e.g., on a custom
Callback, to save aBartfitted with it.- Parameters:
cls (
type[T]) – The dataclass to register, e.g., anequinox.Module. Its fields may holdNone,bool,int,float,str, lists, tuples, dicts withstrkeys without slashes, jax arrays that are not weakly typed, and instances of registered classes.- Returns:
type[T] –clsitself.- Raises:
ValueError – If a different class with the same name is already registered, including the classes of bartz.
Notes
Classes are identified by name alone, so registered classes must have unique names. Registering again the same class, e.g., after reloading its module, replaces it. Registration is not inherited: register each subclass explicitly.
To load an archive, its classes must be registered, i.e., their modules imported, with the same fields as when saving. Loading sets the fields directly, without calling
__init__.