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

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

Open
4 of 8 tasks
SorenSc opened this issue Mar 6, 2023 · 5 comments · Fixed by #826
Open
4 of 8 tasks

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

SorenSc opened this issue Mar 6, 2023 · 5 comments · Fixed by #826
Labels
bug Something isn't working not reproduced yet Not yet tested or reproduced by a reviewer
Milestone

Comments

@SorenSc
Copy link

SorenSc commented Mar 6, 2023

  • I have marked all applicable categories:
    • exception-raising bug
    • RL algorithm bug
    • documentation request (i.e. "X is missing from the documentation.")
    • new feature request
  • I have visited the source website
  • I have searched through the issue tracker for duplicates
  • I have mentioned version numbers, operating system and environment, where applicable:
    import tianshou, gym, torch, numpy, sys
    print(tianshou.__version__, gym.__version__, torch.__version__, numpy.__version__, sys.version, sys.platform)
    # 0.4.11 0.26.2 1.13.1 1.23.5 3.10.9 (main, Mar  1 2023, 12:20:14) [Clang 14.0.6 ] darwin
    # I'm using gymnasium (import gymnasium as gym)
    # I'm running it on an Apple M1 Pro

I'm tryin to execute the example on the start page (https://github.com/thu-ml/tianshou).

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
Copy link
Collaborator

Thanks for reporting this issue, will fix soon!

@Trinkle23897 Trinkle23897 added the bug Something isn't working label Mar 7, 2023
@zzw1123
Copy link

zzw1123 commented Mar 10, 2023

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

@zzw1123
Copy link

zzw1123 commented Mar 10, 2023

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

@Trinkle23897
Copy link
Collaborator

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.

@Trinkle23897 Trinkle23897 linked a pull request Mar 13, 2023 that will close this issue
@Amazingldl
Copy link

Amazingldl commented Aug 30, 2023

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

@Trinkle23897 Trinkle23897 reopened this Aug 30, 2023
@MischaPanch MischaPanch added documentation not reproduced yet Not yet tested or reproduced by a reviewer and removed documentation labels Oct 14, 2023
@MischaPanch MischaPanch added this to To do in Overall Tianshou Status via automation Oct 14, 2023
@MischaPanch MischaPanch added this to the Release 1.0.0 milestone Oct 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working not reproduced yet Not yet tested or reproduced by a reviewer
Development

Successfully merging a pull request may close this issue.

5 participants