Skip to content

Ignore derivatives of parameters that do not depend on internal parameters - #742

Open
janosg wants to merge 1 commit into
mainfrom
ignore-derivatives-of-fixed-params
Open

janosg wants to merge 1 commit into
mainfrom
ignore-derivatives-of-fixed-params

Conversation

@janosg

@janosg janosg commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

A user provided derivative that is infinite or NaN for a fixed parameter made the optimization fail, even though that entry cannot influence the optimization. This was found while discussing this review comment by @hmgaudecker on #727 (point 2), which assumed that such entries are ignored.

Cause. With constraints, the external derivative is multiplied with the Jacobian of the reparametrization. The rows of that Jacobian that belong to fixed parameters are zero, but nan * 0 and inf * 0 are nan, so one non-finite entry made the complete internal derivative nan.

Fix. The converter now determines once which external parameters depend on at least one internal parameter, and sets the derivative entries of all other parameters to zero before the multiplication. This covers fixed parameters and parameters that are equal to a fixed parameter. The dependence is determined from the structure of the reparametrization, not from Jacobian values. All parameters of a transforming constraint count as dependent, so non-finite entries there still raise.

Behavior changes

  1. Non-finite derivatives of fixed parameters are ignored. Before, minimize and maximize raised a UserFunctionRuntimeError at the first derivative evaluation. Non-finite entries for all other parameters raise as before.

Relation to #727

The start params check in #727 uses the same conversion, so it also ignores these entries once this PR is merged. The test requested there (nan in the derivative of a fixed parameter does not raise) needs this PR first.

🤖 Generated with Claude Code

…eters

Infinite or NaN entries in a user provided derivative with respect to fixed
parameters spread to the complete internal derivative, because they were
multiplied with the zero rows of the reparametrization Jacobian. These
entries are now set to zero before the multiplication.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.71795% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/optimagic/parameters/space_conversion.py 90.00% 1 Missing ⚠️
Files with missing lines Coverage Δ
...imagic/optimization/test_invalid_jacobian_value.py 100.00% <100.00%> (ø)
...ests/optimagic/parameters/test_space_conversion.py 100.00% <100.00%> (ø)
src/optimagic/parameters/space_conversion.py 96.94% <90.00%> (-0.58%) ⬇️

... and 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
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