-
-
Notifications
You must be signed in to change notification settings - Fork 553
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fast Hermite interpolation and observables #4464
Fast Hermite interpolation and observables #4464
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop #4464 +/- ##
===========================================
- Coverage 99.46% 99.41% -0.05%
===========================================
Files 293 293
Lines 22332 22554 +222
===========================================
+ Hits 22212 22423 +211
- Misses 120 131 +11 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty minor changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great stuff, thanks @MarcBerliner! I like the refactor of processed variable into subclasses. A few minor points below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From my side it looks good, but lets wait for @martinjrobins to approve of the changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
happy with this, thanks @MarcBerliner
* fast observables * fix release and types * good * faster interp * `double` -> `realtype` * clean separation * good again * private members * cleanup * fix codecov, tests * naming * codecov * codacy, cse/expand * fix `try/except` * Update CHANGELOG.md * address comments * initialize `save_hermite` * fix codecov --------- Co-authored-by: Eric G. Kratz <[email protected]>
Description
This PR adds Hermite interpolation to the
IDAKLUSolver
, which gives more accurate post-solve interpolation accuracy and improves performance by moving code from Python to C++. The high-frequency example below is 25x faster.For simulations that save the adaptive time stepping states
y
, the new solver optionhermite_interpolation
uses the time derivativesyp
to obtain a more accurate interpolator. Previously, our post-solve interpolation involved:v
for the given raw datasol.all_ts
andsol.all_ys
(likev_raw = sol[v].data
)v_raw
onto new time pointst_new
(likenp.interp1d(t_new, sol.t, v_raw)
)This was problematic because linear interpolation does not always provide an accurate solution (like in the example picture above). With the new Hermite interpolation, the two steps are combined into a single step that uses the state derivatives:
y_new
matrix by interpolatingsol.all_ys
ontot_new
accurately usingsol.all_yps
, then observev
at thet_new
andy_new
values. The Hermite interpolation API is justsol[v](t)
sol[v].data
to access thev_raw
data points at thesol.t
pointsThese changes are most visible with very large datasets. Here are the new timings to get an accurate version of the
SPM
witht_new = np.linspace(t0, tf, 1000000)
:t_interp
(old, Python): 10.6 sgiving a 25x speedup for this example.
Main changes in the code:
sol["Voltage [V]"].data
orsol["Voltage [V]"](t)
) from Python to C++ProcessedVariable
class and adds subclasses likeProcessedVariable0D
,ProcessedVariable1D
, etc.all_yps
term to theSolution
classwarn
argument from the interpolatorNotes:
y
andyp
values. This means simulations withoutput_variables
ort_interp
values cannot be supported.ProcessedVariable
that will be cleaned up once we move to a standaloneIDAKLU
packageFixes #4419
Type of change
Please add a line in the relevant section of CHANGELOG.md to document the change (include PR #) - note reverse order of PR #s. If necessary, also add to the list of breaking changes.
Key checklist:
$ pre-commit run
(or$ nox -s pre-commit
) (see CONTRIBUTING.md for how to set this up to run automatically when committing locally, in just two lines of code)$ python run-tests.py --all
(or$ nox -s tests
)$ python run-tests.py --doctest
(or$ nox -s doctests
)You can run integration tests, unit tests, and doctests together at once, using
$ python run-tests.py --quick
(or$ nox -s quick
).Further checks: