Skip to content

Commit 4bb6a20

Browse files
docs: define index- and value- provider interfaces
also update all existing docstrings and restructure `api.md`
1 parent b5d7e18 commit 4bb6a20

14 files changed

+379
-311
lines changed

docs/pages.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
pages = [
44
"Home" => "index.md",
5+
"Terminology" => "terminology.md",
56
"Tutorials" => [
67
"Using the SciML Symbolic Indexing Interface" => "usage.md",
78
"Simple Demonstration of a Symbolic System Structure" => "simple_sii_sys.md",

docs/src/api.md

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Interface Functions
22

3-
## Mandatory methods
3+
## Index provider interface
4+
5+
### Mandatory methods
46

57
```@docs
68
symbolic_container
@@ -22,14 +24,16 @@ solvedvariables
2224
allvariables
2325
```
2426

25-
## Optional Methods
27+
### Optional Methods
2628

27-
### Observed equation handling
29+
#### Observed equation handling
2830

2931
```@docs
3032
observed
3133
```
3234

35+
## Value provider interface
36+
3337
### Parameter indexing
3438

3539
```@docs
@@ -41,6 +45,19 @@ setp
4145
ParameterIndexingProxy
4246
```
4347

48+
#### Parameter timeseries
49+
50+
If a solution object saves a timeseries of parameter values that are updated during the
51+
simulation (such as by callbacks), it must implement the following methods to ensure
52+
correct functioning of [`getu`](@ref) and [`getp`](@ref).
53+
54+
```@docs
55+
parameter_timeseries
56+
parameter_values_at_time
57+
parameter_values_at_state_time
58+
```
59+
60+
4461
### State indexing
4562

4663
```@docs
@@ -54,22 +71,17 @@ getu
5471
setu
5572
```
5673

57-
## Container objects
74+
### Batched Queries and Updates
5875

5976
```@docs
60-
remake_buffer
77+
BatchedInterface
78+
associated_systems
6179
```
6280

63-
### Parameter timeseries
64-
65-
If a solution object saves a timeseries of parameter values that are updated during the
66-
simulation (such as by callbacks), it must implement the following methods to ensure
67-
correct functioning of [`getu`](@ref) and [`getp`](@ref).
81+
## Container objects
6882

6983
```@docs
70-
parameter_timeseries
71-
parameter_values_at_time
72-
parameter_values_at_state_time
84+
remake_buffer
7385
```
7486

7587
# Symbolic Trait
@@ -90,10 +102,3 @@ symbolic_evaluate
90102
SymbolCache
91103
ProblemState
92104
```
93-
94-
### Batched Queries and Updates
95-
96-
```@docs
97-
BatchedInterface
98-
associated_systems
99-
```

docs/src/terminology.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Terminology
2+
3+
SymbolicIndexingInterface.jl uses various library-specific terminology throughout its
4+
documentation. This page attempts to provide comprehensive explanations of the terms
5+
used.
6+
7+
## Indexes
8+
9+
An index is an object that defines how to extract specific data from a data structure.
10+
Indexes may be anything from integer indexes into arrays, to custom types that contain
11+
information specific to a particular data structure.
12+
13+
In code samples, an index is typically denoted with the name `idx` or `i`.
14+
15+
## Symbolic variables
16+
17+
Symbolic variables are objects that represent quantities (states, parameters, time, etc.)
18+
or collections of quantities used in a numerical simulation in a more human-accessible
19+
manner. Typically the values of these quantities are stored in custom data structures
20+
and referred to using indexes that do not convey any semantic meaning to users. Symbolic
21+
variables cannot directly be used to access values from these data structures and need
22+
to be translated into indexes.
23+
24+
In code samples, a symbolic variable is typically denoted with the name `sym`.
25+
26+
Symbolic variables are also sometimes referred to as "symbolic indices".
27+
28+
## Index providers
29+
30+
Index providers translate symbolic variables into indexes. In general, an "index" can
31+
be anything from integer indexes into an array, or custom types that define how to
32+
index into complicated data structures. `nothing` is reserved to denote the absence of
33+
an index, in cases where the index provider is unaware of a particular symbolic variable.
34+
It cannot be used as an index. ModelingToolkit.jl systems are examples of index providers.
35+
36+
In code samples, an index provider is typically denoted with the name `indp`.
37+
38+
## Value providers
39+
40+
Value providers store values of symbolic variables. Given an appropriate index from an
41+
index provider, value providers return the value (or values) stored at that index. The
42+
problem, integrator and solution types in SciML are all examples of value providers.
43+
Each value provider is (directly or indirectly) associated with an index provider that
44+
defines the set of valid symbolic variables for that value provider, and the corresponding
45+
indexes.
46+
47+
A value provider may not store values for all symbolic variables in the corresponding index
48+
provider. For example, a parameter object (even a plain `Array` storing parameter values)
49+
is a value provider specifically for the symbolic variables referring to parameters.
50+
51+
In code samples, a value provider is typically denoted with the name `valp`.
52+
53+
!!! note
54+
It is important to note that an object may be both a value- and index- provider. For
55+
example, SciML's problem, integrator and solution types are both value- and index-
56+
providers. This allows for several syntactic improvements. The [`symbolic_container`](@ref)
57+
function is useful in defining such objects.
58+
59+
!!! note "Timeseries objects"
60+
The documentation uses "Timeseries objects" to refer to value providers which implement
61+
the [`Timeseries`](@ref) variant of the [`is_timeseries`](@ref) trait.

src/SymbolicIndexingInterface.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export is_variable, variable_index, variable_symbols, is_parameter, parameter_in
1717
observed, is_time_dependent, constant_structure, symbolic_container,
1818
all_variable_symbols,
1919
all_symbols, solvedvariables, allvariables, default_values, symbolic_evaluate
20-
include("interface.jl")
20+
include("index_provider_interface.jl")
2121

2222
export SymbolCache
2323
include("symbol_cache.jl")

src/batched_interface.jl

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
"""
22
struct BatchedInterface{S <: AbstractVector, I}
3-
function BatchedInterface(syssyms::Tuple...)
3+
function BatchedInterface(indp_syms::Tuple...)
44
55
A struct which stores information for batched calls to [`getu`](@ref) or [`setu`](@ref).
6-
Given `Tuple`s, where the first element of each tuple is a system and the second an
7-
array of symbols (either variables or parameters) in the system, `BatchedInterface` will
8-
compute the union of all symbols and associate each symbol with the first system with
9-
which it occurs.
6+
Given `Tuple`s, where the first element of each tuple is an index provider and the second
7+
an array of symbolic variables (either states or parameters) in the index provider,
8+
`BatchedInterface` will compute the union of all symbols and associate each symbol with
9+
the first index provider with which it occurs.
1010
11-
For example, given two systems `s1 = SymbolCache([:x, :y, :z])` and
11+
For example, given two index providers `s1 = SymbolCache([:x, :y, :z])` and
1212
`s2 = SymbolCache([:y, :z, :w])`, `BatchedInterface((s1, [:x, :y]), (s2, [:y, :z]))` will
1313
associate `:x` and `:y` with `s1` and `:z` with `s2`. The information that `s1` had
1414
associated symbols `:x` and `:y` and `s2` had associated symbols `:y` and `:z` will also
@@ -24,17 +24,17 @@ See also: [`associated_systems`](@ref).
2424
struct BatchedInterface{S <: AbstractVector, I, T}
2525
"Order of symbols in the union."
2626
symbol_order::S
27-
"Index of the system each symbol in the union is associated with."
27+
"Index of the index provider each symbol in the union is associated with."
2828
associated_systems::Vector{Int}
29-
"Index of symbol in the system it is associated with."
29+
"Index of symbol in the index provider it is associated with."
3030
associated_indexes::I
31-
"Whether the symbol is a state in the system it is associated with."
31+
"Whether the symbol is a state in the index provider it is associated with."
3232
isstate::BitVector
33-
"Map from system to indexes of its symbols in the union."
33+
"Map from index provider to indexes of its symbols in the union."
3434
system_to_symbol_subset::Vector{Vector{Int}}
35-
"Map from system to indexes of its symbols in the system."
35+
"Map from index provider to indexes of its symbols in the index provider."
3636
system_to_symbol_indexes::Vector{Vector{T}}
37-
"Map from system to whether each of its symbols is a state in the system."
37+
"Map from index provider to whether each of its symbols is a state in the index provider."
3838
system_to_isstate::Vector{BitVector}
3939
end
4040

@@ -102,26 +102,27 @@ is_variable(bi::BatchedInterface, sym) = variable_index(bi, sym) !== nothing
102102
associated_systems(bi::BatchedInterface)
103103
104104
Return an array of integers of the same length as `variable_symbols(bi)` where each value
105-
is the index of the system associated with the corresponding symbol in
105+
is the index of the index provider associated with the corresponding symbol in
106106
`variable_symbols(bi)`.
107107
"""
108108
associated_systems(bi::BatchedInterface) = bi.associated_systems
109109

110110
"""
111111
getu(bi::BatchedInterface)
112112
113-
Given a [`BatchedInterface`](@ref) composed from `n` systems (and corresponding symbols),
114-
return a function which takes `n` corresponding problems and returns an array of the values
115-
of the symbols in the union. The returned function can also be passed an `AbstractArray` of
116-
the appropriate `eltype` and size as its first argument, in which case the operation will
117-
populate the array in-place with the values of the symbols in the union.
113+
Given a [`BatchedInterface`](@ref) composed from `n` index providers (and corresponding
114+
symbols), return a function which takes `n` corresponding value providers and returns an
115+
array of the values of the symbols in the union. The returned function can also be passed
116+
an `AbstractArray` of the appropriate `eltype` and size as its first argument, in which
117+
case the operation will populate the array in-place with the values of the symbols in the
118+
union.
118119
119-
Note that all of the problems passed to the function returned by `getu` must satisfy
120+
Note that all of the value providers passed to the function returned by `getu` must satisfy
120121
`is_timeseries(prob) === NotTimeseries()`.
121122
122123
The value of the `i`th symbol in the union (obtained through `variable_symbols(bi)[i]`) is
123-
obtained from the problem corresponding to the associated system (i.e. the problem at
124-
index `associated_systems(bi)[i]`).
124+
obtained from the problem corresponding to the associated index provider (i.e. the value
125+
provider at index `associated_systems(bi)[i]`).
125126
126127
See also: [`variable_symbols`](@ref), [`associated_systems`](@ref), [`is_timeseries`](@ref),
127128
[`NotTimeseries`](@ref).
@@ -180,16 +181,16 @@ end
180181
"""
181182
setu(bi::BatchedInterface)
182183
183-
Given a [`BatchedInterface`](@ref) composed from `n` systems (and corresponding symbols),
184-
return a function which takes `n` corresponding problems and an array of the values, and
185-
updates each of the problems with the values of the corresponding symbols.
184+
Given a [`BatchedInterface`](@ref) composed from `n` index providers (and corresponding
185+
symbols), return a function which takes `n` corresponding problems and an array of the
186+
values, and updates each of the problems with the values of the corresponding symbols.
186187
187-
Note that all of the problems passed to the function returned by `setu` must satisfy
188+
Note that all of the value providers passed to the function returned by `setu` must satisfy
188189
`is_timeseries(prob) === NotTimeseries()`.
189190
190-
Note that if any subset of the `n` systems share common symbols (among those passed to
191-
`BatchedInterface`) then all of the corresponding problems in the subset will be updated
192-
with the values of the common symbols.
191+
Note that if any subset of the `n` index providers share common symbols (among those passed
192+
to `BatchedInterface`) then all of the corresponding value providers in the subset will be
193+
updated with the values of the common symbols.
193194
194195
See also: [`is_timeseries`](@ref), [`NotTimeseries`](@ref).
195196
"""

0 commit comments

Comments
 (0)