-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
[RLlib; Pre-checks/better failure behavior] Env Checker for Gym Environments #20481
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why don't you merge the PR while you are moving things here?
I mean, making separate smaller PRs is way better than keep adding to an open PR. Waleed said the optimal PR size is 80 lines :)
rllib/utils/pre_checks.py
Outdated
Raises: | ||
ValueError: If env is not one of the supported types. | ||
""" | ||
supported_types = (BaseEnv, gym.Env, MultiAgentEnv, RemoteVectorEnv, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
define this as a constant at the top of the file, and use it also in the type annotation?
can we also start a simple unit test file with this PR? basically try to fail whatever tests we are checking here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
of course! I will add a constant and add tests here for every one of the checks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ended not being able to add this as a constant in this file because of circular imports. Not sure where else I would put it -- maybe in rllib/env/init.py but im not sure if thats necessary. Lmk what you think @gjoliver
rllib/utils/pre_checks.py
Outdated
def check_env( | ||
env: [BaseEnv, gym.Env, MultiAgentEnv, RemoteVectorEnv, | ||
VectorEnv]) -> None: | ||
def check_env(env: ["BaseEnv", "gym.Env", "MultiAgentEnv", "RemoteVectorEnv", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does anyone know if this will fail sphinx build?
I need to do this because I need to local import these packages otherwise I have a circular import issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use Union["BaseEnv", ...]
instead?
Quotes are fine if you want to avoid circular imports.
What also may help is to use from typing import TYPE_CHECKING
(search for this in rllib/ to see examples of how imports can be conditioned on whether we are currently type checking or not). But this may not always help.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
Just a few nits (please keep these in mind for future PRs):
- Use unittest.TestCase for your tests (see other test cases on how we do this).
- sort imports in two blocks a) external and b) ray imports.
- within each import block, sort the individual imports alphabetically.
- Try to avoid yellow highlighted code in PyCharm, e.g.:
better:
assert isinstance(reward, (float, int)), ...
instead of:
assert isinstance(reward, [float, int]), ...
Let's wait for tests to pass, then merge! |
Nice! |
Why are these changes needed?
Evaluating and checking envs is buried in the codebase, making error messages hard to parse.
I'm going to keep updating this PR, and asking for reviews @sven1977, @richard4912, @gjoliver
It might be best to filter by most recent commits when looking at this pr.
Related issue number
Checks
scripts/format.sh
to lint the changes in this PR.