Skip to content

Candidates Engine - #837

Draft
AdrianSosic wants to merge 296 commits into
mainfrom
dev/candidates
Draft

Candidates Engine#837
AdrianSosic wants to merge 296 commits into
mainfrom
dev/candidates

Conversation

@AdrianSosic

@AdrianSosic AdrianSosic commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

Fixes #793

PRs merged

Upcoming PRs

To be decided

  • Should the is_constrained property of the search space classes be dropped? Reasons:
    • SubspaceContinuous.is_constrained used to contain non-trivial logic but with the new design it's equivalent to a simple if self.constraints call
    • SubspaceDiscrete.is_constrained was very much meaningless since the constraints attribute itself was flawed (Deprecate SubspaceDiscrete.constraints #835). And with both the legacy and new design, it's not obvious what it actually means!
    • Having an is_constrained attribute only on some of the search space classes is asymmetric
  • SubspaceDiscrete.batch_constraints vs DiscreteBatchConstraint name conflict. Options:
    • rename batch_constraints to something else, e.g. recommendation_constraints. However, batch_constraints is already a generic term. Perhaps we should rather ...
    • rename DiscreteBatchConstraint to something more specific. The latter is actually rather a name for an abstract base class if we decide to add more batch-level constraints, and does not convey anything about what it does. Options would be in the direction of DiscreteSharedValueConstraint
  • Can we fully kick n_batches_done and n_fits_done?
  • How to cleanly separate "filtering" and "batch constraints"? The eval_during_creation and eval_during_modeling are currently not mutually exclusive, so the semantics are not 100% clear, hence the assert statements in searchspace/discrete.py <-- clean up during constraint refactoring?
  • Scaling approach: shall we use complete unfiltered space, filtered space or policy-generated subset? Decision depends heavily on what is cheap and possible in a large lazy space but also what makes conceptually sense (i.e. should adding a hypothetical candidate that is removed through a filter, e.g. by policy or active values, change the induced scaling?). Also impacts methods like comp_rep_bounds, which now behave differently compared to main (Refactor candidates interface #840 (comment)). At the same time, the discrete version of comp_rep_bounds may be dropped entirely since effectively unused at the moment (it's called in optimize_acqf_mixed but the discrete bounds should actually not matter since the candidates are explicitly piped in as separate argument --> needs investigation)
  • Decorrelation: same problem as for scaling above
  • Naming: EmptyCandidates vs NullCandidates
  • encode vs transform vs computational representation terminology. Transform is currently used for continuous-valued objects (e.g. target transforms) but also for in the parameter/searchspace context. However, the latter also uses encoding (e.g. discrete parameters have specified encodings, we have a correspondingly named base class, ...). We somehow need to make this more precise. Perhaps: transform for conti mappings and encode for discrete mappings? Also covers things like the _encoding_table methods etc.
  • move batch constraints to recommender?
  • should we make any guarantees on (preserving) pandas indices? Mention in changelog/docs? If preserved --> tests?

TODOs

  • Freeze SubspaceDiscrete and turn comp_rep into cached_property

Follow-up TODOs (after dev completion)

  • Streamline recommendation call chain (i.e. avoid jumping back and forth between classes)

Add tests for:
- duplicate parameter names (existing validation, missing coverage)
- constraints referencing nonexistent parameters (missing validation)
Add tests for:
- duplicate parameter names (existing validation, missing coverage)
- constraints referencing nonexistent parameters (missing validation)
- validate_parameters is now the sole public entry point for parameter
  validation; the internal validate_parameter_names helper is inlined
  into it and removed. SearchSpace-level concerns (non-empty collection,
  TaskParameter count) are moved out of validate_parameters and into
  SearchSpace.__attrs_post_init__ and SearchSpace.from_product, where
  they semantically belong.

- validate_constraints is now the sole public entry point for constraint
  validation; the internal helpers
  validate_cardinality_constraints_are_nonoverlapping and
  validate_cardinality_constraint_parameter_bounds are made private.

- All field validators and classmethod constructors across
  SubspaceDiscrete, SubspaceContinuous, and SearchSpace consistently
  call these two high-level entry points. Redundant pre-validation calls
  in classmethod constructors are dropped except where they provide
  genuine fail-fast value before expensive operations such as
  build_constrained_product.
Multiple task parameters are now correctly rejected
Adds some missing validators and fixes defaults
* Only parameter that actually appear in constraints are relevant
* Interpoint condition was missing
AdrianSosic and others added 28 commits September 1, 2026 20:10
Replaces the silent argmax-on-zero fallback with an explicit check.
The subsampling path is currently blocking (see comment in code)
The logic in hybrid.py still relies critically on the pandas index
(see comment that file), so there is no point of narwhalifying the
function in any way.
pytest.warns installs warnings.simplefilter('always') on entry, which
shadows all pytest.ini filterwarnings ignores. For SubstanceParameter,
the first transform() call triggers heavy chemistry work via joblib,
emitting an unrelated DeprecationWarning that leaked into pytest.warns
and caused a spurious failure. Pre-computing expected before the context
manager avoids this.
Narwhalifies the recommendation layer, focusing on the core logic. That
is, some methods/functions are narwhalified only at their API boundary,
keeping an internal conversion to `pd.DataFrame`. These internals can be
narhwhalified at any later point in time in the form of isolated PRs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SubspaceDiscrete Refactor — Problem Statement

1 participant