How to speed up simulation?

Typically: "How do I... ", "How can I... " questions
Post Reply
eli
Posts: 1
Joined: 01 Sep 2022, 15:42

How to speed up simulation?

Post by eli »

I am trying to use CoppeliaSim for some Reinforcement Learning which requires a lot of simulation (many hours), so I want to do this as quickly as possible. What I currently do is:

- Launch the scene I want to train on
- Open the Simulation Settings
- "Set the Simulation passes per frame (ppf)" to maximum, which seems to be 200
- Start my training using the ZeroMQ API
- And speed up the simulation even further using: sim.intparam_speedmodifier

Ideally, I would be able to set the ppf using the ZEROMQ API, but I haven't figured out how to do that.

Also I read in the "regular API constants" documentation that setting sim.boolparam_display_enabled to false allows you to enter the fast simulation mode. So, I wonder what fast simulation mode might be, because I couldn't find any documentation about it.

Looking forward to any help I might be able to get! Thanks a lot.

coppelia
Site Admin
Posts: 10378
Joined: 14 Dec 2012, 00:25

Re: How to speed up simulation?

Post by coppelia »

Hello,

yes, the best option in that regard is to disabled rendering during simulation by setting sim.boolparam_display_enabled to false. Everything elase will run in the same fashion, except that there will be no rendering. With sim.intparam_speedmodifier you can obtain something similar, by skipping some rendering frames.

If you now want to further increase speed, you'll have to look at where you bottleneck is: what, in a given simulation step takes most CPU time? Once you have identified that, you can e.g. execute that operation less frequently, i.e. not in every simulation step. As an example, if vision sensors take too much time, then instead of handling them in each simulation step (i.e. generating a new frame in each simulation step), you can set them to explicit handling and handle them in your child script every n simulation step.

You can of course also select a different simulation loop time step (default is 50ms), e.g. at 100ms. While doing this, keep in mind that the physics engine time step will still remain the same (by default 5ms), which is important, otherwise that would mess-up physics fidelity.

Cheers

zven fang
Posts: 2
Joined: 22 Apr 2024, 08:16

Re: How to speed up simulation?

Post by zven fang »

Hello,

Thanks for your answering.
If we disable rendering during simulation, would the vision_sensor still work as before?
And talk about explicit handling, could you please suggest some approach? I'm currently using ZMQ and sim.getVisionSensorCharImage each timestep to read the vision_sensor and then do some image processing during the timestep.

Best Regards,
coppelia wrote: 05 Sep 2022, 13:46 Hello,

yes, the best option in that regard is to disabled rendering during simulation by setting sim.boolparam_display_enabled to false. Everything elase will run in the same fashion, except that there will be no rendering. With sim.intparam_speedmodifier you can obtain something similar, by skipping some rendering frames.

If you now want to further increase speed, you'll have to look at where you bottleneck is: what, in a given simulation step takes most CPU time? Once you have identified that, you can e.g. execute that operation less frequently, i.e. not in every simulation step. As an example, if vision sensors take too much time, then instead of handling them in each simulation step (i.e. generating a new frame in each simulation step), you can set them to explicit handling and handle them in your child script every n simulation step.

You can of course also select a different simulation loop time step (default is 50ms), e.g. at 100ms. While doing this, keep in mind that the physics engine time step will still remain the same (by default 5ms), which is important, otherwise that would mess-up physics fidelity.

Cheers

zven fang
Posts: 2
Joined: 22 Apr 2024, 08:16

Re: How to speed up simulation?

Post by zven fang »

I tried

client = RemoteAPIClient()
self.sim = client.require('sim')
self.sim.setStepping(True)
self.sim.startSimulation()
elf.sim.setBoolParam(self.sim.boolparam_display_enabled,False)

and find the UI in coppeliaSim to be black. Is it normal? Many thanks to you.


coppelia wrote: 05 Sep 2022, 13:46 Hello,

yes, the best option in that regard is to disabled rendering during simulation by setting sim.boolparam_display_enabled to false. Everything elase will run in the same fashion, except that there will be no rendering. With sim.intparam_speedmodifier you can obtain something similar, by skipping some rendering frames.

If you now want to further increase speed, you'll have to look at where you bottleneck is: what, in a given simulation step takes most CPU time? Once you have identified that, you can e.g. execute that operation less frequently, i.e. not in every simulation step. As an example, if vision sensors take too much time, then instead of handling them in each simulation step (i.e. generating a new frame in each simulation step), you can set them to explicit handling and handle them in your child script every n simulation step.

You can of course also select a different simulation loop time step (default is 50ms), e.g. at 100ms. While doing this, keep in mind that the physics engine time step will still remain the same (by default 5ms), which is important, otherwise that would mess-up physics fidelity.

Cheers

coppelia
Site Admin
Posts: 10378
Joined: 14 Dec 2012, 00:25

Re: How to speed up simulation?

Post by coppelia »

Hello,

yes, it is normal that the display is black, since you disabled rendering with:

Code: Select all

sim.setBoolParam(sim.boolparam_display_enabled, False)
Disabling rendering will not disable vision sensors that will still be able to function normally. Instead of sim.getVisionSensorCharImage, use sim.getVisionSensorImg. But even if you do not fetch the image, the vision sensor will render it (and spend time) in each simulation step. To avoid this, set the vision sensor to explicit handling (aux. set also Ignore depth info (faster) to false), then handle the vision sensor at the frequency you want, e.g.:

Code: Select all

--lua

sim=require'sim'

function sysCall_init() 
    sensor = sim.getObject('.')
    updateEveryXSimulationPass = 10
    pass=0
end

function sysCall_sensing() 
    pass = pass + 1
    if pass >= updateEveryXSimulationPass then
        sim.handleVisionSensor(sensor)
        pass=0
    end
end 
Cheers

Post Reply