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

[RLlib; Pre-checks/better failure behavior] Env Checker for Gym Environments #20481

Merged
merged 8 commits into from
Nov 19, 2021

Conversation

avnishn
Copy link
Member

@avnishn avnishn commented Nov 17, 2021

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

  • I've run scripts/format.sh to lint the changes in this PR.
  • I've included any doc changes needed for https://docs.ray.io/en/master/.
  • I've made sure the tests are passing. Note that there might be a few flaky tests, see the recent failures at https://flakey-tests.ray.io/
  • Testing Strategy
    • Unit tests
    • Release tests
    • This PR is not tested :(

Copy link
Member

@gjoliver gjoliver left a 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 :)

Raises:
ValueError: If env is not one of the supported types.
"""
supported_types = (BaseEnv, gym.Env, MultiAgentEnv, RemoteVectorEnv,
Copy link
Member

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.

Copy link
Member Author

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

Copy link
Member Author

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

@avnishn avnishn changed the title Initial Commit Env Checker for Gym Environments Nov 18, 2021
def check_env(
env: [BaseEnv, gym.Env, MultiAgentEnv, RemoteVectorEnv,
VectorEnv]) -> None:
def check_env(env: ["BaseEnv", "gym.Env", "MultiAgentEnv", "RemoteVectorEnv",
Copy link
Member Author

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?

@sven1977.

I need to do this because I need to local import these packages otherwise I have a circular import issue.

Copy link
Contributor

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.

@sven1977 sven1977 self-assigned this Nov 18, 2021
@sven1977 sven1977 marked this pull request as ready for review November 18, 2021 21:13
Copy link
Contributor

@sven1977 sven1977 left a 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]), ...

@sven1977
Copy link
Contributor

Let's wait for tests to pass, then merge!

@sven1977 sven1977 merged commit b6077a3 into ray-project:master Nov 19, 2021
@sven1977
Copy link
Contributor

Nice!

@sven1977 sven1977 changed the title Env Checker for Gym Environments [RLlib; Pre-checks/better failure behavior] Env Checker for Gym Environments Nov 19, 2021
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.

RLlib; Pre-checks/better failure behavior Failure modes environment checking gym environments
3 participants