Skip to content

Commit a713bfe

Browse files
committed
Replace factory aliases with thin subclasses
Simple aliases like `BayBEKernelFactory = SmoothedEDBOKernelFactory` cause the serialized type name to be that of the underlying class, which means the identity is lost on deserialization. Using thin subclasses ensures each factory has its own stable `__name__`.
1 parent 6b08679 commit a713bfe

3 files changed

Lines changed: 16 additions & 13 deletions

File tree

baybe/surrogates/gaussian_process/presets/baybe.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@
2929
from torch import Tensor
3030

3131

32-
_BayBENumericalKernelFactory = _SmoothedEDBONumericalKernelFactory
33-
"""The factory providing the default numerical kernel for Gaussian process surrogates.""" # noqa: E501
32+
class _BayBENumericalKernelFactory(_SmoothedEDBONumericalKernelFactory):
33+
"""The default numerical kernel factory for GP surrogates."""
3434

3535

36-
BayBEKernelFactory = SmoothedEDBOKernelFactory
37-
"""The default kernel factory for Gaussian process surrogates."""
36+
class BayBEKernelFactory(SmoothedEDBOKernelFactory):
37+
"""The default kernel factory for GP surrogates."""
3838

3939

4040
@define
4141
class _BayBETaskKernelFactory(_PureKernelFactory):
42-
"""The factory providing the default task kernel for Gaussian process surrogates."""
42+
"""The default task kernel factory for GP surrogates."""
4343

4444
_uses_parameter_names: ClassVar[bool] = True
4545
# See base class.
@@ -64,11 +64,13 @@ def _make(
6464
)
6565

6666

67-
BayBEMeanFactory = LazyConstantMeanFactory
68-
"""The factory providing the default mean function for Gaussian process surrogates."""
67+
class BayBEMeanFactory(LazyConstantMeanFactory):
68+
"""The default mean factory for GP surrogates."""
69+
70+
71+
class BayBELikelihoodFactory(SmoothedEDBOLikelihoodFactory):
72+
"""The default likelihood factory for GP surrogates."""
6973

70-
BayBELikelihoodFactory = SmoothedEDBOLikelihoodFactory
71-
"""The factory providing the default likelihood for Gaussian process surrogates."""
7274

7375
# Aliases for generic preset imports
7476
PresetKernelFactory = BayBEKernelFactory

baybe/surrogates/gaussian_process/presets/edbo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ def _make(
113113
)
114114

115115

116-
EDBOMeanFactory = LazyConstantMeanFactory
117-
"""A factory providing mean functions for the EDBO preset."""
116+
class EDBOMeanFactory(LazyConstantMeanFactory):
117+
"""A factory providing mean functions for the EDBO preset."""
118118

119119

120120
@define

baybe/surrogates/gaussian_process/presets/edbo_smoothed.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@ def _make(
8383
and interpolates the prior moments linearly in between.
8484
""" # noqa: E501
8585

86-
SmoothedEDBOMeanFactory = LazyConstantMeanFactory
87-
"""A factory providing mean functions for the smoothed EDBO preset."""
86+
87+
class SmoothedEDBOMeanFactory(LazyConstantMeanFactory):
88+
"""A factory providing mean functions for the smoothed EDBO preset."""
8889

8990

9091
@define

0 commit comments

Comments
 (0)