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

Fix discrete CarRacing-v3 #1253

Merged
merged 3 commits into from
Nov 18, 2024

Conversation

Sebastian-Griesbach
Copy link
Contributor

Description

CarRacing-v3 in discrete mode first converts the action to a float value before checking if the action is part of the discrete action-space. This causes an error to be raised.

Minimal example to reproduce this error:

import gymnasium as gym
env = gym.make("CarRacing-v3", continuous=False)
_ = env.reset()
action = env.action_space.sample()
_ = env.step(action)

This problem can be fixed simply by moving the float conversion to after the if self.continuous: check such that for the discrete case else: the action will still be an integer. And the InvalidAction error is not raised.

Please delete options that are not relevant.

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

Checklist:

  • I have run the pre-commit checks with pre-commit run --all-files (see CONTRIBUTING.md instructions to set it up)
  • [NA] I have commented my code, particularly in hard-to-understand areas
  • [NA] I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • [NA] 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

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 for spotting this issue, could you add a test to check that this works, probably in tests/envs/test_env_implementations.py
I believe that Lunar Lander has a similar continuous=False, could you add this to the test. You just need to pass valid and invalid action and check that the error occurs

@Sebastian-Griesbach
Copy link
Contributor Author

Sebastian-Griesbach commented Nov 17, 2024

I added a test that checks if continuous actions fail in the discrete setting and discrete actions don't raise any error both for LunarLander-v3 and CarRacing-v3.

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 for making that change @Sebastian-Griesbach

@pseudo-rnd-thoughts pseudo-rnd-thoughts merged commit d2dc19f into Farama-Foundation:main Nov 18, 2024
12 of 13 checks passed
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