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

Change seeding error message to report seed type #74

Merged

Conversation

theo-brown
Copy link
Contributor

Identical changes to pull request 3128 on OpenAI Gym repository.
Pull requested repeated here:

Description

Changed error message produced when seed argument of env.reset(seed=seed) is the incorrect type to include the type of the incorrect seed rather than the value. This is in line with most other Python error messages.

Fixes #3127

Type of change

Bug fix (non-breaking change which fixes an issue)

Example

import numpy as np
import gym

rng = np.random.default_rng()
seed = rng.integers(2**32)

env = gym.make("MountainCarContinuous-v0")
env.reset(seed=seed)
Before After
gym.error.Error: Seed must be a non-negative integer or omitted, not 1407292551 gym.error.Error: Seed must be a non-negative integer or omitted, not <class 'numpy.int64'> (got 1407292551)

Checklist:

  • I have run the pre-commit checks with pre-commit run --all-files (see CONTRIBUTING.md instructions to set it up)
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

I have not followed the above checklist because I changed so little. Any problems with this PR exist externally in the openai/gym repo.

Identical changes to pull request 3128 on OpenAI Gym repository, openai/gym#3128)
Copy link
Member

@pseudo-rnd-thoughts pseudo-rnd-thoughts left a comment

Choose a reason for hiding this comment

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

Thanks looks good

Copy link
Member

@pseudo-rnd-thoughts pseudo-rnd-thoughts left a comment

Choose a reason for hiding this comment

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

Thinking about it, could we modify the error to

if seed is not None and not (isinstance(seed, int) and 0 <= seed):
    if isinstance(seed, int) is False: 
       raise Error(f"Seed must be a python integer, actual type: {type(seed)}")
    else:
       raise Error(f"Seed must be greater or equal to zero, actual value: {seed}")

Also, would you be able to fix the pre-commit problem

@pseudo-rnd-thoughts
Copy link
Member

@theo-brown Would you be able to add a test that the correct error occurs

@pseudo-rnd-thoughts pseudo-rnd-thoughts merged commit ae3a04e into Farama-Foundation:main Nov 11, 2022
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.

2 participants