Open
Conversation
4a381ec to
1c3bbef
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new batch-level discrete constraint (DiscreteBatchConstraint) that enforces a fixed discrete parameter value across all points in a recommended batch by optimizing over discrete (and hybrid) subspaces, aligning with the existing subspace-based infrastructure used for continuous cardinality constraints.
Changes:
- Introduces
DiscreteBatchConstraint(non-filtering, batch-level) plus validation preventing duplicate batch constraints per parameter. - Extends discrete/hybrid subspace infrastructure (
n_theoretical_subspaces, mask/config iterators, sampling helpers) and wires support intoBotorchRecommenderandRandomRecommenderwith compatibility gating for other recommenders. - Adds documentation and test coverage for discrete + hybrid subspace-generating constraints, replacing prior hybrid-only cardinality tests.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
baybe/constraints/discrete.py |
Adds DiscreteBatchConstraint and its subspace mask generation. |
baybe/constraints/validation.py |
Adds validation to prevent multiple batch constraints on the same parameter. |
baybe/constraints/__init__.py |
Exposes DiscreteBatchConstraint publicly. |
baybe/searchspace/discrete.py |
Adds discrete subspace-generating constraint plumbing and mask enumeration/sampling helpers. |
baybe/searchspace/continuous.py |
Renames/aligns to n_theoretical_subspaces and adds shuffled / with-replacement subspace configuration iteration. |
baybe/searchspace/core.py |
Adds combined discrete+continuous theoretical subspace counting and combined sampling utilities for hybrid spaces. |
baybe/recommenders/pure/base.py |
Adds supports_discrete_subspace_constraints gate and raises IncompatibilityError when unsupported. |
baybe/recommenders/pure/bayesian/botorch.py |
Implements discrete + hybrid optimization over subspaces when batch constraints are present. |
baybe/recommenders/pure/nonpredictive/sampling.py |
Updates RandomRecommender to respect discrete subspace-generating constraints. |
docs/userguide/constraints.md |
Documents DiscreteBatchConstraint and recommender compatibility. |
tests/constraints/test_batch_constraint.py |
Adds focused tests for the new constraint (behavior, validation, incompatibility, subspace counting/masks). |
tests/constraints/test_subspace_constraints_hybrid.py |
Adds parametrized hybrid tests covering discrete batch + (discrete/continuous) cardinality constraints. |
tests/constraints/test_cardinality_constraint_hybrid.py |
Removes older hybrid cardinality-only test file (superseded). |
CHANGELOG.md |
Records new user-facing feature entry. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This comment was marked as resolved.
This comment was marked as resolved.
b852744 to
dd5bbf6
Compare
dd5bbf6 to
23b3348
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #583
Fixes #567
Functionality:
Adds a
DiscreteBatchConstraintwhich works via subspace generation just like the continuous cardinality constraint, just in the discrete searchspace part. While it will quickly lead to many partitions, it is also possible to use multipleDiscreteBatchConstraints and also combine them with the cardinality constraints because there is now a more unified interface for constraints that work via subspace generation.Notes:
subspaceis not optimal, because there is also the concept ofDiscreteSubspace/ContinuousSubspace. I changed the naming that references to creating subspaces for taking care of the constraint intopartition. So we would then have things likepartition_masks,n_theoretical_partitionsetcn_max_partitionswhich controls the max number of subspaces considered in any casereplace=True) or shuffle the order (shuffle=True). The latter is used when subsamapling the spaces because withshuffle=Trueyou can just instantiate the fistnobjects in the iterator to achieve random subsampling. This has some complications, especially for the overall searchspace class which needs to have a parameter to stop the process when replicated samples are drawn too often (likely no other feasible subspace combinations).botorch.pyin recommenders has become very large as a result of this development. So I split it into submodules_FixedNumericalContinuousParameterhad a bugged property which was namedis_numericbut it should beis_numericalContinuousCardinalityConstraintcan now also be applied in hybrid spaces, which fixesContinuousCardinalityConstraintnot considered in hybrid spaces #567Discuss:
n_theoretical_subspacesjust computes the upper limit of subspaces in discrete and hybrid cases. Because subspaces that do not have enough candidates are internally skipped the actual number ofn_feasible_subspacesmight be smaller. However that cannot be easily computed and would require instantiating all masks corresponding to the subspaces. The dispatcher logic is currently based onn_theoretical_subspacesbut to be 100% correct it should ben_feasible_subspaces- this is not implemented due to the mentioned difficulty. I think usingn_theoretical_subspacesworks as a proxy and will not be very different fromn_feasible_subspacesfor nearly all practical problems