Skip to content

Let reinit! keep the step-size controller history - #4400

Merged
ChrisRackauckas merged 2 commits into
SciML:masterfrom
singhharsh1708:fix-pi-reinit
Aug 30, 2026
Merged

ChrisRackauckas merged 2 commits into
SciML:masterfrom
singhharsh1708:fix-pi-reinit

Conversation

@singhharsh1708

@singhharsh1708 singhharsh1708 commented Aug 27, 2026 •

Copy link
Copy Markdown
Member

reinit! gains a reinit_controller = true keyword alongside reinit_dae and friends, so a mid-solve restart can keep the PI controller's converged history; the default is unchanged, set_t! opts out, and DelayDiffEq gets the same keyword. It lives on reinit! rather than reinit_controller! because the latter is public and the documented extension point for algorithm authors, so a keyword there would break downstream methods.

reinit_controller! reseeds errold = qoldinit = 1e-4, right at t0 (Hairer's FACOLD) and wrong mid solve: on the issue's SDIRK2 problem a settled dt of 1.257538e-02 rings at ratios 0.20, 4.90, 0.41, 2.42 afterwards, and opting out reproduces the un-reinit'd sequence to 2.3e-6.

reinit! still sets success_iter = 0, so the step after an opt-out restart is treated as a first step for the growth cap; measured in isolation that is a one-step lag, not the oscillation, and preserving it would also flip SDIRK's first-step predictor branches, so it is left for a separate change.

reinit_test.jl 31/31, disco_tests.jl 28/28, controllers.jl 30/30 with the new testset.

Fixes #4371 for the mid-solve case; the first-step swing is untouched.

AI Disclosure: Claude assisted with this change.

@termi-official

Copy link
Copy Markdown
Contributor

Not sure this actually fixes the root cause. Ofc this fixes the swing after reinit, but the initial swing is still present -- so the current behavior on master is the consistent one for PI.

Given your reinit just sets qold = 1, why should we keep the qoldinit in first (or not simply default it to 1)?

@singhharsh1708 singhharsh1708 changed the title Reset the PI controller to a neutral history on reinit Default the PI controller qoldinit to 1 Aug 27, 2026
@singhharsh1708

singhharsh1708 commented Aug 27, 2026 •

Copy link
Copy Markdown
Member Author

Switched to defaulting qoldinit = 1, which covers both swings; benchmarked 1e-4/1e-2/0.5/1 work-precision normalised at 1.000/0.991/0.960/0.957, details in the description.

@singhharsh1708
singhharsh1708 marked this pull request as draft August 28, 2026 05:45
@singhharsh1708 singhharsh1708 changed the title Default the PI controller qoldinit to 1 Reset the PI controller to a neutral history on reinit Aug 28, 2026
@singhharsh1708

Copy link
Copy Markdown
Member Author

Tried your suggestion and it does not hold up, so I have reverted to the reinit-only change.

Defaulting qoldinit = 1 makes AN5 return a wrong answer:

                        steps   result     error
master (1e-4)           10      1.372800   6.8e-7
qoldinit = 1            28      2.327861   9.6e-1

Exact is 1.3728. More steps and a worse answer, so it is not a speed/accuracy trade. ODEProblemLibrary.prob_ode_linear at reltol = 1e-6, nordsieck_tests.jl catches it.

Across CI it took out 29 lanes that a comparable PR of mine does not touch: StochasticDiffEq, DelayDiffEq, Rosenbrock, Nordsieck, plus six root groups and four downstream packages. The ones I read are accuracy-at-requested-tolerance assertions, e.g. DelayDiffEq l∞ 6.8e-5 < 3.0e-5 and Rosenbrock err_interp 0.0115 < 0.01.

My earlier work-precision table was the wrong metric for this. Normalising to matched accuracy hides the fact that a user asking for 1e-8 gets a larger error, and it never touched a variable-order method, which is where AN5 breaks.

So the initial swing stays for now. Reverting does not fix it, and you are right that it leaves PI asymmetric with PID and Predictive, but the neutral-everywhere version is not safe as it stands.

@termi-official

Copy link
Copy Markdown
Contributor

Defaulting qoldinit = 1 makes AN5 return a wrong answer.

Maybe I am missing something, but if we reinit! at exactly this point in this PR, shouldn't we run into the same problem, as we send the previous error estimate to 1 -- which should surface as the same problem?

@ChrisRackauckas

Copy link
Copy Markdown
Member

Why would qoldinit be 1? This is very odd.

@singhharsh1708 singhharsh1708 changed the title Reset the PI controller to a neutral history on reinit Let reinit! keep the step-size controller history Aug 28, 2026
@singhharsh1708

Copy link
Copy Markdown
Member Author

Both right, and I have replaced that commit. It no longer sets errold to 1 or touches qoldinit at all. It just adds reinit_controller = false to reinit! so a mid-solve restart can keep the history it already has; the default path is unchanged, and qoldinit = 1e-4 stays as the FACOLD seed at t0.

@termi-official yes, exactly that. Sending errold to 1 hits the same problem, which is what reinit_test.jl caught: 7 of 8 trajectory-identity assertions failed, and it also had more sign alternations than master, 6 vs 5. Leaving errold alone instead reproduces the un-reinit'd dt sequence to 2.3e-6.

The initial swing is still there and PI is still asymmetric with PID and Predictive. I did not find a safe way to remove it, so this PR is only the mid-solve half.

@singhharsh1708
singhharsh1708 marked this pull request as ready for review August 28, 2026 14:26
@ChrisRackauckas
ChrisRackauckas merged commit 2943a96 into SciML:master Aug 30, 2026
22 checks passed
@singhharsh1708
singhharsh1708 deleted the fix-pi-reinit branch August 30, 2026 06:39
ChrisRackauckas added a commit that referenced this pull request Sep 7, 2026
- Fix StochasticDiffEqImplicit import ordering (#4408)
- Fix TauLeaping JumpProblem initialization (#4409)
- Fix dense output for the explicit multirate methods (#4233)
- Let reinit! keep the step-size controller history (#4400)
- Mark an operator Jacobian as updated when calc_W! moves it (#4354)
- Restore weighted preconditioning and tolerances for default Krylov solves (#4391)



Agent-Harness: Claude Code
Agent-Model: claude-opus-5[1m]
Claude-Session: https://claude.ai/code/session_014FEzNTLFutCmTEAZ3zBg5R

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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.

reinit_controller! of PIController (errold = qoldinit = 1e-4) causes a period-2 step-size oscillation

3 participants