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

[Feature]: Support for planners and CEM #384

Merged
merged 60 commits into from
Sep 23, 2022
Merged

Conversation

nicolas-dufour
Copy link
Contributor

@nicolas-dufour nicolas-dufour commented Aug 30, 2022

Description

This PR adds support for MPC planners and in particular the CEM planner (The cross-entropy method for optimization, Botev et al 2013)

Motivation and Context

Planners are a key component of RL and is needed for methods such as PlaNet and PETS.

Types of changes

What types of changes does your code introduce? Remove all that do not apply:

  • New feature (non-breaking change which adds core functionality)

Checklist

Go over all the following points, and put an x in all the boxes that apply.
If you are unsure about any of these, don't hesitate to ask. We are here to help!

  • I have read the CONTRIBUTION guide (required)
  • My change requires a change to the documentation.
  • I have updated the tests accordingly (required for a bug fix or a new feature).
  • I have updated the documentation accordingly.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 30, 2022
Copy link
Contributor

@vmoens vmoens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great feature, I love it
LGTM for the implementation, just a few comments before we can land this.

The logic seems to make sense. I'd like to see a test of this too, across mocking and real envs if possible (can be done with SerialEnv, ParallelEnv is paradoxically slower with tests because it takes some time to launch).

torchrl/modules/planners/mpc.py Outdated Show resolved Hide resolved
torchrl/modules/planners/mpc.py Outdated Show resolved Hide resolved
torchrl/modules/planners/mpc.py Outdated Show resolved Hide resolved
torchrl/modules/planners/mpc.py Outdated Show resolved Hide resolved
@vmoens vmoens added the enhancement New feature or request label Aug 31, 2022
test/test_modules.py Outdated Show resolved Hide resolved
torchrl/modules/planners/__init__.py Outdated Show resolved Hide resolved
torchrl/modules/planners/cem.py Outdated Show resolved Hide resolved
torchrl/modules/planners/cem.py Outdated Show resolved Hide resolved
torchrl/modules/planners/cem.py Show resolved Hide resolved
torchrl/modules/planners/cem.py Outdated Show resolved Hide resolved
torchrl/modules/planners/cem.py Outdated Show resolved Hide resolved
torchrl/modules/planners/cem.py Outdated Show resolved Hide resolved
torchrl/modules/planners/common.py Outdated Show resolved Hide resolved
torchrl/modules/planners/common.py Outdated Show resolved Hide resolved
test/test_modules.py Outdated Show resolved Hide resolved
test/test_modules.py Outdated Show resolved Hide resolved

for key in td.keys():
if key != "action":
assert torch.allclose(td[key], td_copy[key])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't you also test the values of the action?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what should i test them for? I'm already testing that they exit and have the right shape but i don't really have any information that could allow to test for the values

torchrl/envs/transforms/transforms.py Outdated Show resolved Hide resolved
torchrl/modules/planners/cem.py Outdated Show resolved Hide resolved
torchrl/modules/planners/common.py Outdated Show resolved Hide resolved
torchrl/modules/planners/common.py Outdated Show resolved Hide resolved
torchrl/modules/planners/common.py Outdated Show resolved Hide resolved
torchrl/modules/planners/common.py Outdated Show resolved Hide resolved
torchrl/modules/planners/common.py Outdated Show resolved Hide resolved
test/test_modules.py Outdated Show resolved Hide resolved
@vmoens vmoens merged commit 2deac6d into pytorch:main Sep 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants