Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 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.
7 changes: 4 additions & 3 deletions docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@ reset_aggregated_jumps!
## Types of Jumps
```@docs
ConstantRateJump
VariableRateJump
MassActionJump
VariableRateJump
RegularJump
JumpSet
```

## Aggregators
Aggregators are the underlying algorithms used for sampling
[`MassActionJump`](@ref)s, [`ConstantRateJump`](@ref)s and
[`ConstantRateJump`](@ref)s, [`MassActionJump`](@ref)s, and
[`VariableRateJump`](@ref)s.
```@docs
Coevolve
Direct
DirectCR
FRM
Expand All @@ -31,7 +33,6 @@ RDirect
RSSA
RSSACR
SortingDirect
Coevolve
```

# Private API Functions
Expand Down
56 changes: 29 additions & 27 deletions docs/src/faq.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
# FAQ

## My simulation is really slow and/or using a lot of memory, what can I do?
Exact methods simulate each and every 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. You often do not need to save all jump poisitons when you
only want to track cumulative counts. Combined with use of `saveat` in the call
to `solve` this can dramatically reduce memory usage.

While `Direct` is often fastest for systems with 10 or less `ConstantRateJump`s,
`VariableRateJump`s, and/or 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).
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
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 @@ -25,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 `ConstantRateJump`,
`VariableRateJump` and `MassActionJump` 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 @@ -45,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 @@ -69,15 +71,15 @@ 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`, `VariableRateJump` or `MassActionJump` occurs, and which
`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 catch-all terms for jump (or point)
processes simulation methods most commonly used in the biochemistry 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.
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,
Expand Down Expand Up @@ -108,10 +110,10 @@ then follow this ordering when assigning an integer id to each jump.
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`, `VariableRateJump` or `MassActionJump` systems?
## How do I use callbacks with jump simulations?

Callbacks can be used with `ConstantRateJump`s, `VariableRateJump`s and
`MassActionJump`s. When solving a pure jump system with `SSAStepper`, only
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.

Expand Down
62 changes: 34 additions & 28 deletions docs/src/jump_solve.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,36 @@ solve(prob::JumpProblem,alg;kwargs)

## Recommended Methods

Because `JumpProblem`s can be solved with two classes of methods, exact and
inexact, they come in two forms. Exact algorithms tend to describe the
realization of each jump chronologically. Alternatively, inexact methods tend to
take small leaps through time so they are guaranteed to terminate in finite
time. These methods can be much faster as they only simulate the total number of
points in each leap interval and thus do not need to simulate the realization of
every single jump. Jumps for exact methods can be defined with
`ConstantRateJump`, `VariableRateJump` and/or `MassActionJump` On the other
hand, jumps for inexact methods are defined with `RegularJump`.

There are special algorithms available for a pure exact `JumpProblem` (a
`JumpProblem` over a `DiscreteProblem`). The `SSAStepper()` is an efficient
streamlined integrator for running simulation algorithms of such problems. This
integrator is named after the term Stochastic Simulation Algorithm (SSA) which
is a catch-all term in biochemistry to denote algorithms for simulating jump
processes. In turn, we denote aggregators algorithms for simulating jump
processes that can use the `SSAStepper()` integrator. These algorithms can solve
problems initialized with `ConstantRateJump`, `VariableRateJump` and/or
`MassActionJump`. Although `SSAStepper()` is usually faster, it is not
compatible with event handling. If events are necessary, then `FunctionMap` does
well.

If there is a `RegularJump`, then inexact 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
`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 @@ -41,9 +46,10 @@ algorithms are optimized for pure jump problems.

### JumpProcesses.jl

- `SSAStepper`: a stepping integrator for pure `ConstantRateJump`,
`VariableRateJump` 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