Skip to content

Radau5ODE: complete models whose callbacks fail at trial points (CVode-like recovery policy) - #138

Open
hubertus65 wants to merge 3 commits into
modelon-community:masterfrom
hubertus65:radau5-rhs-failure-policy
Open

hubertus65 wants to merge 3 commits into
modelon-community:masterfrom
hubertus65:radau5-rhs-failure-policy

Conversation

@hubertus65

Copy link
Copy Markdown

Problem

Radau5ODE gives up with Radau5Error: ... flag -8 ... Repeated unexpected step rejections on models whose rhs (or Jacobian) callback returns a recoverable error at trial points — typically thermofluid models whose property functions (IAPWS-IF97 steam tables) are evaluated outside their region at the stage points during the first milliseconds. CVode completes the same models. Two reasons in radau5.c:

  1. the failure counter was per call to radau5_solve, so the retries of the whole simulation were budgeted together (10), not the consecutive failures of one step;
  2. on each recoverable failure the step was halved and the budget was 10, i.e. the step could shrink by at most 1024× before the solver gave up. CVode quarters the step on a recoverable rhs failure (ETACF = 0.25).

Change (two commits, cherry-pickable)

  • 145c026 counter per consecutive run of failures (reset on the next successful step), not per call.
  • ace4515 step factor 0.25 (named constant RADAU_CALLBACK_FAILURE_STEP_FACTOR) and budget 40 (RADAU_MAX_CONSECUTIVE_CALLBACK_FAILURES). Both only take effect on the recoverable-failure path; every other model is bit-for-bit unchanged.
  • 92af965 CHANGELOG.

Measured (PyFMI, OCT FMUs, rtol 1e-6, compared with rtol 1e-8 references)

model before after
226-state absorption plant (57 indicators) fails at t = 5e-4 s completes, 1783 steps, same results
318-state combined-cycle plant (414 indicators, 30 000 s) fails at t = 0.5–4 ms completes: 1422 steps, 557 Jacobians, 322 s; plant states max 6.7e-4 / median 5.8e-6 off the reference — the most accurate run of any solver on this model (CVode at the same rtol: 3.1e-3)
MSL examples (clutches, friction, rectifier, Cauer, bouncing ball), vehicle model identical counts and results

The plant run uses a finite-difference Jacobian; with the FMU's directional derivatives the DD evaluation itself fails inside the FMU in the same region (an FMU-side issue, unrelated to this change).

Tests: pytest tests/ 330 passed, 5 skipped (Python 3.11, conda-forge SUNDIALS/SuperLU_MT).

Review notes

  • The changed constants only take effect on the recoverable-failure path; every other model is
    bit-for-bit unchanged.
  • Independent of my other branches. My TRBDF2 branch carries these three commits because it uses
    the same policy.

🤖 Generated with Claude Code

https://claude.ai/code/session_01PyrxGeWuwCmAH9LishMW6p

hubertus65 and others added 3 commits September 17, 2026 19:13
…not per call

radau5.c counted "unexpected" (recoverable) callback failures in `nunexpect`,
reset only at the start of a radau5 call, and aborted with
RADAU_ERROR_REP_STEP_REJECT ("Repeated unexpected step rejections") once the
total reached 10. For an FMU whose rhs rejects trial points regularly
(e.g. IF97 steam-table region errors on a 318-state power-plant model, or
Modelica.Fluid pipe models), that budget is exhausted within the first
millisecond even though every individual failure is recoverable by halving
the step; CVode handles the same model by shrinking the step each time.

Reset the counter on every accepted step so the limit applies to
consecutive failures only, matching the error message. No other behaviour
changes; tests/ still 330 passed, 5 skipped.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…ter step, budget 40)

When the model rejects a trial point (a recoverable error from the rhs or the
Jacobian callback), Radau5 halved the step and gave up after 10 consecutive
failures, i.e. after reducing the step by 1024x. CVode quarters the step on a
recoverable rhs failure. On a 318-state combined-cycle plant whose steam-table
functions fail in a region the stage points step into during the first
milliseconds, Radau5 died at t = 0.5-4 ms ("Repeated unexpected step
rejections") in every configuration, while CVode passes.

This makes the factor 0.25 and the budget 40 consecutive failures (both as
named constants). With it, and a finite-difference Jacobian that does not
call the FMU's directional derivatives in that region, Radau5ODE completes
the plant: 1422 steps, 557 Jacobians, 322 s, and the most accurate plant
trajectory of any solver measured against an rtol 1e-8 reference (max
6.7e-4 over 308 plant states, none beyond 1e-3; CVode at the same rtol
3.1e-3). Every other reference model is bit-for-bit unchanged (the path is
only taken on recoverable failures); the Assimulo test suite passes (330).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PyrxGeWuwCmAH9LishMW6p
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PyrxGeWuwCmAH9LishMW6p
@hubertus65
hubertus65 marked this pull request as ready for review September 22, 2026 21:47
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.

1 participant