You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/model_simulation/ensemble_simulations.md
+8-5Lines changed: 8 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,10 +3,10 @@ In many contexts, a single model is re-simulated under similar conditions. Examp
3
3
- Performing Monte Carlo simulations of a stochastic model to gain insight in its behaviour.
4
4
- Scanning a model's behaviour for different parameter values and/or initial conditions.
5
5
6
-
While this can be handled using `for` loops, it is typically better to first create an `EnsembleProblem`, and then perform an ensemble simulation. Advantages include a more concise interface and the option for [automatic simulation parallelisation](@refref). Here we provide a short tutorial on how to perform parallel ensemble simulations, with a more extensive documentation being available [here](@refhttps://docs.sciml.ai/DiffEqDocs/stable/features/ensemble/).
6
+
While this can be handled using `for` loops, it is typically better to first create an `EnsembleProblem`, and then perform an ensemble simulation. Advantages include a more concise interface and the option for [automatic simulation parallelisation](@refode_simulation_performance_parallelisation). Here we provide a short tutorial on how to perform parallel ensemble simulations, with a more extensive documentation being available [here](https://docs.sciml.ai/DiffEqDocs/stable/features/ensemble/).
7
7
8
8
## [Monte Carlo simulations using unmodified conditions](@id ensemble_simulations_monte_carlo)
9
-
We will first consider Monte Carlo simulations where the simulation conditions are identical in-between simulations. First, we declare a [simple self-activation loop](@refref) model
9
+
We will first consider Monte Carlo simulations where the simulation conditions are identical in-between simulations. First, we declare a [simple self-activation loop](@refbasic_CRN_library_self_activation) model
We wish to simulate it as an SDE. Rather than performing a single simulation, however, we want to perform multiple ones. Here, we first create a normal `SDEProblem`, and use it as the single input to a `EnsembleProblem` (`EnsembleProblem` are created similarly for ODE and jump simulations, but the `ODEProblem` or `JumpProblem` is used instead).
21
21
```@example ensemble
22
+
using StochasticDiffEq
22
23
sprob = SDEProblem(sa_model, u0, tspan, ps)
23
24
eprob = EnsembleProblem(sprob)
24
25
nothing # hide
@@ -30,9 +31,10 @@ nothing # hide
30
31
```
31
32
Finally, we can use our ensemble simulation solution as input to `plot` (just like normal simulations):
32
33
```@example ensemble
34
+
using Plots
33
35
plot(sols; la = 0.5)
34
36
```
35
-
Here, each simulation is displayed as an individual trajectory. We also use the [`la` plotting option](@refref) to reduce the transparency of each individual line, improving the plot visual.
37
+
Here, each simulation is displayed as an individual trajectory. We also use the [`la` plotting option](@refsimulation_plotting_options) to reduce the transparency of each individual line, improving the plot visual.
36
38
37
39
Various convenience functions are available for analysing and plotting ensemble simulations (a full list can be found [here]). Here, we use these to first create an `EnsembleSummary` (retrieving each simulation's value at time points `0.0, 1.0, 2.0, ... 1000.0`). Next, we use this as an input to the `plot` command, which automatically plots the mean $X$ activity across the ensemble, while also displaying the 5% and 95% quantiles as the shaded area:
38
40
```@example ensemble
@@ -45,15 +47,16 @@ Previously, we assumed that each simulation used the same initial conditions and
45
47
46
48
Here, we first create an `ODEProblem` of our previous self-activation loop:
47
49
```@example ensemble
48
-
oprob = ODEProblem(sa_model, u0, tspan, p)
50
+
using OrdinaryDiffEq
51
+
oprob = ODEProblem(sa_model, u0, tspan, ps)
49
52
nothing # hide
50
53
```
51
54
Next, we wish to simulate the model for a range of initial conditions of $X$`. To do this we create a problem function, which takes the following arguments:
52
55
-`prob`: The problem given to our `EnsembleProblem` (which is the problem that `prob_func` modifies in each iteration).
53
56
-`i`: The number of this specific Monte Carlo iteration in the interval `1:trajectories`.
54
57
-`repeat`: The iteration of the repeat of the simulation. Typically `1`, but potentially higher if [the simulation re-running option](https://docs.sciml.ai/DiffEqDocs/stable/features/ensemble/#Building-a-Problem) is used.
55
58
56
-
Here we will use the following problem function (utilising [remake](@refref)), which will provide a uniform range of initial concentrations of $X$:
59
+
Here we will use the following problem function (utilising [remake](@refsimulation_structure_interfacing_problems_remake)), which will provide a uniform range of initial concentrations of $X$:
Copy file name to clipboardExpand all lines: docs/src/model_simulation/ode_simulation_performance.md
+11-12Lines changed: 11 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,7 @@ Generally, this short checklist provides a quick guide for dealing with ODE perf
13
13
## [Regarding stiff and non-stiff problems and solvers](@id ode_simulation_performance_stiffness)
14
14
Generally, ODE problems can be categorised into [*stiff ODEs* and *non-stiff ODEs*](https://en.wikipedia.org/wiki/Stiff_equation). This categorisation is important due to stiff ODEs requiring specialised solvers. A common cause of failure to simulate an ODE is the use of a non-stiff solver for a stiff problem. There is no exact way to determine whether a given ODE is stiff or not, however, systems with several different time scales (e.g. a CRN with both slow and fast reactions) typically generate stiff ODEs.
15
15
16
-
Here we simulate the (stiff) [Brusselator](@refref) model using the `Tsit5` solver (which is designed for non-stiff ODEs):
16
+
Here we simulate the (stiff) [Brusselator](@refbasic_CRN_library_brusselator) model using the `Tsit5` solver (which is designed for non-stiff ODEs):
17
17
```@example ode_simulation_performance_1
18
18
using Catalyst, OrdinaryDiffEq, Plots
19
19
@@ -52,7 +52,7 @@ Finally, we should note that stiffness is not tied to the model equations only.
OrdinaryDiffEq implements an unusually large number of ODE solvers, with the performance of the simulation heavily depending on which one is chosen. These are provided as the second argument to the `solve` command, e.g. here we use the `Tsit5` solver to simulate a simple [birth-death process](@refref):
55
+
OrdinaryDiffEq implements an unusually large number of ODE solvers, with the performance of the simulation heavily depending on which one is chosen. These are provided as the second argument to the `solve` command, e.g. here we use the `Tsit5` solver to simulate a simple [birth-death process](@refbasic_CRN_library_bd):
56
56
```@example ode_simulation_performance_2
57
57
using Catalyst, OrdinaryDiffEq
58
58
@@ -123,7 +123,7 @@ nothing # hide
123
123
### [Using a sparse Jacobian](@id ode_simulation_performance_sparse_jacobian)
124
124
For a system with $n$ variables, the Jacobian will be an $n\times n$ matrix. This means that, as $n$ becomes large, the Jacobian can become *very* large, potentially causing a significant strain on memory. In these cases, most Jacobian entries are typically $0$. This means that a [*sparse*](https://en.wikipedia.org/wiki/Sparse_matrix) Jacobian (rather than a *dense* one, which is the default) can be advantageous. To designate sparse Jacobian usage, simply provide the `sparse = true` option when constructing an `ODEProblem`:
@@ -172,10 +172,10 @@ Generally, the use of preconditioners is only recommended for advanced users who
172
172
## [Parallelisation on CPUs and GPUs](@id ode_simulation_performance_parallelisation)
173
173
Whenever an ODE is simulated a large number of times (e.g. when investigating its behaviour for different parameter values), the best way to improve performance is to [parallelise the simulation over multiple processing units](https://en.wikipedia.org/wiki/Parallel_computing). Indeed, an advantage of the Julia programming language is that it was designed after the advent of parallel computing, making it well-suited for this task. Roughly, parallelisation can be divided into parallelisation on [CPUs](https://en.wikipedia.org/wiki/Central_processing_unit) and on [GPUs](https://en.wikipedia.org/wiki/General-purpose_computing_on_graphics_processing_units). CPU parallelisation is most straightforward, while GPU parallelisation requires specialised ODE solvers (which Catalyst have access to).
174
174
175
-
Both CPU and GPU parallelisation require first building an `EnsembleProblem` (which defines the simulations you wish to perform) and then supplying this with the correct parallelisation options. These have [previously been introduced in Catalyst's documentation](@refref) (but in the context of convenient bundling of similar simulations, rather than to improve performance), with a more throughout description being found in [OrdinaryDiffEq's documentation](https://docs.sciml.ai/DiffEqDocs/stable/features/ensemble/#ensemble). Finally, a general documentation of parallel computing in Julia is available [here](https://docs.julialang.org/en/v1/manual/parallel-computing/).
175
+
Both CPU and GPU parallelisation require first building an `EnsembleProblem` (which defines the simulations you wish to perform) and then supplying this with the correct parallelisation options. `EnsembleProblem`s have [previously been introduced in Catalyst's documentation](@refensemble_simulations) (but in the context of convenient bundling of similar simulations, rather than to improve performance), with a more throughout description being found in [OrdinaryDiffEq's documentation](https://docs.sciml.ai/DiffEqDocs/stable/features/ensemble/#ensemble). Finally, a general documentation of parallel computing in Julia is available [here](https://docs.julialang.org/en/v1/manual/parallel-computing/).
For this example (and the one for GPUs), we will consider a modified [Michaelis-Menten enzyme kinetics model](@refref), which describes an enzyme ($E$) that converts a substrate ($S$) to a product ($P$):
178
+
For this example (and the one for GPUs), we will consider a modified [Michaelis-Menten enzyme kinetics model](@refbasic_CRN_library_mm), which describes an enzyme ($E$) that converts a substrate ($S$) to a product ($P$):
179
179
```@example ode_simulation_performance_4
180
180
using Catalyst
181
181
mm_model = @reaction_network begin
@@ -186,12 +186,12 @@ mm_model = @reaction_network begin
186
186
end
187
187
```
188
188
The model can be simulated, showing how $P$ is produced from $S$:
and output the `ODEProblem` simulated in the i'th simulation.
210
210
211
-
Let us assume that we wish to simulate our model 100 times, for $kP = 0.01, 0.02, ..., 0.99, 1.0$. We define our `prob_func` using [`remake`](@refref):
211
+
Let us assume that we wish to simulate our model 100 times, for $kP = 0.01, 0.02, ..., 0.99, 1.0$. We define our `prob_func` using [`remake`](@refsimulation_structure_interfacing_problems_remake):
To utilise multiple processes, you must first give Julia access to these. You can check how many processes are available using the `nprocs` (which requires the [Distributed.jl](https://github.com/JuliaLang/Distributed.jl) package):
243
-
```julia
243
+
```@example ode_simulation_performance_4
244
244
using Distributed
245
245
nprocs()
246
246
```
247
247
Next, more processes can be added using `addprocs`. E.g. here we add an additional 4 processes:
248
-
```julia
248
+
```@example ode_simulation_performance_4
249
249
addprocs(4)
250
250
nothing # hide
251
251
```
@@ -309,7 +309,6 @@ Generally, it is recommended to use `EnsembleGPUArray` for large models (that ha
0 commit comments