Skip to content

Coevolve aggregator for VariableRateJump #276

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 75 commits into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
280b64b
adds working QueueMethod aggregator and ConditionalRateJump.
gzagatti Oct 25, 2022
f39abef
Incorporates conditional history to QueueMethod.
gzagatti Oct 26, 2022
724acb3
remove debugging comments.
gzagatti Oct 26, 2022
28cb924
adds marked jump to QueueMethod.
gzagatti Oct 26, 2022
e27a90b
save history.
gzagatti Oct 27, 2022
ed9c118
reorders exports.
gzagatti Oct 28, 2022
7afd21b
use VariableRateJump instead and tweaks to next_time algorithm.
gzagatti Oct 31, 2022
94dd52e
improve initialization performance by removing FunctionWrapper.
gzagatti Oct 31, 2022
dc9376d
fix bugs.
gzagatti Oct 31, 2022
fa5c0ad
needs jumptovars_map and vartojumps_map.
gzagatti Nov 1, 2022
de6f6a2
remove mark and history from the aggregator.
gzagatti Nov 1, 2022
a56eff4
adds utilities for dealing with history.
gzagatti Nov 2, 2022
2683f85
fix bugs.
gzagatti Nov 2, 2022
c6249d9
adds option for indices when computing conditional rate.
gzagatti Nov 2, 2022
ccbfee5
use Vector instead of Tuple in JumpSet.
gzagatti Nov 2, 2022
98b06fd
adds docstring to function.
gzagatti Nov 2, 2022
2108278
modifies QueueMethod requirement.
gzagatti Nov 2, 2022
ba74592
improve performance and simplify QueueMethod.
gzagatti Nov 4, 2022
6f19944
fix bugs.
gzagatti Nov 4, 2022
42568f9
adds support for MA jumps; pass all unit tests.
gzagatti Nov 25, 2022
c91b021
improves aggregator speed by using FunctionWrappers and avoid allocat…
gzagatti Nov 28, 2022
db541d9
use heap instead of priority queue for improved performance.
gzagatti Nov 28, 2022
7c973b7
fix API.
gzagatti Nov 29, 2022
9cb3770
leave from next_time loop as soon as possible.
gzagatti Nov 30, 2022
837292a
Merge remote-tracking branch 'origin/master' into queue-method-ii
gzagatti Nov 30, 2022
a9484a1
fix QueueMethod requirement.
gzagatti Dec 1, 2022
e0ba083
remove logic for pausing next time as premature optimization.
gzagatti Dec 1, 2022
a18e04f
fix zero rate.
gzagatti Dec 1, 2022
08366d9
move utilities out of the module.
gzagatti Dec 5, 2022
2b1cdd8
adds documentation for VariableRateJump.
gzagatti Dec 7, 2022
d6ac52d
fix if statement.
gzagatti Dec 7, 2022
ceb293b
adds test for VariableRateJump.
gzagatti Dec 7, 2022
c7a832c
linting.
gzagatti Dec 7, 2022
7574367
fix documentation.
gzagatti Dec 7, 2022
efdb3a3
adds source to documentation.
gzagatti Dec 7, 2022
82aff42
fix problem initialization.
gzagatti Dec 7, 2022
bd67a7f
renames QueueMethod to Coevolve; fix documentation references.
gzagatti Dec 8, 2022
6cb6881
linting and file rename.
gzagatti Dec 8, 2022
77b4cb2
adds default for lrate; fix VariableRateJump API.
gzagatti Dec 11, 2022
41b8f2a
ensure correct type inference.
gzagatti Dec 11, 2022
f0dc9a7
removes unncessary update_state! from Coevolve.
gzagatti Dec 11, 2022
a8cf1c6
corrects eltype to typeof.
gzagatti Dec 11, 2022
c1b7589
inlines get_rate in Coevolve.
gzagatti Dec 11, 2022
138b07f
adds Coevolve to more tests.
gzagatti Dec 11, 2022
b87e00e
fix update_state! call.
gzagatti Dec 11, 2022
27707e6
adds supports_variablerates trait.
gzagatti Dec 11, 2022
0b59e52
re-use random number.
gzagatti Dec 12, 2022
a4abd47
revert JumpSet changes.
gzagatti Dec 12, 2022
54ed717
avoid creating anonymous function when not needed.
gzagatti Dec 12, 2022
0ca1493
remove the VariableRateJump initializer from a ConstantRateJump.
gzagatti Dec 12, 2022
4d89b5d
fix comments.
gzagatti Dec 12, 2022
f51fc44
treat all jump types differently in Coevolve.
gzagatti Dec 12, 2022
c55691c
fix local doc builds and add some tutorial updates
isaacsas Dec 14, 2022
bf6771a
fix error message.
gzagatti Dec 14, 2022
d3ce32b
Merge remote-tracking branch 'origin/master' into queue-method-ii
gzagatti Dec 14, 2022
f513ec9
Merge remote-tracking branch 'github-desktop-gzagatti/queue-method-ii…
isaacsas Dec 14, 2022
ca46720
change L to rateinterval
isaacsas Dec 14, 2022
e271864
L -> rateinterval
isaacsas Dec 14, 2022
8c393e2
add global nullrate function
isaacsas Dec 14, 2022
a6f8889
format
isaacsas Dec 14, 2022
b0259a0
more doc updates
isaacsas Dec 22, 2022
199564f
fix typos
isaacsas Dec 22, 2022
5dda9b8
more doc updates
isaacsas Dec 28, 2022
e75c34f
finish tutorial updates
isaacsas Dec 28, 2022
6ceef8d
tutorial bug fix
isaacsas Dec 29, 2022
bba4aaf
doc tweaks
isaacsas Dec 29, 2022
72ac0a1
simplify coevolve
isaacsas Dec 30, 2022
cd7ddf5
add inbounds
isaacsas Dec 30, 2022
176ca81
make lrate optional
isaacsas Dec 31, 2022
cf0f050
fix initialization bug
isaacsas Dec 31, 2022
d5cacb3
rework JumpProblem
isaacsas Jan 1, 2023
9b41d17
format
isaacsas Jan 1, 2023
1103cd0
add tests
isaacsas Jan 2, 2023
e4556d7
Update docs/src/jump_types.md
isaacsas Jan 3, 2023
b0d72b5
Apply suggestions from code review
isaacsas Jan 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Breaking updates and feature summaries across releases

## JumpProcesses unreleased (master branch)
- 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.
6 changes: 4 additions & 2 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using Documenter, JumpProcesses

cp("./docs/Manifest.toml", "./docs/src/assets/Manifest.toml", force = true)
cp("./docs/Project.toml", "./docs/src/assets/Project.toml", force = true)
docpath = Base.source_dir()
assetpath = joinpath(docpath, "src", "assets")
cp(joinpath(docpath, "Manifest.toml"), joinpath(assetpath, "Manifest.toml"), force = true)
cp(joinpath(docpath, "Project.toml"), joinpath(assetpath, "Project.toml"), force = true)

include("pages.jl")

Expand Down
7 changes: 5 additions & 2 deletions docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ reset_aggregated_jumps!
ConstantRateJump
MassActionJump
VariableRateJump
RegularJump
JumpSet
```

## Aggregators
Aggregators are the underlying algorithms used for sampling
[`MassActionJump`](@ref)s and [`ConstantRateJump`](@ref)s.
[`ConstantRateJump`](@ref)s, [`MassActionJump`](@ref)s, and
[`VariableRateJump`](@ref)s.
```@docs
Coevolve
Direct
DirectCR
FRM
Expand All @@ -36,4 +39,4 @@ SortingDirect
```@docs
ExtendedJumpArray
SSAIntegrator
```
```
58 changes: 33 additions & 25 deletions docs/src/faq.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
# FAQ

## My simulation is really slow and/or using a lot of memory, what can I do?
To reduce memory use, use `save_positions=(false,false)` in the `JumpProblem`
constructor as described [earlier](@ref save_positions_docs) to turn off saving
the system state before and after every jump. Combined with use of `saveat` in
the call to `solve` this can dramatically reduce memory usage.
Exact methods simulate every jump, and by default save the state before and
after each jump. To reduce memory use, use `save_positions = (false, false)` in
the `JumpProblem` constructor as described [earlier](@ref save_positions_docs)
to turn off saving the system state before and after every jump. Combined with
use of `saveat` in the call to `solve`, to specify the specific times at which
to save the state, this can dramatically reduce memory usage.

While `Direct` is often fastest for systems with 10 or less `ConstantRateJump`s
or `MassActionJump`s, if your system has many jumps or one jump occurs most
frequently, other stochastic simulation algorithms may be faster. See [Constant
Rate Jump Aggregators](@ref) and the subsequent sections there for guidance on
choosing different SSAs (called aggregators in JumpProcesses).
and/or `MassActionJump`s, if your system has many jumps or one jump occurs most
frequently, other stochastic simulation algorithms may be faster. See [Jump
Aggregators for Exact Simulation](@ref) and the subsequent sections there for
guidance on choosing different SSAs (called aggregators in JumpProcesses). For
systems with bounded `VariableRateJump`s using `Coevolve` with `SSAStepper`
instead of an ODE/SDE time stepper can give a significant performance boost.

## When running many consecutive simulations, for example within an `EnsembleProblem` or loop, how can I update `JumpProblem`s?

Expand All @@ -22,8 +26,9 @@ internal aggregators for each new parameter value or initial condition.
## How can I define collections of many different jumps and pass them to `JumpProblem`?

We can use `JumpSet`s to collect jumps together, and then pass them into
`JumpProblem`s directly. For example, using the `MassActionJump` and
`ConstantRateJump` defined earlier we can write
`JumpProblem`s directly. For example, using a `MassActionJump` and
`ConstantRateJump` defined in the [second tutorial](@ref ssa_tutorial), we can
write

```julia
jset = JumpSet(mass_act_jump, birth_jump)
Expand All @@ -42,8 +47,8 @@ vj1 = VariableRateJump(rate3, affect3!)
vj2 = VariableRateJump(rate4, affect4!)
vjtuple = (vj1, vj2)

jset = JumpSet(; constant_jumps=cjvec, variable_jumps=vjtuple,
massaction_jumps=mass_act_jump)
jset = JumpSet(; constant_jumps = cjvec, variable_jumps = vjtuple,
massaction_jumps = mass_act_jump)
```

## How can I set the random number generator used in the jump process sampling algorithms (SSAs)?
Expand All @@ -66,16 +71,19 @@ default. On versions below 1.7 it uses `Xoroshiro128Star`.
## What are these aggregators and aggregations in JumpProcesses?

JumpProcesses provides a variety of methods for sampling the time the next
`ConstantRateJump` or `MassActionJump` occurs, and which jump type happens at
that time. These methods are examples of stochastic simulation algorithms
(SSAs), also known as Gillespie methods, Doob's method, or Kinetic Monte Carlo
methods. In the JumpProcesses terminology we call such methods "aggregators", and
the cache structures that hold their basic data "aggregations". See [Constant
Rate Jump Aggregators](@ref) for a list of the available SSA aggregators.
`ConstantRateJump`, `MassActionJump`, or `VariableRateJump` occurs, and which
jump type happens at that time. These methods are examples of stochastic
simulation algorithms (SSAs), also known as Gillespie methods, Doob's method, or
Kinetic Monte Carlo methods. These are all names for jump (or point) processes
simulation methods used across the biology, chemistry, engineering, mathematics,
and physics literature. In the JumpProcesses terminology we call such methods
"aggregators", and the cache structures that hold their basic data
"aggregations". See [Jump Aggregators for Exact Simulation](@ref) for a list of
the available SSA aggregators.

## How should jumps be ordered in dependency graphs?
Internally, JumpProcesses SSAs (aggregators) order all `MassActionJump`s first,
then all `ConstantRateJumps`. i.e. in the example
then all `ConstantRateJumps` and/or `VariableRateJumps`. i.e. in the example

```julia
using JumpProcesses
Expand All @@ -99,15 +107,15 @@ The four jumps would be ordered by the first jump in `maj`, the second jump in
`maj`, `cj1`, and finally `cj2`. Any user-generated dependency graphs should
then follow this ordering when assigning an integer id to each jump.

See also [Constant Rate Jump Aggregators Requiring Dependency Graphs](@ref) for
See also [Jump Aggregators Requiring Dependency Graphs](@ref) for
more on dependency graphs needed for the various SSAs.

## How do I use callbacks with `ConstantRateJump` or `MassActionJump` systems?
## How do I use callbacks with jump simulations?

Callbacks can be used with `ConstantRateJump`s and `MassActionJump`s. When
solving a pure jump system with `SSAStepper`, only discrete callbacks can be
used (otherwise a different time stepper is needed). When using an ODE or SDE
time stepper any callback should work.
Callbacks can be used with `ConstantRateJump`s, `MassActionJump`s, and
`VariableRateJump`s. When solving a pure jump system with `SSAStepper`, only
discrete callbacks can be used (otherwise a different time stepper is needed).
When using an ODE or SDE time stepper any callback should work.

*Note, when modifying `u` or `p` within a callback, you must call
[`reset_aggregated_jumps!`](@ref) after making updates.* This ensures that the
Expand Down
29 changes: 16 additions & 13 deletions docs/src/index.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# JumpProcesses.jl: Stochastic Simulation Algorithms for Jump Processes, Jump-ODEs, and Jump-Diffusions
JumpProcesses.jl, formerly DiffEqJump.jl, provides methods for simulating jump
processes, known as stochastic simulation algorithms (SSAs), Doob's method,
Gillespie methods, or Kinetic Monte Carlo methods across different fields of
science. It also enables the incorporation of jump processes into hybrid
jump-ODE and jump-SDE models, including jump diffusions.
(or point) processes. Across different fields of science such methods are also
known as stochastic simulation algorithms (SSAs), Doob's method, Gillespie
methods, or Kinetic Monte Carlo methods . It also enables the incorporation of
jump processes into hybrid jump-ODE and jump-SDE models, including jump
diffusions.

JumpProcesses is a component package in the [SciML](https://sciml.ai/) ecosystem,
and one of the core solver libraries included in
Expand Down Expand Up @@ -78,31 +79,33 @@ versioninfo() # hide
```
```@example
using Pkg # hide
Pkg.status(;mode = PKGMODE_MANIFEST) # hide
Pkg.status(; mode = PKGMODE_MANIFEST) # hide
```
```@raw html
</details>
```
```@raw html
You can also download the
You can also download the
<a href="
```
```@eval
using TOML
version = TOML.parse(read("../../Project.toml",String))["version"]
name = TOML.parse(read("../../Project.toml",String))["name"]
link = "https://github.com/SciML/"*name*".jl/tree/gh-pages/v"*version*"/assets/Manifest.toml"
projtoml = joinpath("..", "..", "Project.toml")
version = TOML.parse(read(projtoml, String))["version"]
name = TOML.parse(read(projtoml, String))["name"]
link = "https://github.com/SciML/" * name * ".jl/tree/gh-pages/v" * version * "/assets/Manifest.toml"
```
```@raw html
">manifest</a> file and the
<a href="
```
```@eval
using TOML
version = TOML.parse(read("../../Project.toml",String))["version"]
name = TOML.parse(read("../../Project.toml",String))["name"]
link = "https://github.com/SciML/"*name*".jl/tree/gh-pages/v"*version*"/assets/Project.toml"
projtoml = joinpath("..", "..", "Project.toml")
version = TOML.parse(read(projtoml, String))["version"]
name = TOML.parse(read(projtoml, String))["name"]
link = "https://github.com/SciML/" * name * ".jl/tree/gh-pages/v" * version * "/assets/Project.toml"
```
```@raw html
">project</a> file.
```
```
51 changes: 35 additions & 16 deletions docs/src/jump_solve.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,37 @@ solve(prob::JumpProblem,alg;kwargs)

## Recommended Methods

A `JumpProblem(prob,aggregator,jumps...)` comes in two forms. The first major
form is if it does not have a `RegularJump`. In this case, it can be solved with
any integrator on `prob`. However, in the case of a pure `JumpProblem` (a
`JumpProblem` over a `DiscreteProblem`), there are special algorithms
available. The `SSAStepper()` is an efficient streamlined algorithm for running
the `aggregator` version of the SSA for pure `ConstantRateJump` and/or
`MassActionJump` problems. However, it is not compatible with event handling. If
events are necessary, then `FunctionMap` does well.

If there is a `RegularJump`, then specific methods must be used. The current
recommended method is `TauLeaping` if you need adaptivity, events, etc. If you
just need the most barebones fixed time step leaping method, then `SimpleTauLeaping`
can have performance benefits.
`JumpProblem`s can be solved with two classes of methods, exact and inexact.
Exact algorithms currently sample realizations of the jump processes in
chronological order, executing individual jumps sequentially at randomly sampled
times. In contrast, inexact (τ-leaping) methods are time-step based, executing
multiple occurrences of jumps during each time-step. These methods can be much
faster as they only simulate the total number of jumps over each leap interval,
and thus do not need to simulate the realization of every single jump. Jumps for
use with exact simulation methods can be defined as `ConstantRateJump`s,
`MassActionJump`s, and/or `VariableRateJump`. Jumps for use with inexact
τ-leaping methods should be defined as `RegularJump`s.

There are special algorithms available for efficiently simulating an exact, pure
`JumpProblem` (i.e. a `JumpProblem` over a `DiscreteProblem`). `SSAStepper()`
is an efficient streamlined integrator for time stepping such problems from
individual jump to jump. This integrator is named after Stochastic Simulation
Algorithms (SSAs), commonly used naming in chemistry and biology applications
for the class of exact jump process simulation algorithms. In turn, we denote by
"aggregators" the algorithms that `SSAStepper` calls to calculate the next jump
time and to execute a jump (i.e. change the system state appropriately). All
JumpProcesses aggregators can be used with `ConstantRateJump`s and
`MassActionJump`s, with a subset of aggregators also working with bounded
`VariableRateJump`s (see [the first tutorial](@ref poisson_proc_tutorial) for
the definition of bounded `VariableRateJump`s). Although `SSAStepper()` is
usually faster, it only supports discrete events (`DiscreteCallback`s), for pure
jump problems requiring continuous events (`ContinuousCallback`s) the less
performant `FunctionMap` time-stepper can be used.

If there is a `RegularJump`, then inexact τ-leaping methods must be used. The
current recommended method is `TauLeaping` if one needs adaptivity, events, etc.
If ones only needs the most barebones fixed time-step leaping method, then
`SimpleTauLeaping` can have performance benefits.

## Special Methods for Pure Jump Problems

Expand All @@ -28,9 +46,10 @@ algorithms are optimized for pure jump problems.

### JumpProcesses.jl

- `SSAStepper`: a stepping algorithm for pure `ConstantRateJump` and/or
`MassActionJump` `JumpProblem`s. Supports handling of `DiscreteCallback`
and saving controls like `saveat`.
- `SSAStepper`: a stepping integrator for `JumpProblem`s defined over
`DiscreteProblem`s involving `ConstantRateJump`s, `MassActionJump`s, and/or
bounded `VariableRateJump`s . Supports handling of `DiscreteCallback`s and
saving controls like `saveat`.

## RegularJump Compatible Methods

Expand Down
Loading