Refactor candidates interface#840
Merged
Merged
Conversation
Now returns only the experimental representation to avoid wasteful computation of the computational representation when not needed.
c011dc1 to
559c40c
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the discrete candidate interface to make SubspaceDiscrete.get_candidates() the single access point for experimental candidates, and shifts computational-representation generation to explicit, on-demand transform(...) calls. This is a preparatory step toward enabling lazy/large-space candidate handling and reducing eager materialization coupling.
Changes:
- Make the experimental representation field private (
_exp_rep, aliased asexp_repfor serialization) and deprecateexp_rep/comp_repaccessors in favor ofget_candidates()andtransform(get_candidates()). - Simplify
SubspaceDiscrete.get_candidates()to return only the experimental representation (pd.DataFrame). - Update internal call sites, tests, and examples to use the new candidate retrieval + explicit transform flow.
Reviewed changes
Copilot reviewed 26 out of 26 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
baybe/searchspace/discrete.py |
Privatizes experimental candidates, deprecates legacy accessors, and changes get_candidates() to return only exp-rep. |
baybe/searchspace/core.py |
Adjusts task column indexing to avoid relying on eager comp_rep. |
baybe/campaign.py |
Updates candidate filtering/toggling logic to use get_candidates() and evolved discrete subspaces. |
baybe/recommenders/pure/base.py |
Updates discrete candidate count check to use get_candidates(). |
baybe/recommenders/naive.py |
Switches discrete comp-rep access to on-demand transform(...). |
baybe/recommenders/pure/nonpredictive/sampling.py |
Updates discrete recommendation flow to fetch candidates via get_candidates() and compute comp-rep via transform(...). |
baybe/recommenders/pure/nonpredictive/clustering.py |
Same as sampling: comp-rep now computed explicitly from get_candidates(). |
baybe/recommenders/pure/bayesian/botorch/discrete.py |
Replaces eager comp-rep access with transform(get_candidates()) and updates subset evolution. |
baybe/recommenders/pure/bayesian/botorch/hybrid.py |
Updates hybrid discrete candidate transforms and subset evolution to use get_candidates(). |
baybe/acquisition/acqfs.py |
Updates integration-point generation to explicitly transform candidates on demand. |
baybe/simulation/scenarios.py |
Updates groupby simulation to build groups from get_candidates(). |
tests/utils/test_sampling_algorithms.py |
Adapts FPS utilities tests to transform candidates explicitly. |
tests/utils/test_dataframe.py |
Switches fuzzy matching tests to use get_candidates(). |
tests/test_searchspace.py |
Updates discrete searchspace assertions and memory estimate test to use explicit transforms. |
tests/test_campaign.py |
Updates candidate-related tests to use get_candidates(). |
tests/test_deprecations.py |
Adds coverage for deprecated exp_rep/comp_rep access warnings. |
tests/hypothesis_strategies/alternative_creation/test_searchspace.py |
Updates hypothesis-based discrete space creation tests to use get_candidates(). |
tests/constraints/test_constraints_discrete.py |
Updates discrete constraint tests to use get_candidates(). |
tests/constraints/test_cardinality_constraint_discrete.py |
Updates cardinality constraint tests to use get_candidates(). |
examples/Mixtures/slot_based.py |
Updates example to use get_candidates() instead of exp_rep. |
examples/Custom_Surrogates/custom_pretrained.py |
Updates example training data preparation to explicitly transform candidates. |
examples/Constraints_Discrete/prodsum_constraints.py |
Updates example assertions to use get_candidates(). |
examples/Constraints_Discrete/exclusion_constraints.py |
Updates example assertions to use get_candidates(). |
examples/Constraints_Discrete/dependency_constraints.py |
Updates example assertions to use get_candidates(). |
examples/Constraints_Discrete/custom_constraints.py |
Updates example assertions to use get_candidates(). |
CHANGELOG.md |
Documents breaking API changes and deprecations around candidate accessors. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
myrazma
reviewed
Jun 25, 2026
myrazma
reviewed
Jun 26, 2026
With the upcoming changes, subsequent calls may yield different results
cbe9d46 to
fdbe7ba
Compare
AVHopp
requested changes
Jun 26, 2026
AVHopp
left a comment
Collaborator
There was a problem hiding this comment.
There is an issue with the computation of the comp_rep_bounds, otherwise LGTM
myrazma
approved these changes
Jun 26, 2026
fabianliebig
approved these changes
Jun 26, 2026
AVHopp
approved these changes
Jun 26, 2026
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.
Preparation to fix #795, #796 and #798.
Background
As part of the broader effort toward lazy, on-demand evaluation of candidate sets (see linked issues), this PR removes the dependency on the eagerly pre-computed, fully materialized
exp_repandcomp_reppublic attributes ofSubspaceDiscrete. The old design forced the full candidate space to be computed and cached upfront, even when only a subset is needed — blocking future subsampling policies and backend-agnostic mechanisms required for handling large spaces.The key step is giving
get_candidatesa clean, single-purpose method signature as the sole access point for the experimental representation, so that transformation into the computational representation happens only when explicitly requested and only on the relevant data (the subset selection will be enabled later).Out of scope
The return type of
get_candidatesis expected to be elevated to a higher-level object in a follow-up (e.g.TableCandidatesor a similar abstraction). This PR deliberately keeps the return type aspd.DataFrameto stay focused on the interface decoupling.Changes
Make
exp_repprivate (baybe/searchspace/discrete.py)Renames the field to
_exp_rep(withalias="exp_rep"for serialization compatibility), updates the validator reference, and replaces all internal accesses.Simplify
get_candidatessignature (baybe/searchspace/discrete.py)Returns only the experimental representation (
pd.DataFrame) instead of atuple[pd.DataFrame, pd.DataFrame], avoiding wasteful upfront computation of the computational representation.Update all internal call sites (
baybe/campaign.py,baybe/recommenders/,baybe/simulation/,baybe/searchspace/core.py,baybe/acquisition/)Replaces tuple-unpacking calls to
get_candidatesand directexp_rep/comp_repaccesses with the new API throughout. Computational representation is now computed on-demand, at the point of use.Update examples and tests (
examples/,tests/)Adapts all affected examples and tests to the new
get_candidatesreturn type.Deprecate
exp_repandcomp_repproperties (baybe/searchspace/discrete.py)Adds
DeprecationWarningshims forexp_rep(pointing toget_candidates()) andcomp_rep(pointing totransform(get_candidates())), with corresponding deprecation tests.