Skip to content

Commit e8d2f2c

Browse files
vpratzLarsKue
andauthored
serialization: apply new scheme for package (breaking change) (#457)
* serialization: apply new scheme for `package` (breaking) - introduces new policy for consistent naming for serilization (see #451 for a discussion): standard is the path of a module a class resides in, trucated at depth to. So for all class in bayesflow.networks, we set package="bayesflow.networks", even if the live in the bayesflow.networks.mlp submodule. - The `serializable` decorator checks this and errors if this is not followed. The check can be disabled for certain cases (e.g., classes in the experimental module, that might eventually live somewhere else). - After this commit, previously saved models will not be loadable. As we introduced a bug regarding this anyway (#451), we will accept this and should inform users about it. - usage of direct calls to `keras.saving.register_keras_serializable` were replaced with our custom decorator. * update serilization policy in dev docs * README: add not regarding breaking changes until 2.1 release * standardize use of serializable decorator * [no ci] change (de)serialize to new pipeline in transform * serialization check: exempt classes not in bayesflow module This should ensure that users that try to use our decorator with external classes do not encounter the error. Possible edge case: they also name their module "bayesflow". --------- Co-authored-by: LarsKue <lars@kuehmichel.de>
1 parent ddd4ea8 commit e8d2f2c

File tree

90 files changed

+155
-116
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+155
-116
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ It provides users and researchers with:
1515
BayesFlow (version 2+) is designed to be a flexible and efficient tool that enables rapid statistical inference
1616
fueled by continuous progress in generative AI and Bayesian inference.
1717

18+
> [!IMPORTANT]
19+
> As the 2.0 version introduced many new features, we still have to make breaking changes from time to time.
20+
> This especially concerns **saving and loading** of models. We aim to stabilize this from the 2.1 release onwards.
21+
> Until then, consider pinning your BayesFlow 2.0 installation to an exact version, or re-training after an update
22+
> for less costly models.
23+
1824
## Important Note for Existing Users
1925

2026
You are currently looking at BayesFlow 2.0+, which is a complete rewrite of the library.

bayesflow/adapters/adapter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from .transforms.filter_transform import Predicate
3030

3131

32-
@serializable
32+
@serializable("bayesflow.adapters")
3333
class Adapter(MutableSequence[Transform]):
3434
"""
3535
Defines an adapter to apply various transforms to data.

bayesflow/adapters/transforms/as_set.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from .elementwise_transform import ElementwiseTransform
66

77

8-
@serializable
8+
@serializable("bayesflow.adapters")
99
class AsSet(ElementwiseTransform):
1010
"""The `.as_set(["x", "y"])` transform indicates that both `x` and `y` are treated as sets.
1111

bayesflow/adapters/transforms/as_time_series.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from .elementwise_transform import ElementwiseTransform
66

77

8-
@serializable
8+
@serializable("bayesflow.adapters")
99
class AsTimeSeries(ElementwiseTransform):
1010
"""The `.as_time_series` transform can be used to indicate that variables shall be treated as time series.
1111

bayesflow/adapters/transforms/broadcast.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from .transform import Transform
77

88

9-
@serializable
9+
@serializable("bayesflow.adapters")
1010
class Broadcast(Transform):
1111
"""
1212
Broadcasts arrays or scalars to the shape of a given other array.

bayesflow/adapters/transforms/concatenate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from .transform import Transform
88

99

10-
@serializable
10+
@serializable("bayesflow.adapters")
1111
class Concatenate(Transform):
1212
"""Concatenate multiple arrays into a new key. Used to specify how data variables should be treated by the network.
1313

bayesflow/adapters/transforms/constrain.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from .elementwise_transform import ElementwiseTransform
1212

1313

14-
@serializable
14+
@serializable("bayesflow.adapters")
1515
class Constrain(ElementwiseTransform):
1616
"""
1717
Constrains neural network predictions of a data variable to specified bounds.

bayesflow/adapters/transforms/convert_dtype.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from .elementwise_transform import ElementwiseTransform
66

77

8-
@serializable
8+
@serializable("bayesflow.adapters")
99
class ConvertDType(ElementwiseTransform):
1010
"""
1111
Default transform used to convert all floats from float64 to float32 to be in line with keras framework.

bayesflow/adapters/transforms/drop.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from .transform import Transform
66

77

8-
@serializable
8+
@serializable("bayesflow.adapters")
99
class Drop(Transform):
1010
"""
1111
Transform to drop variables from further calculation.

bayesflow/adapters/transforms/elementwise_transform.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from bayesflow.utils.serialization import serializable, deserialize
44

55

6-
@serializable
6+
@serializable("bayesflow.adapters")
77
class ElementwiseTransform:
88
"""Base class on which other transforms are based"""
99

0 commit comments

Comments
 (0)