Skip to content

Conversation

@jfeist
Copy link
Contributor

@jfeist jfeist commented Dec 19, 2025

The interpolation for GPUVern7 and GPUVern9 used the current time t after the last timestep as the "reference" time to evaluate the function, but should use the previous time tprev (so that the function is evaluated within the interval [tprev,t]). This gave wrong interpolated values when using saveat for any time-dependent ODE. A very simple example (simply solving $u'(t) = p t$, i.e., $u(t) = p t^2/2$):

using OrdinaryDiffEqCore
using DiffEqGPU
using DiffEqGPU: vectorized_asolve, make_prob_compatible
using StaticArrays
using JLArrays

f(u, p, t) = SA[p * t] 
ode_prob(p, tmax) = ODEProblem{false}(f, SA[0.0], (0.0, tmax), p)

t = 0:0.1:20
ps = 0:0.1:1.
sq_ana = ps' .* t.^2 ./ 2

probs = ode_prob.(ps, t[end])
jlprobs = JLArray(make_prob_compatible.(probs))

for alg in (GPUTsit5, GPUVern7, GPUVern9)
    ts, us = vectorized_asolve(jlprobs, probs[1], alg(); saveat=t, reltol=1e-12, abstol=1e-12)
    sq_num = first.(us)
    println("alg: ", alg, "  err: ", sum(abs2,sq_num .- sq_ana))
end

On master, I get:

alg: GPUTsit5  err: 5.0895151945504214e-23
alg: GPUVern7  err: 76368.43220161786
alg: GPUVern9  err: 42300.10632221898

After the fix, it is

alg: GPUTsit5  err: 5.0895151945504214e-23
alg: GPUVern7  err: 4.705062089752212e-21
alg: GPUVern9  err: 5.6572466674974e-19

@ChrisRackauckas ChrisRackauckas merged commit 7649e4c into SciML:master Dec 19, 2025
8 of 25 checks passed
@ChrisRackauckas
Copy link
Member

Yes thanks!

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