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/simulation_structure_interfacing.md
+17-31Lines changed: 17 additions & 31 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
# [Interfacing problems, integrators, and solutions](@id simulation_structure_interfacing)
2
2
When simulating a model, one begins with creating a [problem](https://docs.sciml.ai/DiffEqDocs/stable/basics/problem/). Next, a simulation is performed on the problem, during which the simulation's state is recorded through an [integrator](https://docs.sciml.ai/DiffEqDocs/stable/basics/integrator/). Finally, the simulation output is returned as a [solution](https://docs.sciml.ai/DiffEqDocs/stable/basics/solution/). This tutorial describes how to access (or modify) the state (or parameter) values of problem, integrator, and solution structures.
3
3
4
-
Generally, when we have a structure `simulation_struct` and want to interface with the unknown (or parameter) `x`, we use `simulation_struct[:x]` to access the value, and `simulation_struct[:x] = 5.0` to set it to a new value. For situations where a value is accessed (or changed) a large number of times, it can *improve performance* to first create a [specialised getter/setter function](@ref simulation_structure_interfacing_functions).
4
+
Generally, when we have a structure `simulation_struct` and want to interface with the unknown (or parameter) `x`, we use `simulation_struct[:x]` to access the value. For situations where a value is accessed (or changed) a large number of times, it can *improve performance* to first create a [specialised getter/setter function](@ref simulation_structure_interfacing_functions).
5
5
6
6
## [Interfacing problem objects](@id simulation_structure_interfacing_problems)
7
7
@@ -35,26 +35,6 @@ To retrieve several species initial condition (or parameter) values, simply give
35
35
oprob[[:S₁, :S₂]]
36
36
```
37
37
38
-
We can change a species's initial condition value using a similar notation. Here we increase the initial concentration of $C$ (and also confirm that the new value is stored in an updated `oprob`):
39
-
```@example structure_indexing
40
-
oprob[:C] = 0.1
41
-
oprob[:C]
42
-
```
43
-
Again, parameter values can be changed using a similar notation, however, again requiring `oprob.ps` notation:
44
-
```@example structure_indexing
45
-
oprob.ps[:k₁] = 10.0
46
-
oprob.ps[:k₁]
47
-
```
48
-
Finally, vectors can be used to update multiple quantities simultaneously
49
-
```@example structure_indexing
50
-
oprob[[:S₁, :S₂]] = [0.5, 0.3]
51
-
oprob[[:S₁, :S₂]]
52
-
```
53
-
Generally, when updating problems, it is often better to use the [`remake` function](@ref simulation_structure_interfacing_problems_remake) (especially when several values are updated).
54
-
55
-
!!! warn
56
-
Indexing *should not* be used not modify `JumpProblem`s. Here, [remake](@ref simulation_structure_interfacing_problems_remake) should be used exclusively.
57
-
58
38
A problem's time span can be accessed through the `tspan` field:
59
39
```@example structure_indexing
60
40
oprob.tspan
@@ -64,8 +44,8 @@ oprob.tspan
64
44
Here we have used an `ODEProblem`to demonstrate all interfacing functionality. However, identical workflows work for the other problem types.
65
45
66
46
### [Remaking problems using the `remake` function](@id simulation_structure_interfacing_problems_remake)
67
-
The `remake` function offers an (to indexing) alternative approach for updating problems. Unlike indexing, `remake` creates a new problem (rather than updating the old one). Furthermore, it permits the updating of several values simultaneously. The `remake` function takes the following inputs:
68
-
- The problem that is remakes.
47
+
To modify a problem, the `remake` function should be used. It takes an already created problem, and returns a new, updated, one (the input problem is unchanged). The `remake` function takes the following inputs:
48
+
- The problem that it remakes.
69
49
- (optionally) `u0`: A vector with initial conditions that should be updated. The vector takes the same form as normal initial condition vectors, but does not need to be complete (in which case only a subset of the initial conditions are updated).
70
50
- (optionally) `tspan`: An updated time span (using the same format as time spans normally are given in).
71
51
- (optionally) `p`: A vector with parameters that should be updated. The vector takes the same form as normal parameter vectors, but does not need to be complete (in which case only a subset of the parameters are updated).
@@ -74,22 +54,28 @@ Here we modify our problem to increase the initial condition concentrations of t
Typically, when using `remake` to update a problem, the common workflow is to overwrite the old one with the output. E.g. to set the value of `k₁` to `5.0` in `oprob`, you would do:
During a simulation, the solution is stored in an integrator object. Here, we will describe how to interface with these. The almost exclusive circumstance when integrator-interfacing is relevant is when simulation events are implemented through callbacks. However, to demonstrate integrator indexing in this tutorial, we will create one through the `init` function (while circumstances where one might [want to use `init` function exist](https://docs.sciml.ai/DiffEqDocs/stable/basics/integrator/#Initialization-and-Stepping), since integrators are automatically created during simulations, these are rare).
73
+
During a simulation, the solution is stored in an integrator object. Here, we will describe how to interface with these. The almost exclusive circumstance when integrator-interfacing is relevant is when simulation events are implemented through [callbacks](https://docs.sciml.ai/DiffEqDocs/stable/features/callback_functions/). However, to demonstrate integrator indexing in this tutorial, we will create one through the `init` function (while circumstances where one might [want to use `init` function exist](https://docs.sciml.ai/DiffEqDocs/stable/basics/integrator/#Initialization-and-Stepping), since integrators are automatically created during simulations, these are rare).
88
74
```@example structure_indexing
89
75
integrator = init(oprob)
90
76
nothing # hide
91
77
```
92
-
We can interface with our integrator using an identical syntax as [was used for problems](@ref simulation_structure_interfacing_problems) (with the exception that `remake`is not available). Here we update, and then check the values of, first the species $C$ and then the parameter $k₁$:
78
+
We can interface with our integrator using an identical syntax as [was used for problems](@ref simulation_structure_interfacing_problems). The primary exception is that there is no `remake`function for integrators. Instead, we can update species and parameter values using normal indexing. Here we update, and then check the values of, first the species $C$ and then the parameter $k₁$:
93
79
```@example structure_indexing
94
80
integrator[:C] = 0.0
95
81
integrator[:C]
@@ -164,7 +150,7 @@ get_S(oprob)
164
150
## [Interfacing using symbolic representations](@id simulation_structure_interfacing_symbolic_representation)
165
151
When e.g. [programmatic modelling is used](@ref programmatic_CRN_construction), species and parameters can be represented as *symbolic variables*. These can be used to index a problem, just like symbol-based representations can. Here we create a simple [two-state model](@ref basic_CRN_library_two_states) programmatically, and use its symbolic variables to check, and update, an initial condition:
Symbolic variables can be used to access or update species or parameters for all the cases when `Symbol`s can (including when using `remake` or e.g. `getu`).
This can be used to form symbolic expressions using model quantities when a model has been created using the DSL (as an alternative to @unpack). Alternatively, [creating an observable](@ref dsl_advanced_options_observables), and then interface using its `Symbol` representation, is also possible.
198
184
199
-
!!! warn
200
-
With interfacing with a simulating structure using symbolic variables stored in a `ReactionSystem` model, ensure that the model is complete.
185
+
!!! warning
186
+
When accessing a simulation structure using symbolic variables from a `ReactionSystem` model, such as `rn.A` for `rn` a `ReactionSystem` and `A` a species within it, ensure that the model is complete.
0 commit comments