-
-
Notifications
You must be signed in to change notification settings - Fork 38
Fixing SDE algorithms (EM and SIEA) for Metal #380
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
Fixing SDE algorithms (EM and SIEA) for Metal #380
Conversation
| _saveat = get(prob.kwargs, :saveat, nothing) | ||
|
|
||
| saveat = _saveat === nothing ? saveat : _saveat |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be retained
| # no need for n; just advance until t reaches t1 | ||
| # tolerance avoids off-by-one from fp error | ||
| tol = eps(Tt) * abs(t1) + Tt(1e-7) * dt | ||
| while t + dt <= t1 + tol | ||
| uprev = u | ||
| u = uprev + f(uprev, p, t) * dt + sqdt * g(uprev, p, t) .* randn(typeof(u0)) | ||
| t += dt | ||
| end | ||
| if saveat === nothing && !save_everystep | ||
| @inbounds us[2] = u | ||
| @inbounds ts[2] = t |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| # no need for n; just advance until t reaches t1 | |
| # tolerance avoids off-by-one from fp error | |
| tol = eps(Tt) * abs(t1) + Tt(1e-7) * dt | |
| while t + dt <= t1 + tol | |
| uprev = u | |
| u = uprev + f(uprev, p, t) * dt + sqdt * g(uprev, p, t) .* randn(typeof(u0)) | |
| t += dt | |
| end | |
| if saveat === nothing && !save_everystep | |
| @inbounds us[2] = u | |
| @inbounds ts[2] = t | |
| while t <= t1 + tol | |
| uprev = u | |
| u = uprev + f(uprev, p, t) * dt + sqdt * g(uprev, p, t) .* randn(typeof(u0)) | |
| t += dt | |
| end | |
| if saveat === nothing && !save_everystep | |
| @inbounds us[2] = u | |
| @inbounds ts[2] = t |
Needs to stop one step earlier otherwise the final point will be saved twice
| elseif saveat !== nothing | ||
| while cur_t <= length(saveat) && saveat[cur_t] <= t | ||
| savet = saveat[cur_t] | ||
| Θ = (savet - (t - dt)) / dt | ||
| # Linear Interpolation | ||
| @inbounds us[cur_t] = uprev + (u - uprev) * Θ | ||
| @inbounds ts[cur_t] = savet | ||
| cur_t += 1 | ||
| end | ||
| else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't right, the linear interpolation code is needed. The else branch doesn't actually support saveat or use it
modified: src/ensemblegpukernel/perform_step/gpu_siea_perform_step.jl
|
I rewrote the fix to change as little as possible compared to before. |
|
The last step isn't correct with this because of accumulation error, for example 0.1+0.10.1 != 0.3 because it is larger. So the last step should at least be corrected to match the tspan[2] |
|
#383 is a more correct way here |
Add any other context about the problem here.
With the suggested code changes the algorithms run using Metal (when saveat is not specified).
Code was generated with the help of AI. Given that I am no expert, code could require review.