Skip to content

Commit eb57dde

Browse files
Merge pull request #108 from frankschae/formatter
Use SciML format?
2 parents 6c0e216 + b08d099 commit eb57dde

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+4845
-4643
lines changed

.JuliaFormatter.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
style = "sciml"

.github/workflows/FormatCheck.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: format-check
2+
3+
on:
4+
push:
5+
branches:
6+
- 'master'
7+
- 'release-'
8+
tags: '*'
9+
pull_request:
10+
11+
jobs:
12+
build:
13+
runs-on: ${{ matrix.os }}
14+
strategy:
15+
matrix:
16+
julia-version: [1]
17+
julia-arch: [x86]
18+
os: [ubuntu-latest]
19+
steps:
20+
- uses: julia-actions/setup-julia@latest
21+
with:
22+
version: ${{ matrix.julia-version }}
23+
24+
- uses: actions/checkout@v1
25+
- name: Install JuliaFormatter and format
26+
# This will use the latest version by default but you can set the version like so:
27+
#
28+
# julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter", version="0.13.0"))'
29+
run: |
30+
julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter"))'
31+
julia -e 'using JuliaFormatter; format(".", verbose=true)'
32+
- name: Format check
33+
run: |
34+
julia -e '
35+
out = Cmd(`git diff --name-only`) |> read |> String
36+
if out == ""
37+
exit(0)
38+
else
39+
@error "Some files have not been formatted !!!"
40+
write(stdout, out)
41+
exit(1)
42+
end'

docs/make.jl

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,14 @@ using Documenter, DiffEqNoiseProcess
22

33
include("pages.jl")
44

5-
makedocs(
6-
sitename="DiffEqNoiseProcess.jl",
7-
authors="Chris Rackauckas",
8-
modules=[DiffEqNoiseProcess],
9-
clean=true,doctest=false,
10-
format = Documenter.HTML(analytics = "UA-90474609-3",
11-
assets = ["assets/favicon.ico"],
12-
canonical="https://noise.sciml.ai/stable/"),
13-
pages=pages
14-
)
5+
makedocs(sitename = "DiffEqNoiseProcess.jl",
6+
authors = "Chris Rackauckas",
7+
modules = [DiffEqNoiseProcess],
8+
clean = true, doctest = false,
9+
format = Documenter.HTML(analytics = "UA-90474609-3",
10+
assets = ["assets/favicon.ico"],
11+
canonical = "https://noise.sciml.ai/stable/"),
12+
pages = pages)
1513

16-
deploydocs(
17-
repo = "github.com/SciML/DiffEqNoiseProcess.jl.git";
18-
push_preview = true
19-
)
14+
deploydocs(repo = "github.com/SciML/DiffEqNoiseProcess.jl.git";
15+
push_preview = true)

docs/pages.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Put in a separate page so it can be used by SciMLDocs.jl
22

3-
pages=[
3+
pages = [
44
"Home" => "index.md",
55
"noise_processes.md",
6-
"abstract_noise_processes.md"
7-
]
6+
"abstract_noise_processes.md",
7+
]

src/DiffEqNoiseProcess.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import RandomNumbers: Xorshifts
99
import RandomNumbers, Random123
1010

1111
import DiffEqBase: isinplace, solve, AbstractNoiseProcess,
12-
DEIntegrator, AbstractNoiseProblem
12+
DEIntegrator, AbstractNoiseProblem
1313

1414
import PoissonRandom, Distributions
1515

src/bridges.jl

Lines changed: 58 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ BrownianBridge!(t0,tend,W0,Wend,Z0=nothing,Zend=nothing;kwargs...)
1010
1111
where `W(t0)=W₀`, `W(tend)=Wend`, and likewise for the `Z` process if defined.
1212
"""
13-
function BrownianBridge(t0,tend,W0,Wend,Z0=nothing,Zend=nothing;kwargs...)
14-
W = WienerProcess(t0,W0,Z0;kwargs...)
15-
h = tend-t0
16-
Wh = Wend-W0
17-
if Z0 != nothing
18-
Zh = Zend - Z0
19-
else
20-
Zh = nothing
21-
end
22-
push!(W.S₁,(h,Wh,Zh))
23-
W
13+
function BrownianBridge(t0, tend, W0, Wend, Z0 = nothing, Zend = nothing; kwargs...)
14+
W = WienerProcess(t0, W0, Z0; kwargs...)
15+
h = tend - t0
16+
Wh = Wend - W0
17+
if Z0 != nothing
18+
Zh = Zend - Z0
19+
else
20+
Zh = nothing
21+
end
22+
push!(W.S₁, (h, Wh, Zh))
23+
W
2424
end
2525

2626
@doc doc"""
@@ -35,57 +35,59 @@ BrownianBridge!(t0,tend,W0,Wend,Z0=nothing,Zend=nothing;kwargs...)
3535
3636
where `W(t0)=W₀`, `W(tend)=Wend`, and likewise for the `Z` process if defined.
3737
"""
38-
function BrownianBridge!(t0,tend,W0,Wh,Z0=nothing,Zh=nothing;kwargs...)
39-
W = WienerProcess!(t0,W0,Z0;kwargs...)
40-
h = tend-t0
41-
Wh .-= W0
42-
if Z0 != nothing
43-
Zh .-= Z0
44-
else
45-
Zh = nothing
46-
end
47-
push!(W.S₁,(h,Wh,Zh))
48-
W
38+
function BrownianBridge!(t0, tend, W0, Wh, Z0 = nothing, Zh = nothing; kwargs...)
39+
W = WienerProcess!(t0, W0, Z0; kwargs...)
40+
h = tend - t0
41+
Wh .-= W0
42+
if Z0 != nothing
43+
Zh .-= Z0
44+
else
45+
Zh = nothing
46+
end
47+
push!(W.S₁, (h, Wh, Zh))
48+
W
4949
end
5050

51-
function GeometricBrownianBridge(μ,σ,t0,tend,W0,Wend,Z0=nothing,Zend=nothing;kwargs...)
52-
W = GeometricBrownianMotionProcess(μ,σ,t0,W0,Z0;kwargs...)
53-
h = tend-t0
54-
Wh = Wend-W0
55-
if Z0 != nothing
56-
Zh = Zend - Z0
57-
else
58-
Zh = nothing
59-
end
60-
push!(W.S₁,(h,Wh,Zh))
61-
W
51+
function GeometricBrownianBridge(μ, σ, t0, tend, W0, Wend, Z0 = nothing, Zend = nothing;
52+
kwargs...)
53+
W = GeometricBrownianMotionProcess(μ, σ, t0, W0, Z0; kwargs...)
54+
h = tend - t0
55+
Wh = Wend - W0
56+
if Z0 != nothing
57+
Zh = Zend - Z0
58+
else
59+
Zh = nothing
60+
end
61+
push!(W.S₁, (h, Wh, Zh))
62+
W
6263
end
6364

64-
function GeometricBrownianBridge!(μ,σ,t0,tend,W0,Wh,Z0=nothing,Zh=nothing;kwargs...)
65-
W = GeometricBrownianMotionProcess!(μ,σ,t0,W0,Z0;kwargs...)
66-
h = tend-t0
67-
Wh .-= W0
68-
if Z0 != nothing
69-
Zh .-= Z0
70-
else
71-
Zh = nothing
72-
end
73-
push!(W.S₁,(h,Wh,Zh))
74-
W
65+
function GeometricBrownianBridge!(μ, σ, t0, tend, W0, Wh, Z0 = nothing, Zh = nothing;
66+
kwargs...)
67+
W = GeometricBrownianMotionProcess!(μ, σ, t0, W0, Z0; kwargs...)
68+
h = tend - t0
69+
Wh .-= W0
70+
if Z0 != nothing
71+
Zh .-= Z0
72+
else
73+
Zh = nothing
74+
end
75+
push!(W.S₁, (h, Wh, Zh))
76+
W
7577
end
7678

77-
function CompoundPoissonBridge(rate,t0,tend,W0,Wend;kwargs...)
78-
W = CompoundPoissonProcess(rate,t0,W0;kwargs...)
79-
h = tend-t0
80-
Wh = Wend-W0
81-
push!(W.S₁,(h,Wh,nothing))
82-
W
79+
function CompoundPoissonBridge(rate, t0, tend, W0, Wend; kwargs...)
80+
W = CompoundPoissonProcess(rate, t0, W0; kwargs...)
81+
h = tend - t0
82+
Wh = Wend - W0
83+
push!(W.S₁, (h, Wh, nothing))
84+
W
8385
end
8486

85-
function CompoundPoissonBridge!(rate,t0,tend,W0,Wh;kwargs...)
86-
W = CompoundPoissonProcess!(rate,t0,W0;kwargs...)
87-
h = tend-t0
88-
Wh .-= W0
89-
push!(W.S₁,(h,Wh,nothing))
90-
W
87+
function CompoundPoissonBridge!(rate, t0, tend, W0, Wh; kwargs...)
88+
W = CompoundPoissonProcess!(rate, t0, W0; kwargs...)
89+
h = tend - t0
90+
Wh .-= W0
91+
push!(W.S₁, (h, Wh, nothing))
92+
W
9193
end

src/compoundpoisson.jl

Lines changed: 55 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,55 @@
1-
function cpp_bridge(dW,cpp,W,W0,Wh,q,h,u,p,t,rng)
2-
rand.(rng,Distributions.Binomial.(Int.(Wh),float.(q)))
3-
end
4-
function cpp_bridge!(rand_vec,cpp,W,W0,Wh,q,h,u,p,t,rng)
5-
rand_vec .= rand.(rng,Distributions.Binomial.(Int.(Wh),float.(q)))
6-
end
7-
8-
"""
9-
https://www.math.wisc.edu/~anderson/papers/AndPostleap.pdf
10-
Incorporating postleap checks in tau-leaping
11-
J. Chem. Phys. 128, 054103 (2008); https://doi.org/10.1063/1.2819665
12-
"""
13-
mutable struct CompoundPoissonProcess{R,CR}
14-
rate::R
15-
currate::CR
16-
computerates::Bool
17-
function CompoundPoissonProcess(rate,t0,W0;computerates=true,kwargs...)
18-
cpp = new{typeof(rate),typeof(W0)}(rate,W0,computerates)
19-
NoiseProcess{false}(t0,W0,nothing,cpp,(dW,W,W0,Wh,q,h,u,p,t,rng)->cpp_bridge(dW,cpp,W,W0,Wh,q,h,u,p,t,rng);continuous=false,cache=cpp,kwargs...)
20-
end
21-
end
22-
function (P::CompoundPoissonProcess)(dW,W,dt,u,p,t,rng)
23-
P.computerates && (P.currate = P.rate(u,p,t))
24-
PoissonRandom.pois_rand.(rng,dt.*P.currate)
25-
end
26-
27-
"""
28-
https://www.math.wisc.edu/~anderson/papers/AndPostleap.pdf
29-
Incorporating postleap checks in tau-leaping
30-
J. Chem. Phys. 128, 054103 (2008); https://doi.org/10.1063/1.2819665
31-
"""
32-
struct CompoundPoissonProcess!{R,CR}
33-
rate::R
34-
currate::CR
35-
computerates::Bool
36-
function CompoundPoissonProcess!(rate,t0,W0;computerates=true,kwargs...)
37-
cpp = new{typeof(rate),typeof(W0)}(rate,copy(W0),computerates)
38-
NoiseProcess{true}(t0,W0,nothing,cpp,(rand_vec,W,W0,Wh,q,h,u,p,t,rng)->cpp_bridge!(rand_vec,cpp,W,W0,Wh,q,h,u,p,t,rng);continuous=false,cache=cpp,kwargs...)
39-
end
40-
end
41-
function (P::CompoundPoissonProcess!)(rand_vec,W,dt,u,p,t,rng)
42-
P.computerates && P.rate(P.currate,u,p,t)
43-
@. rand_vec = PoissonRandom.pois_rand(rng,dt*P.currate)
44-
end
1+
function cpp_bridge(dW, cpp, W, W0, Wh, q, h, u, p, t, rng)
2+
rand.(rng, Distributions.Binomial.(Int.(Wh), float.(q)))
3+
end
4+
function cpp_bridge!(rand_vec, cpp, W, W0, Wh, q, h, u, p, t, rng)
5+
rand_vec .= rand.(rng, Distributions.Binomial.(Int.(Wh), float.(q)))
6+
end
7+
8+
"""
9+
https://www.math.wisc.edu/~anderson/papers/AndPostleap.pdf
10+
Incorporating postleap checks in tau-leaping
11+
J. Chem. Phys. 128, 054103 (2008); https://doi.org/10.1063/1.2819665
12+
"""
13+
mutable struct CompoundPoissonProcess{R, CR}
14+
rate::R
15+
currate::CR
16+
computerates::Bool
17+
function CompoundPoissonProcess(rate, t0, W0; computerates = true, kwargs...)
18+
cpp = new{typeof(rate), typeof(W0)}(rate, W0, computerates)
19+
NoiseProcess{false}(t0, W0, nothing, cpp,
20+
(dW, W, W0, Wh, q, h, u, p, t, rng) -> cpp_bridge(dW, cpp, W,
21+
W0, Wh, q, h,
22+
u, p, t, rng);
23+
continuous = false, cache = cpp, kwargs...)
24+
end
25+
end
26+
function (P::CompoundPoissonProcess)(dW, W, dt, u, p, t, rng)
27+
P.computerates && (P.currate = P.rate(u, p, t))
28+
PoissonRandom.pois_rand.(rng, dt .* P.currate)
29+
end
30+
31+
"""
32+
https://www.math.wisc.edu/~anderson/papers/AndPostleap.pdf
33+
Incorporating postleap checks in tau-leaping
34+
J. Chem. Phys. 128, 054103 (2008); https://doi.org/10.1063/1.2819665
35+
"""
36+
struct CompoundPoissonProcess!{R, CR}
37+
rate::R
38+
currate::CR
39+
computerates::Bool
40+
function CompoundPoissonProcess!(rate, t0, W0; computerates = true, kwargs...)
41+
cpp = new{typeof(rate), typeof(W0)}(rate, copy(W0), computerates)
42+
NoiseProcess{true}(t0, W0, nothing, cpp,
43+
(rand_vec, W, W0, Wh, q, h, u, p, t, rng) -> cpp_bridge!(rand_vec,
44+
cpp, W,
45+
W0, Wh,
46+
q, h, u,
47+
p, t,
48+
rng);
49+
continuous = false, cache = cpp, kwargs...)
50+
end
51+
end
52+
function (P::CompoundPoissonProcess!)(rand_vec, W, dt, u, p, t, rng)
53+
P.computerates && P.rate(P.currate, u, p, t)
54+
@. rand_vec = PoissonRandom.pois_rand(rng, dt * P.currate)
55+
end

0 commit comments

Comments
 (0)