Repository navigation
Fix symbolic save_idxs skipping translation when selecting all state variables - #1460
Conversation
…variables `SavedSubsystem` returns `nothing` for a save-everything request, and the `get_save_idxs_and_saved_subsystem` generic method misread that `nothing` as "no translation needed", returning the raw symbolic `save_idxs` unchanged. Raw `Symbol`/`Num` then leaked into the integer indexing path, failing with `ArgumentError: unable to check bounds for indices of type Symbol` (or a `TypeError` for `Num`) whenever the selection named all state variables, including permutations like `[:z, :y, :x]`. Translate symbolic `save_idxs` to integer state indexes in the `nothing` branch, preserving the requested order (so permutations reorder correctly) and scalarizing symbolic arrays. Non-symbolic `save_idxs` pass through untouched, and observed/non-state expressions are still rejected. Fixes SciML#1454 Co-Authored-By: Chris Rackauckas <[email protected]>
Post-merge verification (master CI triage, 2026-07-23)Status: MERGED ( Code review of the fixRoot cause confirmed: The fix introduces
Adjacent all-vars paths checked
No remaining silent skip of symbolic→int translation when CI notePR CI had some Downstream/Integration reds that match unrelated master failures (ODE InterfaceIII resize verbosity, Catalyst |
Since SciML#1460, `translate_symbolic_save_idxs` copies every non-symbolic index array into a `Vector{Int}`, so static indices like `SOneTo(4)` lose their type and an out-of-place `SVector` solve saves each point as a heap-allocated `Vector`.
This PR should be ignored until reviewed by @ChrisRackauckas.
Fixes #1454.
Problem
Symbolic
save_idxssilently skipped index translation when the selection named all state variables, leaking rawSymbol/Numinto the integer indexing path.With a 3-variable MTK Lotka-Volterra system:
save_idxs[:x, :z](subset)[1, 3][:x, :y, :z](ALL)ArgumentError: unable to check bounds for indices of type Symbol[:z, :y, :x](ALL, permuted)Reproduced with
Vector{Symbol}andVector{Num}(the latter:TypeError: non-boolean (Num) used in boolean context).Root cause
SavedSubsystemdeliberately returnsnothingfor a save-everything request (its docstring: "returnsnothingwhen no metadata is needed, including ... requests that save all state variables"). Theget_save_idxs_and_saved_subsystemgeneric method'sif saved_subsystem !== nothingguard misread thatnothingas "no translation needed" and returned the raw symbolicsave_idxsunchanged.Fix
In the
saved_subsystem === nothingbranch, translate symbolicsave_idxsto integer state indexes viavariable_index, preserving the requested order (so permutations like[:z, :y, :x]reorder correctly rather than collapsing to a sorted/identity shortcut) and scalarizing symbolic arrays. Non-symbolicsave_idxs(integers,Colon) pass through untouched; observed / non-state expressions are still rejected bySavedSubsystemas before.Verification (run locally, Julia 1.11)
save_idxs = [:x, :y, :z]and[:z, :y, :x](and theirNumequivalents) now succeed, and the saved solution matches a full solve in the requested order:Subset, single-symbol, integer, permuted-integer, and
nothingcases all still work;[x + y](non-state expression) still errors.Tests
Added a regression test to
test/downstream/solution_interface.jlin the "Saved subsystem" testset covering: symbolic all-vars (natural + permuted),Numall-vars, theget_save_idxs_and_saved_subsystemtranslation output, subset/single/integer regressions, and non-state rejection.Full
solution_interface.jl(Solution Indexing) suite passes locally: 260 passed, 0 failed, 0 errored.