Physic engines are not deterministic.

Requests or suggestions for new features
Post Reply
Alper
Posts: 6
Joined: 29 Jul 2024, 13:49

Physic engines are not deterministic.

Post by Alper »

I set different the torque limit values in ASTI's leg joints and count the steps it can walk. As long as I start over the simulation it falls at the same step. But when I save and close the scene and reopen it falls at a different step, whereas the torque limit did not change. I tried out all the physic engines. They are all showing non-deterministic behavior. Is there any way to make them work more deterministically?

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

Re: Physic engines are not deterministic.

Post by coppelia »

Hello,

what version/revision of CoppeliaSim are you running?
Some engines use non-deterministic algorithms on purpose (e.g. randomly shuffling constraints so as to not prioritize one over another), but what you are describing goes into the direction that a scene information is not properly serialized (e.g. there could be some precision loss that happens during the save/load process).

If you load the saved scene, run the simulation, and repeat that n times (load + run), do you also notice this non-deterministic behaviour?

Cheers

Alper
Posts: 6
Joined: 29 Jul 2024, 13:49

Re: Physic engines are not deterministic.

Post by Alper »

I am running Coppeliasim Edu version 4.9.0 (rev. 6).
I followed your instruction which is repeating load+run and also again noticed non-deterministic behavior. It can walk until 17. step whereas sometimes it cannot even reach out 5. step with the same torque limit. The results are so far from each other as much as it shouldn't be.

Alper
Posts: 6
Joined: 29 Jul 2024, 13:49

Re: Physic engines are not deterministic.

Post by Alper »

While I was discussing the possible reasons behind this non-deterministic behavior with ChatGPT, the simIK functions drew my attention. Particularly simIK.handleGroup function which moves the ASTI's foottips to the targets. It computes with the iterative numerical methods which requires an initial guess. I think this initial guess is random, and this might be the reason.

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

Re: Physic engines are not deterministic.

Post by coppelia »

The results are so far from each other as much as it shouldn't be
Keep in mind that if two simulation run differ by only a tiny detail at simulation start, then integration errors will accumulate and you can very quickly end up in 2 completely different situations.

The Asti robot doesn't use any randomness. And it runs exactly the same from one simulation run to the other (within a same loaded scene/model)

Cheers

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

Re: Physic engines are not deterministic.

Post by coppelia »

I tested it again on Windows, CoppeliaSim V4.9.rev6: an empty scene running the Asti robot runs exactly the same again and again (tested with Bullet, ODE, Newton and Mujoco).

Easiest to test this is to use the Animation capture add-on, located at [Menu bar > Modules > Tools > Animation capture]: with that, you can easily compare individual simulation runs.

Cheers

Alper
Posts: 6
Joined: 29 Jul 2024, 13:49

Re: Physic engines are not deterministic.

Post by Alper »

I kept trying. The problem is still existing.
Here is what I did:
1) Opened a new scene.
2) Added ASTI into the scene.
3) Opened the dialog screen of right knee joint.
4) Modified the max torque as 53 (which is 100 as default)
5) Ran the simulation with Bullet 2.78 and counted the steps it could walk.
6) Saved it and reloaded again.
7) Ran the simulation again and again without making any change and counted the steps.

Please do the same. I wonder, if you will see the difference.

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

Re: Physic engines are not deterministic.

Post by coppelia »

Using the Mujoco engine, there is no difference in simulation runs, even after saving/loading the scene again. With the other engines, there are very small differences. The small differences will accumulate over time (error compounding) and can give a completely different result. This is very similar to what happens in the real world.
So you should never expect to always get the exact same results, especially if tiny error are anyway compounding (e.g. friction/slipping, etc.)

Cheers

Alper
Posts: 6
Joined: 29 Jul 2024, 13:49

Re: Physic engines are not deterministic.

Post by Alper »

Oh yess. It worked. Thanks. But now I cannot use dummies with overlap constraint. I need them because I gotta construct dynamic loops. How to solve it?

Edit: I tried it also in another scene. It worked. Interesting! I hope it will not happen again.

Edit2: I figured out why dummy linkage did not work. The dummies must be set as child of a primitive shape instead of a compound shape.

Post Reply