From 4c206a6ca960f625b327041aefe0e3416ad6fc5f Mon Sep 17 00:00:00 2001 From: AdrianSosic Date: Sat, 3 Aug 2024 21:51:36 +0200 Subject: [PATCH 1/3] Bump attrs to 24.1.0 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 974e4f9c7..fdb67dbff 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,7 +28,7 @@ keywords = [ ] dynamic = ['version'] dependencies = [ - "attrs>=22.2.0", + "attrs>=24.1.0", "botorch>=0.9.3,<1", "cattrs>=23.2.0", "exceptiongroup", From 6feb9502b70a4c14e3853eca21d44e685f96004c Mon Sep 17 00:00:00 2001 From: AdrianSosic Date: Thu, 4 Jan 2024 16:15:28 +0100 Subject: [PATCH 2/3] Make parameter classes slotted --- CHANGELOG.md | 4 ++++ baybe/parameters/base.py | 11 +++-------- baybe/parameters/categorical.py | 4 ++-- baybe/parameters/custom.py | 2 +- baybe/parameters/numerical.py | 4 ++-- baybe/parameters/substance.py | 2 +- 6 files changed, 13 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0fcb475fc..17b19caaf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/baybe/parameters/base.py b/baybe/parameters/base.py index 4eef14a65..9b584dff1 100644 --- a/baybe/parameters/base.py +++ b/baybe/parameters/base.py @@ -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. @@ -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.""" @@ -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.""" diff --git a/baybe/parameters/categorical.py b/baybe/parameters/categorical.py index dc47a57ff..d44521d6f 100644 --- a/baybe/parameters/categorical.py +++ b/baybe/parameters/categorical.py @@ -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.""" @@ -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.""" diff --git a/baybe/parameters/custom.py b/baybe/parameters/custom.py index aa9b721c6..120f6c659 100644 --- a/baybe/parameters/custom.py +++ b/baybe/parameters/custom.py @@ -16,7 +16,7 @@ from baybe.utils.numerical import DTypeFloatNumpy -@define(frozen=True, slots=False) +@define(frozen=True) class CustomDiscreteParameter(DiscreteParameter): """Custom parameters. diff --git a/baybe/parameters/numerical.py b/baybe/parameters/numerical.py index 93dbb8e7f..3040b3a67 100644 --- a/baybe/parameters/numerical.py +++ b/baybe/parameters/numerical.py @@ -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).""" @@ -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.""" diff --git a/baybe/parameters/substance.py b/baybe/parameters/substance.py index 40a741238..f4b21860e 100644 --- a/baybe/parameters/substance.py +++ b/baybe/parameters/substance.py @@ -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. From 0d2e7e8139c1059effbdf1fd0e08f56b16b23101 Mon Sep 17 00:00:00 2001 From: AdrianSosic Date: Thu, 18 Apr 2024 16:25:28 +0200 Subject: [PATCH 3/3] Make objective classes slotted --- CHANGELOG.md | 2 +- baybe/objectives/base.py | 5 +---- baybe/objectives/desirability.py | 2 +- baybe/objectives/single.py | 2 +- 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 17b19caaf..131c6b9f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Fixed -- Parameter classes are now slotted due to `cached_property` attrs support +- Parameter and objective classes are now slotted due to `cached_property` attrs support ## [0.10.0] - 2024-08-02 ### Breaking Changes diff --git a/baybe/objectives/base.py b/baybe/objectives/base.py index 785b07557..18c84e358 100644 --- a/baybe/objectives/base.py +++ b/baybe/objectives/base.py @@ -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.""" diff --git a/baybe/objectives/desirability.py b/baybe/objectives/desirability.py index a96326903..6b3fd20da 100644 --- a/baybe/objectives/desirability.py +++ b/baybe/objectives/desirability.py @@ -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.""" diff --git a/baybe/objectives/single.py b/baybe/objectives/single.py index 50266fe39..9c713b55d 100644 --- a/baybe/objectives/single.py +++ b/baybe/objectives/single.py @@ -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."""