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] A dataclass in "next" doesn't get copied over in step_mdp #1919

Closed
3 tasks done
maximilianigl opened this issue Feb 16, 2024 · 3 comments · Fixed by #1944
Closed
3 tasks done

[BUG] A dataclass in "next" doesn't get copied over in step_mdp #1919

maximilianigl opened this issue Feb 16, 2024 · 3 comments · Fixed by #1944
Assignees
Labels
bug Something isn't working

Comments

@maximilianigl
Copy link

maximilianigl commented Feb 16, 2024

Describe the bug

A dataclass in "next" doesn't get copied over in step_mdp.

To Reproduce

import dataclasses
from tensordict.tensordict import TensorDict
import torch
from torchrl.envs import step_mdp


@dataclasses.dataclass
class Test:
    a: int


dataclass = Test(1)
new_tensordict = step_mdp(
    TensorDict(
        {"next": {"state": torch.tensor([1.0]), "test": dataclass}}, batch_size=1
    )
)
print(new_tensordict.keys())
>> _StringKeys({'state': tensor([1.])})

Expected behavior

"test" in the example should be copied over.

System info

Using version 0.3.0 for both tensordict and torchrl.

Checklist

  • I have checked that there is no similar issue in the repo (required)
  • I have read the documentation (required)
  • I have provided a minimal working example to reproduce the bug (required)
@maximilianigl maximilianigl added the bug Something isn't working label Feb 16, 2024
@maximilianigl maximilianigl changed the title [BUG] [BUG] A dataclass in "next" doesn't get copied over in step_mdp Feb 16, 2024
@vmoens vmoens linked a pull request Feb 21, 2024 that will close this issue
@tejhande
Copy link

import dataclasses
from tensordict.tensordict import TensorDict
import torch
import copy
from torchrl.envs import step_mdp

@dataclasses.dataclass
class Test:
a: int

dataclass = Test(1)

Deep copy the dataclass before passing it to step_mdp

dataclass_copy = copy.deepcopy(dataclass)

new_tensordict = step_mdp(
TensorDict(
{"next": {"state": torch.tensor([1.0]), "test": dataclass_copy}}, batch_size=1
)
)
print(new_tensordict.keys())### 1919

@vmoens
Copy link
Contributor

vmoens commented Feb 24, 2024

Non tensor data is not well supported atm but it's going to be a feature of the next release! Stay tuned!
Let's use this thread to talk about the feature once the PR lands

@tejhande
Copy link

Absolutely, I appreciate the heads up! It's great to hear that non-tensor data will be supported in the next release. This feature will certainly enhance the flexibility and usability of the library. I look forward to exploring it further once the PR lands. Feel free to reach out anytime if you need assistance or feedback during the development process.

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

Successfully merging a pull request may close this issue.

3 participants