Repository navigation
Bump GPy - #493
Bump GPy#493
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
|
hi @apaleyes , this looks like awesomeness! I'll try to get through the PR by tomorrow. Thanks a lot for addressing this. |
|
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 |
|
@mmahsereci any luck? |
working on it... apologies for the delay. give me one more day please :) |
mmahsereci
left a comment
There was a problem hiding this comment.
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).
- 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) |
There was a problem hiding this comment.
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))
There was a problem hiding this comment.
good catch, thanks! test could use existing fixture, otherwise worked as advertised - failed when predicted, and fix worked too
|
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
left a comment
There was a problem hiding this comment.
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.
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:
basically all places that were implicitly converting single valued arrays
[1]or even[[1]]to1now have to explicitly extract the floatTODO:
integration-testsandexamplesextras - got rid of examplesTesting. 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.