Skip to content

Conversation

@errikos-melissinos
Copy link

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.

Comment on lines 14 to 16
_saveat = get(prob.kwargs, :saveat, nothing)

saveat = _saveat === nothing ? saveat : _saveat
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be retained

Comment on lines 40 to 50
# 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# 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

Comment on lines 59 to 39
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
Copy link
Member

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
@errikos-melissinos
Copy link
Author

I rewrote the fix to change as little as possible compared to before.

@ChrisRackauckas
Copy link
Member

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]

@ChrisRackauckas
Copy link
Member

#383 is a more correct way here

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.

2 participants