Refine line search convergence criteria.

The line search now requires a negative cost (improvement) in addition to a small derivative to declare convergence, preventing premature termination when no actual improvement has been made.

Follows the proposal in github.com/google-deepmind/mujoco_warp/pull/1471

PiperOrigin-RevId: 941579503
Change-Id: I8fcd20f7b959e50d77cd5d6de0a3c6d95f86b9e1
This commit is contained in:
Yuval Tassa
2026-07-02 02:55:47 -07:00
committed by Copybara-Service
parent fb259a5edd
commit f8462a156d
+2 -2
View File
@@ -1855,7 +1855,7 @@ static mjtNum PrimalSearch(mjPrimalContext* ctx, mjtNum tolerance, mjtNum ls_ite
PrimalEval(ctx, &p1);
// check for initial convergence
if (mju_abs(p1.deriv[0]) < gtol) {
if (mju_abs(p1.deriv[0]) < gtol && (p1.alpha == 0 || p1.cost < 0)) {
if (p1.alpha == 0) {
ctx->LSresult = 2; // no improvement, initial convergence
} else {
@@ -1916,7 +1916,7 @@ static mjtNum PrimalSearch(mjPrimalContext* ctx, mjtNum tolerance, mjtNum ls_ite
PrimalEval(ctx, &p1);
// check for convergence
if (mju_abs(p1.deriv[0]) < gtol) {
if (mju_abs(p1.deriv[0]) < gtol && p1.cost < 0) {
ctx->LSslope = mju_abs(p1.deriv[0])*slopescl;
*improvement = -p1.cost;
return p1.alpha; // SUCCESS