How to get deterministic results?

Zeal
Posts: 47
Joined: Thu Oct 18, 2007 6:49 am

How to get deterministic results?

Post by Zeal »

Ive used Opal (a abstract wrapper for ODE) for about a year, but the project has since died, so I decided to make a switch. Bullet seems to be the most active opensource library out there, so I thought I would give it a try. I just had a quick question before I dove in...

After running the demos, it is clear that Bullet is NOT deterministic. Is there a way to change this? I really need my simulations to run the same everytime they are 'reset'.

Thanks!
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: How to get deterministic results?

Post by Erwin Coumans »

Zeal wrote:After running the demos, it is clear that Bullet is NOT deterministic. Is there a way to change this? I really need my simulations to run the same everytime they are 'reset'.
Please check the AllBulletDemo combined demo in (release candidate of) Bullet 2.64, and press the 'R' key for reset. This re-creates all objects and dynamics world, and should be deterministic.

The space key in the demos doesn't reset the entire state, which causes non-determinism. This should be fixed, but it is just a demo issue.

Thanks,
Erwin
Frederic-Felix
Posts: 5
Joined: Tue Feb 05, 2008 8:01 am

Re: How to get deterministic results?

Post by Frederic-Felix »

Hey Guys,

i fiddled around with bullet and try to do some proper 'reset the scene' action in my application.
So far the pseudo-code is as follows:

Code: Select all

for each body
{
  set linear/angular velocity to (0, 0, 0)
  reset the forces (btRigidBody::resetForces())

  create new transform: trans
  btMotionState *state = body->getMotionState();
  state->setWorldTransform( trans );
  body->setMotionState( state );
}
That's it, but still doesn't work for me. What am i missing out? Sometimes it works quite well, but sometimes the objects seem to be reset to the previous positions...My assumption is that there are some interpolated transforms sticking around or even worse, some contacts still active. Anyone any hints?

Thanks in advance,
Frédéric-Felix
RobW
Posts: 33
Joined: Fri Feb 01, 2008 9:44 am

Re: How to get deterministic results?

Post by RobW »

A few things I came across in the same situation, and some other thoughts;

It definitely won't be deterministic if you run a non-fixed timestep, due to floating point precision.
The randomised contraint ordering seed needs to be reset when you reset the scene, or just turn off the randomisation (might degrade solver convergence though).
You should probably remove all objects from the world, and add them all back, to ensure no persistent manifolds survive.
If you're applying forces/impulses etc from your application, that must also run at a fixed timestep or you will get the same problem of floating point precision.

Hope this helps,
Rob
Frederic-Felix
Posts: 5
Joined: Tue Feb 05, 2008 8:01 am

Re: How to get deterministic results?

Post by Frederic-Felix »

Thanks a lot for the input.

Unfortuneatly i get an exception when i try to remove the rigid bodies.

Code: Select all

void	btMultiSapBroadphase::destroyProxy(btBroadphaseProxy* proxy,btDispatcher* dispatcher)
{
	///not yet
	btAssert(0);

}
I switched to bt32BitAxisSweep3 and i works very well. Still....it didn't resolve the issue.
I never heard "randomised contraint ordering seed" so how do i reset it?
I am sorry, i am very new to bullet, so bear with me...

Thanks,
Frédéric
RobW
Posts: 33
Joined: Fri Feb 01, 2008 9:44 am

Re: How to get deterministic results?

Post by RobW »

No problem.

Constraints are solved in a random order to try to get better convergence by eliminating a bias due to the ordering. If you don't reset this when you reset the scene, you'll get slightly different results when the constraints are solved which will soon compound into tangible differences to the first time you ran the simulation.

The seed is btSequentialImpulseConstraintSolver::m_btSeed2, which is a protected member. As a simple measure, you could derive a new class from btSequentialImpulseConstraintSolver, and add a method to reset the seed. I'm a couple of versions out of date, but I don't think there is currently a method exposed to set it.

Cheers,
Rob
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: How to get deterministic results?

Post by Erwin Coumans »

RobW wrote:The seed is btSequentialImpulseConstraintSolver::m_btSeed2, which is a protected member. As a simple measure, you could derive a new class from btSequentialImpulseConstraintSolver, and add a method to reset the seed. I'm a couple of versions out of date, but I don't think there is currently a method exposed to set it.
Yes there is, the btSequentialImpulseConstraintSolver::reset method sets the m_btSeed2 to zero:

Code: Select all

	///clear internal cached data and reset random seed
	virtual	void	reset();
Hope this helps,
Erwin