facebookresearch / BenchMARL

A collection of MARL benchmarks based on TorchRL
https://benchmarl.readthedocs.io/
MIT License
191 stars 23 forks source link

[Feature] Allow any name for observation and global_state keys #72

Closed matteobettini closed 3 months ago

matteobettini commented 3 months ago

This PR allows any name for the group observation key and the global state key.

Before benchmarl constrained the observation to be named "observation" and the global state to be named "state"

cc @ezhang7423

matteobettini commented 3 months ago

The next PR will allow any shape observation and state.

However there is a problem. DDPG and SAC critics take as input the concatenation of the state and the actions.

Up until now we had only 1-dimensional states and observation so concatenating the actions was easy.

Now if the state and obs can be pictures, concatenating them to actions is less trivial.

They should ideally be prrcessed by different nets before being concatenated.

This poses a non-trivial problem to the way BenchMARL is designed. In particular:

Proposed solution

The proposed solution is to allow models to get more than one key as input.

For example if an MLP receives 2 keys, it will concatenate them before processing (just like in torchrl https://github.com/pytorch/rl/blob/2461eb20d21b79a410e01aed71c26b77712a30d8/torchrl/modules/models/models.py#L295)

If an CNN receives multiple inputs, it will also try to concatenate them, but if they have different shapes, it will just cat the images, process them and then cat the other tensors to the output.

This means that if you have a CNN+MLP model and you pass it an image and a tensor, the CNN will process the image and cat the output to the other inputs and the MLP will process this

I implemented this in #73

codecov-commenter commented 3 months ago

Codecov Report

Attention: Patch coverage is 0% with 14 lines in your changes are missing coverage. Please review.

Project coverage is 47.57%. Comparing base (276345b) to head (eb69934).

Files Patch % Lines
benchmarl/algorithms/qmix.py 0.00% 6 Missing :warning:
benchmarl/algorithms/common.py 0.00% 2 Missing :warning:
benchmarl/algorithms/maddpg.py 0.00% 2 Missing :warning:
benchmarl/algorithms/masac.py 0.00% 2 Missing :warning:
benchmarl/algorithms/iddpg.py 0.00% 1 Missing :warning:
benchmarl/algorithms/isac.py 0.00% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #72 +/- ## =========================================== - Coverage 89.96% 47.57% -42.40% =========================================== Files 69 69 Lines 2731 2739 +8 =========================================== - Hits 2457 1303 -1154 - Misses 274 1436 +1162 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.