How to speed up PyBullet Simulation?

Post Reply
aled96
Posts: 5
Joined: Fri Jan 28, 2022 2:24 pm

How to speed up PyBullet Simulation?

Post by aled96 »

I am new to PyBullet and I am trying to develop a planner in which I have to simulate some actions, so I need to do this as fast as possible.

I am initializing like this:

Code: Select all

self.useRealTimeSimulation = 0
self.time_step = 0.0001
     
if use_gui:
     pybullet.connect(pybullet.GUI)
else:
     pybullet.connect(pybullet.DIRECT)
            
            
pybullet.setGravity(0, 0, -9.81)
pybullet.setTimeStep(self.time_step)
pybullet.setRealTimeSimulation(self.useRealTimeSimulation)
pybullet.setPhysicsEngineParameter(numSubSteps=0)
Then I control an arm to reach a position and hit small box, using setJointMotorControl2.

Finally I have this:

Code: Select all

for i in range(self.steps):
      pybullet.stepSimulation()
The overall test needs more or less 3 seconds to be execute, but since this has to be run several amount of times, how can I make it much faster?

Thank you !
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: How to speed up PyBullet Simulation?

Post by drleviathan »

This forum is mostly about the Bullet C++ libraries. You might consider asking this question in the pybullet section of these forums.

That said... here are some easy ideas from someone who doesn't know much about the python API:

(1) your time_step = 0.0001 seems kinda small. Perhaps you can get by with a longer substep?

(2) Run the multiple tries on multiple threads.

(3) Throw more and better hardware at the problem.

(4) Implement your logic in C++.
aled96
Posts: 5
Joined: Fri Jan 28, 2022 2:24 pm

Re: How to speed up PyBullet Simulation?

Post by aled96 »

Thank you for the answer. Sorry for the wrong section used.

I will try to use Bullet C++, I saw that it should be more optimized and so faster. Also the multiple threads will help a lot.

For what concerns the point 1, I do not know exactly how to proceed because if I change step or substeps the simulation becomes a mess generally..

I tried to increase the step and select a substep of 5 or 10 but the results were very different.
Post Reply