Repository navigation
Add IDAKLU upsampling_factor for scalar output resolution - #5998
Open
MarcBerliner wants to merge 6 commits into
Open
MarcBerliner wants to merge 6 commits into
MarcBerliner wants to merge 6 commits into
Conversation
Inside each accepted step, bisect and save extra points until the cubic Hermite interpolant of a scalar output (built from its value and analytic time derivative) matches the integrator's interpolant to solver_tol / (factor - 1). Points are only added. Works with or without stored Hermite data, with output_variables and with sensitivities. Experiment steps choose the output (voltage, or current for voltage steps) via hermite_upsampling_variable, carried on the built model as hermite_upsampling_variables; algebraic states are skipped.
Prototype: check the midpoint against linear interpolation between step ends instead of the cubic Hermite, and skip the analytic time derivative.
Check each step midpoint against linear interpolation of the upsampled variables' values, so the function needs only (t, y, p): no analytic time derivative and no yp interpolation. Rename hermite_upsampling_* to upsampling_* (option, function, step and model attributes).
The upsampled variable is now one scalar (model.upsampling_variable), passed to C++ as the function from process(). Midpoints interpolate into y_cache so the step-end state in yy needs no copy or restore, and the redundant t_val > t_prev guard is dropped.
MarcBerliner
marked this pull request as ready for review
October 28, 2026 18:15
Contributor
|
| Project | PyBaMM |
| Branch | claude/linear-upsampling-experiment |
| Testbed | bare-metal |
🐰 View full continuous benchmarking report in Bencher
⚠️ WARNING: Truncated view!The full continuous benchmarking report exceeds the maximum length allowed on this platform.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5998 +/- ##
=======================================
Coverage 98.23% 98.23%
=======================================
Files 350 350
Lines 36104 36127 +23
=======================================
+ Hits 35468 35491 +23
Misses 636 636 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch has not been deployed
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.
Description
Adds the
IDAKLUSolveroptionupsampling_factor. When it is above 1.0, the solver saves extra points inside each accepted step until linear interpolation of one scalar output matches the integrator's own interpolant totol / (factor - 1), wheretol = atol + rtol·|v|. So1is off,2is about the solver tolerance, and larger values add more points. Points are only ever added.How it works (inline, in the C++ step loop)
process()codegen, the same path asoutput_variables, and passed to the solver group asupsampling_fcn(t, y, p).t_valis evaluated once from the state already loaded and reused as the next step's start. The value at the step midpoint comes fromIDAGetDky, written intoy_cache. If|(v_a + v_b)/2 − v_m|misses the budget, the step is bisected and each midpoint is saved through the normalSavePoint.output_variables, and with sensitivities. Sensitivities at added points are IDA's own interpolated values.upsampling_variable:"Voltage [V]"by default,"Current [A]"for voltage steps. It is attached to the built model at build time. The unified model keeps the voltage default.hermite_reduction_factor > 1, and inactive whent_interpis given.SPMe (Chen2020) benchmarks, fastest of 15 warm solves:
Max linear-interpolation error of V between saved points, relative to the solver tolerance, on the 1C discharge: 350 (off), 13 (1.1), 2.5 (2), 0.42 (5), 0.08 (21).
A cubic Hermite version that also used the analytic
dV/dtwas explored first (5e86f72e4) and replaced. It needed fewer points for the same error, but cost about twice as much per solve at loose budgets.create_casadi_solver_groupgains a requiredupsampling_fcnargument, so this needs the matching pybammsolvers build.Type of change
## Features.Important checks:
pre-commit runon changed filespackages/pybamm/tests/unit/test_solvers,test_experimentsandtest_simulation.py(932 passed); the pybammsolvers tests (70 passed)nox -s doctests(not run)TestUpsamplingintest_idaklu_solver.py, andtest_upsampling_variableintest_base_step.py