CVODEBase: enforce mxstep budget on the CV_ONE_STEP path - #34
Merged
Conversation
CVodeSetMaxNumSteps(mxstep) bounds internal steps PER CVode() call. On the CV_NORMAL path a whole interval is one call, so CVODE raises CV_TOO_MUCH_WORK at mxstep and stiff draws fail fast. But the scenario/evolve output loops run CV_ONE_STEP — one internal step per call — so that ceiling is never reached and the loops have NO total-work cap: a stiff / near-singular draw crawls in sub-ULP steps until an external per-sim timeout kills it (minutes of wall time). The earlier 500000 -> 50000 mxstep reduction only ever protected the CV_NORMAL path for this reason. simOdeStepOne now checks getNumSteps() (cumulative steps since the last re-init, i.e. per integration segment — the same unit a CV_NORMAL call spans) and raises CV_TOO_MUCH_WORK once it crosses mxstep, so a bad draw fails in seconds (~18s at mxstep=50000) identical to CV_NORMAL, becoming NaN downstream instead of a multi-minute straggler.
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.
The CV_ONE_STEP scenario loop (simOdeStepOne) had no total-step ceiling — CVodeSetMaxNumSteps(mxstep) only bounds steps per CVode call, which is inert in one-step mode where each call advances exactly one step. A pathologically stiff θ could therefore grind indefinitely between dose boundaries.
This adds an explicit cumulative-step check inside simOdeStepOne: once getNumSteps() exceeds mxstep (50000), it raises CV_TOO_MUCH_WORK, matching the CV_NORMAL path's existing behavior. Valid sims that pass the CV_NORMAL 50k cap also pass this one, so no new failures are introduced — only genuinely non-converging stiff sims are cut.