Skip to content

Bump GPy - #493

Merged
apaleyes merged 22 commits into
mainfrom
andrei/gpy-update
Nov 18, 2026
Merged

apaleyes merged 22 commits into
mainfrom
andrei/gpy-update

Conversation

@apaleyes

@apaleyes apaleyes commented Aug 14, 2026 •

Copy link
Copy Markdown
Collaborator

Issue #, if available: n/a

Description of changes: GPy caught up with numpy>2, let's update!

By far the most common, and the most annoying, error is this:

TypeError: only 0-dimensional arrays can be converted to Python scalars

basically all places that were implicitly converting single valued arrays [1] or even [[1]] to 1 now have to explicitly extract the float

TODO:

Testing. First of all, all CI is green, with GPy being declared a core dependency. I've also used two different agents to compare scopes of this PR against #477 to ensure none of the workarounds and caveats remain.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@codecov

codecov Bot commented Aug 15, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.27%. Comparing base (7cd414c) to head (4b7a8f6).
⚠️ Report is 13 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #493      +/-   ##
==========================================
+ Coverage   89.10%   89.27%   +0.17%     
==========================================
  Files         137      137              
  Lines        4847     4850       +3     
  Branches      479      476       -3     
==========================================
+ Hits         4319     4330      +11     
+ Misses        402      394       -8     
  Partials      126      126              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@apaleyes
apaleyes marked this pull request as ready for review November 10, 2026 00:15
@apaleyes
apaleyes requested review from mmahsereci and a balanced review from Copilot and removed request for Copilot November 10, 2026 00:16
@apaleyes apaleyes changed the title Try bumping gpy Bump GPy Nov 10, 2026
@mmahsereci

Copy link
Copy Markdown
Contributor

hi @apaleyes , this looks like awesomeness! I'll try to get through the PR by tomorrow. Thanks a lot for addressing this.

@apaleyes

Copy link
Copy Markdown
Collaborator Author

thanks @mmahsereci! to be fair, most if not all of the changes are quite mechanical: fix up numpy 2 array handling, remove no-GPy workarounds, clean up docs and comments. Many files were touched, but there isn't anything tricky going on

@apaleyes

Copy link
Copy Markdown
Collaborator Author

@mmahsereci any luck?

@mmahsereci

Copy link
Copy Markdown
Contributor

@mmahsereci any luck?

working on it... apologies for the delay. give me one more day please :)

@mmahsereci mmahsereci 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.

Hi @apaleyes , thanks again for the PR and sorry for the delay. I looked through the PR but also had some help from Claude. It found some silent bug for batch sizes q > 2 for batch EI. I am not claiming I understand the batch EI code entirely but this seemed sensible to me. I am pasting the summary of that investigation below; some more details are comments inline proposing some shape tests for batch EI to catch that in the future.

One more thing is that we could perhaps declare a scipy minimum version. lower_limit from scipy.stats.multivariate_normal was added in scipy 1.10. pyproject.toml lists scipy unpinned.

Summary for the review (Claude).

  1. q-EI gradients crash for batch size q ≥ 3.
  • Where: the PR replaces mvnun with multivariate_normal.cdf at emukit/bayesian_optimization/acquisitions/expected_improvement.py:581.
  • Cause: x2, moy and low are column vectors of shape (d, 1). cdf only accepts 1-D arrays once d ≥ 2. The old mvnun accepted them.
  • When it happens: decompose_mvn gets called on q − 1 dimensions (gradient, k = [i]) and q − 2 dimensions (Hessian, k = [i, j]). Every gradient evaluation
    reaches it, exact and fast_compute alike.
  • Not a shape misuse: all of these arrays are built inside the class; the user passes a normal (q, input_dim) input.
  • Effect: evaluate_with_gradients raises ValueError: Array 'mean' must be a vector of length ... for q ≥ 3. main with older scipy handles this case, so it's a
    regression.
  • Why CI is green: the only gradient test (tests/emukit/bayesian_optimization/test_multipoint_expected_improvement.py:65) uses q = 2, and no shape tests exist
    for q-EI.
  • Fix: see inline comments

return (
scipy.stats.multivariate_normal.pdf(x1.flatten(), mu[k].flatten(), Sig11)
* scipy.stats.mvn.mvnun(low, x2, moy, varcov, maxpts=1000 * q)[0]
* scipy.stats.multivariate_normal.cdf(x2, mean=moy, cov=varcov, maxpts=1000 * q, lower_limit=low)

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.

This seems to fail for batch sizes q > 2 now.

Suggestion (by Claude) is to use

scipy.stats.multivariate_normal.cdf(
      x2.ravel(), mean=moy.ravel(), cov=varcov, maxpts=1000 * q, lower_limit=low.ravel()
  )

Suggested shape test (by Claude)

  @pytest.fixture
  def qei_model():
      rng = np.random.RandomState(42)
      x_init = rng.rand(10, 2)
      y_init = rng.rand(10, 1)
      return GPyModelWrapper(GPy.models.GPRegression(x_init, y_init))


  @pytest.mark.parametrize("fast_compute", [False, True])
  @pytest.mark.parametrize("q", [2, 3, 4])
  def test_multipoint_expected_improvement_shapes(qei_model, q, fast_compute):
      acquisition = MultipointExpectedImprovement(qei_model, fast_compute=fast_compute)
      x = np.random.RandomState(0).rand(q, 2)

      value = acquisition.evaluate(x)
      value_with_gradients, gradients = acquisition.evaluate_with_gradients(x)

      assert np.shape(value) == ()
      assert np.shape(value_with_gradients) == ()
      assert gradients.shape == (q, 2)
      assert np.all(np.isfinite(gradients))

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

good catch, thanks! test could use existing fixture, otherwise worked as advertised - failed when predicted, and fix worked too

@apaleyes

Copy link
Copy Markdown
Collaborator Author

thanks @mmahsereci ! the issue was real. i also noticed that black formatting didn't really work at all, and there was one line fix for that. so now there is some formatting stuff in this PR too

@mmahsereci mmahsereci 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.

Thanks @apaleyes ! It look good now. I added some more minor suggestions such as using the n_dims fixture in the new test but approving already.

Comment thread tests/emukit/conftest.py Resolved
Comment thread README.md Resolved
@apaleyes
apaleyes merged commit 4e28140 into main Nov 18, 2026
20 of 27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants