Skip to content

Commit

Permalink
reapply formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnoStrouwen committed Feb 25, 2024
1 parent 1a24034 commit bebb035
Show file tree
Hide file tree
Showing 66 changed files with 761 additions and 723 deletions.
3 changes: 2 additions & 1 deletion .JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
style = "sciml"
format_markdown = true
format_markdown = true
format_docstrings = true
2 changes: 1 addition & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ mathengine = MathJax3(Dict(:loader => Dict("load" => ["[tex]/require", "[tex]/ma
"ams",
"autoload",
"mathtools",
"require",
"require"
])))

makedocs(sitename = "JumpProcesses.jl",
Expand Down
2 changes: 1 addition & 1 deletion docs/pages.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ pages = ["index.md",
"Type Documentation" => Any["Jumps, JumpProblem, and Aggregators" => "jump_types.md",
"Jump solvers" => "jump_solve.md"],
"FAQ" => "faq.md",
"API" => "api.md",
"API" => "api.md"
]
13 changes: 5 additions & 8 deletions docs/src/applications/advanced_point_process.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,7 @@ processes connected to it by ``alpha``. This influence will then decrease at
rate ``\beta``.

The conditional intensity of this process has a recursive formulation which we
can use to our advantage to significantly speed simulation. Let ``t_{N_i} = \max
\{t_{n_j} < t \mid j \in E_i\}`` and ``\phi_i^\ast(t)`` below.
can use to our advantage to significantly speed simulation. Let ``t_{N_i} = \max \{t_{n_j} < t \mid j \in E_i\}`` and ``\phi_i^\ast(t)`` below.

```math
\begin{split}
Expand Down Expand Up @@ -224,8 +223,7 @@ end
nothing # hide
```

We assume that each sup-process `i` is a marked TPP. With probability ``(1 -
\omega^\ast(t))``, we draw a mark from a 2-dimensional Gaussian
We assume that each sup-process `i` is a marked TPP. With probability ``(1 - \omega^\ast(t))``, we draw a mark from a 2-dimensional Gaussian
distribution centered in ``\mu_i`` with ``\sigma_1`` standard deviation; and
with probability ``\omega^\ast(t)`` we draw from a 2-dimensional Gaussian
distribution centered on the last location visited by ``i`` with ``\sigma_2``
Expand Down Expand Up @@ -321,7 +319,7 @@ using Graphs
using Distributions
V = 10
G = erdos_renyi(V, 0.2)
g = [[[i] ; neighbors(G, i)] for i in 1:nv(G)]
g = [[[i]; neighbors(G, i)] for i in 1:nv(G)]
mark_dist = [MvNormal(rand(2), [0.2, 0.2]) for i in 1:nv(G)]
jumps = [hawkes_jump(i, g, mark_dist) for i in 1:nv(G)]
tspan = (0.0, 50.0)
Expand All @@ -330,7 +328,7 @@ hawkes = SciMLPointProcess{
eltype(jumps),
typeof(g),
eltype(mark_dist),
eltype(tspan),
eltype(tspan)
}(jumps,
mark_dist,
g,
Expand All @@ -342,8 +340,7 @@ hawkes = SciMLPointProcess{
## [Sampling](@id tpp_sampling)

JumpProcesses shines in the simulation of SDEs with discontinuous jumps. The
mapping we introduced in the [previous Section](@ref tpp_theory) whereby ``du =
dN(t)`` implies that JumpProcesses also excels in simulating TPPs.
mapping we introduced in the [previous Section](@ref tpp_theory) whereby ``du = dN(t)`` implies that JumpProcesses also excels in simulating TPPs.

JumpProcesses offers a plethora of simulation algorithms for TPPs. The library
call them _aggregators_ because these algorithms are methods for aggregating
Expand Down
15 changes: 8 additions & 7 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,26 @@ As jump and point processes are often considered from a variety of perspectives
across different fields, JumpProcesses provides three tutorials on using the
package for those with different backgrounds:

- [Simulating basic Poisson processes](@ref poisson_proc_tutorial)
- [Simulating jump processes via SSAs (i.e., Gillespie methods)](@ref ssa_tutorial)
- [Simulating temporal point processes (TPPs)](@ref tpp_tutorial)
- [Simulating basic Poisson processes](@ref poisson_proc_tutorial)
- [Simulating jump processes via SSAs (i.e., Gillespie methods)](@ref ssa_tutorial)
- [Simulating temporal point processes (TPPs)](@ref tpp_tutorial)

These tutorials also explain the types of jump/point processes that can be
mathematically modelled with JumpProcesses.jl. For more complicated models that
couple ODEs and/or SDEs with continuous noise to jump processes, we provide a
tutorial on

- [Simulating jump-diffusion processes](@ref jump_diffusion_tutorial)
- [Simulating jump-diffusion processes](@ref jump_diffusion_tutorial)

For jump processes that involve spatial transport on a graph/mesh, such
as Reaction-Diffusion Master Equation models, we provide a tutorial on

- [Spatial SSAs](@ref Spatial-SSAs-with-JumpProcesses.jl)
- [Spatial SSAs](@ref Spatial-SSAs-with-JumpProcesses.jl)

Finally, we provide application tutorials which are more extensive tutorials that
interface with other libraries going deeper into a topic.

- [Temporal Point Processes (TPP) with JumpProcesses and PointProcesses](@ref tpp_advanced)
- [Temporal Point Processes (TPP) with JumpProcesses and PointProcesses](@ref tpp_advanced)

We provide a mathematical overview of the library below, but note users may also
skip to the appropriate tutorial listed above to get started with using
Expand Down Expand Up @@ -73,6 +73,7 @@ can then generate exact realizations of pure jump processes of the form
```math
du = \sum_{i=1}^I h_i(u,p,t) \, dN_i(t),
```

where ``h_i(u,p,t)`` represents the amount that ``u(t)`` changes when ``N_i(t)``
jumps. JumpProcesses encodes such changes via a user-provided `affect!`
function, which allows even more general changes to the state, ``u(t)``, when
Expand Down Expand Up @@ -146,7 +147,7 @@ Pkg.add("JumpProcesses")

- See the [SciML Style Guide](https://github.com/SciML/SciMLStyle) for common coding practices and other style decisions.
- There are a few community forums for getting help and asking questions:

+ The #diffeq-bridged and #sciml-bridged channels in the
[Julia Slack](https://julialang.org/slack/)
+ The #diffeq-bridged and #sciml-bridged channels in the
Expand Down
4 changes: 2 additions & 2 deletions docs/src/tutorials/discrete_stochastic_example.md
Original file line number Diff line number Diff line change
Expand Up @@ -453,11 +453,11 @@ latter determining the affect function.
rateidxs = [1, 2] # i.e., [β, ν]
reactant_stoich = [
[1 => 1, 2 => 1], # 1*S and 1*I
[2 => 1], # 1*I
[2 => 1] # 1*I
]
net_stoich = [
[1 => -1, 2 => 1], # -1*S and 1*I
[2 => -1, 3 => 1], # -1*I and 1*R
[2 => -1, 3 => 1] # -1*I and 1*R
]
mass_act_jump = MassActionJump(reactant_stoich, net_stoich; param_idxs = rateidxs)
```
Expand Down
2 changes: 1 addition & 1 deletion docs/src/tutorials/point_process_simulation.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ and hence the dependencies of `seasonal_process` are only `[2]`.
Therefore, we obtain the following dependency graph:

```@example tpp-tutorial
dep_graph = [[1,2], [2]]
dep_graph = [[1, 2], [2]]
```

We can then construct the corresponding problem `JumpProblem`, passing our
Expand Down
32 changes: 16 additions & 16 deletions ext/JumpProcessFastBroadcastExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,30 @@ module JumpProcessFastBroadcastExt
using JumpProcesses, FastBroadcast

@inline function FastBroadcast.fast_materialize!(::FastBroadcast.False, ::DB, dst::EJA,
bc::Base.Broadcast.Broadcasted{S}) where {
S,
DB,
EJA <:
ExtendedJumpArray
}
bc::Base.Broadcast.Broadcasted{S}) where {
S,
DB,
EJA <:
ExtendedJumpArray
}
FastBroadcast.fast_materialize!(FastBroadcast.False(), DB(), dst.u,
JumpProcesses.repack(bc, Val(:u)))
JumpProcesses.repack(bc, Val(:u)))
FastBroadcast.fast_materialize!(FastBroadcast.False(), DB(), dst.jump_u,
JumpProcesses.repack(bc, Val(:jump_u)))
JumpProcesses.repack(bc, Val(:jump_u)))
dst
end

@inline function FastBroadcast.fast_materialize!(::FastBroadcast.True, ::DB, dst::EJA,
bc::Base.Broadcast.Broadcasted{S}) where {
S,
DB,
EJA <:
ExtendedJumpArray
}
bc::Base.Broadcast.Broadcasted{S}) where {
S,
DB,
EJA <:
ExtendedJumpArray
}
FastBroadcast.fast_materialize!(FastBroadcast.True(), DB(), dst.u,
JumpProcesses.repack(bc, Val(:u)))
JumpProcesses.repack(bc, Val(:u)))
FastBroadcast.fast_materialize!(FastBroadcast.True(), DB(), dst.jump_u,
JumpProcesses.repack(bc, Val(:jump_u)))
JumpProcesses.repack(bc, Val(:jump_u)))
dst
end

Expand Down
36 changes: 18 additions & 18 deletions src/SSA_stepper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ function DiffEqBase.u_modified!(integrator::SSAIntegrator, bool::Bool)
end

function DiffEqBase.__solve(jump_prob::JumpProblem,
alg::SSAStepper;
kwargs...)
alg::SSAStepper;
kwargs...)
integrator = init(jump_prob, alg; kwargs...)
solve!(integrator)
integrator.sol
Expand Down Expand Up @@ -145,15 +145,15 @@ function DiffEqBase.solve!(integrator::SSAIntegrator)
end

function DiffEqBase.__init(jump_prob::JumpProblem,
alg::SSAStepper;
save_start = true,
save_end = true,
seed = nothing,
alias_jump = Threads.threadid() == 1,
saveat = nothing,
callback = nothing,
tstops = eltype(jump_prob.prob.tspan)[],
numsteps_hint = 100)
alg::SSAStepper;
save_start = true,
save_end = true,
seed = nothing,
alias_jump = Threads.threadid() == 1,
saveat = nothing,
callback = nothing,
tstops = eltype(jump_prob.prob.tspan)[],
numsteps_hint = 100)
if !(jump_prob.prob isa DiscreteProblem)
error("SSAStepper only supports DiscreteProblems.")
end
Expand Down Expand Up @@ -184,9 +184,9 @@ function DiffEqBase.__init(jump_prob::JumpProblem,
end

sol = DiffEqBase.build_solution(prob, alg, t, u, dense = false,
calculate_error = false,
stats = DiffEqBase.Stats(0),
interp = DiffEqBase.ConstantInterpolation(t, u))
calculate_error = false,
stats = DiffEqBase.Stats(0),
interp = DiffEqBase.ConstantInterpolation(t, u))
save_everystep = any(cb.save_positions)

if saveat isa Number
Expand Down Expand Up @@ -217,8 +217,8 @@ function DiffEqBase.__init(jump_prob::JumpProblem,
error("The time interval to solve over is non-increasing, i.e. tspan[2] <= tspan[1]. This is not allowed for pure jump problem.")

integrator = SSAIntegrator(prob.f, copy(prob.u0), prob.tspan[1], prob.tspan[1], tdir,
prob.p, sol, 1, prob.tspan[1], cb, _saveat, save_everystep,
save_end, cur_saveat, opts, tstops, 1, false, true)
prob.p, sol, 1, prob.tspan[1], cb, _saveat, save_everystep,
save_end, cur_saveat, opts, tstops, 1, false, true)
cb.initialize(cb, integrator.u, prob.tspan[1], integrator)
DiffEqBase.initialize!(opts.callback, integrator.u, prob.tspan[1], integrator)
integrator
Expand All @@ -235,7 +235,7 @@ end
# The Jump aggregators should not register the next jump through add_tstop! for SSAIntegrator
# such that we can achieve maximum performance
@inline function register_next_jump_time!(integrator::SSAIntegrator,
p::AbstractSSAJumpAggregator, t)
p::AbstractSSAJumpAggregator, t)
integrator.tstop = p.next_jump_time
nothing
end
Expand Down Expand Up @@ -279,7 +279,7 @@ function DiffEqBase.step!(integrator::SSAIntegrator)

if !(integrator.opts.callback.discrete_callbacks isa Tuple{})
discrete_modified, saved_in_cb = DiffEqBase.apply_discrete_callback!(integrator,
integrator.opts.callback.discrete_callbacks...)
integrator.opts.callback.discrete_callbacks...)
else
saved_in_cb = false
end
Expand Down
16 changes: 8 additions & 8 deletions src/aggregators/aggregated_api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,41 @@ Notes
vector is unchanged, this can safely be set to false to improve performance.
"""
function reset_aggregated_jumps!(integrator, uprev = nothing; update_jump_params = true,
kwargs...)
kwargs...)
reset_aggregated_jumps!(integrator, uprev, integrator.opts.callback,
update_jump_params = update_jump_params, kwargs...)
update_jump_params = update_jump_params, kwargs...)
nothing
end

function reset_aggregated_jumps!(integrator, uprev, callback::Nothing;
update_jump_params = true, kwargs...)
update_jump_params = true, kwargs...)
nothing
end

function reset_aggregated_jumps!(integrator, uprev, callback::CallbackSet;
update_jump_params = true, kwargs...)
update_jump_params = true, kwargs...)
if !isempty(callback.discrete_callbacks)
reset_aggregated_jumps!(integrator, uprev, callback.discrete_callbacks...,
update_jump_params = update_jump_params, kwargs...)
update_jump_params = update_jump_params, kwargs...)
end
nothing
end

function reset_aggregated_jumps!(integrator, uprev, cb::DiscreteCallback, cbs...;
update_jump_params = true, kwargs...)
update_jump_params = true, kwargs...)
if cb.condition isa AbstractSSAJumpAggregator
maj = cb.condition.ma_jumps
update_jump_params && using_params(maj) &&
update_parameters!(cb.condition.ma_jumps, integrator.p; kwargs...)
cb.condition(cb, integrator.u, integrator.t, integrator)
end
reset_aggregated_jumps!(integrator, uprev, cbs...;
update_jump_params = update_jump_params, kwargs...)
update_jump_params = update_jump_params, kwargs...)
nothing
end

function reset_aggregated_jumps!(integrator, uprev, cb::DiscreteCallback;
update_jump_params = true, kwargs...)
update_jump_params = true, kwargs...)
if cb.condition isa AbstractSSAJumpAggregator
maj = cb.condition.ma_jumps
update_jump_params && using_params(maj) &&
Expand Down
2 changes: 1 addition & 1 deletion src/aggregators/aggregators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ algorithm with optimal binning, Journal of Chemical Physics 143, 074108
struct DirectCRDirect <: AbstractAggregatorAlgorithm end

const JUMP_AGGREGATORS = (Direct(), DirectFW(), DirectCR(), SortingDirect(), RSSA(), FRM(),
FRMFW(), NRM(), RSSACR(), RDirect(), Coevolve())
FRMFW(), NRM(), RSSACR(), RDirect(), Coevolve())

# For JumpProblem construction without an aggregator
struct NullAggregator <: AbstractAggregatorAlgorithm end
Expand Down
2 changes: 1 addition & 1 deletion src/aggregators/bracketing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ get brackets for the rate of reaction rx by first checking if the reaction is a
return get_majump_brackets(p.ulow, p.uhigh, rx, ma_jumps)
else
@inbounds return get_cjump_brackets(p.ulow, p.uhigh, p.rates[rx - num_majumps],
params, t)
params, t)
end
end

Expand Down
Loading

0 comments on commit bebb035

Please sign in to comment.