Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reproducibility issue of XGBoostSampler results for Windows and Linux #49

Open
marcofavoritobi opened this issue Mar 18, 2023 · 0 comments

Comments

@marcofavoritobi
Copy link
Contributor

Subject of the issue

There is a reproducibility issue for the XGBoostSampler across platforms. In particular, when I use XGBoostSampler on Linux and on Windows, I get different results even if random_state is set correctly.

Your environment

  • OS: Windows 11, Ubuntu 22.04
  • Python version: Python 3.10.9
  • Package Version 0.2.1, commit cffd29e
  • Anything else you consider helpful.

Steps to reproduce

Run the following script on both Windows and Ubuntu:

import numpy as np

from black_it.calibrator import Calibrator
from black_it.loss_functions.msm import MethodOfMomentsLoss
from black_it.samplers.halton import HaltonSampler
from black_it.samplers.xgboost import XGBoostSampler
from black_it.search_space import SearchSpace

xs = np.linspace(0, 1, 6)
ys = np.linspace(0, 1, 6)
xys_list = []
losses_list = []

for x in xs:
    for y in ys:
        xys_list.append([x, y])
        losses_list.append(x**2 + y**2)

xys = np.array(xys_list)
losses = np.array(losses_list)

sampler = XGBoostSampler(batch_size=4, random_state=0)
param_grid = SearchSpace(
    parameters_bounds=np.array([[0, 1], [0, 1]]).T,
    parameters_precision=np.array([0.01, 0.01]),
    verbose=False,
)
new_params = sampler.sample(param_grid, xys, losses)

On Ubuntu, the value of new_params is:

[[0.24 0.26]
 [0.37 0.21]
 [0.43 0.14]
 [0.11 0.04]]

On Windows, the value of new_params is:

[[0.24 0.26]
 [0.19 0.11]
 [0.13 0.22]
 [0.11 0.05]]

Expected behaviour

I expected to get the same result.

Actual behaviour

Different result, see above.

Furhter comments

I understand that the provided details might not be enough for the exact reproduction of the bug. This issue is more a way to point out the reproducibility issue when using the XGBoostSampler.

On the other hand, I suspect this does not depends on black-it, but rather on the underlying implementation of XGBoost, provided by the package xgboost. The following links already document reproducibility issues for that package:

marcofavoritobi pushed a commit that referenced this issue Mar 18, 2023
We had to workaround issue #49 by providing different expected results
for Windows.
marcofavoritobi pushed a commit that referenced this issue Mar 18, 2023
We had to workaround issue #49 by providing different expected results
for Windows.
marcofavoritobi pushed a commit that referenced this issue Mar 18, 2023
We had to workaround issue #49 by providing different expected results
for Windows.
marcofavoritobi pushed a commit that referenced this issue Mar 18, 2023
We had to workaround issue #49 by providing different expected results
for Windows.
marcofavoritobi pushed a commit that referenced this issue Mar 18, 2023
We had to workaround issue #49 by providing different expected results
for Windows.
marcofavoritobi pushed a commit that referenced this issue Mar 18, 2023
We had to workaround issue #49 by providing different expected results
for Windows.
marcofavoritobi pushed a commit that referenced this issue Mar 20, 2023
We had to workaround issue #49 by providing different expected results
for Windows.
marcofavoritobi pushed a commit that referenced this issue Mar 20, 2023
We had to workaround issue #49 by providing different expected results
for Windows.
marcofavoritobi pushed a commit that referenced this issue Mar 20, 2023
We had to workaround issue #49 by providing different expected results
for Windows.
marcofavoritobi pushed a commit that referenced this issue Mar 21, 2023
We had to workaround issue #49 by providing different expected results
for Windows.
marcofavoritobi pushed a commit that referenced this issue Sep 20, 2023
To reproduce the errors:
```
ruff check --select "NPY" tests
```

This commit updates the tests code so to make them to use np.random.default_rng with a certain seed, rather than relying on global random seed handling, i.e. using np.random.seed.

To do so, a new fixture, 'rng', has been added so to avoid the tests code to initialize a np.random.Generator instance manually.

This allowed to remove the special case for macOS platforms in TestCalibrate.test_calibrator_calibrate tests. Fix #49.
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

No branches or pull requests

1 participant