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

pararell enviroments on Windows raise overflow error " Python int too large to convert to C long " #21

Open
userman2213 opened this issue Apr 26, 2024 · 0 comments

Comments

@userman2213
Copy link

userman2213 commented Apr 26, 2024

When I run the environment with parallel environments on my Windows device, I get an overflow error "Python int too large to convert to C long" in gymnasium\vector\vector_env.py, line 300, in _add_info info_array[env_num], array_mask[env_num] = info[k], True
after several iterations.
On my Linux device, this problem does not occur. After some research, I found out that Windows specifically uses 32-bit integers instead of 64-bit.

I have found a workaround that involves converting the INT type to an int64 type. However, I am not sure if this method is legitimate and if it might introduce further errors. Nonetheless, I have modified the def _init_info_arrays in vector_env.py as follows. Additionally, I am not sure if the source of the error lies in gym or in the TradingEnv or MultiDatasetTradingEnv.

def _init_info_arrays(self, dtype: type) -> Tuple[np.ndarray, np.ndarray]:
        """Initialize the info array.

        Initialize the info array. If the dtype is numeric
        the info array will have the same dtype, otherwise
        will be an array of `None`. Also, a boolean array
        of the same length is returned. It will be used for
        assessing which environment has info data.

        Args:
            dtype (type): data type of the info coming from the env.

        Returns:
            array (np.ndarray): the initialized info array.
            array_mask (np.ndarray): the initialized boolean array.

        """
        if dtype in [int, np.int64]:
            array = np.zeros(self.num_envs, dtype=np.int64)
        elif dtype in [float, bool] or issubclass(dtype, np.number):
            array = np.zeros(self.num_envs, dtype=dtype)
        else:
            array = np.zeros(self.num_envs, dtype=object)
            array[:] = None
        array_mask = np.zeros(self.num_envs, dtype=bool)
        return array, array_mask
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