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 a Bart fitted with it.

Parameters:

cls (type[T]) – The dataclass to register, e.g., an equinox.Module. Its fields may hold None, bool, int, float, str, lists, tuples, dicts with str keys without slashes, jax arrays that are not weakly typed, and instances of registered classes.

Returns:

type[T] – cls itself.

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__.