vwxyzjn/cleanrl

code error when running dqn.py

Closed this issue · 4 comments

Hi,
I am new to RL.
I am trying to use the dqn model provided for my environment. But I got an error when trying
running the original demo.

Traceback (most recent call last):
  File "/home/zuoj/FC_maintenance_decision/dqn_or.py", line 187, in <module>
    rb.add(obs, real_next_obs, actions, rewards, dones, infos)
  File "/home/zuoj/anaconda3_2022/envs/cleanrl/lib/python3.9/site-packages/stable_baselines3/common/buffers.py", line 266, in add
    self.timeouts[self.pos] = np.array([info.get("TimeLimit.truncated", False) for info in infos])
ValueError: could not broadcast input array from shape (0,) into shape (1,)

I got the same error in my environment.

I see in this dqn.py uses the vectorized environment:
envs = gym.vector.SyncVectorEnv([make_env(args.env_id, args.seed, 0, args.capture_video, run_name)])
but this line indicates that there is only one env in the list?
In code line 174 and 175:
for info in infos: if "episode" in info.keys():
I also got an error in line 175 indicates info is an int object, why not [infos]?
Thank you very much!

It’s probably dependency version issues. Please use poetry install.

Thank you very much for checking my problem.

I just tried reinstalling using poetry, and it works (also works in my case).
Is this because of the version of gym? Which gym version (or gymnasium?) would you suggest for
constructing my own RL env?

Thank you very much!

The newer gym /gymnasium versions should also work and require minimal modifications. You should feel free to use the one that's easier to use for you :) CleanRL illustrates the principles but it's up to you to customize.

Got it, thank you very much @vwxyzjn