Skip to content

Cannot create compose on SqueezeTransform, UnsqueezeTransform and FlattenTransform #692

@altre

Description

@altre

Some transforms assume to already have a parent when calling set_parent(), in which case creating a new Compose with them fails:

>>> Compose(t)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/alanschelten/rl/torchrl/envs/transforms/transforms.py", line 630, in __init__
    t.set_parent(self)
  File "/Users/alanschelten/rl/torchrl/envs/transforms/transforms.py", line 1115, in set_parent
    batch_size = parent.batch_size
AttributeError: 'NoneType' object has no attribute 'batch_size'
>>> t = UnsqueezeTransform(0)
>>> Compose(t)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/alanschelten/rl/torchrl/envs/transforms/transforms.py", line 630, in __init__
    t.set_parent(self)
  File "/Users/alanschelten/rl/torchrl/envs/transforms/transforms.py", line 1115, in set_parent
    batch_size = parent.batch_size
AttributeError: 'NoneType' object has no attribute 'batch_size'
>>> t = FlattenObservation()
>>> Compose(t)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/alanschelten/rl/torchrl/envs/transforms/transforms.py", line 630, in __init__
    t.set_parent(self)
  File "/Users/alanschelten/rl/torchrl/envs/transforms/transforms.py", line 1045, in set_parent
    observation_spec = self.parent.observation_spec
  File "/Users/alanschelten/rl/torchrl/envs/transforms/transforms.py", line 241, in parent
    raise ValueError(
ValueError: Compose parent was of type <class 'NoneType'> but expected TransformedEnv.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions