num_ode_rk4_adaptive ignores h_min when h_min is at least the integration span, taking steps 400x below it while h_min just under the span errors

Open
#374 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
62/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
r, rust
Domain
backend

Research direction

Start by locating num_ode_rk4_adaptive and reading its step selection and minimum step rejection paths. Reproduce the reported case with h_min equal to the integration span, then compare it with h_min just below the span. Done means the solver enforces the documented minimum step and reports an error when the tolerance requires smaller steps; run the relevant Rust tests.

Written by the indexing model from the issue text.

Description

area/ode-pde good first issue help wanted kind/contract severity/3-major

When h_min is at least the integration span, num_ode_rk4_adaptive silently ignores it and returns hundreds of steps that are all far below h_min, while the same call with h_min just under the span correctly raises the documented step-limit error — so raising h_min turns an error into a success that violates the bound.

suppressWarnings(suppressMessages(library(rssn)))
s <- rssn_session()
rhs <- rssn_callback(function(t, y) -y, s, op = "num_ode_rk4_adaptive", index = 11)
run <- function(hmin, t1) {
  r <- tryCatch(call_value("num_ode_rk4_adaptive", 0, t1, list(1), 1e-12, 1e-12,
                           0.1, hmin, 10, 1e6, 1e6, rhs, session = s),
                error = function(e) "ERROR")
  if (identical(r, "ERROR")) return(sprintf("t1=%-4g h_min=%-5g ERROR", t1, hmin))
  tt <- sapply(value_json(r)$record$fields[[1]][[2]]$tensor$data, function(z) z$float)
  sprintf("t1=%-4g h_min=%-5g ok  nsteps=%d  min_h=%.4g  steps_below_h_min=%d",
          t1, hmin, length(tt) - 1, min(diff(tt)), sum(diff(tt) < hmin))
}
for (a in list(c(0.9, 1), c(1, 1), c(1.9, 2), c(2, 2), c(2, 0.5))) cat(run(a[1], a[2]), "\n")
t1=1    h_min=0.9   ERROR
t1=1    h_min=1     ok  nsteps=394  min_h=0.001589  steps_below_h_min=394
t1=2    h_min=1.9   ERROR
t1=2    h_min=2     ok  nsteps=722  min_h=0.00237   steps_below_h_min=722
t1=0.5  h_min=2     ok  nsteps=206  min_h=7.5e-05   steps_below_h_min=206

y' = -y on [0, 1] at atol = rtol = 1e-12 needs steps of about 0.002, so a minimum step of 1 is unsatisfiable and the docstring says exactly what should happen: "an error for ... a tolerance requiring a smaller step than h_min". With h_min = 0.9 that error is raised; with h_min = 1 — equal to the span — every one of the 394 accepted steps is below h_min by a factor of 400 and no error is reported. The answer is still numerically right (y(1) = 0.367879441171), so the defect is that h_min stops being enforced rather than that the solution is wrong; a caller who uses h_min to bound the work per interval, or to detect an unsatisfiable tolerance, is given a green light instead.

The trigger is h_min >= t1 - t0 (confirmed at spans 0.5, 1 and 2, and independent of h_max, which was 10 here and 1/2/4 in a second run): that case appears to take a "finish the interval in one step" path which skips the min-step rejection, but the solver then subdivides normally instead of taking the single step.

rssn 0.3.0, R 4.6.2 binding, Windows x86_64.

Dominant language
Rust
Stars
36
Forks
3
Avg merge
14h 51m
Merged PRs (30d)
29

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Apich-Organization/rssn

All issues in Apich-Organization/rssn

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.