You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
DiscreteExcludeConstraint is really a general pruning constraint hardwired to removal. We introduce a new DiscreteFilteringConstraint and an exclude flag that standardizes selection semantics across all pruning constraints, i.e. every discrete constraint except DiscreteBatchConstraint (which does not prune the search space). Pruning constraints keep the entries their specification describes by default (inclusion-by-default); exclude=True inverts the selection to keep the complement. DiscreteFilteringConstraint(..., exclude=True) reproduces today's DiscreteExcludeConstraint.
Todo
Add abstract DiscretePruningConstraint base in the derivation chain, owning the pruning machinery (get_invalid/get_valid, get_invalid_polars, has_polars_implementation) and the kw-only exclude flag; move these off DiscreteConstraint.
Let subclasses express positive "valid rows" logic via a _get_valid hook (and _get_valid_polars); the base derives the removal set and applies the exclude inversion for both pandas and Polars.
Implement _can_evaluate per subclass reading self.exclude (partial-evaluation soundness depends on the constraint and, for the condition-based filter, on the combiner; verified empirically). No global rule.
Remove the dead _get_invalid placeholder from DiscreteBatchConstraint.
Rename DISCRETE_CONSTRAINTS_FILTERING_ORDER → DISCRETE_CONSTRAINTS_PRUNING_ORDER, remove DiscreteBatchConstraint from it, and switch filtering selection to isinstance(c, DiscretePruningConstraint).
Deprecation (per AGENTS.md §10): keep DiscreteExcludeConstraint as a deprecated wrapper mapping to DiscreteFilteringConstraint(..., exclude=True); add cattrs (de)serialization redirect; cover in tests/test_deprecations.py.
Add a focused naive == incremental test parametrized over exclude for the early-filtering constraints.
Update fixtures, docs, and examples (rename exclusion_constraints example → filtering_constraints).
Motivation
DiscreteExcludeConstraintis really a general pruning constraint hardwired to removal. We introduce a newDiscreteFilteringConstraintand anexcludeflag that standardizes selection semantics across all pruning constraints, i.e. every discrete constraint exceptDiscreteBatchConstraint(which does not prune the search space). Pruning constraints keep the entries their specification describes by default (inclusion-by-default);exclude=Trueinverts the selection to keep the complement.DiscreteFilteringConstraint(..., exclude=True)reproduces today'sDiscreteExcludeConstraint.Todo
DiscretePruningConstraintbase in the derivation chain, owning the pruning machinery (get_invalid/get_valid,get_invalid_polars,has_polars_implementation) and the kw-onlyexcludeflag; move these offDiscreteConstraint._get_validhook (and_get_valid_polars); the base derives the removal set and applies theexcludeinversion for both pandas and Polars._can_evaluateper subclass readingself.exclude(partial-evaluation soundness depends on the constraint and, for the condition-based filter, on the combiner; verified empirically). No global rule.DiscreteFilteringConstraint(replacesDiscreteExcludeConstraint, inclusion-by-default)._get_invalidplaceholder fromDiscreteBatchConstraint.DISCRETE_CONSTRAINTS_FILTERING_ORDER→DISCRETE_CONSTRAINTS_PRUNING_ORDER, removeDiscreteBatchConstraintfrom it, and switch filtering selection toisinstance(c, DiscretePruningConstraint).DiscreteExcludeConstraintas a deprecated wrapper mapping toDiscreteFilteringConstraint(..., exclude=True); add cattrs (de)serialization redirect; cover intests/test_deprecations.py.naive == incrementaltest parametrized overexcludefor the early-filtering constraints.exclusion_constraintsexample →filtering_constraints).Code References
DiscreteExcludeConstraint:baybe/constraints/discrete.py:39-80baybe/constraints/base.py:103-188baybe/searchspace/utils.py:277-294discrete.py:572-585,searchspace/utils.py:195,269