serializable#
- bayesflow.utils.serialization.serializable(cls, package: str, name: str | None = None, disable_module_check: bool = False)[source]#
Register class as Keras serializable.
Wrapper function around keras.saving.register_keras_serializable to automatically check consistency of the supplied package argument with the module a class resides in. The package name should generally be the module the class resides in, truncated at depth two. Valid examples would be “bayesflow.networks” or “bayesflow.adapters”. The check can be disabled if necessary by setting disable_module_check to True. This should only be done in exceptional cases, and accompanied by a comment why it is necessary for a given class.
- Parameters:
- clstype
The class to register.
- packagestr
package argument forwarded to keras.saving.register_keras_serializable. Should generally correspond to the module of the class, truncated at depth two (e.g., “bayesflow.networks”).
- namestr, optional
name argument forwarded to keras.saving.register_keras_serializable. If None is provided, the classe’s __name__ attribute is used.
- disable_module_checkbool, optional
Disable check that the provided package is consistent with the location of the class within the library.
- Raises:
- ValueError
If the supplied package does not correspond to the module of the class, truncated at depth two, and disable_module_check is False. No error is thrown when a class is not part of the bayesflow module.