Problem generating NoiseProcess following example in docs

Hey!

I’ve been trying to follow the example in DiffEqNoiseProcess.jl on how to create a NoiseProcess generating gaussian white noise. The code is basically

using DiffEqNoiseProcess
  @inline function WHITE_NOISE_DIST(W, dt, rng)
      if typeof(W.dW) <: AbstractArray && !(typeof(W.dW) <: SArray)
          return @fastmath sqrt(abs(dt)) * wiener_randn(rng, W.dW)
      else
          return @fastmath sqrt(abs(dt)) * wiener_randn(rng, typeof(W.dW))
      end
  end

function WHITE_NOISE_BRIDGE(W, W0, Wh, q, h, rng)
    if typeof(W.dW) <: AbstractArray
        return @fastmath sqrt((1 - q) * q * abs(h)) * wiener_randn(rng, W.dW) + q * Wh
    else
        return @fastmath sqrt((1 - q) * q * abs(h)) * wiener_randn(rng, typeof(W.dW)) +
                         q * Wh
    end
end

W = NoiseProcess(0.0, 0.0, nothing, WHITE_NOISE_DIST, WHITE_NOISE_BRIDGE)

and I get the error:

ERROR: All methods for the model function `f` had too few arguments. For example,
an ODEProblem `f` must define either `f(u,p,t)` or `f(du,u,p,t)`. This error
can be thrown if you define an ODE model for example as `f(u,t)`. The parameters
`p` are not optional in the definition of `f`! For more information on the required
number of arguments for the function you were defining, consult the documentation
for the `SciMLProblem` or `SciMLFunction` type that was being constructed.

For example, here is the no parameter Lorenz equation. The two valid versions
are out of place:

...

Offending function: f
Methods:
# 1 method for generic function "WHITE_NOISE_DIST" from Main:
 [1] WHITE_NOISE_DIST(W, dt, rng)
     @ REPL[2]:1

Stacktrace:
 [1] isinplace(f::Function, inplace_param_number::Int64, fname::String, iip_preferred::Bool; has_two_dispatches::Bool, isoptimization::Bool)
   @ SciMLBase ~/.julia/packages/SciMLBase/s9wrq/src/utils.jl:267
 [2] isinplace
   @ ~/.julia/packages/SciMLBase/s9wrq/src/utils.jl:240 [inlined]
 [3] isinplace(f::Function, inplace_param_number::Int64)
   @ SciMLBase ~/.julia/packages/SciMLBase/s9wrq/src/utils.jl:240
 [4] NoiseProcess(t0::Float64, W0::Float64, Z0::Nothing, dist::Function, bridge::Function; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ DiffEqNoiseProcess ~/.julia/dev/DiffEqNoiseProcess/src/types.jl:299
 [5] NoiseProcess(t0::Float64, W0::Float64, Z0::Nothing, dist::Function, bridge::Function)
   @ DiffEqNoiseProcess ~/.julia/dev/DiffEqNoiseProcess/src/types.jl:298
 [6] top-level scope
   @ REPL[4]:1

My package is at version DiffEqNoiseProcess v5.18.0.

Could someone please help me figure out what is the problem here? Am I missing something? Is there a version mismatch somehow?

Thanks a lot!

Those functions don’t have the right number of arguments, as stated in the error. For example, here’s the code in the package itself:

@inline function WHITE_NOISE_DIST(dW, W, dt, u, p, t, rng)
    if typeof(dW) <: AbstractArray && !(typeof(dW) <: StaticArraysCore.SArray)
        return @fastmath sqrt(abs(dt)) * wiener_randn(rng, dW)
    else
        return @fastmath sqrt(abs(dt)) * wiener_randn(rng, typeof(dW))
    end
end

function WHITE_NOISE_BRIDGE(dW, W, W0, Wh, q, h, u, p, t, rng)
    if typeof(dW) <: AbstractArray
        return @fastmath sqrt((1 - q) * q * abs(h)) * wiener_randn(rng, dW) + q * Wh
    else
        return @fastmath sqrt((1 - q) * q * abs(h)) * wiener_randn(rng, typeof(dW)) + q * Wh
    end
end
1 Like

Awesome, that does it! Maybe the docs need to be updated then?

Yes, I think I just noted somewhere else that these docs needed an update. They are in the old style that doesn’t run the code on PRs, and so they are getting old… I or someone else need to take a pass over them sometime soon.

1 Like