Skip to content

Parameter validation for kernel factories#776

Merged
AdrianSosic merged 13 commits intodev/gpfrom
feature/parameter_support
Apr 24, 2026
Merged

Parameter validation for kernel factories#776
AdrianSosic merged 13 commits intodev/gpfrom
feature/parameter_support

Conversation

@AdrianSosic
Copy link
Copy Markdown
Collaborator

@AdrianSosic AdrianSosic commented Apr 2, 2026

DevPR, parent is #745

Adds a validation mechanism to ensure kernel factories only produce kernels for search spaces they are intended for.
This is achieved via a new _ParameterKind flag enum that factories can use to signal which parameter types they support.

@AdrianSosic AdrianSosic self-assigned this Apr 2, 2026
@AdrianSosic AdrianSosic requested a review from Scienfitz as a code owner April 2, 2026 11:55
@AdrianSosic AdrianSosic added the new feature New functionality label Apr 2, 2026
@AdrianSosic AdrianSosic requested a review from AVHopp as a code owner April 2, 2026 11:55
@AdrianSosic AdrianSosic added the dev label Apr 2, 2026
Copilot AI review requested due to automatic review settings April 2, 2026 11:55
@AdrianSosic AdrianSosic changed the title Feature/parameter support Parameter validation for kernel factories Apr 2, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a parameter-kind validation mechanism for Gaussian process kernel factories and updates kernel translation to infer dimensions from a SearchSpace, enabling factories to explicitly declare and enforce which parameter roles (e.g., task vs. regular) they support.

Changes:

  • Add ParameterKind (flag enum) + Parameter.kind and enforce supported parameter kinds in KernelFactory.
  • Introduce parameter sub-selection via parameter_selector / parameter_names, and refactor Kernel.to_gpytorch to take a SearchSpace for automatic active_dims/ard_num_dims.
  • Add a deprecation guard that raises a DeprecationError when using a custom kernel in multi-task GP contexts unless suppressed via env var.

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
baybe/kernels/base.py Refactors to_gpytorch to use SearchSpace-derived dimensions; adds parameter_names to basic kernels.
baybe/parameters/enum.py Introduces ParameterKind flag enum.
baybe/parameters/base.py Adds Parameter.kind property derived from ParameterKind.
baybe/parameters/__init__.py Exposes ParameterKind in public parameters API.
baybe/parameters/selector.py Adds parameter selector protocol + concrete selectors (e.g., TypeSelector).
baybe/surrogates/gaussian_process/components/generic.py Renames factory protocol type to GPComponentFactoryProtocol and updates conversion helper typing.
baybe/surrogates/gaussian_process/components/kernel.py Adds kernel factory base class with parameter-kind validation and introduces ICMKernelFactory.
baybe/surrogates/gaussian_process/components/mean.py Switches to protocol-based mean factory typing.
baybe/surrogates/gaussian_process/components/likelihood.py Switches to protocol-based likelihood factory typing.
baybe/surrogates/gaussian_process/components/__init__.py Exposes new *Protocol factory types.
baybe/surrogates/gaussian_process/presets/baybe.py Replaces alias with explicit default kernel/task-kernel factories (incl. multitask handling).
baybe/surrogates/gaussian_process/presets/edbo.py Updates EDBO kernel factory to use parameter_names selection; adjusts likelihood factory typing.
baybe/surrogates/gaussian_process/presets/edbo_smoothed.py Same as above for smoothed EDBO.
baybe/surrogates/gaussian_process/core.py Updates GP surrogate to use protocol factories, SearchSpace-based kernel conversion, and adds multitask custom-kernel deprecation guard.
baybe/settings.py Whitelists and validates BAYBE_DISABLE_CUSTOM_KERNEL_WARNING.
tests/test_kernels.py Updates kernel assembly test to build a SearchSpace and validate inferred dims / mapping.
tests/hypothesis_strategies/kernels.py Extends kernel strategies to optionally generate parameter_names.
tests/test_deprecations.py Adds deprecation test for multitask custom-kernel behavior and env-var suppression.
CHANGELOG.md Documents new features, breaking changes, and the new deprecation.
Comments suppressed due to low confidence (2)

baybe/surrogates/gaussian_process/presets/edbo.py:76

  • effective_dims is now train_x.shape[-1], which will include task columns in multi-task settings even though this factory can be used with parameter_selector to exclude TaskParameters. Since effective_dims controls prior/initialization regime selection, it should reflect the dimensionality of the kernel’s active (selected) inputs (e.g., based on self.get_parameter_names(searchspace) / BasicKernel._get_dimensions(searchspace)), otherwise priors will shift when adding a task parameter.
    @override
    def _make(
        self, searchspace: SearchSpace, train_x: Tensor, train_y: Tensor
    ) -> Kernel:
        effective_dims = train_x.shape[-1]

        switching_condition = _contains_encoding(
            searchspace.discrete, _EDBO_ENCODINGS
        ) and (effective_dims >= 50)

        # low D priors
        if effective_dims < 5:
            lengthscale_prior = GammaPrior(1.2, 1.1)

baybe/surrogates/gaussian_process/presets/edbo_smoothed.py:60

  • Same as in EDBOKernelFactory: effective_dims=train_x.shape[-1] will count task dimensions even when a parameter_selector excludes them. Since the interpolated priors depend on effective_dims, compute it from the selected/active dimensions instead of the raw train_x width to keep behavior stable in multi-task setups.
    @override
    def _make(
        self, searchspace: SearchSpace, train_x: Tensor, train_y: Tensor
    ) -> Kernel:
        effective_dims = train_x.shape[-1]

        # Interpolate prior moments linearly between low D and high D regime.
        # The high D regime itself is the average of the EDBO OHE and Mordred regime.
        # Values outside the dimension limits will get the border value assigned.
        lengthscale_prior = GammaPrior(
            np.interp(effective_dims, _DIM_LIMITS, [1.2, 2.5]),
            np.interp(effective_dims, _DIM_LIMITS, [1.1, 0.55]),
        )
        lengthscale_initial_value = np.interp(effective_dims, _DIM_LIMITS, [0.2, 6.0])
        outputscale_prior = GammaPrior(

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread baybe/kernels/base.py Outdated
Comment thread baybe/kernels/base.py Outdated
Comment thread baybe/kernels/base.py Outdated
Comment thread baybe/surrogates/gaussian_process/components/kernel.py Outdated
Comment thread baybe/parameters/enum.py Outdated
@AdrianSosic AdrianSosic mentioned this pull request Apr 2, 2026
24 tasks
Comment thread baybe/surrogates/gaussian_process/components/kernel.py
@AdrianSosic AdrianSosic force-pushed the feature/parameter_support branch from 671e81c to 602ecf3 Compare April 15, 2026 12:01
@AdrianSosic AdrianSosic force-pushed the feature/parameter_support branch from 602ecf3 to 741997b Compare April 15, 2026 12:43
@AdrianSosic AdrianSosic requested a review from Scienfitz April 16, 2026 07:11
Comment thread CHANGELOG.md
Copy link
Copy Markdown
Collaborator

@AVHopp AVHopp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the general approach of using the ParameterKind. However, I have some questions/concerns regarding the design, specifically making the _KernelFactory internal and the use of the _use_parameter_names. Also, I think the change made in the __call__ of the ÌCMKernelFactory` is incorrect from a type perspective and needs to be fixed.

Comment thread baybe/parameters/enum.py
Comment thread baybe/surrogates/gaussian_process/components/kernel.py
Comment thread CHANGELOG.md
Comment thread baybe/surrogates/gaussian_process/components/kernel.py Outdated
Comment thread baybe/surrogates/gaussian_process/components/kernel.py Outdated
Comment thread docs/conf.py Outdated
Comment thread baybe/surrogates/gaussian_process/components/kernel.py Outdated
@AdrianSosic AdrianSosic merged commit 07d5d16 into dev/gp Apr 24, 2026
12 of 13 checks passed
@AdrianSosic AdrianSosic deleted the feature/parameter_support branch April 24, 2026 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dev new feature New functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants