Skip to content

Commit

Permalink
Merge: Release 0.10.0 (emdgroup#332)
Browse files Browse the repository at this point in the history
  • Loading branch information
Scienfitz authored Aug 2, 2024
2 parents ad1bcfc + f8f85a3 commit 4282f1c
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 409 deletions.
17 changes: 15 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ 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]
## [0.10.0] - 2024-08-02
### Breaking Changes
- Providing an explicit `batch_size` is now mandatory when asking for recommendations
- `RecommenderProtocol.recommend` now accepts an optional `Objective`
Expand Down Expand Up @@ -65,7 +65,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
two fixed low and high dimensional prior regimes
- The previous default kernel factory has been renamed to `EDBOKernelFactory` and now
fully reflects the original logic
- The default acquisition function has been changed from "qEI" to "qLogEI" for improved
- The default acquisition function has been changed from `qEI` to `qLogEI` for improved
numerical stability

### Removed
Expand Down Expand Up @@ -95,6 +95,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Passing a dataframe via the `data` argument to the `transform` methods of
`SearchSpace`, `SubspaceDiscrete` and `SubspaceContinuous` is no longer possible.
The dataframe must now be passed as positional argument.
- The new `allow_extra` flag is automatically set to `True` in `transform` methods
of search space classes when left unspecified

### Expired Deprecations (from 0.7.*)
- `Interval.is_finite` property
- Specifying target configs without type information
- Specifying parameters/constraints at the top level of a campaign configs
- Passing `numerical_measurements_must_be_within_tolerance` to `Campaign`
- `batch_quantity` argument
- Passing `allow_repeated_recommendations` or `allow_recommending_already_measured`
to `MetaRecommender` (or former `Strategy`)
- `*Strategy` classes and `baybe.strategies` subpackage
- Specifying `MetaRecommender` (or former `Strategy`) configs without type information

## [0.9.1] - 2024-06-04
### Changed
Expand Down
55 changes: 1 addition & 54 deletions baybe/campaign.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from attrs.converters import optional
from attrs.validators import instance_of

from baybe.exceptions import DeprecationError
from baybe.objectives.base import Objective, to_objective
from baybe.parameters.base import Parameter
from baybe.recommenders.base import RecommenderProtocol
Expand Down Expand Up @@ -83,10 +82,6 @@ class Campaign(SerialMixin):
)
"""The cached recommendations."""

# Deprecation
numerical_measurements_must_be_within_tolerance: bool = field(default=None)
"""Deprecated! Raises an error when used."""

def __str__(self) -> str:
start_bold = "\033[1m"
end_bold = "\033[0m"
Expand All @@ -102,28 +97,6 @@ def __str__(self) -> str:

return campaign_str.replace("\n", "\n ").replace("\r", "\r ")

strategy: RecommenderProtocol = field(default=None)
"""Deprecated! Raises an error when used."""

@numerical_measurements_must_be_within_tolerance.validator
def _validate_tolerance_flag(self, _, value) -> None:
"""Raise a DeprecationError if the tolerance flag is used."""
if value is not None:
raise DeprecationError(
f"Passing 'numerical_measurements_must_be_within_tolerance' to "
f"the constructor is deprecated. The flag has become a parameter of "
f"{self.__class__.__name__}.{Campaign.add_measurements.__name__}."
)

@strategy.validator
def _validate_strategy(self, _, value) -> None:
"""Raise a DeprecationError if the strategy attribute is used."""
if value is not None:
raise DeprecationError(
"Passing 'strategy' to the constructor is deprecated. The attribute "
"has been renamed to 'recommender'."
)

@property
def measurements(self) -> pd.DataFrame:
"""The experimental data added to the Campaign."""
Expand All @@ -149,13 +122,7 @@ def from_config(cls, config_json: str) -> Campaign:
Returns:
The constructed campaign.
"""
from baybe.deprecation import compatibilize_config

config = json.loads(config_json)

# Temporarily enable backward compatibility
config = compatibilize_config(config)

return converter.structure(config, Campaign)

@classmethod
Expand All @@ -165,13 +132,7 @@ def validate_config(cls, config_json: str) -> None:
Args:
config_json: The JSON that should be validated.
"""
from baybe.deprecation import compatibilize_config

config = json.loads(config_json)

# Temporarily enable backward compatibility
config = compatibilize_config(config)

_validation_converter.structure(config, Campaign)

def add_measurements(
Expand Down Expand Up @@ -255,27 +216,18 @@ def add_measurements(
def recommend(
self,
batch_size: int,
batch_quantity: int = None, # type: ignore[assignment]
) -> pd.DataFrame:
"""Provide the recommendations for the next batch of experiments.
Args:
batch_size: Number of requested recommendations.
batch_quantity: Deprecated! Use ``batch_size`` instead.
Returns:
Dataframe containing the recommendations in experimental representation.
Raises:
ValueError: If ``batch_size`` is smaller than 1.
"""
if batch_quantity is not None:
raise DeprecationError(
f"Passing the keyword 'batch_quantity' to "
f"'{self.__class__.__name__}.{self.recommend.__name__}' is deprecated. "
f"Use 'batch_size' instead."
)

if batch_size < 1:
raise ValueError(
f"You must at least request one recommendation per batch, but provided "
Expand Down Expand Up @@ -325,12 +277,7 @@ def _drop_version(dict_: dict) -> dict:

# Register de-/serialization hooks
unstructure_hook = cattrs.gen.make_dict_unstructure_fn(
Campaign,
converter,
_cattrs_include_init_false=True,
# TODO: Remove once deprecation got expired:
numerical_measurements_must_be_within_tolerance=cattrs.override(omit=True),
strategy=cattrs.override(omit=True),
Campaign, converter, _cattrs_include_init_false=True
)
structure_hook = cattrs.gen.make_dict_structure_fn(
Campaign, converter, _cattrs_include_init_false=True, _cattrs_forbid_extra_keys=True
Expand Down
49 changes: 0 additions & 49 deletions baybe/deprecation.py

This file was deleted.

6 changes: 4 additions & 2 deletions baybe/recommenders/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import pandas as pd

from baybe.objectives.base import Objective
from baybe.recommenders.deprecation import structure_recommender_protocol
from baybe.searchspace import SearchSpace
from baybe.serialization import converter, unstructure_base
from baybe.serialization.core import get_base_structure_hook


@runtime_checkable
Expand Down Expand Up @@ -57,4 +57,6 @@ def recommend(
),
),
)
converter.register_structure_hook(RecommenderProtocol, structure_recommender_protocol)
converter.register_structure_hook(
RecommenderProtocol, get_base_structure_hook(RecommenderProtocol)
)
42 changes: 0 additions & 42 deletions baybe/recommenders/deprecation.py

This file was deleted.

37 changes: 5 additions & 32 deletions baybe/recommenders/meta/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,21 @@

import cattrs
import pandas as pd
from attrs import define, field
from attrs import define

from baybe.exceptions import DeprecationError
from baybe.objectives.base import Objective
from baybe.recommenders.base import RecommenderProtocol
from baybe.recommenders.deprecation import structure_recommender_protocol
from baybe.recommenders.pure.base import PureRecommender
from baybe.recommenders.pure.nonpredictive.base import NonPredictiveRecommender
from baybe.searchspace import SearchSpace
from baybe.serialization import SerialMixin, converter, unstructure_base
from baybe.serialization.core import get_base_structure_hook


@define
class MetaRecommender(SerialMixin, RecommenderProtocol, ABC):
"""Abstract base class for all meta recommenders."""

allow_repeated_recommendations: bool = field(default=None, kw_only=True)
"""Deprecated! The flag has become an attribute of
:class:`baybe.recommenders.pure.base.PureRecommender`."""

allow_recommending_already_measured: bool = field(default=None, kw_only=True)
"""Deprecated! The flag has become an attribute of
:class:`baybe.recommenders.pure.base.PureRecommender`."""

@allow_repeated_recommendations.validator
def _validate_allow_repeated_recommendations(self, _, value):
"""Raise a ``DeprecationError`` if the flag is used."""
if value is not None:
raise DeprecationError(
f"Passing 'allow_repeated_recommendations' to "
f"'{self.__class__.__name__}' is deprecated. The flag has become an "
f"attribute of the '{PureRecommender.__name__}' classes."
)

@allow_recommending_already_measured.validator
def _validate_allow_recommending_already_measured(self, _, value):
"""Raise a ``DeprecationError`` if the flag is used."""
if value is not None:
raise DeprecationError(
f"Passing 'allow_recommending_already_measured' to "
f"{self.__class__.__name__} is deprecated. The flag has become an "
f"attribute of {PureRecommender.__name__}."
)

@abstractmethod
def select_recommender(
self,
Expand Down Expand Up @@ -117,4 +88,6 @@ def recommend(
),
),
)
converter.register_structure_hook(MetaRecommender, structure_recommender_protocol)
converter.register_structure_hook(
MetaRecommender, get_base_structure_hook(MetaRecommender)
)
13 changes: 0 additions & 13 deletions baybe/strategies/__init__.py

This file was deleted.

45 changes: 0 additions & 45 deletions baybe/strategies/deprecation.py

This file was deleted.

Loading

0 comments on commit 4282f1c

Please sign in to comment.