Skip to content
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

generalize reset to work with NoiseFunction #494

Merged
merged 5 commits into from
Aug 24, 2022

Conversation

rmsrosa
Copy link
Contributor

@rmsrosa rmsrosa commented Aug 17, 2022

This changes the way reset is done for a new solve in a way to accommodate noises of type NoiseFunction.

It checks for W.curt != t instead of W.t[end] != t, so it works for the usual noises, which do have the field t and for which W.curt is the same as W.t[end], and for NoiseFunctions, which do not have the field t.

To be fully functional, this depends on implementing a proper dispatch of reinit! to NoiseFunction in SciML/DiffEqNoiseProcesses.jl, as proposed in the PR SciML/DiffEqNoiseProcess.jl#114.

This should close #493.

With these things implemented, we get the proper behavior (c.f. #493):

using StochasticDiffEq, DiffEqNoiseProcess

f(u, p, t, Y) = Y * u

y(a, p, t) = -t
Y = NoiseFunction(0.0, y, reset=true)

u0 = 1.0
tspan = (0.0, 1.0)

prob = RODEProblem(f, u0, tspan, noise=Y)
julia> sol = solve(prob, RandomEM(), dt=1/100)
retcode: Success
Interpolation: 1st order linear
t: 101-element Vector{Float64}:
 0.0
 
 1.0
u: 101-element Vector{Float64}:
 1.0
 
 0.6085659649572785

julia> sol = solve(prob, RandomEM(), dt=1/100)
retcode: Success
Interpolation: 1st order linear
t: 101-element Vector{Float64}:
 0.0
 
 1.0
u: 101-element Vector{Float64}:
 1.0
 
 0.6024803053077056

julia> Y.curt
1.0

And preserving the behavior for "regular" noises

julia> prob = RODEProblem(f, u0, tspan, noise=W)

RODEProblem with uType Float64 and tType Float64. In-place: false
timespan: (0.0, 1.0)
u0: 1.0

julia> sol = solve(prob, RandomEM(), dt=1/100);

julia> sol = solve(prob, RandomEM(), dt=1/100);

julia> W.curt
1.0

@ChrisRackauckas
Copy link
Member

ChrisRackauckas commented Aug 18, 2022

@ChrisRackauckas
Copy link
Member

@frankschae can you track down the regression in the weak adaptive GPU? I think it's a KernelAbstractions.jl Rational support bug, so @vchuravy might need an MWE.

But this looks fine to merge.

@ChrisRackauckas
Copy link
Member

This needs a test which would catch it.

@rmsrosa
Copy link
Contributor Author

rmsrosa commented Aug 20, 2022

Yeah, a test is good. Just added some.

@ChrisRackauckas ChrisRackauckas merged commit ee5d071 into SciML:master Aug 24, 2022
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.

NoiseFunction not resetting for new solves
2 participants