Skip to content

Commit

Permalink
Make parameter classes slotted
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianSosic committed Aug 3, 2024
1 parent 4c206a6 commit 6a8474b
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- Parameter classes are now slotted due to `cached_property` attrs support

## [0.10.0] - 2024-08-02
### Breaking Changes
- Providing an explicit `batch_size` is now mandatory when asking for recommendations
Expand Down
9 changes: 2 additions & 7 deletions baybe/parameters/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@
from baybe.searchspace.core import SearchSpace
from baybe.searchspace.discrete import SubspaceDiscrete

# TODO: Reactive slots in all classes once cached_property is supported:
# https://github.com/python-attrs/attrs/issues/164


@define(frozen=True, slots=False)
@define(frozen=True)
class Parameter(ABC, SerialMixin):
"""Abstract base class for all parameters.
Expand Down Expand Up @@ -79,12 +76,10 @@ def to_searchspace(self) -> SearchSpace:
return SearchSpace.from_parameter(self)


@define(frozen=True, slots=False)
@define(frozen=True)
class DiscreteParameter(Parameter, ABC):
"""Abstract class for discrete parameters."""

# TODO [15280]: needs to be refactored

# class variables
encoding: ParameterEncoding | None = field(init=False, default=None)
"""An optional encoding for the parameter."""
Expand Down
4 changes: 2 additions & 2 deletions baybe/parameters/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from baybe.utils.numerical import DTypeFloatNumpy


@define(frozen=True, slots=False)
@define(frozen=True)
class CategoricalParameter(DiscreteParameter):
"""Parameter class for categorical parameters."""

Expand Down Expand Up @@ -60,7 +60,7 @@ def comp_df(self) -> pd.DataFrame: # noqa: D102
return comp_df


@define(frozen=True, slots=False)
@define(frozen=True)
class TaskParameter(CategoricalParameter):
"""Parameter class for task parameters."""

Expand Down
2 changes: 1 addition & 1 deletion baybe/parameters/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from baybe.utils.numerical import DTypeFloatNumpy


@define(frozen=True, slots=False)
@define(frozen=True)
class CustomDiscreteParameter(DiscreteParameter):
"""Custom parameters.
Expand Down
4 changes: 2 additions & 2 deletions baybe/parameters/numerical.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from baybe.utils.numerical import DTypeFloatNumpy


@define(frozen=True, slots=False)
@define(frozen=True)
class NumericalDiscreteParameter(DiscreteParameter):
"""Parameter class for discrete numerical parameters (a.k.a. setpoints)."""

Expand Down Expand Up @@ -97,7 +97,7 @@ def is_in_range(self, item: float) -> bool: # noqa: D102
return any(differences_acceptable)


@define(frozen=True, slots=False)
@define(frozen=True)
class NumericalContinuousParameter(ContinuousParameter):
"""Parameter class for continuous numerical parameters."""

Expand Down
2 changes: 1 addition & 1 deletion baybe/parameters/substance.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"""Type alias for SMILES strings."""


@define(frozen=True, slots=False)
@define(frozen=True)
class SubstanceParameter(DiscreteParameter):
"""Generic substances that are treated with cheminformatics descriptors.
Expand Down

0 comments on commit 6a8474b

Please sign in to comment.