Skip to content

Commit 4506fdf

Browse files
committed
small changes
1 parent b9731d8 commit 4506fdf

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

docs/src/introduction_to_catalyst/catalyst_for_new_julia_users.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@ To import a Julia package into a session, you can use the `using PackageName` co
5555
using Pkg
5656
Pkg.add("Catalyst")
5757
```
58-
Here, the Julia package manager package (`Pkg`) is by default installed on your computer when Julia is installed, and can be activated directly. Next, we also wish to install the `DifferentialEquations` and `Plots` packages (for numeric simulation of models, and plotting, respectively).
58+
Here, the Julia package manager package (`Pkg`) is by default installed on your computer when Julia is installed, and can be activated directly. Next, we also wish to install the `OrdinaryDiffEq` and `Plots` packages (for numeric simulation of models, and plotting, respectively).
5959
```julia
60-
Pkg.add("DifferentialEquations")
60+
Pkg.add("OrdinaryDiffEq")
6161
Pkg.add("Plots")
6262
```
6363
Once a package has been installed through the `Pkg.add` command, this command does not have to be repeated if we restart our Julia session. We can now import all three packages into our current session with:
6464
```@example ex2
6565
using Catalyst
66-
using DifferentialEquations
66+
using OrdinaryDiffEq
6767
using Plots
6868
```
6969
Here, if we restart Julia, these `using` commands *must be rerun*.
@@ -130,7 +130,11 @@ For more information about the numerical simulation package, please see the [Dif
130130
## Additional modelling example
131131
To make this introduction more comprehensive, we here provide another example, using a more complicated model. Instead of simulating our model as concentrations evolve over time, we will now simulate the individual reaction events through the [Gillespie algorithm](https://en.wikipedia.org/wiki/Gillespie_algorithm) (a common approach for adding *noise* to models).
132132

133-
Remember (unless we have restarted Julia) we do not need to activate our packages (through the `using` command) again.
133+
Remember (unless we have restarted Julia) we do not need to activate our packages (through the `using` command) again. However, we do need to install, and then import, the JumpProcesses package (just to perform Gillespie, and other jump, simulations)
134+
```julia
135+
Pkg.add("JumpProcesses")
136+
using JumpProcesses
137+
```
134138

135139
This time, we will declare a so-called [SIR model for an infectious disease](https://en.wikipedia.org/wiki/Compartmental_models_in_epidemiology#The_SIR_model). Note that even if this model does not describe a set of chemical reactions, it can be modelled using the same framework. The model consists of 3 species:
136140
* $S$, the amount of *susceptible* individuals.
@@ -164,12 +168,13 @@ nothing # hide
164168

165169
Previously we have bundled this information into an `ODEProblem` (denoting a deterministic *ordinary differential equation*). Now we wish to simulate our model as a jump process (where each reaction event corresponds to a single jump in the state of the system). We do this by first creating a `DiscreteProblem`, and then using this as an input to a `JumpProblem`.
166170
```@example ex2
171+
using JumpProcesses # hide
167172
dprob = DiscreteProblem(sir_model, u0, tspan, params)
168173
jprob = JumpProblem(sir_model, dprob, Direct())
169174
```
170175
Again, the order in which the inputs are given to the `DiscreteProblem` and the `JumpProblem` is important. The last argument to the `JumpProblem` (`Direct()`) denotes which simulation method we wish to use. For now, we recommend that users simply use the `Direct()` option, and then consider alternative ones (see the [JumpProcesses.jl docs](https://docs.sciml.ai/JumpProcesses/stable/)) when they are more familiar with modelling in Catalyst and Julia.
171176

172-
Finally, we can simulate our model using the `solve` function, and plot the solution using the `plot` function. Here, the `solve` function also has a second argument (`SSAStepper()`). This is a time-stepping algorithm that calls the `Direct` solver to advance a simulation. Again, we recommend at this stage you simply use this option, and then explore exactly what this means at a later stage.
177+
Finally, we can simulate our model using the `solve` function, and plot the solution using the `plot` function. For jump simulations, the `solve` function also requires a second argument (`SSAStepper()`). This is a time-stepping algorithm that calls the `Direct` solver to advance a simulation. Again, we recommend at this stage you simply use this option, and then explore exactly what this means at a later stage.
173178
```@example ex2
174179
sol = solve(jprob, SSAStepper())
175180
sol = solve(jprob, SSAStepper(); seed=1234) # hide

docs/src/model_simulation/ode_simulation_performance.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,17 +235,17 @@ plot(0.01:0.01:1.0, map(sol -> sol[:P][end], esol.u), xguide = "kP", yguide = "P
235235
```
236236

237237
Above, we have simply used `EnsembleProblem` as a convenient interface to run a large number of similar simulations. However, these problems have the advantage that they allow the passing of an *ensemble algorithm* to the `solve` command, which describes a strategy for parallelising the simulations. By default, `EnsembleThreads` is used. This parallelises the simulations using [multithreading](https://en.wikipedia.org/wiki/Multithreading_(computer_architecture)) (parallelisation within a single process), which is typically advantageous for small problems on shared memory devices. An alternative is `EnsembleDistributed` which instead parallelises the simulations using [multiprocessing](https://en.wikipedia.org/wiki/Multiprocessing) (parallelisation across multiple processes). To do this, we simply supply this additional solver to the solve command:
238-
```@example ode_simulation_performance_4
238+
```julia
239239
esol = solve(eprob, Tsit5(), EnsembleDistributed(); trajectories=100)
240240
nothing # hide
241241
```
242242
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-
```@example ode_simulation_performance_4
243+
```julia
244244
using Distributed
245245
nprocs()
246246
```
247247
Next, more processes can be added using `addprocs`. E.g. here we add an additional 4 processes:
248-
```@example ode_simulation_performance_4
248+
```julia
249249
addprocs(4)
250250
nothing # hide
251251
```
@@ -268,7 +268,7 @@ Furthermore (while not required) to receive good performance, we should also mak
268268
- We should designate all our vectors (i.e. initial conditions and parameter values) as [static vectors](https://github.com/JuliaArrays/StaticArrays.jl).
269269

270270
We will assume that we are using the CUDA GPU hardware, so we will first load the [CUDA.jl](https://github.com/JuliaGPU/CUDA.jl) backend package, as well as DiffEqGPU:
271-
```@example ode_simulation_performance_5
271+
```julia
272272
using CUDA, DiffEqGPU
273273
```
274274
Which backend package you should use depends on your available hardware, with the alternatives being listed [here](https://docs.sciml.ai/DiffEqGPU/stable/manual/backends/).
@@ -306,7 +306,7 @@ We can now simulate our model using a GPU-based ensemble algorithm. Currently, t
306306
- While `EnsembleGPUArray` can use standard ODE solvers, `EnsembleGPUKernel` requires specialised versions (such as `GPUTsit5`). A list of available such solvers can be found [here](https://docs.sciml.ai/DiffEqGPU/dev/manual/ensemblegpukernel/#specialsolvers).
307307

308308
Generally, it is recommended to use `EnsembleGPUArray` for large models (that have at least $100$ variables), and `EnsembleGPUKernel` for smaller ones. Here we simulate our model using both approaches (noting that `EnsembleGPUKernel` requires `GPUTsit5`):
309-
```@example ode_simulation_performance_5
309+
```julia
310310
esol1 = solve(eprob, Tsit5(), EnsembleGPUArray(CUDA.CUDABackend()); trajectories = 10000)
311311
esol2 = solve(eprob, GPUTsit5(), EnsembleGPUKernel(CUDA.CUDABackend()); trajectories = 10000)
312312
nothing # hide

test/dsl/dsl_basic_model_construction.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,3 +438,4 @@ let
438438
@test_throws LoadError @eval @reaction k, 0 --> nothing
439439
end
440440

441+

0 commit comments

Comments
 (0)