Skip to content

Visit the callbacks of save_discretes_if_enabled! without a splatting recursion - #1653

Merged
ChrisRackauckas merged 3 commits into
SciML:masterfrom
pankgeorg:save-discretes-no-splat
Oct 30, 2026
Merged

ChrisRackauckas merged 3 commits into
SciML:masterfrom
pankgeorg:save-discretes-no-splat

Conversation

@pankgeorg

@pankgeorg pankgeorg commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

save_discretes_if_enabled!(integrator, ::CallbackSet; kw...) splatted all callbacks into _save_discretes_if_enabled!(integrator, cb, cbs...; kw...), which recursed on the rest with the keywords forwarded. Over a CallbackSet of different callback types inference widens that keyword-call recursion and leaves a dynamic call; an ahead-of-time compiler (WasmCodegen.jl) rejects the Core.svec it builds for the splatted keyword call in a program whose discrete callbacks save (save_positions = (false, true)). The continuous and discrete callback tuples (or vectors) are now visited with one call per element, with skip_duplicates as the only keyword. Order and behaviour are unchanged.

A second commit makes save_discretes!(integ, idx) return before computing values when the solution has no parameter time series (is_parameter_timeseries(integ.sol), decided from the type). Before, a problem whose function has no symbolic system threw MethodError: symbolic_container(::SymbolCache) at init, from the callbacks' initial discrete save (test: test/save_discretes_without_timeseries.jl, a unit check of the early return, not a reproducer of the init failure).

Unblocks: trimming and other ahead-of-time compilation of solves whose callbacks save discrete values, e.g. clocked/sampled-data models.

Test: test/save_discretes_dispatch.jl checks with AllocCheck that save_discretes_if_enabled! over a CallbackSet of a ContinuousCallback and two different DiscreteCallbacks has no dynamic dispatch, and that the callbacks that should save are visited in order with skip_duplicates forwarded, for tuple- and vector-held sets.

🤖 Generated with Claude Code

pankgeorg and others added 3 commits October 25, 2026 00:27
… recursion

`_save_discretes_if_enabled!(integrator, cb, cbs...; kw...)` called itself with the remaining
callbacks splatted into a keyword call. Over a `CallbackSet` of different callback types
inference widens that recursion and leaves a dynamic call, which `juliac --trim=safe`
rejects. The callbacks of a `CallbackSet` (its continuous and discrete tuples, or vectors)
are now visited by one call per element, with `skip_duplicates` as the only keyword. Order
and behaviour are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`save_discretes!(integ, timeseries_idx)` computed the values to save through
`get_saveable_values(get_sol(integ), …)` before `save_discretes!(sol, …)`
checked whether the solution has a parameter time series collection to save
into. For a problem whose function has no symbolic system (an `ODEFunction`
built from a generated right-hand side, as ahead-of-time compiled programs
use), the solution has no collection, and the lookup walks the symbolic
containers down to a `SymbolCache` and throws
`MethodError: no method matching symbolic_container(::SymbolCache…)`
at `init`, from the callbacks' initial discrete save. The check now comes
first; with a collection nothing changes, without one nothing was ever saved.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… save order in the tests

The vector/vector save_discretes_if_enabled! method forwards skip_duplicates
like the tuple one; the varargs wrapper it replaced is removed. The dispatch
test records each saving callback and its skip_duplicates, for tuple- and
vector-held sets, and asserts the sequence.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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