lab icon indicating copy to clipboard operation
lab copied to clipboard

Why is reset so slow?

Open jodusan opened this issue 5 years ago • 9 comments

I'm finding it that reset of the envrionment takes around 0.35 secs which is kinda slowish? Is there a way to optimize it?

I have been searching through the code but apart from the start() method which has two for loops haven't find anything slow? Is it due to the quake engine or smth else?

Any info is highly appreciated

jodusan avatar May 16 '19 11:05 jodusan

I think 0.35 seconds is about as fast as it gets. Internally, I believe they restart/reload the level from scratch on every reset. If you're using something like random maze generation, then it gets worse with 5-15 seconds per reset. However, this can be optimized with the level cache.

alex-petrenko avatar Jun 06 '19 22:06 alex-petrenko

@alex-petrenko thanks for answering! Is there any way to hack it not to reload the level from scratch just randomly reset positions of objects/colors? No need to reload everything, it would be a huge boost to total frames per second for RL.

jodusan avatar Jun 07 '19 08:06 jodusan

There must be a way but I'm not an expert. I'd guess you can just do it on the level of the scenario, basically running the same very long episode but just resetting positions of the actors. This won't give you done=True, but in your RL code you can use some auxiliary variables from info dictionary to detect episode termination.

alex-petrenko avatar Jun 07 '19 08:06 alex-petrenko

@alex-petrenko that's what I was thinking too, any idea where I should look first? codebase is new to me

jodusan avatar Jun 07 '19 08:06 jodusan

Sorry, I'm relatively new too. My first suggestion is to measure how much you're actually losing. Try to minimize the losses by making your episode longer and/or doing all resets in parallel if you can (e.g. set episode duration to the exact same number of frames for all envs).

If you absolutely need to fix this, I think you need to look at the Lua code of the scenario that you're using, and figure out from there. It is possible to create callbacks between C++ and Lua code, so you can detect the reset event and trigger the cleanup in Lua. Sorry, I don't think I can guide you any further :)

alex-petrenko avatar Jun 07 '19 08:06 alex-petrenko

@alex-petrenko Thanks for all the info!

jodusan avatar Jun 07 '19 08:06 jodusan

Hi, You can return an empty string from getNextMap. This will quick reload the current map.

charlesbeattie avatar Jun 07 '19 14:06 charlesbeattie

@charlesbeattie Do you know if it randomizes the level still and where can it be located? Thanks!

jodusan avatar Jun 12 '19 10:06 jodusan

Anything related to map generation is baked in. The some entities are contained within the map and so are baked in. But you can add entities dynamically too. See game_scripts/levels/demos/extra_entities.lua for an example for creating entities without rebuilding the map. (These features came in later in the dev cycle so we more heavily relied on level caching.)

charlesbeattie avatar Jun 12 '19 13:06 charlesbeattie