Skip to content

SII indexing for ComponentArray ODE solutions (sol[:x], sol(t; idxs=:x)) - #396

Merged
ChrisRackauckas merged 3 commits into
SciML:mainfrom
ChrisRackauckas-Claude:cr/sii-componentarray-indexing
Jul 24, 2026
Merged

SII indexing for ComponentArray ODE solutions (sol[:x], sol(t; idxs=:x))#396
ChrisRackauckas merged 3 commits into
SciML:mainfrom
ChrisRackauckas-Claude:cr/sii-componentarray-indexing

Conversation

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member

Summary

Implements SymbolicIndexingInterface support for ODE problems whose state is a ComponentArray, so named solution indexing works without a hand-built SymbolCache.

Fixes the ergonomics request in SciML/DifferentialEquations.jl#957 (and follows the design note there from @AayushSabharwal / @ChrisRackauckas: SII overloads rather than getproperty forwarding on DiffEqArray).

Behavior

When u0 isa ComponentArray and the ODEFunction has no symbolic sys:

  • sol[:x], sol(t; idxs=:x), sol(t; idxs=[:x, :y]) use top-level component keys
  • If p isa ComponentArray, sol.ps[:a] works the same way
  • Nested top-level keys (e.g. u.b = (x,y)) remain indexable as sol[:b] (returns the sub-component)

When sys is already set on the function (MTK / manual SymbolCache), that system is left alone.

Implementation

  • Expand ext/ComponentArraysSciMLBaseExt.jl with a small ComponentArrayIndexProvider and symbolic_container(::AbstractODEProblem{<:ComponentArray})
  • Keep existing getsyms plotting labels

Tests

  • Downstream DiffEq tests covering the #957 API, nested components, and non-override of explicit sys
  • Locally verified (17 assertions) with OrdinaryDiffEq v7.1.3 / SciMLBase v3.37.0

Notes

This PR should be ignored until reviewed by @ChrisRackauckas.

Limitations / follow-ups

  • Only AbstractODEProblem for now (SDE/DDE/etc. can reuse the same provider later)
  • Leaf paths like Symbol("b.x") are not registered as separate variables (top-level keys only)
  • Does not change save_idxs ComponentArray behavior (already worked for single labels)

When an AbstractODEProblem has ComponentArray u0 and no symbolic sys is
set on the ODEFunction, expose top-level component keys (and parameter
keys when p is also a ComponentArray) through SII. This makes sol[:x],
sol(t; idxs=:x), sol(t; idxs=[:x,:y]), and sol.ps[:a] work without a
manual SymbolCache, matching the interface discussed on
SciML/DifferentialEquations.jl#957.

Existing getsyms plotting labels are unchanged. Explicit sys on the
ODEFunction is still preferred when present.

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
New #957 indexing tests `using SymbolicIndexingInterface`; it must be a
direct Downstream dep (not only transitive via SciMLBase).

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
@ChrisRackauckas
ChrisRackauckas marked this pull request as ready for review July 24, 2026 06:17
@ChrisRackauckas
ChrisRackauckas merged commit d486e54 into SciML:main Jul 24, 2026
20 checks passed
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.

2 participants