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] Replace ordinary pygame imports by try_imports #31332

Merged
merged 8 commits into from
Jan 17, 2023

Conversation

ArturNiederfahrenhorst
Copy link
Contributor

Signed-off-by: Artur Niederfahrenhorst [email protected]

Why are these changes needed?

Replaces imports of pygame with try_imports, akin to the ones we use for frameworks.
This helps us output a more informative import error.

Related issue number

#31321

Checks

  • I've signed off every commit(by using the -s flag, i.e., git commit -s) in this PR.
  • 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 :(

Signed-off-by: Artur Niederfahrenhorst <[email protected]>
from typing import Optional

import numpy as np
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious, is this a new sorting convention? Three blocks: a) included python modules, b) other third-party imports, c) ray imports?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The three categories you describe (and the formating changes here) conform with PEP-8 I belive.
-> https://peps.python.org/pep-0008/#imports
I think we should adhere at least to PEP-8. The google style guide is optional.

I use PyCharm's "optimize imports" feature to do these, but PyCharm also groups "import x as y" vs "import x" and separates them which makes for apparent missing alphabetical order.

error: Whether to raise an error if pyspiel cannot be imported.

Returns:
The tfp module.
Copy link
Contributor

Choose a reason for hiding this comment

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

-> "pyspiel", not tfp

The tfp module.

Raises:
ImportError: If error=True and tfp is not installed.
Copy link
Contributor

Choose a reason for hiding this comment

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

-> "pyspiel" instead of tfp

import re

import numpy as np
from open_spiel.python.rl_environment import Environment
Copy link
Contributor

Choose a reason for hiding this comment

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

Dumb question: what was the difference between open_spiel and pyspiel again? Would we need to return the open_spiel package as well from try_import_pyspiel()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

open spiel uses pygame, which is a game engine with a python interface.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They are separate packages though.
We list pygame in our test requirements and open_spiel nowhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have added open_spiel to this PR with the same behaviour!

import sys

import numpy as np
from open_spiel.python.rl_environment import Environment
Copy link
Contributor

Choose a reason for hiding this comment

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

same question as above.

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.

Thanks for the fixes. Just a few questions on pyspiel vs open_spiel.

Signed-off-by: Artur Niederfahrenhorst <[email protected]>
Signed-off-by: Artur Niederfahrenhorst <[email protected]>
Signed-off-by: Artur Niederfahrenhorst <[email protected]>
Signed-off-by: Artur Niederfahrenhorst <[email protected]>
Signed-off-by: Artur Niederfahrenhorst <[email protected]>
@ArturNiederfahrenhorst ArturNiederfahrenhorst added the tests-ok The tagger certifies test failures are unrelated and assumes personal liability. label Dec 30, 2022
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.

LGTM.

@sven1977 sven1977 merged commit 5e66cbf into ray-project:master Jan 17, 2023
andreapiso pushed a commit to andreapiso/ray that referenced this pull request Jan 22, 2023
cassidylaidlaw pushed a commit to cassidylaidlaw/ray that referenced this pull request Mar 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests-ok The tagger certifies test failures are unrelated and assumes personal liability.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants