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] Using sorted() on the keys() attribute of a CompositeSpec #775

Closed
matteobettini opened this issue Dec 31, 2022 · 0 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@matteobettini
Copy link
Contributor

matteobettini commented Dec 31, 2022

Describe the bug

In a number of places in the code, the sorted() method is run on the keys() attribute of a CompositeSpec.

The bug was found when trying to create a ParallelEnv for Brax.

Here it fails as for nested specs the outputs of keys can be tuples.

env = ParallelEnv(1, lambda: BraxEnv(_get_envs()[0]))
env.rand_step()

The error is found is in

  File "/Users/Matteo/PycharmProjects/torchrl/torchrl/envs/vec_env.py", line 426, in _create_td
    self.env_input_keys = sorted(self.input_spec.keys())

but I suspect it might not be the only occurrance

To Reproduce

import torchrl

env = ParallelEnv(1, lambda: BraxEnv(_get_envs()[0]))
env.rand_step()
Traceback (most recent call last):
  File "/Users/Matteo/PycharmProjects/VectorizedMultiAgentSimulator/vmas/examples/torch_rl.py", line 30, in <module>
    env.rand_step()
  File "/Users/Matteo/PycharmProjects/torchrl/torchrl/envs/common.py", line 529, in rand_step
    return self.step(tensordict)
  File "/Users/Matteo/PycharmProjects/torchrl/torchrl/envs/common.py", line 341, in step
    tensordict_out = self._step(tensordict)
  File "/Users/Matteo/PycharmProjects/torchrl/torchrl/envs/vec_env.py", line 32, in decorated_fun
    self._create_td()
  File "/Users/Matteo/PycharmProjects/torchrl/torchrl/envs/vec_env.py", line 426, in _create_td
    self.env_input_keys = sorted(self.input_spec.keys())
TypeError: '<' not supported between instances of 'tuple' and 'str'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants