Description
To Reproduce
On dev
or main
, run
import bayesflow as bf
import keras
keras.saving.get_registered_name(bf.Adapter) # or any other class without "package" set in the serializable decorator
Output:
'bayesflow.utils.decorators>Adapter'
Expected behavior
The path should be the path to the module, so
'bayesflow.adapters.adapter>Adapter'
Solution
In utils.serialization.serializable
, increase the depth
in the sys._getframe
call to 2
.
Additional context
I came across this for #449 and #450, and first assumed my changes to the allow_args decorator had caused it, so I already fixed it in a1b4d19, which is included in those PRs. Upon further testing, I noticed the problem already existed in dev
and main
.
The fix will break loading of serialized files created while the bug was present, but I think fixing it quickly and putting out an update is probably the best way forward. We might want to combine this with the deprecation of our old serialization helper functions in #450.
I think we should reflect on whether we want to keep the functionality of serializable
like this. In my opinion, it brings a certain fragility, because moving classes to a different file or folder breaks deserialization, even when the class itself did not change. Requiring package
to be set manually will remove this footgun, and thereby remove one cause for accidentally breaking serializability.