Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make parameter and objective classes slotted #74

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 and objective classes are now slotted due to `cached_property` attrs support
AdrianSosic marked this conversation as resolved.
Show resolved Hide resolved

## [0.10.0] - 2024-08-02
### Breaking Changes
- Providing an explicit `batch_size` is now mandatory when asking for recommendations
Expand Down
5 changes: 1 addition & 4 deletions baybe/objectives/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@
from baybe.serialization.mixin import SerialMixin
from baybe.targets.base import Target

# 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 Objective(ABC, SerialMixin):
"""Abstract base class for all objectives."""

Expand Down
2 changes: 1 addition & 1 deletion baybe/objectives/desirability.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def scalarize(
return func(values, weights=weights)


@define(frozen=True, slots=False)
@define(frozen=True)
class DesirabilityObjective(Objective):
"""An objective scalarizing multiple targets using desirability values."""

Expand Down
2 changes: 1 addition & 1 deletion baybe/objectives/single.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from baybe.targets.base import Target


@define(frozen=True, slots=False)
@define(frozen=True)
class SingleTargetObjective(Objective):
"""An objective focusing on a single target."""

Expand Down
11 changes: 3 additions & 8 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 Expand Up @@ -143,7 +138,7 @@ def summary(self) -> dict: # noqa: D102
return param_dict


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

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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ keywords = [
]
dynamic = ['version']
dependencies = [
"attrs>=22.2.0",
"attrs>=24.1.0",
AdrianSosic marked this conversation as resolved.
Show resolved Hide resolved
"botorch>=0.9.3,<1",
"cattrs>=23.2.0",
"exceptiongroup",
Expand Down
Loading