44This tutorial will show how to define the entire Symbolic Indexing Interface on an
55` ExampleSystem ` :
66
7- ``` julia
7+ ``` @example implementing_sii
8+ using SymbolicIndexingInterface
89struct ExampleSystem
910 state_index::Dict{Symbol,Int}
1011 parameter_index::Dict{Symbol,Int}
@@ -24,7 +25,7 @@ supports specific functionality. Consider the following struct, which needs to i
2425
2526These are the simple functions which describe how to turn symbols into indices.
2627
27- ``` julia
28+ ``` @example implementing_sii
2829function SymbolicIndexingInterface.is_variable(sys::ExampleSystem, sym)
2930 haskey(sys.state_index, sym)
3031end
6566
6667SymbolicIndexingInterface.constant_structure(::ExampleSystem) = true
6768
68- function SymbolicIndexingInterface. all_solvable_symbols (sys:: ExampleSystem )
69+ function SymbolicIndexingInterface.all_variable_symbols (sys::ExampleSystem)
6970 return vcat(
7071 collect(keys(sys.state_index)),
7172 collect(keys(sys.observed)),
7475
7576function SymbolicIndexingInterface.all_symbols(sys::ExampleSystem)
7677 return vcat(
77- all_solvable_symbols (sys),
78+ all_variable_symbols (sys),
7879 collect(keys(sys.parameter_index)),
7980 sys.independent_variable === nothing ? Symbol[] : sys.independent_variable
8081 )
9091These are for handling symbolic expressions and generating equations which are not directly
9192in the solution vector.
9293
93- ``` julia
94+ ``` @example implementing_sii
9495using RuntimeGeneratedFunctions
9596RuntimeGeneratedFunctions.init(@__MODULE__)
9697
@@ -167,7 +168,7 @@ not typically useful for solution objects, it may be useful for integrators. Typ
167168the default implementations for ` getp ` and ` setp ` will suffice, and manually defining
168169them is not necessary.
169170
170- ``` julia
171+ ``` @example implementing_sii
171172function SymbolicIndexingInterface.parameter_values(sys::ExampleSystem)
172173 sys.p
173174end
@@ -183,7 +184,7 @@ the system's symbols. This also requires that the type implement
183184
184185Consider the following ` ExampleIntegrator `
185186
186- ``` julia
187+ ``` @example implementing_sii
187188mutable struct ExampleIntegrator
188189 u::Vector{Float64}
189190 p::Vector{Float64}
@@ -199,8 +200,8 @@ SymbolicIndexingInterface.current_time(sys::ExampleIntegrator) = sys.t
199200```
200201
201202Then 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() )
204205integrator = ExampleIntegrator([1.0, 2.0, 3.0], [4.0, 5.0], 6.0, sys)
205206getx = getsym(sys, :x)
206207getx(integrator) # 1.0
@@ -289,7 +290,7 @@ interface and allows using [`getp`](@ref) and [`setp`](@ref) to get and set para
289290values. This allows for a cleaner interface for parameter indexing. Consider the
290291following example for ` ExampleIntegrator ` :
291292
292- ``` julia
293+ ``` @example implementing_sii
293294function Base.getproperty(obj::ExampleIntegrator, sym::Symbol)
294295 if sym === :ps
295296 return ParameterIndexingProxy(obj)
301302
302303This enables the following API:
303304
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 )
306307
307308integrator.ps[:a] # 4.0
308309getp(integrator, :a)(integrator) # functionally the same as above
@@ -312,7 +313,7 @@ setp(integrator, :b)(integrator, 3.0) # functionally the same as above
312313```
313314
314315The parameters will display as a table:
315- ``` @example show_params
316+ ``` @example implementing_sii
316317integrator.ps
317318```
318319
0 commit comments