Skip to content

[Bug] ValueError: high is out of bounds for int32 on Windows (vecrl.py, SyncVectorEnv) #125

@FredericThoma

Description

@FredericThoma

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

  1. Use Windows (native, not WSL)
  2. 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)")
  1. 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, 2
32, 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions