Skip to content

1614 Extend RKIntegratorCore with fixed-step Runge-Kutta methods and optional stage recording - #1615

Open
HenrZu wants to merge 5 commits into
mainfrom
1614-Extend-RKIntegratorCore
Open

HenrZu wants to merge 5 commits into
mainfrom
1614-Extend-RKIntegratorCore

Conversation

@HenrZu

@HenrZu HenrZu commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Changes and Information

Please briefly list the changes (main added features, changed items, or corrected bugs) made:

  • Added a fixed-step mode and predefined methods (Euler, midpoint, Kutta 3, classical RK4) to RKIntegratorCore
  • Added optional recording of the RK stage values of (accepted) steps (set_stage_recording)
  • Renamed adapt_rk.h/.cpp -> runge_kutta.h/.cpp

If need be, add additional information and what the reviewer should look out for in particular:

Merge Request - Guideline Checklist

Please check our git workflow. Use the draft feature if the Pull Request is not yet ready to review.

Checks by code author

  • Every addressed issue is linked (use the "Closes #ISSUE" keyword below).
  • New code adheres to coding guidelines.
  • No large data files have been added (files should in sum not exceed 100 KB, avoid PDFs, Word docs, etc.).
  • Tests are added for new functionality and a local test run was successful (with and without OpenMP).
  • Appropriate documentation within the code (Doxygen) for new functionality has been added in the code.
  • Appropriate external documentation (ReadTheDocs) for new functionality has been added to the online documentation and checked in the preview.
  • Proper attention to licenses, especially no new third-party software with conflicting license has been added.
  • (For ABM development) Checked benchmark results and ran and posted a local test above from before and after development to ensure performance is monitored.

Checks by code reviewer(s)

  • Corresponding issue(s) is/are linked and addressed.
  • Code is clean of development artifacts (no deactivated or commented code lines, no debugging printouts, etc.).
  • Appropriate unit tests have been added, CI passes, code coverage and performance is acceptable (did not decrease).
  • No large data files added in the whole history of commits(files should in sum not exceed 100 KB, avoid PDFs, Word docs, etc.).
  • On merge, add 2-5 lines with the changes (main added features, changed items, or corrected bugs) to the merge-commit-message. This can be taken from the briefly-list-the-changes above (best case) or the separate commit messages (worst case).

@HenrZu HenrZu linked an issue Dec 2, 2026 that may be closed by this pull request
2 tasks done
@codecov

codecov Bot commented Dec 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.54902% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.52%. Comparing base (760ec38) to head (4609580).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
cpp/memilio/math/runge_kutta.h 97.54% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1615      +/-   ##
==========================================
- Coverage   97.52%   97.52%   -0.01%     
==========================================
  Files         190      190              
  Lines       16104    16219     +115     
==========================================
+ Hits        15705    15817     +112     
- Misses        399      402       +3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@HenrZu
HenrZu requested a review from reneSchm December 2, 2026 12:20

@reneSchm reneSchm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A nice addition, though I'd like to discuss some changes.

// compute first column of kt, i.e. kt_0 for each y in yt_eval
f(m_yt_eval, t, m_kt_values.col(0));
if (m_record_stages) {
m_stage_values.col(0) = m_yt_eval;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it wouldn't be better to add a step to m_stage_history, and write into its columns directly, similar to how we (sometimes) use TimeSeries.
Should avoid one copy of the matrix, though still allocates the same space, probably.

m_yt_eval = yt;

if (!m_tab_final.is_adaptive()) {
compute_stages(f, t, dt, ytp1);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Step calculation should happen after the step size asserts and checks (522-529)

Comment on lines +330 to +346
/// @brief Runge-Kutta matrix a of the method (S x S).
const Eigen::MatrixX<FP>& get_a() const
{
return m_a;
}

/// @brief Weights b of the propagated solution.
const Eigen::VectorX<FP>& get_b() const
{
return m_b;
}

/// @brief Nodes c of the method.
const Eigen::VectorX<FP>& get_c() const
{
return m_c;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a, b, c are awful names, and the documentation gives little information either. Can you either give proper descriptive names to the variables, or give context on each function, i.e., butcher tableau for non-adaptive method with

c A
0 b^T

Comment on lines +240 to +241
void set_tableaus(const Tableau<FP>& tab, const TableauFinal<FP>& final_tab)
{

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point, maybe refactor Tableau/TableauFinal to a single Tableau class containing entries in this form ([[c A][0 b^T]]) already?
The integration only uses Eigen operations on the high/low entries, the main tableau (A) is used element-wise. So the changes there should be minimal.

This would also make the get_a etc redundant, as the Tableau can provide them. I think you don't need to store the Tableau in this class, anyways.

It also avoids the "use with Tableau::xxx" comments. One possible source of errors less.


m_yt_eval = yt;

if (!m_tab_final.is_adaptive()) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!m_tab_final.is_adaptive()) {
// step calculation for direct methods
if (!m_tab_final.is_adaptive()) {

Comment on lines +468 to +486
/// @brief Remove all steps from the stage history.
void reset_stage_history()
{
m_stage_history.set_tableaus(m_tab, m_tab_final);
}

/**
* @brief Access the stage values of the recorded steps.
* @{
*/
const RungeKuttaStageHistory<FP>& get_stage_history() const
{
return m_stage_history;
}
RungeKuttaStageHistory<FP>& get_stage_history()
{
return m_stage_history;
}
/** @} */

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we usually pass the IntegratorCore's as unique_ptr, I am not sure that this is interface is usable (without dynamic casting a IntegratorCore*). Maybe ask for an (optional?) shared_ptr<RungeKuttaStageHistory> in the constructor instead?

This branch has not been deployed

No deployments
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.

Extend RKIntegratorCore with fixed-step Runge-Kutta methods and optional stage recording

2 participants