Skip to content

Commit d28b0fb

Browse files
committed
Use custom classproperty
1 parent 7fe5d9f commit d28b0fb

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

baybe/acquisition/__init__.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
qSimpleRegret,
1414
qUpperConfidenceBound,
1515
)
16-
from baybe.acquisition.adapter import AdapterModel
17-
from baybe.acquisition.partial import PartialAcquisitionFunction
1816

1917
EI = ExpectedImprovement
2018
qEI = qExpectedImprovement
@@ -55,8 +53,4 @@
5553
"PI",
5654
"qPI",
5755
"qSR",
58-
# -----------------------------
59-
# Helpers
60-
"AdapterModel",
61-
"PartialAcquisitionFunction",
6256
]

baybe/acquisition/base.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,14 @@
1010
import pandas as pd
1111
from attrs import define
1212

13-
from baybe.acquisition.adapter import AdapterModel
1413
from baybe.serialization.core import (
1514
converter,
1615
get_base_structure_hook,
1716
unstructure_base,
1817
)
1918
from baybe.serialization.mixin import SerialMixin
2019
from baybe.surrogates.base import Surrogate
21-
from baybe.utils.basic import filter_attributes
22-
from baybe.utils.dataframe import to_tensor
20+
from baybe.utils.basic import classproperty, filter_attributes
2321

2422

2523
@define(frozen=True)
@@ -29,8 +27,7 @@ class AcquisitionFunction(ABC, SerialMixin):
2927
_abbreviation: ClassVar[str]
3028
"""An alternative name for type resolution."""
3129

32-
@classmethod
33-
@property
30+
@classproperty
3431
def is_mc(cls) -> bool:
3532
"""Flag indicating whether this is a Monte-Carlo acquisition function."""
3633
return cls._abbreviation.startswith("q")
@@ -44,6 +41,9 @@ def to_botorch(
4441
"""Create the botorch-ready representation of the function."""
4542
import botorch.acquisition as botorch_analytical_acqf
4643

44+
from baybe.acquisition.adapter import AdapterModel
45+
from baybe.utils.dataframe import to_tensor
46+
4747
acqf_cls = getattr(botorch_analytical_acqf, self.__class__.__name__)
4848
fields_dict = filter_attributes(object=self, callable_=acqf_cls.__init__)
4949

baybe/utils/basic.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,18 @@ def filter_attributes(
128128
for p in params
129129
if (p not in ignore) and hasattr(object, p)
130130
}
131+
132+
133+
class classproperty:
134+
"""A decorator to make class properties.
135+
136+
A class property combines the characteristics of @property and @classmethod. The
137+
simple chaining of these two existing decorators is deprecated and causes mypy
138+
issues.
139+
"""
140+
141+
def __init__(self, fn: Callable) -> None:
142+
self.fn = fn
143+
144+
def __get__(self, _, cl: type):
145+
return self.fn(cl)

0 commit comments

Comments
 (0)