RobotLocomotion / drake

Model-based design and verification for robotics.
https://drake.mit.edu
Other
3.27k stars 1.26k forks source link

SAP failure case with Newton line search #21435

Open amcastro-tri opened 4 months ago

amcastro-tri commented 4 months ago

What happened?

@chen-tianjian reported this problem in the Drake developers Slack channel.

In one of their simulations SAP fails with the message:

Failure at multibody/contact_solvers/newton_with_bisection.cc:21 in DoNewtonWithBisectionFallback(): condition 'bracket.inside(x_guess)' failed.

@mshalm analyzed the problem and found out that our initial guess can sometimes be outside the solver's bracket, thus causing the exception.

The solution is to provide a guess inside the bracket. For as long the guess is inside the bracket, the solver should always succeed. Options are:

Related to #19322, it's in the critical path.

amcastro-tri commented 4 months ago

Progress note: As @mshalm pointed out, it is true that we are ussing d²ℓ/dα²(αₘₐₓ) instead of the (correct) d²ℓ/dα²(α=0) to estimate the initial guess of the line search, in this line.

However, at that point we already verified that dℓ/dα(α=0) < 0 and therefore that line (which takes the maximum with αₘₐₓ) effectively computes a guess that is guaranteed to be within the line search bracket [0, αₘₐₓ]. Therefore, unless there is a floiting point exception, the check for the guess to be inside the bracket from within DoNewtonWithBisectionFallback() should always succeed.

My guess is that somehow alpha_guess is becoming nan, which would explain the failure. Now, this does not explain the original cause of the problem, which might be very far from SAP's source.

@chen-tianjian, @mshalm, could you confirm?

chen-tianjian commented 4 months ago

Yes, I checked in initial guess and it is nan