proroklab / VectorizedMultiAgentSimulator

VMAS is a vectorized differentiable simulator designed for efficient Multi-Agent Reinforcement Learning benchmarking. It is comprised of a vectorized 2D physics engine written in PyTorch and a set of challenging multi-robot scenarios. Additional scenarios can be implemented through a simple and modular interface.
https://vmas.readthedocs.io
GNU General Public License v3.0
350 stars 71 forks source link

[Feature] Vectorized lidar #124

Closed matteobettini closed 4 months ago

matteobettini commented 4 months ago

continuation of #122

What we vectorize

Let me recap the levels of looping:

  1. there are multiple agents

  2. each agent can have multiple lidars

  3. each lidar sees multtiple entities

  4. at multiple angles

  5. in multiple environments

    And here is what we vectorize:

  6. I wouldn't vectorize this as of now as not all agents have lidars

  7. i also would not vectorize this as the user might want to read out different lidars at different times (although I would consider it in the future)

  8. in this PR

  9. in this PR

  10. vmas does this already

Benchmarking

pollock scenario

use_vmas_env(
        scenario_name="pollock",
        render=False,
        save_render=False,
        random_action=True,
        continuous_actions=False,
        n_agents=15,
        n_lines=15,
        n_boxes=15,
        lidar=True,
        n_steps=100,
        num_envs=32,
 )

before PR:

M1 cpu: 134.55210709571838s CUDA: 571.7651047706604s

after PR:

M1 cpu: 22.2061710357666s (0.16x the previous time) CUDA: 91.27248549461365s (0.15 x the previous time)

benefit will increase in the number of steps and envs

🚀

codecov[bot] commented 4 months ago

Codecov Report

Attention: Patch coverage is 99.46524% with 1 line in your changes missing coverage. Please review.

Project coverage is 88.22%. Comparing base (a9d545f) to head (418ad04).

Files Patch % Lines
vmas/simulator/core.py 99.37% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #124 +/- ## ========================================== + Coverage 87.47% 88.22% +0.75% ========================================== Files 82 83 +1 Lines 9507 9688 +181 ========================================== + Hits 8316 8547 +231 + Misses 1191 1141 -50 ```

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

matteobettini commented 4 months ago

@Zartris if you wanna review / try it out this shoulf be mega fasttttt

Zartris commented 4 months ago

Oh that was quick! Ill take a look today

matteobettini commented 4 months ago

pollock scenario

use_vmas_env(
        scenario_name="pollock",
        render=False,
        save_render=False,
        random_action=True,
        continuous_actions=False,
        n_agents=15,
        n_lines=15,
        n_boxes=15,
        lidar=True,
        n_steps=100,
        num_envs=32,
 )

before PR:

after PR:

🚀

Zartris commented 4 months ago

Everything seems to work good.