-
-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
abstol and or reltol work differently with ForwardDiff vs FiniteDiff #57
Comments
@avik-pal could this be due to the new termination conditions? |
That is not entirely surprising to me. The tolerances for time-stepping specified via SteadyStateDiffEq.jl/src/algorithms.jl Line 47 in 063e958
|
The abstol and reltol are inside DynamicSS, not attached to solve. Moving them outside of DynamicSS into solve makes the termination much worse, as expected. But these are definitely inside DynamicSS and affecting termination. |
Corrected in edit: xxx[Okay, I think the root issues are the aggressive time step growth and the reltol = 1e-6 is too large. The delta t is growing fast and the residuals are bouncing around. Setting dtmax in solve and lowering reltol to say 1e-10 leads to a well-behaved algorithm for both the FiniteDiff and ForwardDiff gradient. Nope, this only worked because I had changed p_guess to [10.0,3.0]. With the original p_guess, it terminates too quickly with reltol=1e-10. As Avik mentioned, the time stepping can be affected by the abstol and reltol to solve, so this might be better than dtmax:
Here, unfortunately, the solver must run to t=1e6 to get good results and avoid early termination consistently, or hit these very low values of reltol and abstol within DynamicSS. |
Is this fixed with the new termination conditions? https://docs.sciml.ai/NonlinearSolve/stable/basics/TerminationCondition/ |
It appears to be exactly the same, but I'm only 99% sure of my implementation of TerminationCondition:
|
Using very small values for abstol and reltol (1e-14) with DynamicSS on a SteadyStateProblem, FiniteDiff solves out to t = 70,000, while ForwardDiff stops at t = 228. The true gradient is [0.0, -296.29629633013286], and FiniteDiff gets that with [-2.6518679901607456e-7, -296.2962963356087], while ForwardDiff is [0.0015469937539040605, -296.29629629628164], good but not great. The gradients are calculated at the bottom of the code with FiniteDiff.finite_difference_gradient and ForwardDiff.gradient
Are the tolerances actually being met with ForwardDiff? Is there a maxiter in the termination conditions in DiffEqBase that is getting hit? Reducing the tolerances to 1e-16 crashes FiniteDiff but ForwardDiff improves to [1.2214211430632144e-5, -296.2962962962962] and goes to t = 1219.
While DynamicSS is not needed on this MWE, it very often is the best choice.
The text was updated successfully, but these errors were encountered: