Skip to content

Narwhalify model layer - #913

Open
AdrianSosic wants to merge 9 commits into
dev/candidatesfrom
refactor/narwhalify_surrogate_layer
Open

Narwhalify model layer#913
AdrianSosic wants to merge 9 commits into
dev/candidatesfrom
refactor/narwhalify_surrogate_layer

Conversation

@AdrianSosic

@AdrianSosic AdrianSosic commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

Extends the narwhalification series to the surrogates, GP component factories, acquisition functions, and the Bayesian recommender layer.

@AdrianSosic AdrianSosic added this to the 0.16.0 milestone Sep 7, 2026
@AdrianSosic AdrianSosic self-assigned this Sep 7, 2026
@AdrianSosic AdrianSosic added enhancement Expand / change existing functionality refactor labels Sep 7, 2026
@AdrianSosic AdrianSosic mentioned this pull request Sep 7, 2026
10 tasks
@AdrianSosic
AdrianSosic marked this pull request as ready for review September 7, 2026 11:05
@AdrianSosic
AdrianSosic requested review from fabianliebig and myrazma and a lite review from Copilot September 7, 2026 11:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

A confirmed regression in Surrogate.posterior_stats uses vals.numpy() instead of a safe CPU conversion, which can raise at runtime when tensors are not on CPU.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR continues the “narwhalification” effort by updating the modeling stack (objectives → surrogates → acquisition functions → Bayesian recommenders/campaign APIs) to accept/return Narwhals-compatible dataframe/series inputs, reducing direct pandas coupling in the model layer.

Changes:

  • Switch many model-layer interfaces from pd.DataFrame to Narwhals typing (IntoDataFrame, IntoDataFrameT, IntoSeries) and use narwhals.stable.v2 conversions internally.
  • Refactor objective missing-value handling to a private, backend-preserving helper (Objective._handle_missing_values).
  • Update surrogate posterior statistics and acquisition evaluation paths to return backend-native objects with index preservation helpers.
File summaries
File Description
CHANGELOG.md Document breaking change: Objective.handle_missing_values made private.
baybe/surrogates/gaussian_process/presets/hvarfner.py Narwhals-typed measurements for GP component factories.
baybe/surrogates/gaussian_process/presets/edbo.py Narwhals-typed measurements for kernel/likelihood factories.
baybe/surrogates/gaussian_process/presets/edbo_smoothed.py Narwhals-typed measurements for smoothed preset factories.
baybe/surrogates/gaussian_process/presets/chen.py Narwhals-typed measurements for Chen kernel factory.
baybe/surrogates/gaussian_process/presets/botorch.py Narwhals-typed measurements for BoTorch preset kernel factory.
baybe/surrogates/gaussian_process/presets/baybe.py Narwhals-typed measurements across BayBE preset factories.
baybe/surrogates/gaussian_process/core.py Store GP model context measurements as nw.DataFrame.
baybe/surrogates/gaussian_process/components/mean.py Narwhals-typed measurements for mean factories.
baybe/surrogates/gaussian_process/components/likelihood.py Narwhals-typed measurements for likelihood factories.
baybe/surrogates/gaussian_process/components/kernel.py Narwhals-typed measurements across kernel factory protocols/implementations.
baybe/surrogates/gaussian_process/components/generic.py Update GP component factory protocol to accept Narwhals-compatible dataframes.
baybe/surrogates/gaussian_process/components/fit_criterion.py Narwhals-typed measurements in fit-criterion factory.
baybe/surrogates/composite.py Use Narwhals conversions during per-quantity fitting and horizontal concat of posterior stats.
baybe/surrogates/base.py Accept Narwhals inputs for fit/posterior APIs; return backend-native posterior stats with index copying.
baybe/recommenders/pure/bayesian/base.py Pass Narwhals-compatible frames through Bayesian recommender training/acqf setup and acquisition evaluation.
baybe/recommenders/naive.py Stop forcing pandas conversion when delegating to Bayesian recommender acqf setup.
baybe/objectives/base.py Introduce private, backend-preserving _handle_missing_values; update dataframe utilities usage.
baybe/campaign.py Widen campaign acquisition/pending-experiments typing to Narwhals-compatible frames/series.
baybe/acquisition/base.py Return backend-native series from acquisition evaluation with index copying.
baybe/acquisition/acqfs.py Return integration points in the configured default dataframe backend via Narwhals conversion.
baybe/acquisition/_builder.py Make builder generic over dataframe backend and preserve backend in target-config selection.
Review details
  • Files reviewed: 22/22 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread baybe/surrogates/base.py
@AdrianSosic
AdrianSosic force-pushed the refactor/narwhalify_surrogate_layer branch 2 times, most recently from cdb7e1a to a731147 Compare September 8, 2026 13:39
@AdrianSosic
AdrianSosic force-pushed the refactor/narwhalify_surrogate_layer branch 2 times, most recently from 3ce7882 to 742adde Compare September 8, 2026 14:39
@AdrianSosic
AdrianSosic force-pushed the refactor/narwhalify_surrogate_layer branch from 742adde to 03d6bf9 Compare September 10, 2026 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dev enhancement Expand / change existing functionality refactor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants