Description
Running any script that uses VecGymNE (e.g. with PGPE or CoSyNE) on Windows fails with the following error:
ValueError: high is out of bounds for int32
Root cause
In evotorch/neuroevolution/net/vecrl.py, line 1661:
seeds = self.__random_state.randint(0, 2**32, self.num_envs)
On Windows, NumPy's default integer type is int32, so passing 2**32 as the
high argument to numpy.random.RandomState.randint exceeds the maximum value
for that dtype and raises a ValueError.
On Linux (and WSL), NumPy's default integer type is int64, so the same call
succeeds.
Steps to reproduce
- Use Windows (native, not WSL)
- Run this script:
from evotorch.algorithms import PGPE
from evotorch.decorators import pass_info
from evotorch.neuroevolution import VecGymNE
from torch import nn
@pass_info
class LunarPolicy(nn.Module):
def __init__(self, obs_length: int, act_length: int, **kwargs):
super().__init__()
self.net = nn.Sequential(
nn.Linear(obs_length, 16),
nn.Tanh(),
nn.Linear(16, act_length),
)
def forward(self, x):
return self.net(x)
problem = VecGymNE(
env="LunarLander-v3",
network=LunarPolicy,
num_episodes=1,
num_actors=1,
)
searcher = PGPE(problem, popsize=10, radius_init=4.5, center_learning_rate=0.2, stdev_learning_rate=0.1)
searcher.step()
print("OK — no error (you are likely on Linux/WSL)")
- Observe the
ValueError
Full traceback
Traceback (most recent call last):
File "C:\Users<USER>\Documents\EvotorchFork\evotorch\examples\scripts\reproduce_bug.py", line 42, in
searcher.step()
File "C:\Users<USER>\Documents\EvotorchFork\evotorch\src\evotorch\algorithms\searchalgorithm.py", line 390, in step
self._step()
File "C:\Users<USER>\Documents\EvotorchFork\evotorch\src\evotorch\algorithms\distributed\gaussian.py", line 354, in _step_non_distributed
fill_and_eval_pop()
File "C:\Users<USER>\Documents\EvotorchFork\evotorch\src\evotorch\algorithms\distributed\gaussian.py", line 295, in fill_and_eval_pop
self.problem.evaluate(self._population)
File "C:\Users<USER>\Documents\EvotorchFork\evotorch\src\evotorch\core.py", line 2559, in evaluate
self._evaluate_all(batch)
File "C:\Users<USER>\Documents\EvotorchFork\evotorch\src\evotorch\core.py", line 2577, in _evaluate_all
self._evaluate_batch(batch)
File "C:\Users<USER>\Documents\EvotorchFork\evotorch\src\evotorch\neuroevolution\vecgymne.py", line 738, in _evaluate_batch
self._evaluate_subbatch(batch)
File "C:\Users<USER>\Documents\EvotorchFork\evotorch\src\evotorch\neuroevolution\vecgymne.py", line 752, in _evaluate_subbatch
obs_per_env = env.reset()
^^^^^^^^^^^
File "C:\Users<USER>\Documents\EvotorchFork\evotorch\src\evotorch\neuroevolution\net\vecrl.py", line 492, in reset
reset_result = self.env.reset(*args, kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users<USER>\Documents\EvotorchFork\evotorch\src\evotorch\neuroevolution\net\vecrl.py", line 1776, in reset
seed_kwargs_list = self.__pop_seed_kwargs()
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users<USER>\Documents\EvotorchFork\evotorch\src\evotorch\neuroevolution\net\vecrl.py", line 1661, in __pop_seed_kwargs
seeds = self.__random_state.randint(0, 232, self.num_envs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "numpy/random/mtrand.pyx", line 799, in numpy.random.mtrand.RandomState.randint
File "numpy/random/_bounded_integers.pyx", line 2881, in numpy.random._bounded_integers._rand_int32
ValueError: high is out of bounds for int32
Proposed fix
Add dtype=np.int64 to the randint call:
seeds = self.__random_state.randint(0, 2**32, self.num_envs, dtype=np.int64)
Workarounds
- Recommended: Run inside WSL (Windows Subsystem for Linux)
- Manual patch: Edit
.venv\Lib\site-packages\evotorch\neuroevolution\net\vecrl.py
line 1661 as shown above
Environment
- OS: Windows (native)
- Python: Python 3.12.10
- NumPy: 2.4.4
- EvoTorch: 0.1.dev80+gcebcac4f2
Description
Running any script that uses
VecGymNE(e.g. with PGPE or CoSyNE) on Windows fails with the following error:ValueError: high is out of bounds for int32
Root cause
In
evotorch/neuroevolution/net/vecrl.py, line 1661:On Windows, NumPy's default integer type is
int32, so passing2**32as thehighargument tonumpy.random.RandomState.randintexceeds the maximum valuefor that dtype and raises a
ValueError.On Linux (and WSL), NumPy's default integer type is
int64, so the same callsucceeds.
Steps to reproduce
ValueErrorFull traceback
Traceback (most recent call last):
File "C:\Users<USER>\Documents\EvotorchFork\evotorch\examples\scripts\reproduce_bug.py", line 42, in
searcher.step()
File "C:\Users<USER>\Documents\EvotorchFork\evotorch\src\evotorch\algorithms\searchalgorithm.py", line 390, in step
self._step()
File "C:\Users<USER>\Documents\EvotorchFork\evotorch\src\evotorch\algorithms\distributed\gaussian.py", line 354, in _step_non_distributed
fill_and_eval_pop()
File "C:\Users<USER>\Documents\EvotorchFork\evotorch\src\evotorch\algorithms\distributed\gaussian.py", line 295, in fill_and_eval_pop
self.problem.evaluate(self._population)
File "C:\Users<USER>\Documents\EvotorchFork\evotorch\src\evotorch\core.py", line 2559, in evaluate
self._evaluate_all(batch)
File "C:\Users<USER>\Documents\EvotorchFork\evotorch\src\evotorch\core.py", line 2577, in _evaluate_all
self._evaluate_batch(batch)
File "C:\Users<USER>\Documents\EvotorchFork\evotorch\src\evotorch\neuroevolution\vecgymne.py", line 738, in _evaluate_batch
self._evaluate_subbatch(batch)
File "C:\Users<USER>\Documents\EvotorchFork\evotorch\src\evotorch\neuroevolution\vecgymne.py", line 752, in _evaluate_subbatch
obs_per_env = env.reset()
^^^^^^^^^^^
File "C:\Users<USER>\Documents\EvotorchFork\evotorch\src\evotorch\neuroevolution\net\vecrl.py", line 492, in reset
reset_result = self.env.reset(*args, kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users<USER>\Documents\EvotorchFork\evotorch\src\evotorch\neuroevolution\net\vecrl.py", line 1776, in reset
seed_kwargs_list = self.__pop_seed_kwargs()
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users<USER>\Documents\EvotorchFork\evotorch\src\evotorch\neuroevolution\net\vecrl.py", line 1661, in __pop_seed_kwargs
seeds = self.__random_state.randint(0, 232, self.num_envs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "numpy/random/mtrand.pyx", line 799, in numpy.random.mtrand.RandomState.randint
File "numpy/random/_bounded_integers.pyx", line 2881, in numpy.random._bounded_integers._rand_int32
ValueError: high is out of bounds for int32
Proposed fix
Add
dtype=np.int64to therandintcall:Workarounds
.venv\Lib\site-packages\evotorch\neuroevolution\net\vecrl.pyline 1661 as shown above
Environment