feat: add store_first_last solver kwarg for memory-light long experiments#5499
Merged
rtimms merged 6 commits intoMay 11, 2026
Merged
Conversation
…ents When set, the solver only stores the first and last sample of each integration window — one experiment step in `Simulation.solve`, or the full `[t_eval[0], t_eval[-1]]` window in a plain `solve` call. Composes with `output_variables` for ageing simulations whose post-processing only reads per-step first/last values. Has effect on solvers that support intra-solve interpolation (`IDAKLUSolver`); other solvers warn and no-op. With this flag set, intra-step interpolation falls back to linear across the whole step, so it is not appropriate when post-processing queries an intra-step time. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- Extract `_store_first_last_endpoints` and use it from both `solve()` and `process_t_interp()` so the endpoint array is constructed in one place. - Gate the no-op warning on a per-instance flag so it fires once per non-IDAKLU solver instance instead of once per `step()` call. - Drop a couple of narrating comments restating the next line. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5499 +/- ##
==========================================
- Coverage 98.17% 98.16% -0.01%
==========================================
Files 338 338
Lines 31222 31245 +23
==========================================
+ Hits 30651 30673 +22
- Misses 571 572 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
BradyPlanden
requested changes
May 11, 2026
Member
BradyPlanden
left a comment
There was a problem hiding this comment.
This is looking good, just a few comments on docs / alignment.
- Drop defensive getattr in BaseStep._setup_timestepping; expose store_first_last on test duck-typed solvers (DummySolver, SolverWithoutInterp) so the attribute is guaranteed on all solver-likes, matching t_eval / t_interp. - Reword store_first_last docstrings in BaseSolver and IDAKLUSolver to drop the ambiguous "Composes with output_variables" phrasing. - Append a section to the 06-output-variables notebook demonstrating store_first_last + output_variables together. - Drop the explanatory comment block above _store_first_last_endpoints in BaseSolver.solve. - Trim docstring on _build_simple_dae_model. - Tighten end-of-step reference-solve tolerance to solver precision (both runs stop at the same t_eval points). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
BradyPlanden
approved these changes
May 11, 2026
Member
BradyPlanden
left a comment
There was a problem hiding this comment.
Nice one! The notebook results are great 🚀
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.
Summary
store_first_last: bool = Falsekwarg toBaseSolver(forwarded throughIDAKLUSolver,CasadiSolver,ScipySolver,JaxSolver).True, only the first and last sample of each integration window are stored: one experiment step inSimulation.solve, or the full[t_eval[0], t_eval[-1]]window in plainBaseSolver.solve.output_variablesfor memory-light long ageing experiments whose post-processing only reads per-step first/last values (e.g. metrics built on per-cycle/per-stepFirst/Lastaggregators).IDAKLUSolver); other solvers warn once per instance and no-op.The flag is intended for the case where post-processing only needs first/last state. With this flag set, intra-step interpolation falls back to linear across the whole step (IDAKLU's Hermite checkpoints are auto-disabled by the existing
t_interpnon-empty path), so it is not appropriate when post-processing queries an intra-step time (e.g. aRelativeTime-style sample).Implementation notes
BaseSolver._store_first_last_endpoints, called from bothsolve()(collapsest_evalso IDAKLU stops only at endpoints) andprocess_t_interp()(setst_interpto the same endpoints).BaseStep._setup_timesteppingshort-circuits tot_interp = [0, tf]when the flag is set, overriding any per-stepperiodand any caller-providedt_interp.Serialise.serialise_solverautomatically (reflected from the__init__signature).Test plan
solver.solve(model, t_eval=...)returns 2 stored samples on IDAKLU.periodand callert_interpare overridden when the flag is on.output_variablescomposes (variables-only × endpoints-only).to_config()/from_config()round-trips for IDAKLU and Casadi.🤖 Generated with Claude Code