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

Fix random seed int32 for Windows #1655

Merged
merged 4 commits into from
Aug 30, 2023

Conversation

PatrickHelm
Copy link
Contributor

Description

I recognized the error described in #1579 while running the tests for another pull request on Windows. To fix it, I changed high in np.random.randint from 2**32-1 to 2**31-1. The solution proposed by @MikhailGerasimov in #1579 did not work as Gymnasium does not accept numpy integers as seeds.

Motivation and Context

closes #1579

  • I have raised an issue to propose this change (required for new features and bug fixes)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation (update in the documentation)

Checklist

  • I've read the CONTRIBUTION guide (required)
  • I have updated the changelog accordingly (required).
  • My change requires a change to the documentation.
  • I have updated the tests accordingly (required for a bug fix or a new feature).
  • I have updated the documentation accordingly.
  • I have opened an associated PR on the SB3-Contrib repository (if necessary)
  • I have opened an associated PR on the RL-Zoo3 repository (if necessary)
  • I have reformatted the code using make format (required)
  • I have checked the codestyle using make check-codestyle and make lint (required)
  • I have ensured make pytest and make type both pass. (required)
  • I have checked that the documentation builds using make doc (required)

Note: You can run most of the checks using make commit-checks.

Note: we are using a maximum length of 127 characters per line

@araffin
Copy link
Member

araffin commented Aug 25, 2023

he solution proposed by @MikhailGerasimov in #1579 did not work as Gymnasium does not accept numpy integers as seeds.

Hmm, does an explicit cast int(np.random(..., dtype=np.int64)) works? (the question: is int(2**32 - 1) of the correct type on windows?)

@araffin araffin changed the title Bugfix/oob for int32 closing #1579 Fix random seed int32 for Windows Aug 25, 2023
@MikhailGerasimov
Copy link

I would suggest a small improvement to eliminate the magic number.
int(np.random.randint(0, np.iinfo(np.uint32).max, dtype=np.uint32))

2**32 - 1 == np.iinfo(np.uint32).max == 4294967295

(the question: is int(2**32 - 1) of the correct type on windows?)

The issue lies not with Windows, but with NumPy. It uses different implicit types for Windows and Linux. On Windows, it's a signed 32-bit integer, while on Linux, it's a 64-bit integer. By explicitly setting the type, everything should function correctly.

On Windows
print(np.iinfo(np.int_).max) == 2147483647
On Linux
print(np.iinfo(np.int_).max) == 9223372036854775807

https://docs.scipy.org/doc/numpy-1.10.1/user/basics.types.html

@araffin
Copy link
Member

araffin commented Aug 30, 2023

@PatrickHelm could you test @MikhailGerasimov solution on windows?

Copy link
Member

@araffin araffin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks =)

@araffin araffin merged commit 5c93e9f into DLR-RM:master Aug 30, 2023
@PatrickHelm PatrickHelm deleted the bugfix/oob_for_int32 branch August 30, 2023 09:24
@PatrickHelm
Copy link
Contributor Author

@PatrickHelm could you test @MikhailGerasimov solution on windows?
I tested it on Windows already before pushing and it worked.

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

Successfully merging this pull request may close these issues.

[Bug]: ValueError: high is out of bounds for int32
3 participants