thu-ml / tianshou

An elegant PyTorch deep reinforcement learning library.
https://tianshou.org
MIT License
7.96k stars 1.13k forks source link

Getting started example causes TypeError: object of type 'TimeLimit' has no len() #819

Open SorenSc opened 1 year ago

SorenSc commented 1 year ago

When running

  collector = ts.data.Collector(policy, env, exploration_noise=True)

I ran into the following

  ---------------------------------------------------------------------------
  TypeError                                 Traceback (most recent call last)
  Cell In[8], line 3
        1 policy.eval()
        2 policy.set_eps(eps_test)
  ----> 3 collector = ts.data.Collector(policy, env, exploration_noise=True)
        4 collector.collect(n_episode=1, render=1 / 35)  

  File ~/miniconda3/envs/rl-index/lib/python3.10/site-packages/tianshou/data/collector.py:72, in Collector.__init__(self, policy, env, buffer, preprocess_fn, exploration_noise)
       70 else:
       71     self.env = env  # type: ignore
  ---> 72 self.env_num = len(self.env)
       73 self.exploration_noise = exploration_noise
       74 self._assign_buffer(buffer)  

  TypeError: object of type 'TimeLimit' has no len()

When doing the same in GoogleColab, I'm having the same issue.

Trinkle23897 commented 1 year ago

Thanks for reporting this issue, will fix soon!

zzw1123 commented 1 year ago

I have the same issue when running DQN in CartPole-v0. Please stay in touch when you fix it! Thx. image

zzw1123 commented 1 year ago

Just change "import gym" to "import gymnasium as gym" in collector.py.

Trinkle23897 commented 1 year ago

Update: I can't reproduce the above error. I think it's because of a version mismatch, since I ran with current master version instead of using tianshou==0.4.11. Will post a new version to pypi today.

Amazingldl commented 1 year ago

Update: I can't reproduce the above error. I think it's because of a version mismatch, since I ran with current master version instead of using tianshou==0.4.11. Will post a new version to pypi today.

Hello, @Trinkle23897 Thanks for the great work, but I am still getting this issue: Just copy the example-1 from https://tianshou.readthedocs.io/zh/latest/docs/5-example.html image