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

maskless_step and maskless_backward_step should throw an error if you don't return a tensor #145

Closed
josephdviviano opened this issue Nov 1, 2023 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@josephdviviano
Copy link
Collaborator

Right now when writing environments, it's quite natural to manipulate the states object in place, and return the modified state. However the Env class expects a Tensor to be returned, not a States class instance.

E.g.,:

    def maskless_step(self, states: States, actions: Actions) -> TT["batch_shape", 1, torch.float]:
        states.tensor[..., 0] = states.tensor[..., 0] + actions.tensor.squeeze(-1)  # x position.
        states.tensor[..., 1] = states.tensor[..., 1] + 1  # Step counter.
        return states

throws a bug downstream,

[/usr/local/lib/python3.10/dist-packages/gfn/env.py](https://localhost:8080/#) in step(self, states, actions)
    158         #     new_not_done_states.masks = self.update_masks(not_done_states, not_done_actions)
    159 
--> 160         new_states.tensor[~new_sink_states_idx] = new_not_done_states_tensor
    161 
    162         return new_states

TypeError: can't assign a LineStates to a torch.FloatTensor

The fix is simply to return states.tensor.

@josephdviviano josephdviviano self-assigned this Nov 1, 2023
@josephdviviano josephdviviano added the enhancement New feature or request label Nov 1, 2023
@josephdviviano
Copy link
Collaborator Author

addressed in #165

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant