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 #3128

Closed
wants to merge 2 commits into from

Conversation

theo-brown
Copy link

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'>

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.

@balisujohn
Copy link
Contributor

balisujohn commented Oct 16, 2022

Thanks for your contribution! One small nitpick: I think it would be good to print both the type and the value. For reference, right now if I'm reading it right if I gave the reset function seed = int(-1), I'd get the message

gym.error.Error: Seed must be a non-negative integer or omitted, not <class 'int'>

So maybe something like:

gym.error.Error: Seed must be a non-negative integer or omitted: current type: <class 'int'>, current value: -1

It seems like we already have adequate testing coverage for this function in https://github.com/openai/gy/blob/master/tests/utils/test_seeding.py , so I don't think there is a super strong need to add a test.

@theo-brown
Copy link
Author

I was following the example TypeError from the Python docs, which doesn't print the value:

>>> '2' + 2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: can only concatenate str (not "int") to str

@balisujohn
Copy link
Contributor

LGTM :^)

theo-brown added a commit to theo-brown/Gymnasium that referenced this pull request Oct 25, 2022
Identical changes to pull request 3128 on OpenAI Gym repository, openai/gym#3128)
@pseudo-rnd-thoughts
Copy link
Contributor

Hey, we just launched gymnasium, a fork of Gym by the maintainers of Gym for the past 18 months where all maintenance and improvements will happen moving forward. Could you please move this over to the new repo?

If you'd like to read more about the story behind the backstory behind this and our plans going forward, click here.

@jkterry1 jkterry1 closed this 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.

[Bug Report] Error message after seeding with a non-int does not show incorrect seed type
4 participants