Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
59972e0
Add DiscreteDegeneracyConstraint
Scienfitz Aug 4, 2026
9d53629
Deprecate NoLabelDuplicates and LinkedParameters constraints
Scienfitz Aug 4, 2026
2718c3b
Migrate usages to DiscreteDegeneracyConstraint
Scienfitz Aug 4, 2026
5c8c86c
Update constraint documentation
Scienfitz Aug 4, 2026
e26056d
Expand DiscreteDegeneracyConstraint documentation
Scienfitz Aug 5, 2026
6c0048f
Parametrize degeneracy deprecation tests
Scienfitz Aug 5, 2026
100036a
Reflect filtering-constraint requirement in toggle_discrete_candidates
Scienfitz Aug 9, 2026
d496288
Vectorize degeneracy constraint filtering
Scienfitz Aug 5, 2026
470977a
Fix keyword collision in DiscreteLinkedParametersConstraint alias
Scienfitz Aug 9, 2026
b84559e
Fix backend parity for DiscreteDegeneracyConstraint
Scienfitz Aug 9, 2026
e4111b1
Update tests
Scienfitz Aug 19, 2026
cfa3c59
Improve wording
Scienfitz Aug 27, 2026
812854e
Remove hardcoded field references from constraint deprecations
Scienfitz Aug 27, 2026
41e99c3
Use explicit signatures in degeneracy deprecation wrappers
Scienfitz Aug 27, 2026
47dee07
Simplify legacy constraint deserialization hook
Scienfitz Aug 27, 2026
b5ced96
Add doctests to discrete filtering constraints
Scienfitz Aug 27, 2026
9ad7577
Use Sphinx class references in deprecation wrapper docstrings
Scienfitz Aug 28, 2026
44703cb
Replace Polars map_elements with native pairwise expression
Scienfitz Aug 28, 2026
f57f120
Rename DiscreteDegeneracyConstraint to DiscreteRepetitionConstraint
Scienfitz Aug 28, 2026
5494f0a
Replace n_max_occurrences with n_min/n_max_repetitions bounds
Scienfitz Aug 28, 2026
abe3515
Fix mixed Polars/pandas constraint test to use pandas-only constraint
Scienfitz Aug 28, 2026
2b594bd
Enable early filtering for n_min under exclude=True
Scienfitz Aug 28, 2026
9a637bf
Shift per-field validation to attrs validators for repetition bounds
Scienfitz Aug 28, 2026
044acde
Refine repetition constraint bound validation
Scienfitz Sep 2, 2026
96f7648
Add repetition constraint validation tests
Scienfitz Sep 2, 2026
b74a215
Remove minimum repetition bound
Scienfitz Sep 3, 2026
df6ee6e
Make Polars annotations available to Sphinx
Scienfitz Sep 3, 2026
1e9600e
Update CHANGELOG.md
Scienfitz Sep 3, 2026
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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
`TransferLearningMode` enum) for selecting the kernel that models the task
correlations in transfer learning, taking precedence over the task kernel of the
configured kernel factory
- `DiscreteRepetitionConstraint` for controlling value repetition across parameters
via `n_max_repetitions` (replaces `DiscreteNoLabelDuplicatesConstraint` and
`DiscreteLinkedParametersConstraint`)

### Changed
- `BOTORCH` GP preset now includes `BetaPrior(2.5, 1.5)` for the task covariance
Expand All @@ -63,6 +66,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Deprecations
- `DiscreteExcludeConstraint` in favor of
`DiscreteSelectionConstraint(..., exclude=True)`
- `DiscreteNoLabelDuplicatesConstraint` in favor of
`DiscreteRepetitionConstraint(..., n_max_repetitions=1)`
- `DiscreteLinkedParametersConstraint` in favor of
`DiscreteRepetitionConstraint(..., n_max_repetitions=len(parameters)-1,
exclude=True)`

## [0.15.0] - 2026-06-11
### Breaking Changes
Expand Down
12 changes: 6 additions & 6 deletions baybe/campaign.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from attrs.validators import instance_of
from typing_extensions import override

from baybe.constraints.base import DiscreteConstraint, DiscreteFilteringConstraint
from baybe.constraints.base import DiscreteFilteringConstraint
from baybe.exceptions import (
IncompatibilityError,
NoMeasurementsError,
Expand Down Expand Up @@ -426,7 +426,7 @@ def update_measurements(

def toggle_discrete_candidates( # noqa: DOC501
self,
constraints: Collection[DiscreteConstraint] | pd.DataFrame,
constraints: Collection[DiscreteFilteringConstraint] | pd.DataFrame,
exclude: bool,
complement: bool = False,
dry_run: bool = False,
Expand All @@ -436,8 +436,8 @@ def toggle_discrete_candidates( # noqa: DOC501
Args:
constraints: A filtering mechanism determining the candidates subset to be
in-/excluded. Can be either a collection of
:class:`~baybe.constraints.base.DiscreteConstraint` or a dataframe.
For the latter, see :func:`~baybe.utils.dataframe.filter_df`
:class:`~baybe.constraints.base.DiscreteFilteringConstraint` or a
dataframe. For the latter, see :func:`~baybe.utils.dataframe.filter_df`
for details.
exclude: If ``True``, the specified candidates are excluded.
If ``False``, the candidates are considered for recommendation.
Expand Down Expand Up @@ -483,8 +483,8 @@ def toggle_discrete_candidates( # noqa: DOC501

else:
raise TypeError(
"Candidate toggling is not implemented for the given type of "
"constraint specifications."
f"Candidate toggling requires a dataframe or a collection of "
f"'{DiscreteFilteringConstraint.__name__}' instances."
)

if not dry_run:
Expand Down
4 changes: 3 additions & 1 deletion baybe/constraints/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
DiscreteNoLabelDuplicatesConstraint,
DiscretePermutationInvarianceConstraint,
DiscreteProductConstraint,
DiscreteRepetitionConstraint,
DiscreteSelectionConstraint,
DiscreteSumConstraint,
)
Expand All @@ -34,11 +35,12 @@
"DiscreteCustomConstraint",
"DiscreteDependenciesConstraint",
"DiscreteExcludeConstraint",
"DiscreteSelectionConstraint",
"DiscreteLinkedParametersConstraint",
"DiscreteNoLabelDuplicatesConstraint",
"DiscretePermutationInvarianceConstraint",
"DiscreteProductConstraint",
"DiscreteRepetitionConstraint",
"DiscreteSelectionConstraint",
"DiscreteSumConstraint",
# --- Other --- #
"validate_constraints",
Expand Down
12 changes: 9 additions & 3 deletions baybe/constraints/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,25 +197,31 @@ def has_polars_implementation(cls) -> bool:
is not DiscreteFilteringConstraint._get_matching_rows_polars
)

def get_invalid_polars(self) -> pl.Expr:
def get_invalid_polars(self, schema: pl.Schema) -> pl.Expr:
"""Translate the constraint to a Polars expression identifying rows to remove.

Args:
schema: The Polars schema of the dataframe being filtered.

Returns:
The Polars expression.
"""
matching_expr = self._get_matching_rows_polars()
matching_expr = self._get_matching_rows_polars(schema)
if self.exclude:
return matching_expr
return ~matching_expr

def _get_matching_rows_polars(self) -> pl.Expr:
def _get_matching_rows_polars(self, schema: pl.Schema) -> pl.Expr:
"""Translate the constraint to a Polars expression identifying matching rows.

Subclasses with a Polars implementation override this method. The expression
should evaluate to ``True`` for rows that the specification matches/keeps
(as if ``exclude=False``). The ``exclude`` inversion is applied by the base
class in :meth:`get_invalid_polars`, not here.

Args:
schema: The Polars schema of the dataframe being filtered.

Returns:
A Polars expression that evaluates to ``True`` for matching rows.

Expand Down
Loading