Repository navigation
Add analytical parameter jacobian code generation - #5083
Merged
Merged
Conversation
oxinabox
reviewed
Sep 7, 2026
| if sparse | ||
| return sparsejacobian(rhs, ps; simplify) | ||
| else | ||
| return jacobian(rhs, ps; simplify) |
Contributor
There was a problem hiding this comment.
is this really all there is to it?
Member
Author
There was a problem hiding this comment.
Mostly yes: full_equations already inlines observed and torn equations, and check_lhs guarantees every lhs is 0 or D(x), so eq.rhs is the f the solver integrates. Mass matrices are constant, so there is no dM/dp term.
Two things it did miss, both now fixed: a delay parameter got a silently zero column, since Symbolics.jacobian treats x(t - tau) as opaque, so calculate_paramjac throws for DDEs; and the sparse in-place function filled a mismatched buffer in the wrong cells, so it now asserts the pattern like generate_jacobian does.
Member
There was a problem hiding this comment.
yup the symbolic machinery takes care of most of it.
…ace buffer pattern
ChrisRackauckas
added a commit
that referenced
this pull request
Sep 7, 2026
- Add analytical parameter jacobian code generation (#5083) - Document observed access and plotting from a live integrator (#5081) - [bot] Solve implicit affects at the ODE solver's tolerance (#5080) Agent-Harness: Claude Code Agent-Model: claude-opus-5[1m] Claude-Session: https://claude.ai/code/session_014FEzNTLFutCmTEAZ3zBg5R Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
MTK can already generate analytical jacobians with respect to unknowns (
jac = true) and inputs (calculate_control_jacobian), but nothing with respect to parameters. SciMLBase already defines aparamjacfield onODEFunction, so this just populates it.Adds
calculate_paramjacandgenerate_paramjac, modelled on the existing control jacobian, plus aparamjac = falsekeyword onODEFunction.Column
jofpJis the derivative with respect to entryjofSciMLStructures.canonicalize(SciMLStructures.Tunable(), p)[1], which is what SciMLSensitivity consumes.tunable_parametersis not usable as the column basis despite its docstring: it is a metadata filter, so it also returnsInitial(...),::Int,FnTypeand discrete parameters. The columns come fromreorder_parameters(sys, ps; flatten = false)[1], the same callcompleteuses to lay outsys.ps.Notes:
paramjacdefaults tofalse, so nothing changes unless you opt in.sparseworks oncalculate_paramjac/generate_paramjacbut is not forwarded fromODEFunction, since SciMLBase has noparamjac_prototype.n x 0array fails inside SymbolicUtils.Tests cover the column ordering, agreement with central differences, sparse and dense, in place and out of place, time independent and non split systems, and the
ODEFunctionwiring. Adjoint gradients through SciMLSensitivity match ForwardDiff to 3e-11.AI Disclosure: Used Opus 5