facebookresearch / nevergrad

A Python toolbox for performing gradient-free optimization
https://facebookresearch.github.io/nevergrad/
MIT License
3.89k stars 349 forks source link

Int has an overflow on windows #1595

Open IntelleKarl opened 4 months ago

IntelleKarl commented 4 months ago

Steps to reproduce

  1. Have windows
  2. Have parametrization._layering.Int deterministically process a floating point number larger than the maximum 32-bit integer
  3. Enjoy int overflow (specifically on windows)

Observed Results

On Windows, I happen to get this warning from numpy:

RuntimeWarning: invalid value encountered in cast
  out = np.round(out).astype(int)

Expected Results

Not to receive any warnings on windows.

Relevant Code

import nevergrad
test_scalar = nevergrad.p.Scalar(lower=1e12, upper=1e13).set_integer_casting()
test_scalar.sample()

I believe this is because np.dtype(int) is platform dependant. On Windows, this is interpreted as dtype('int32') whilst on Linux it is dtype('int64'). I believe a fix for this would simply be to use np.int64 directly.