Skip to content

Commit

Permalink
Merge pull request #286 from ArnoStrouwen/md
Browse files Browse the repository at this point in the history
format markdown
  • Loading branch information
ChrisRackauckas committed Jan 23, 2023
2 parents 4d0f532 + ba646f2 commit eeede56
Show file tree
Hide file tree
Showing 23 changed files with 681 additions and 416 deletions.
3 changes: 2 additions & 1 deletion .JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
style = "sciml"
style = "sciml"
format_markdown = true
13 changes: 7 additions & 6 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
## JumpProcesses unreleased (master branch)

## 9.3
- Support for "bounded" `VariableRateJump`s that can be used with the `Coevolve`
aggregator for faster simulation of jump processes with time-dependent rates.
In particular, if all `VariableRateJump`s in a pure-jump system are bounded one
can use `Coevolve` with `SSAStepper` for better performance. See the
documentation, particularly the first and second tutorials, for details on
defining and using bounded `VariableRateJump`s.

- Support for "bounded" `VariableRateJump`s that can be used with the `Coevolve`
aggregator for faster simulation of jump processes with time-dependent rates.
In particular, if all `VariableRateJump`s in a pure-jump system are bounded one
can use `Coevolve` with `SSAStepper` for better performance. See the
documentation, particularly the first and second tutorials, for details on
defining and using bounded `VariableRateJump`s.
1 change: 0 additions & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ The JumpDiffEq.jl package is licensed under the MIT "Expat" License:
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
> SOFTWARE.
>
68 changes: 38 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[![codecov](https://codecov.io/gh/SciML/JumpProcesses.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/SciML/JumpProcesses.jl)
[![Build Status](https://github.com/SciML/JumpProcesses.jl/workflows/CI/badge.svg)](https://github.com/SciML/JumpProcesses.jl/actions?query=workflow%3ACI)

[![ColPrac: Contributor's Guide on Collaborative Practices for Community Packages](https://img.shields.io/badge/ColPrac-Contributor's%20Guide-blueviolet)](https://github.com/SciML/ColPrac)
[![ColPrac: Contributor's Guide on Collaborative Practices for Community Packages](https://img.shields.io/badge/ColPrac-Contributor%27s%20Guide-blueviolet)](https://github.com/SciML/ColPrac)
[![SciML Code Style](https://img.shields.io/static/v1?label=code%20style&message=SciML&color=9558b2&labelColor=389826)](https://github.com/SciML/SciMLStyle)

*Note, JumpProcesses.jl is a renaming of DiffEqJump.jl, providing the current version of the latter.*
Expand All @@ -26,18 +26,20 @@ and one of the core solver libraries included in
For information on using the package,
[see the stable documentation](https://docs.sciml.ai/JumpProcesses/stable/). Use the
[in-development documentation](https://docs.sciml.ai/JumpProcesses/dev/) for the version of
the documentation which contains unreleased features.
the documentation which contains unreleased features.

The documentation includes
- [a tutorial on simulating basic Poisson processes](https://docs.sciml.ai/JumpProcesses/stable/tutorials/simple_poisson_process/)
- [a tutorial and details on using JumpProcesses to simulate jump processes via SSAs (i.e. Gillespie methods)](https://docs.sciml.ai/JumpProcesses/stable/tutorials/discrete_stochastic_example/),
- [a tutorial on simulating jump-diffusion processes](https://docs.sciml.ai/JumpProcesses/stable/tutorials/jump_diffusion/),
- [a reference on the types of jumps and available simulation methods](https://docs.sciml.ai/JumpProcesses/stable/jump_types/),
- [a reference on jump time stepping methods](https://docs.sciml.ai/JumpProcesses/stable/jump_solve/),
- [a FAQ](https://docs.sciml.ai/JumpProcesses/stable/faq) with information on changing parameters between simulations and using callbacks,
- [the JumpProcesses.jl API documentation](https://docs.sciml.ai/JumpProcesses/stable/api/).

- [a tutorial on simulating basic Poisson processes](https://docs.sciml.ai/JumpProcesses/stable/tutorials/simple_poisson_process/)
- [a tutorial and details on using JumpProcesses to simulate jump processes via SSAs (i.e. Gillespie methods)](https://docs.sciml.ai/JumpProcesses/stable/tutorials/discrete_stochastic_example/),
- [a tutorial on simulating jump-diffusion processes](https://docs.sciml.ai/JumpProcesses/stable/tutorials/jump_diffusion/),
- [a reference on the types of jumps and available simulation methods](https://docs.sciml.ai/JumpProcesses/stable/jump_types/),
- [a reference on jump time stepping methods](https://docs.sciml.ai/JumpProcesses/stable/jump_solve/),
- [a FAQ](https://docs.sciml.ai/JumpProcesses/stable/faq) with information on changing parameters between simulations and using callbacks,
- [the JumpProcesses.jl API documentation](https://docs.sciml.ai/JumpProcesses/stable/api/).

## Installation

There are two ways to install `JumpProcesses.jl`. First, users may install the meta
`DifferentialEquations.jl` package, which installs and wraps `OrdinaryDiffEq.jl`
for solving ODEs, `StochasticDiffEq.jl` for solving SDEs, and `JumpProcesses.jl`,
Expand All @@ -52,6 +54,7 @@ details](https://docs.sciml.ai/DiffEqDocs/stable/).
If the user wishes to separately install the `JumpProcesses.jl` library, which is a
lighter dependency than `DifferentialEquations.jl`, then the following code will
install `JumpProcesses.jl` using the Julia package manager:

```julia
using Pkg
Pkg.add("JumpProcesses")
Expand All @@ -60,43 +63,46 @@ Pkg.add("JumpProcesses")
## Examples

### Stochastic Chemical Kinetics SIR Model

Here we consider the stochastic chemical kinetics jump process model for the
basic SIR model, involving three species, $(S,I,R)$, that can undergo the
reactions $S + I \to 2I$ and $I \to R$ (each represented as a jump process)

```julia
using JumpProcesses, Plots

# here we order S = 1, I = 2, and R = 3
# substrate stoichiometry:
substoich = [[1 => 1, 2 => 1], # 1*S + 1*I
[2 => 1]] # 1*I
[2 => 1]] # 1*I
# net change by each jump type
netstoich = [[1 => -1, 2 => 1], # S -> S-1, I -> I+1
[2 => -1, 3 => 1]] # I -> I-1, R -> R+1
[2 => -1, 3 => 1]] # I -> I-1, R -> R+1
# rate constants for each jump
p = (0.1/1000, 0.01)
p = (0.1 / 1000, 0.01)

# p[1] is rate for S+I --> 2I, p[2] for I --> R
pidxs = [1, 2]

maj = MassActionJump(substoich, netstoich; param_idxs=pidxs)
maj = MassActionJump(substoich, netstoich; param_idxs = pidxs)

u₀ = [999, 1, 0] #[S(0),I(0),R(0)]
u₀ = [999, 1, 0] #[S(0),I(0),R(0)]
tspan = (0.0, 250.0)
dprob = DiscreteProblem(u₀, tspan, p)

# use the Direct method to simulate
jprob = JumpProblem(dprob, Direct(), maj)

# solve as a pure jump process, i.e. using SSAStepper
sol = solve(jprob, SSAStepper())
sol = solve(jprob, SSAStepper())
plot(sol)
```

![SIR Model](docs/src/assets/SIR.png)

Instead of `MassActionJump`, we could have used the less efficient, but more
flexible, `ConstantRateJump` type

```julia
rate1(u, p, t) = p[1] * u[1] * u[2] # p[1]*S*I
function affect1!(integrator)
Expand All @@ -112,12 +118,14 @@ function affect2!(integrator)
end
jump2 = ConstantRateJump(rate2, affect2!)
jprob = JumpProblem(dprob, Direct(), jump, jump2)
sol = solve(jprob, SSAStepper())
sol = solve(jprob, SSAStepper())
```

### Jump-ODE Example

Let's solve an ODE for exponential growth, but coupled to a constant rate jump
(Poisson) process that halves the solution each time it fires

```julia
using DifferentialEquations, Plots

Expand All @@ -135,7 +143,7 @@ prob = ODEProblem(f, u₀, tspan)
rate(u, p, t) = 2

# halve the solution when firing
affect!(integrator) = (integrator.u[1] = integrator.u[1]/2)
affect!(integrator) = (integrator.u[1] = integrator.u[1] / 2)
jump = ConstantRateJump(rate, affect!)

# use the Direct method to handle simulating the jumps
Expand All @@ -148,18 +156,18 @@ plot(sol)

![constant_rate_jump](docs/src/assets/constant_rate_jump.png)


## Contributing and Getting Help

- Please refer to the
[SciML ColPrac: Contributor's Guide on Collaborative Practices for Community Packages](https://github.com/SciML/ColPrac/blob/master/README.md)
for guidance on PRs, issues, and other matters relating to contributing to SciML.
- 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
[Julia Zulip](https://julialang.zulipchat.com/#narrow/stream/279055-sciml-bridged)
- The [Julia Discourse forums](https://discourse.julialang.org)
- See also the [SciML Community page](https://sciml.ai/community/)

- Please refer to the
[SciML ColPrac: Contributor's Guide on Collaborative Practices for Community Packages](https://github.com/SciML/ColPrac/blob/master/README.md)
for guidance on PRs, issues, and other matters relating to contributing to SciML.

- 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
[Julia Zulip](https://julialang.zulipchat.com/#narrow/stream/279055-sciml-bridged)
+ The [Julia Discourse forums](https://discourse.julialang.org)
+ See also the [SciML Community page](https://sciml.ai/community/)
26 changes: 18 additions & 8 deletions docs/old/cut.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## Coupling Jump Problems
## Coupling Jump Problems

THIS NEEDS UPDATING

In many applications one is interested in coupling two stochastic processes.
Expand All @@ -9,9 +10,11 @@ the underlying Poisson processes driving the jump components.

Suppose `prob` and `prob_control` are two problems we wish to couple. Then the
coupled problem is obtained by

```@example tut3
prob_coupled = SplitCoupledJumpProblem(jump_prob, jump_prob_control, Direct(), coupling_map)
prob_coupled = SplitCoupledJumpProblem(jump_prob, jump_prob_control, Direct(), coupling_map)
```

Here, `coupling_map` specifies which jumps to couple. If `(j,i)` is in
`coupling_map`, then the `i`th jump in `prob` will be coupled to the `j`th jump
in `prob_control`. Note that currently `SplitCoupledJumpProblem` is only
Expand All @@ -20,6 +23,7 @@ implemented for `ConstantRateJump` problems.
As an example, consider a doubly stochastic Poisson process, that is, a Poisson
process whose rate is itself a stochastic process. In particular, we will take
the rate to randomly switch between zero and `10` at unit rates:

```@example tut3
rate(u, p, t) = 10 * u[2]
affect!(integrator) = integrator.u[1] += 1
Expand All @@ -29,36 +33,42 @@ rate(u, p, t) = u[2]
affect!(integrator) = (integrator.u[2] -= 1; integrator.u[3] += 1)
jump2 = ConstantRateJump(rate, affect!)
rate(u,p,t) = u[3]
rate(u, p, t) = u[3]
affect!(integrator) = (integrator.u[2] += 1; integrator.u[3] -= 1)
jump3 = ConstantRateJump(rate, affect!)
prob = DiscreteProblem(u0, tspan)
jump_prob = JumpProblem(prob, Direct(), jump1, jump2, jump3)
```

The doubly stochastic Poisson process has two sources of randomness: one due to
the Poisson process, and another due to random evolution of the rate. This is
typical of many multiscale stochastic processes appearing in applications, and
it is often useful to compare such a process to one obtained by removing one
source of randomness. In present context, this means looking at an ODE with
constant jump rates, where the deterministic evolution between jumps is given by
the expected value of the Poisson process:

```@example tut3
function f(du, u, p, t)
du[1] = 10 * u[2]
du[2] = 0
du[3] = 0
du[1] = 10 * u[2]
du[2] = 0
du[3] = 0
end
prob_control = ODEProblem(f, [0.0, 0.0, 1.0], tspan)
jump_prob_control = JumpProblem(prob_control, Direct(), jump2, jump3)
```

Let's couple the two problems by coupling the jumps corresponding to the
switching of the rate:

```@example tut3
coupling_map = [(2,1), (3,2)]
prob_coupled = SplitCoupledJumpProblem(jump_prob, jump_prob_control, Direct(), coupling_map)
coupling_map = [(2, 1), (3, 2)]
prob_coupled = SplitCoupledJumpProblem(jump_prob, jump_prob_control, Direct(), coupling_map)
```

Now `prob_coupled` can be solved like any other `JumpProblem`:

```@example tut3
sol = solve(prob_coupled, Tsit5())
```
6 changes: 6 additions & 0 deletions docs/src/api.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
# JumpProcesses.jl API

```@meta
CurrentModule = JumpProcesses
```

## Core Types

```@docs
JumpProblem
SSAStepper
reset_aggregated_jumps!
```

## Types of Jumps

```@docs
ConstantRateJump
MassActionJump
Expand All @@ -20,9 +23,11 @@ JumpSet
```

## Aggregators

Aggregators are the underlying algorithms used for sampling
[`ConstantRateJump`](@ref)s, [`MassActionJump`](@ref)s, and
[`VariableRateJump`](@ref)s.

```@docs
Coevolve
Direct
Expand All @@ -36,6 +41,7 @@ SortingDirect
```

# Private API Functions

```@docs
ExtendedJumpArray
SSAIntegrator
Expand Down
Loading

0 comments on commit eeede56

Please sign in to comment.