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

[Bug Report] Bug title #3304

Closed
ChengYoghurt opened this issue Dec 1, 2024 · 2 comments
Closed

[Bug Report] Bug title #3304

ChengYoghurt opened this issue Dec 1, 2024 · 2 comments

Comments

@ChengYoghurt
Copy link

ChengYoghurt commented Dec 1, 2024

Describe the bug
I used the "CarRacing-v3" environment and set the "continuous=False", and created a stable baseline3 DQR agent to train on it, I got error message like this:
image

According to the error message, I checked the source code of "class CarRacing", and noticed that:
image (1)

action = action.astype(np.float64)
will be executed even when action is sampled from Discrete Action Space, i.e. when action is an Integer.

Code example
`import gymnasium as gym
from gymnasium.spaces import Tuple, Discrete, Box
from stable_baselines3 import PPO, DQN
from stable_baselines3.common.monitor import Monitor
from stable_baselines3.common.vec_env import DummyVecEnv, VecVideoRecorder
import numpy as np

config = {
"policy_type": "MlpPolicy",
"total_timesteps": 25000,
"learning_rate": 0.01,
"gamma": 0.95,
"env_name": "CarRacing-v3",
}

env = gym.make(config["env_name"], render_mode="rgb_array", continuous=False,)
env = Monitor(env) # record stats such as returns
env = DummyVecEnv([make_env])

Initialize PPO model

model = DQN(
"MlpPolicy", # Use a multi-layer perceptron policy
env,
verbose=1,
learning_rate=config["learning_rate"],
# n_steps=512, # Number of steps to run for each environment per update
gamma=config["gamma"], # Discount factor
)

Train DQN

model.learn(total_timesteps=config["total_timesteps"], ),

`

System Info
Describe the characteristic of your environment:

  • my Gym was installed via pip
  • I ran into this problem on a linux machine
  • Python version=3.12

Checklist

  • [yes] I have checked that there is no similar issue in the repo (required)
@pseudo-rnd-thoughts
Copy link
Contributor

Thank for raising this, it was fixed in Farama-Foundation/Gymnasium#1253 and will be part of Gymnasium v1.1

@ChengYoghurt
Copy link
Author

I see. Thanks for your prompt help!

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

No branches or pull requests

2 participants