Skip to content

Keep finite-difference residual evaluations within bounds - #3566

Open
yurekami wants to merge 1 commit into
google-deepmind:mainfrom
yurekami:codex/bound-finite-difference-probes
Open

Keep finite-difference residual evaluations within bounds#3566
yurekami wants to merge 1 commit into
google-deepmind:mainfrom
yurekami:codex/bound-finite-difference-probes

Conversation

@yurekami

@yurekami yurekami commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

jacobian_fd chooses an inward finite-difference direction, but its relative step can still cross the opposite bound when the interval is narrow. For example, with bounds [0, 1e-10], the default perturbation from zero evaluates the residual at about 1.49e-8. This can make least_squares fail for residuals defined only inside the supplied bounds.

Clip the actual evaluation points to the box and use their actual displacement as the finite-difference denominator. Step inward explicitly at the upper bound, including when an adjacent-float interval's midpoint rounds to that endpoint. Clipping the points themselves also avoids a rounding excursion across zero that can remain after clipping only the displacement.

The regression tests cover lower/interior/upper points, mixed parameter scales, intervals crossing zero, adjacent floating-point bounds, exact linear Jacobians, and a bounded least-squares solve. Before the fix, the nine new helper subcases and the solver regression fail. After the fix, the full minimizer suite passes: 18 tests and 13 subtests.

Validation used the current checkout's Python module and tests on Windows/Python 3.12 with installed MuJoCo 3.12.0 native bindings; no native code was changed or rebuilt. Reproduce that configuration from the repository root with:

from pathlib import Path
import mujoco
import pytest

mujoco.__path__.insert(0, str(Path('python/mujoco').resolve()))
raise SystemExit(pytest.main(['python/mujoco/minimize_test.py', '-q']))

Pyink checks pass for the changed regions, isort passes with mujoco classified as a third-party extension package, and the applicable pre-commit checks pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant