diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..700707c --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,7 @@ +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" # Location of package manifests + schedule: + interval: "weekly" diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 45aab7b..febd1ce 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -17,11 +17,11 @@ jobs: - '1' - '1.6' steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: julia-actions/setup-julia@v1 with: version: ${{ matrix.version }} - - uses: actions/cache@v1 + - uses: actions/cache@v3 env: cache-name: cache-artifacts with: @@ -36,6 +36,6 @@ jobs: - uses: julia-actions/julia-processcoverage@v1 with: directories: src, ext - - uses: codecov/codecov-action@v1 + - uses: codecov/codecov-action@v3 with: file: lcov.info diff --git a/.github/workflows/Documentation.yml b/.github/workflows/Documentation.yml index f64a315..fe3c958 100644 --- a/.github/workflows/Documentation.yml +++ b/.github/workflows/Documentation.yml @@ -12,7 +12,7 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: julia-actions/setup-julia@latest with: version: '1' @@ -24,6 +24,6 @@ jobs: DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} # For authentication with SSH deploy key run: julia --project=docs/ --code-coverage=user docs/make.jl - uses: julia-actions/julia-processcoverage@v1 - - uses: codecov/codecov-action@v1 + - uses: codecov/codecov-action@v3 with: file: lcov.info diff --git a/.github/workflows/Downstream.yml b/.github/workflows/Downstream.yml index 1c99921..320250c 100644 --- a/.github/workflows/Downstream.yml +++ b/.github/workflows/Downstream.yml @@ -23,14 +23,14 @@ jobs: - {user: SciML, repo: SciMLSensitivity.jl, group: SDE2} - {user: SciML, repo: SciMLSensitivity.jl, group: SDE3} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: julia-actions/setup-julia@v1 with: version: ${{ matrix.julia-version }} arch: x64 - uses: julia-actions/julia-buildpkg@latest - name: Clone Downstream - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: repository: ${{ matrix.package.user }}/${{ matrix.package.repo }} path: downstream @@ -52,6 +52,6 @@ jobs: exit(0) # Exit immediately, as a success end - uses: julia-actions/julia-processcoverage@v1 - - uses: codecov/codecov-action@v1 + - uses: codecov/codecov-action@v3 with: file: lcov.info diff --git a/.github/workflows/FormatCheck.yml b/.github/workflows/FormatCheck.yml index 2a3517a..f80d0b1 100644 --- a/.github/workflows/FormatCheck.yml +++ b/.github/workflows/FormatCheck.yml @@ -21,7 +21,7 @@ jobs: with: version: ${{ matrix.julia-version }} - - uses: actions/checkout@v1 + - uses: actions/checkout@v3 - name: Install JuliaFormatter and format # This will use the latest version by default but you can set the version like so: # diff --git a/Project.toml b/Project.toml index 314febc..a2da1ee 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "DiffEqNoiseProcess" uuid = "77a26b50-5914-5dd7-bc55-306e6241c503" authors = ["Chris Rackauckas "] -version = "5.16.0" +version = "5.17.1" [deps] DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e" @@ -20,7 +20,7 @@ RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd" Requires = "ae029012-a4dd-5104-9daa-d747884805df" ResettableStacks = "ae5879a3-cd67-5da8-be7f-38c6eb64a37b" SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462" -StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" +StaticArraysCore = "1e83bf80-4336-4d27-bf5d-d5a4f845583c" Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" [weakdeps] @@ -43,7 +43,7 @@ RecursiveArrayTools = "2" ResettableStacks = "0.6, 1.0" Requires = "1" SciMLBase = "1" -StaticArrays = "0.10, 0.11, 0.12, 1.0" +StaticArraysCore = "1.4" julia = "1.6" [extras] diff --git a/ext/DiffEqNoiseProcessReverseDiffExt.jl b/ext/DiffEqNoiseProcessReverseDiffExt.jl index b2e7343..556f768 100644 --- a/ext/DiffEqNoiseProcessReverseDiffExt.jl +++ b/ext/DiffEqNoiseProcessReverseDiffExt.jl @@ -4,19 +4,19 @@ using DiffEqNoiseProcess, DiffEqBase, Random isdefined(Base, :get_extension) ? (import ReverseDiff) : (import ..ReverseDiff) @inline function DiffEqNoiseProcess.wiener_randn(rng::Random.AbstractRNG, - proto::ReverseDiff.TrackedArray) -ReverseDiff.track(convert.(eltype(proto.value), randn(rng, size(proto)))) + proto::ReverseDiff.TrackedArray) + ReverseDiff.track(convert.(eltype(proto.value), randn(rng, size(proto)))) end @inline function DiffEqNoiseProcess.wiener_randn!(rng::AbstractRNG, - rand_vec::Array{<:ReverseDiff.TrackedReal - }) -rand_vec .= ReverseDiff.track.(randn.((rng,), typeof.(DiffEqBase.value.(rand_vec)))) + rand_vec::Array{<:ReverseDiff.TrackedReal + }) + rand_vec .= ReverseDiff.track.(randn.((rng,), typeof.(DiffEqBase.value.(rand_vec)))) end @inline function DiffEqNoiseProcess.wiener_randn!(rng::AbstractRNG, - rand_vec::AbstractArray{ - <:ReverseDiff.TrackedReal - }) -rand_vec .= ReverseDiff.track.(randn.((rng,), typeof.(DiffEqBase.value.(rand_vec)))) + rand_vec::AbstractArray{ + <:ReverseDiff.TrackedReal + }) + rand_vec .= ReverseDiff.track.(randn.((rng,), typeof.(DiffEqBase.value.(rand_vec)))) end -end \ No newline at end of file +end diff --git a/src/DiffEqNoiseProcess.jl b/src/DiffEqNoiseProcess.jl index 85e6c0b..eb8d059 100644 --- a/src/DiffEqNoiseProcess.jl +++ b/src/DiffEqNoiseProcess.jl @@ -1,7 +1,7 @@ module DiffEqNoiseProcess using ResettableStacks, DiffEqBase, RecipesBase -using RecursiveArrayTools, StaticArrays, Random, Statistics +using RecursiveArrayTools, StaticArraysCore, Random, Statistics using LinearAlgebra import RandomNumbers: Xorshifts diff --git a/src/noise_interfaces/common.jl b/src/noise_interfaces/common.jl index cb866dc..b59c3a4 100644 --- a/src/noise_interfaces/common.jl +++ b/src/noise_interfaces/common.jl @@ -226,3 +226,4 @@ function Base.reverse(W::AbstractNoiseProcess) end return backwardnoise end +Base.reverse(W::VirtualBrownianTree) = W diff --git a/src/noise_interfaces/virtual_brownian_tree_interface.jl b/src/noise_interfaces/virtual_brownian_tree_interface.jl index 03b08d5..4356808 100644 --- a/src/noise_interfaces/virtual_brownian_tree_interface.jl +++ b/src/noise_interfaces/virtual_brownian_tree_interface.jl @@ -152,9 +152,9 @@ end function split_VBT_seed(rng::Random123.AbstractR123, parent_seed, current_depth, Nt) # seed left - seed_l = convert(typeof(parent_seed), parent_seed - (Nt - 1) / 2^(current_depth + 1)) + seed_l = convert(typeof(parent_seed), parent_seed - (Nt - 1) ÷ 2^(current_depth + 1)) # seed right - seed_r = convert(typeof(parent_seed), parent_seed + (Nt - 1) / 2^(current_depth + 1)) + seed_r = convert(typeof(parent_seed), parent_seed + (Nt - 1) ÷ 2^(current_depth + 1)) RandomNumbers.Random123.set_counter!(rng, parent_seed) return seed_l, seed_r, parent_seed diff --git a/src/ornstein_uhlenbeck.jl b/src/ornstein_uhlenbeck.jl index 41a50d9..02d0322 100644 --- a/src/ornstein_uhlenbeck.jl +++ b/src/ornstein_uhlenbeck.jl @@ -10,9 +10,9 @@ function (X::OrnsteinUhlenbeck)(dW, W, dt, u, p, t, rng) #dist else rand_val = wiener_randn(rng, typeof(dW)) end - drift = X.μ .+ (W[end] .- X.μ) .* exp.(-X.Θ * dt) + drift = X.μ .+ (W.curW .- X.μ) .* exp.(-X.Θ * dt) diffusion = X.σ .* sqrt.((1 .- exp.(-2X.Θ * dt)) ./ (2X.Θ)) - drift .+ rand_val .* diffusion .- W[end] + drift .+ rand_val .* diffusion .- W.curW end #= @@ -59,8 +59,8 @@ end function (X::OrnsteinUhlenbeck!)(rand_vec, W, dt, u, p, t, rng) #dist! wiener_randn!(rng, rand_vec) - @.. rand_vec = X.μ + (W[end] - X.μ) * exp(-X.Θ * dt) + - rand_vec * X.σ * sqrt((1 - exp.(-2 * X.Θ .* dt)) / (2 * X.Θ)) - W[end] + @.. rand_vec = X.μ + (W.curW - X.μ) * exp(-X.Θ * dt) + + rand_vec * X.σ * sqrt((1 - exp.(-2 * X.Θ .* dt)) / (2 * X.Θ)) - W.curW end @doc doc""" diff --git a/src/wiener.jl b/src/wiener.jl index a60dbd2..52200c9 100644 --- a/src/wiener.jl +++ b/src/wiener.jl @@ -1,19 +1,17 @@ const one_over_sqrt2 = 1 / sqrt(2) @inline wiener_randn(rng::AbstractRNG, ::Type{T}) where {T} = randn(rng, T) -@inline function wiener_randn(rng::AbstractRNG, proto::Array{T}) where {T} - randn(rng, size(proto)) + +@inline function wiener_randn(rng::AbstractRNG, proto::AbstractArray{T}) where {T<:Number} + randn(rng, T, size(proto)) end -@inline function wiener_randn(rng::AbstractRNG, proto::T) where {T <: SArray} +@inline function wiener_randn(rng::AbstractRNG, + proto::T) where {T <: StaticArraysCore.SArray} randn(rng, T) end @inline function wiener_randn(rng::AbstractRNG, proto) convert(typeof(proto), randn(rng, size(proto))) end -@inline wiener_randn!(rng::AbstractRNG, rand_vec::Array) = randn!(rng, rand_vec) -@inline function wiener_randn(y::AbstractRNG, ::Type{Complex{T}}) where {T} - convert(T, one_over_sqrt2) * (randn(y, T) + im * randn(y, T)) -end - +@inline wiener_randn!(rng::AbstractRNG, rand_vec::AbstractArray) = randn!(rng, rand_vec) @inline function wiener_randn!(rng::AbstractRNG, rand_vec) rand_vec .= Base.Broadcast.Broadcasted(randn, ()) end @@ -32,7 +30,7 @@ end end @inline function WHITE_NOISE_DIST(dW, W, dt, u, p, t, rng) - if typeof(dW) <: AbstractArray && !(typeof(dW) <: SArray) + 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)) diff --git a/test/runtests.jl b/test/runtests.jl index 8062c92..36daa46 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -28,4 +28,5 @@ using Test include("reinit_test.jl") include("BWT_test.jl") include("pcn_test.jl") + include("savestep_test.jl") end diff --git a/test/savestep_test.jl b/test/savestep_test.jl new file mode 100644 index 0000000..144e416 --- /dev/null +++ b/test/savestep_test.jl @@ -0,0 +1,27 @@ +@testset "save_everystep Keyword" begin + #Test whether the result of the process is dependent on 'save_everystep'. + using DiffEqNoiseProcess, DiffEqBase, Test, Statistics, Random + processes = [ OrnsteinUhlenbeckProcess(1., 1., 0.3, 0., 0., nothing ), + WienerProcess(0.,0.,nothing ), + CorrelatedWienerProcess([1. 0.; 0. 1.],0.,[0.; 0.],nothing ), + GeometricBrownianMotionProcess(1., 1., 0., 0., nothing ) + ] + + + + @testset "Noise_process = $(proc.dist)" for proc in processes + + cproc = deepcopy(proc) + cproc.save_everystep = true + prob = NoiseProblem(cproc, (0.0, 1.0); seed=1234) + sol_save = solve(prob; dt = 0.1) + + + cproc = deepcopy(proc) + cproc.save_everystep = false + prob = NoiseProblem(cproc, (0.0, 1.0); seed=1234) + sol_nosave = solve(prob; dt = 0.1) + + @test sol_save.curW == sol_nosave.curW + end +end \ No newline at end of file