Skip to content

Commit 0d92e7f

Browse files
committed
add to documentation
1 parent 2bfcbed commit 0d92e7f

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

docs/src/complete_sii.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
This 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
89
struct 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

2526
These are the simple functions which describe how to turn symbols into indices.
2627

27-
```julia
28+
```@example implementing_sii
2829
function SymbolicIndexingInterface.is_variable(sys::ExampleSystem, sym)
2930
haskey(sys.state_index, sym)
3031
end
@@ -65,7 +66,7 @@ end
6566
6667
SymbolicIndexingInterface.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)),
@@ -74,7 +75,7 @@ end
7475
7576
function 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
)
@@ -90,7 +91,7 @@ end
9091
These are for handling symbolic expressions and generating equations which are not directly
9192
in the solution vector.
9293

93-
```julia
94+
```@example implementing_sii
9495
using RuntimeGeneratedFunctions
9596
RuntimeGeneratedFunctions.init(@__MODULE__)
9697
@@ -167,7 +168,7 @@ not typically useful for solution objects, it may be useful for integrators. Typ
167168
the default implementations for `getp` and `setp` will suffice, and manually defining
168169
them is not necessary.
169170

170-
```julia
171+
```@example implementing_sii
171172
function SymbolicIndexingInterface.parameter_values(sys::ExampleSystem)
172173
sys.p
173174
end
@@ -183,7 +184,7 @@ the system's symbols. This also requires that the type implement
183184

184185
Consider the following `ExampleIntegrator`
185186

186-
```julia
187+
```@example implementing_sii
187188
mutable struct ExampleIntegrator
188189
u::Vector{Float64}
189190
p::Vector{Float64}
@@ -199,8 +200,8 @@ SymbolicIndexingInterface.current_time(sys::ExampleIntegrator) = sys.t
199200
```
200201

201202
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())
204205
integrator = ExampleIntegrator([1.0, 2.0, 3.0], [4.0, 5.0], 6.0, sys)
205206
getx = getsym(sys, :x)
206207
getx(integrator) # 1.0
@@ -289,7 +290,7 @@ interface and allows using [`getp`](@ref) and [`setp`](@ref) to get and set para
289290
values. This allows for a cleaner interface for parameter indexing. Consider the
290291
following example for `ExampleIntegrator`:
291292

292-
```julia
293+
```@example implementing_sii
293294
function Base.getproperty(obj::ExampleIntegrator, sym::Symbol)
294295
if sym === :ps
295296
return ParameterIndexingProxy(obj)
@@ -301,8 +302,8 @@ end
301302

302303
This 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
307308
integrator.ps[:a] # 4.0
308309
getp(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

314315
The parameters will display as a table:
315-
```@example show_params
316+
```@example implementing_sii
316317
integrator.ps
317318
```
318319

src/SymbolicIndexingInterface.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ include("batched_interface.jl")
4545
export ProblemState
4646
include("problem_state.jl")
4747

48-
export ParameterIndexingProxy, showparams
48+
export ParameterIndexingProxy, show_params
4949
include("parameter_indexing_proxy.jl")
5050

5151
export remake_buffer

src/parameter_indexing_proxy.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function Base.setindex!(p::ParameterIndexingProxy, val, idx)
1919
end
2020

2121
function Base.show(io::IO, ::MIME"text/plain", pip::ParameterIndexingProxy)
22-
showparams(io, pip; num_rows = 20, show_all = false, scalarize = true)
22+
show_params(io, pip; num_rows = 20, show_all = false, scalarize = true)
2323
end
2424

2525
"""
@@ -31,7 +31,7 @@ Method for customizing the table output. Keyword args:
3131
- scalarize: whether to scalarize array symbolics in the table output.
3232
- kwargs... are passed to the pretty_table call.
3333
"""
34-
function showparams(io::IO, pip::ParameterIndexingProxy; num_rows = 20,
34+
function show_params(io::IO, pip::ParameterIndexingProxy; num_rows = 20,
3535
show_all = false, scalarize = true, kwargs...)
3636
params = Any[]
3737
vals = Any[]

0 commit comments

Comments
 (0)