4
4
This tutorial will show how to define the entire Symbolic Indexing Interface on an
5
5
` ExampleSystem ` :
6
6
7
- ``` julia
7
+ ``` @example implementing_sii
8
+ using SymbolicIndexingInterface
8
9
struct ExampleSystem
9
10
state_index::Dict{Symbol,Int}
10
11
parameter_index::Dict{Symbol,Int}
@@ -24,7 +25,7 @@ supports specific functionality. Consider the following struct, which needs to i
24
25
25
26
These are the simple functions which describe how to turn symbols into indices.
26
27
27
- ``` julia
28
+ ``` @example implementing_sii
28
29
function SymbolicIndexingInterface.is_variable(sys::ExampleSystem, sym)
29
30
haskey(sys.state_index, sym)
30
31
end
65
66
66
67
SymbolicIndexingInterface.constant_structure(::ExampleSystem) = true
67
68
68
- function SymbolicIndexingInterface. all_solvable_symbols (sys:: ExampleSystem )
69
+ function SymbolicIndexingInterface.all_variable_symbols (sys::ExampleSystem)
69
70
return vcat(
70
71
collect(keys(sys.state_index)),
71
72
collect(keys(sys.observed)),
74
75
75
76
function SymbolicIndexingInterface.all_symbols(sys::ExampleSystem)
76
77
return vcat(
77
- all_solvable_symbols (sys),
78
+ all_variable_symbols (sys),
78
79
collect(keys(sys.parameter_index)),
79
80
sys.independent_variable === nothing ? Symbol[] : sys.independent_variable
80
81
)
90
91
These are for handling symbolic expressions and generating equations which are not directly
91
92
in the solution vector.
92
93
93
- ``` julia
94
+ ``` @example implementing_sii
94
95
using RuntimeGeneratedFunctions
95
96
RuntimeGeneratedFunctions.init(@__MODULE__)
96
97
@@ -167,7 +168,7 @@ not typically useful for solution objects, it may be useful for integrators. Typ
167
168
the default implementations for ` getp ` and ` setp ` will suffice, and manually defining
168
169
them is not necessary.
169
170
170
- ``` julia
171
+ ``` @example implementing_sii
171
172
function SymbolicIndexingInterface.parameter_values(sys::ExampleSystem)
172
173
sys.p
173
174
end
@@ -183,7 +184,7 @@ the system's symbols. This also requires that the type implement
183
184
184
185
Consider the following ` ExampleIntegrator `
185
186
186
- ``` julia
187
+ ``` @example implementing_sii
187
188
mutable struct ExampleIntegrator
188
189
u::Vector{Float64}
189
190
p::Vector{Float64}
@@ -199,8 +200,8 @@ SymbolicIndexingInterface.current_time(sys::ExampleIntegrator) = sys.t
199
200
```
200
201
201
202
Then the following example would work:
202
- ``` julia
203
- sys = ExampleSystem (Dict (:x => 1 , :y => 2 , :z => 3 ), Dict (:a => 1 , :b => 2 ), :t , Dict ())
203
+ ``` @example implementing_sii
204
+ sys = ExampleSystem(Dict(:x => 1, :y => 2, :z => 3), Dict(:a => 1, :b => 2), :t, Dict(), Dict() )
204
205
integrator = ExampleIntegrator([1.0, 2.0, 3.0], [4.0, 5.0], 6.0, sys)
205
206
getx = getsym(sys, :x)
206
207
getx(integrator) # 1.0
@@ -289,7 +290,7 @@ interface and allows using [`getp`](@ref) and [`setp`](@ref) to get and set para
289
290
values. This allows for a cleaner interface for parameter indexing. Consider the
290
291
following example for ` ExampleIntegrator ` :
291
292
292
- ``` julia
293
+ ``` @example implementing_sii
293
294
function Base.getproperty(obj::ExampleIntegrator, sym::Symbol)
294
295
if sym === :ps
295
296
return ParameterIndexingProxy(obj)
301
302
302
303
This enables the following API:
303
304
304
- ``` julia
305
- integrator = ExampleIntegrator ([1.0 , 2.0 , 3.0 ], [4.0 , 5.0 ], 6.0 , Dict ( :x => 1 , :y => 2 , :z => 3 ), Dict ( :a => 1 , :b => 2 ), :t )
305
+ ``` @example implementing_sii
306
+ integrator = ExampleIntegrator([1.0, 2.0, 3.0], [4.0, 5.0], 6.0, sys )
306
307
307
308
integrator.ps[:a] # 4.0
308
309
getp(integrator, :a)(integrator) # functionally the same as above
@@ -311,6 +312,11 @@ integrator.ps[:b] = 3.0
311
312
setp(integrator, :b)(integrator, 3.0) # functionally the same as above
312
313
```
313
314
315
+ The parameters will display as a table:
316
+ ``` @example implementing_sii
317
+ integrator.ps
318
+ ```
319
+
314
320
## Parameter Timeseries
315
321
316
322
If a solution object includes modified parameter values (such as through callbacks) during the
0 commit comments