Repository navigation
Visit the callbacks of save_discretes_if_enabled! without a splatting recursion - #1653
Merged
Merged
Conversation
… 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]>
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.
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 aCallbackSetof different callback types inference widens that keyword-call recursion and leaves a dynamic call; an ahead-of-time compiler (WasmCodegen.jl) rejects theCore.svecit 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, withskip_duplicatesas 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 threwMethodError: symbolic_container(::SymbolCache)atinit, from the callbacks' initial discrete save (test:test/save_discretes_without_timeseries.jl, a unit check of the early return, not a reproducer of theinitfailure).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.jlchecks with AllocCheck thatsave_discretes_if_enabled!over aCallbackSetof aContinuousCallbackand two differentDiscreteCallbacks has no dynamic dispatch, and that the callbacks that should save are visited in order withskip_duplicatesforwarded, for tuple- and vector-held sets.🤖 Generated with Claude Code