Skip to content

Merge NoLabelDuplicates And LinkedParameters Constraints Into DegeneracyConstraint #874

Description

@Scienfitz

Motivation

DiscreteNoLabelDuplicatesConstraint and DiscreteLinkedParametersConstraint are two extremes of the same degeneracy concept (value repetition across a parameter group). They can be unified into a single DiscreteDegeneracyConstraint parametrized by n_max_occurrences (the maximum number of times any single value may appear in a row), combined with the inherited exclude flag.

  • n_max_occurrences=1 → keep only all-distinct rows (old DiscreteNoLabelDuplicatesConstraint)
  • n_max_occurrences=M-1, exclude=True → keep only all-identical rows (old DiscreteLinkedParametersConstraint, with M the number of parameters)

Todo

  • Introduce DiscreteDegeneracyConstraint with n_max_occurrences: int = 1 (default = all-distinct), reusing the inherited exclude flag.
  • Implement pandas and Polars matching-row logic (row kept iff no value occurs more than n_max_occurrences times).
  • Deprecation (per AGENTS.md §10): replace the two old classes with same-named factory functions that warn and return the correspondingly configured DiscreteDegeneracyConstraint; add cattrs (de)serialization redirects for the old class names; cover in tests/test_deprecations.py.
  • Replace the two entries in the pruning order tuple with DiscreteDegeneracyConstraint.
  • Update fixtures, hypothesis strategies, docs, and examples.
  • [ ]

Code Refs

  • DiscreteNoLabelDuplicatesConstraint: baybe/constraints/discrete.py:220-260 (pandas + Polars)
  • DiscreteLinkedParametersConstraint: baybe/constraints/discrete.py:263-297 (pandas + Polars)
  • Deprecation pattern to mirror (`DiscreteExclu

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions