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
349 stars 71 forks source link

Vectorized raycast for lidar #122

Closed Zartris closed 4 months ago

Zartris commented 4 months ago

Currently, the lidar is a MAJOR bottleneck. It loops over all angles and all entities, so if you want a lidar with a remotely similar amount of rays as a true lidar this takes seconds for each sensor you use in the environment.

I have optimized it so now we are not looping over each angle and it gives me num_rays x improvement

Here I included a test with each landmark/ shape type. I have a timer in the measurement function (needs to be removed if you agree to accept the PR) The measurement function is doing both the loop and the vectorized methods to test if they are truly similar. I left these in so you can test for a bit yourself. Then I will clean it up and we can merge.

With 100 rays, a single agent, 3 objects:

LOOP TIME: 0.06827758200051903
VEC TIME: 0.000823776999823167
matteobettini commented 4 months ago

cc @janblumenkamp since this was your feature

matteobettini commented 4 months ago

I am happy to take over from here if you don't have time :)

Zartris commented 4 months ago

Hi Matteo, sorry for not answering, and as you guessed I have been a bit busy. I do not mind doing the implementation, but then it would take a while as I am finishing up papers and collecting results. So if you'd like it to happen anytime soon, feel free to take it over. I just did the PR so others could use the lidar in their projects.

matteobettini commented 4 months ago

Got it, I think with the code you wrote so far it'll be quick for me to finish this. I'll use all your commits so far so you get the credit :)

matteobettini commented 4 months ago

colsed in favor of #124