Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisRackauckas authored Jun 21, 2023
2 parents 85879b4 + 7411f46 commit 7cd0267
Show file tree
Hide file tree
Showing 14 changed files with 72 additions and 38 deletions.
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -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"
6 changes: 3 additions & 3 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
4 changes: 2 additions & 2 deletions .github/workflows/Documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
6 changes: 3 additions & 3 deletions .github/workflows/Downstream.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion .github/workflows/FormatCheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
#
Expand Down
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "DiffEqNoiseProcess"
uuid = "77a26b50-5914-5dd7-bc55-306e6241c503"
authors = ["Chris Rackauckas <[email protected]>"]
version = "5.16.0"
version = "5.17.1"

[deps]
DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"
Expand All @@ -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]
Expand All @@ -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]
Expand Down
20 changes: 10 additions & 10 deletions ext/DiffEqNoiseProcessReverseDiffExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
end
2 changes: 1 addition & 1 deletion src/DiffEqNoiseProcess.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions src/noise_interfaces/common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,4 @@ function Base.reverse(W::AbstractNoiseProcess)
end
return backwardnoise
end
Base.reverse(W::VirtualBrownianTree) = W
4 changes: 2 additions & 2 deletions src/noise_interfaces/virtual_brownian_tree_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/ornstein_uhlenbeck.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

#=
Expand Down Expand Up @@ -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"""
Expand Down
16 changes: 7 additions & 9 deletions src/wiener.jl
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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))
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ using Test
include("reinit_test.jl")
include("BWT_test.jl")
include("pcn_test.jl")
include("savestep_test.jl")
end
27 changes: 27 additions & 0 deletions test/savestep_test.jl
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 7cd0267

Please sign in to comment.