Skip to content

Fix linearize without inputs and name differentiated inputs from the linearization function - #5225

Merged
AayushSabharwal merged 1 commit into
masterfrom
linearize-without-inputs
Sep 29, 2026
Merged

AayushSabharwal merged 1 commit into
masterfrom
linearize-without-inputs

Conversation

@baggepinnen

Copy link
Copy Markdown
Contributor

Split out of #5173.

Summary

Two fixes in linearize:

  • linearize(sys, [], outputs) failed in ForwardDiff with Invalid Tag object, since the Jacobians with respect to the inputs were prepared and evaluated for an empty, Any-typed input vector. The input vector now has the element type of the state, and the input Jacobians are not evaluated when there are no inputs; B and D then have zero columns. The case without unknowns and inputs, which produced an h_xz of the wrong shape, is handled as well.
  • LinearizationFunction stores its input symbols, and the diagnostic for differentiated inputs names them from there. It previously indexed inputs(sys), which is empty when the inputs of a compiled system are parameters that are not marked as inputs, and threw a BoundsError in place of the message.

Tests

The testset "Linearization without inputs" in test/linearize.jl covers both backends and the case without unknowns; it fails on master with the tag error and passes with this change.

🤖 Generated with Claude Code

https://claude.ai/code/session_01QBgBrXDidWG1G2KF64gAte

…e linearization function

`linearize(sys, [], outputs)` failed in ForwardDiff with an invalid tag, since the
Jacobians with respect to the inputs were prepared for an empty, `Any`-typed input
vector. The input vector now has the element type of the state and the input Jacobians
are not evaluated when there are no inputs, so that `B` and `D` have zero columns.
`LinearizationFunction` stores its input symbols, from which the diagnostic for
differentiated inputs takes their names; it previously indexed `inputs(sys)`, which is
empty when the inputs of a compiled system are parameters not marked as inputs.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QBgBrXDidWG1G2KF64gAte
@github-actions

Copy link
Copy Markdown
Contributor

Benchmark Results (Julia vlts)

Time benchmarks
master 796cc48... master / 796cc48...
ODEProblem 4.54 ± 0.57 ms 4.43 ± 0.14 ms 1.02 ± 0.13
init 0.0837 ± 0.027 ms 0.0608 ± 0.027 ms 1.38 ± 0.76
large_parameter_init/ODEProblem 12.7 ± 0.66 ms 12.9 ± 1.5 ms 0.986 ± 0.13
large_parameter_init/init 0.0795 ± 0.023 ms 0.0791 ± 0.025 ms 1 ± 0.43
mtkcompile 7.95 ± 0.37 ms 7.99 ± 0.34 ms 0.995 ± 0.063
sparse_analytical_jacobian/ODEProblem 16 ± 0.69 ms 15.7 ± 1.2 ms 1.02 ± 0.088
sparse_analytical_jacobian/f_iip 0.06 ± 0 μs 0.06 ± 0 μs 1 ± 0
sparse_analytical_jacobian/f_oop 0.309 ± 0.0071 ms 0.308 ± 0.0068 ms 1 ± 0.032
time_to_load 5.59 ± 0.016 s 5.63 ± 0.06 s 0.993 ± 0.011
Memory benchmarks
master 796cc48... master / 796cc48...
ODEProblem 0.0346 M allocs: 1.82 MB 0.0346 M allocs: 1.82 MB 1
init 0.508 k allocs: 0.0846 MB 0.508 k allocs: 0.0846 MB 1
large_parameter_init/ODEProblem 0.147 M allocs: 5.54 MB 0.147 M allocs: 5.54 MB 1
large_parameter_init/init 0.64 k allocs: 0.179 MB 0.64 k allocs: 0.179 MB 1
mtkcompile 0.0594 M allocs: 3.37 MB 0.0594 M allocs: 3.37 MB 1
sparse_analytical_jacobian/ODEProblem 0.106 M allocs: 5.33 MB 0.106 M allocs: 5.33 MB 1
sparse_analytical_jacobian/f_iip 0 allocs: 0 B 0 allocs: 0 B
sparse_analytical_jacobian/f_oop 0.634 k allocs: 19.6 kB 0.634 k allocs: 19.6 kB 1
time_to_load 0.153 k allocs: 14.5 kB 0.153 k allocs: 14.5 kB 1

@github-actions

Copy link
Copy Markdown
Contributor

Benchmark Results (Julia v1)

Time benchmarks
master 796cc48... master / 796cc48...
ODEProblem 5.07 ± 0.078 ms 5.03 ± 0.085 ms 1.01 ± 0.023
init 0.0456 ± 0.0066 ms 0.0448 ± 0.0052 ms 1.02 ± 0.19
large_parameter_init/ODEProblem 13.2 ± 0.6 ms 13.3 ± 0.59 ms 0.995 ± 0.063
large_parameter_init/init 0.0661 ± 0.032 ms 0.0655 ± 0.03 ms 1.01 ± 0.68
mtkcompile 8.48 ± 0.93 ms 8.48 ± 0.86 ms 1 ± 0.15
sparse_analytical_jacobian/ODEProblem 16.6 ± 1.7 ms 16.5 ± 1.7 ms 1.01 ± 0.15
sparse_analytical_jacobian/f_iip 0.07 ± 0.01 μs 0.07 ± 0 μs 1 ± 0.14
sparse_analytical_jacobian/f_oop 0.103 ± 0.013 ms 0.103 ± 0.013 ms 1.01 ± 0.18
time_to_load 5.09 ± 0.024 s 5.09 ± 0.025 s 1 ± 0.0068
Memory benchmarks
master 796cc48... master / 796cc48...
ODEProblem 0.034 M allocs: 1.61 MB 0.034 M allocs: 1.59 MB 1.01
init 0.475 k allocs: 0.0602 MB 0.475 k allocs: 0.0602 MB 1
large_parameter_init/ODEProblem 0.143 M allocs: 4.85 MB 0.143 M allocs: 4.85 MB 1
large_parameter_init/init 0.757 k allocs: 0.166 MB 0.757 k allocs: 0.166 MB 1
mtkcompile 0.0558 M allocs: 2.63 MB 0.0558 M allocs: 2.63 MB 1
sparse_analytical_jacobian/ODEProblem 0.102 M allocs: 4.24 MB 0.102 M allocs: 4.24 MB 1
sparse_analytical_jacobian/f_iip 0 allocs: 0 B 0 allocs: 0 B
sparse_analytical_jacobian/f_oop 0.848 k allocs: 27 kB 0.848 k allocs: 27 kB 1
time_to_load 0.2 k allocs: 11.7 kB 0.2 k allocs: 11.7 kB 1

@AayushSabharwal
AayushSabharwal merged commit 58dc6b0 into master Sep 29, 2026
79 of 86 checks passed
@AayushSabharwal
AayushSabharwal deleted the linearize-without-inputs branch September 29, 2026 14:50
ChrisRackauckas referenced this pull request Sep 29, 2026
build: bump MTKBase, MTK patch versions
@BambOoxX

BambOoxX commented Oct 6, 2026

Copy link
Copy Markdown

It seems this fixes #4886 as well, but I'll let you confirm.

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.

3 participants