Skip to content

Commit 74cada4

Browse files
Merge pull request #2432 from AayushSabharwal/as/states-unknowns
refactor: rename states to unknowns, and related changes
2 parents 882f721 + ff1382a commit 74cada4

File tree

78 files changed

+666
-667
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+666
-667
lines changed

docs/src/basics/AbstractSystem.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Generally, it follows the order of:
2222

2323
1. Equations
2424
2. Independent Variables
25-
3. Dependent Variables (or States)
25+
3. Dependent Variables (or Unknowns)
2626
4. Parameters
2727

2828
All other pieces are handled via keyword arguments. `AbstractSystem`s share the
@@ -37,19 +37,19 @@ same keyword arguments, which are:
3737
## Composition and Accessor Functions
3838

3939
Each `AbstractSystem` has lists of variables in context, such as distinguishing
40-
parameters vs states. In addition, an `AbstractSystem` can also hold other
41-
`AbstractSystem` types. Direct accessing of the values, such as `sys.states`,
42-
gives the immediate list, while the accessor functions `states(sys)` gives the
40+
parameters vs unknowns. In addition, an `AbstractSystem` can also hold other
41+
`AbstractSystem` types. Direct accessing of the values, such as `sys.unknowns`,
42+
gives the immediate list, while the accessor functions `unknowns(sys)` gives the
4343
total set, which includes that of all systems held inside.
4444

4545
The values which are common to all `AbstractSystem`s are:
4646

4747
- `equations(sys)`: All equations that define the system and its subsystems.
48-
- `states(sys)`: All the states in the system and its subsystems.
48+
- `unknowns(sys)`: All the unknowns in the system and its subsystems.
4949
- `parameters(sys)`: All parameters of the system and its subsystems.
5050
- `nameof(sys)`: The name of the current-level system.
5151
- `get_eqs(sys)`: Equations that define the current-level system.
52-
- `get_states(sys)`: States that are in the current-level system.
52+
- `get_unknowns(sys)`: Unknowns that are in the current-level system.
5353
- `get_ps(sys)`: Parameters that are in the current-level system.
5454
- `get_systems(sys)`: Subsystems of the current-level system.
5555

@@ -129,7 +129,7 @@ pairs `var=>value`, which allows the user to designate the values without having
129129
to know the order that ModelingToolkit is internally using.
130130

131131
For the value maps, the parameters are allowed to be functions of each other,
132-
and value maps of states can be functions of the parameters, i.e. you can do:
132+
and value maps of unknowns can be functions of the parameters, i.e. you can do:
133133

134134
```
135135
u0 = [

docs/src/basics/Composition.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ an optional forcing function, and allowing the user to specify the
1212
forcing later. Here, the library author defines a component named
1313
`decay`. The user then builds two `decay` components and connects them,
1414
saying the forcing term of `decay1` is a constant while the forcing term
15-
of `decay2` is the value of the state variable `x`.
15+
of `decay2` is the value of the unknown variable `x`.
1616

1717
```@example composition
1818
using ModelingToolkit
@@ -70,18 +70,18 @@ subsystems. A model is the composition of itself and its subsystems.
7070
For example, if we have:
7171

7272
```julia
73-
@named sys = compose(ODESystem(eqs, indepvar, states, ps), subsys)
73+
@named sys = compose(ODESystem(eqs, indepvar, unknowns, ps), subsys)
7474
```
7575

7676
the `equations` of `sys` is the concatenation of `get_eqs(sys)` and
77-
`equations(subsys)`, the states are the concatenation of their states,
77+
`equations(subsys)`, the unknowns are the concatenation of their unknowns,
7878
etc. When the `ODEProblem` or `ODEFunction` is generated from this
7979
system, it will build and compile the functions associated with this
8080
composition.
8181

8282
The new equations within the higher level system can access the variables
8383
in the lower level system by namespacing via the `nameof(subsys)`. For
84-
example, let's say there is a variable `x` in `states` and a variable
84+
example, let's say there is a variable `x` in `unknowns` and a variable
8585
`x` in `subsys`. We can declare that these two variables are the same
8686
by specifying their equality: `x ~ subsys.x` in the `eqs` for `sys`.
8787
This algebraic relationship can then be simplified by transformations
@@ -133,7 +133,7 @@ sys = ODESystem(
133133
sys.y = u * 1.1
134134
```
135135

136-
In a hierarchical system, variables of the subsystem get namespaced by the name of the system they are in. This prevents naming clashes, but also enforces that every state and parameter is local to the subsystem it is used in. In some cases it might be desirable to have variables and parameters that are shared between subsystems, or even global. This can be accomplished as follows.
136+
In a hierarchical system, variables of the subsystem get namespaced by the name of the system they are in. This prevents naming clashes, but also enforces that every unknown and parameter is local to the subsystem it is used in. In some cases it might be desirable to have variables and parameters that are shared between subsystems, or even global. This can be accomplished as follows.
137137

138138
```julia
139139
@parameters t a b c d e f
@@ -186,12 +186,12 @@ i.e. equations which result in `0~0` expressions, in over-specified systems.
186186

187187
Model inheritance can be done in two ways: implicitly or explicitly. First, one
188188
can use the `extend` function to extend a base model with another set of
189-
equations, states, and parameters. An example can be found in the
189+
equations, unknowns, and parameters. An example can be found in the
190190
[acausal components tutorial](@ref acausal).
191191

192192
The explicit way is to shadow variables with equality expressions. For example,
193193
let's assume we have three separate systems which we want to compose to a single
194-
one. This is how one could explicitly forward all states and parameters to the
194+
one. This is how one could explicitly forward all unknowns and parameters to the
195195
higher level system:
196196

197197
```@example compose
@@ -225,7 +225,7 @@ sir = compose(ODESystem([
225225
reqn.γ => γ], name = :sir), seqn, ieqn, reqn)
226226
```
227227

228-
Note that the states are forwarded by an equality relationship, while
228+
Note that the unknowns are forwarded by an equality relationship, while
229229
the parameters are forwarded through a relationship in their default
230230
values. The user of this model can then solve this model simply by
231231
specifying the values at the highest level:
@@ -266,7 +266,7 @@ more efficient and more stable.
266266
## Components with discontinuous dynamics
267267

268268
When modeling, e.g., impacts, saturations or Coulomb friction, the dynamic
269-
equations are discontinuous in either the state or one of its derivatives. This
269+
equations are discontinuous in either the unknown or one of its derivatives. This
270270
causes the solver to take very small steps around the discontinuity, and
271271
sometimes leads to early stopping due to `dt <= dt_min`. The correct way to
272272
handle such dynamics is to tell the solver about the discontinuity by a

docs/src/basics/ContextualVariables.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ the `@variable` which is defined by
1010
@variables x y(x)
1111
```
1212

13-
This is used for the “normal” variable of a given system, like the states of a
13+
This is used for the “normal” variable of a given system, like the unknowns of a
1414
differential equation or objective function. All the macros below support
1515
the same syntax as `@variables`.
1616

1717
## Parameters
1818

1919
All modeling projects have some form of parameters. `@parameters` marks a variable
2020
as being the parameter of some system, which allows automatic detection algorithms
21-
to ignore such variables when attempting to find the states of a system.
21+
to ignore such variables when attempting to find the unknowns of a system.
2222

2323
## Constants
2424

docs/src/basics/Events.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ event conditions, and the second vector of equations describes the effect on the
4343
state. Each affect equation must be of the form
4444

4545
```julia
46-
single_state_variable ~ expression_involving_any_variables_or_parameters
46+
single_unknown_variable ~ expression_involving_any_variables_or_parameters
4747
```
4848

4949
or
@@ -151,13 +151,13 @@ of one or more equations, an affect is defined as a `tuple`:
151151
[x ~ 0] => (affect!, [v, x], [p, q], ctx)
152152
```
153153

154-
where, `affect!` is a Julia function with the signature: `affect!(integ, u, p, ctx)`; `[u,v]` and `[p,q]` are the symbolic states (variables) and parameters
154+
where, `affect!` is a Julia function with the signature: `affect!(integ, u, p, ctx)`; `[u,v]` and `[p,q]` are the symbolic unknowns (variables) and parameters
155155
that are accessed by `affect!`, respectively; and `ctx` is any context that is
156156
passed to `affect!` as the `ctx` argument.
157157

158158
`affect!` receives a [DifferentialEquations.jl
159159
integrator](https://docs.sciml.ai/DiffEqDocs/stable/basics/integrator/)
160-
as its first argument, which can then be used to access states and parameters
160+
as its first argument, which can then be used to access unknowns and parameters
161161
that are provided in the `u` and `p` arguments (implemented as `NamedTuple`s).
162162
The integrator can also be manipulated more generally to control solution
163163
behavior, see the [integrator
@@ -167,7 +167,7 @@ documentation. In affect functions, we have that
167167
```julia
168168
function affect!(integ, u, p, ctx)
169169
# integ.t is the current time
170-
# integ.u[u.v] is the value of the state `v` above
170+
# integ.u[u.v] is the value of the unknown `v` above
171171
# integ.p[p.q] is the value of the parameter `q` above
172172
end
173173
```
@@ -222,8 +222,8 @@ where conditions are symbolic expressions that should evaluate to `true` when an
222222
individual affect should be executed. Here `affect1` and `affect2` are each
223223
either a vector of one or more symbolic equations, or a functional affect, just
224224
as for continuous events. As before, for any *one* event the symbolic affect
225-
equations can either all change states (i.e. variables) or all change
226-
parameters, but one cannot currently mix state and parameter changes within one
225+
equations can either all change unknowns (i.e. variables) or all change
226+
parameters, but one cannot currently mix unknown variable and parameter changes within one
227227
individual event.
228228

229229
### Example: Injecting cells into a population

docs/src/basics/FAQ.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ julia> ModelingToolkit.missing_variable_defaults(sys, [1,2,3])
130130
x3ˍtt(t) => 3
131131
```
132132

133-
## Change the state vector type
133+
## Change the unknown variable vector type
134134

135135
Use the `u0_constructor` keyword argument to map an array to the desired
136136
container type. For example:

docs/src/basics/Linearization.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,16 @@ matrices, simplified_sys = linearize(sys, [r], [y]) # Linearize from r to y
3434
matrices
3535
```
3636

37-
The named tuple `matrices` contains the matrices of the linear statespace representation, while `simplified_sys` is an `ODESystem` that, among other things, indicates the state order in the linear system through
37+
The named tuple `matrices` contains the matrices of the linear statespace representation, while `simplified_sys` is an `ODESystem` that, among other things, indicates the unknown variable order in the linear system through
3838

3939
```@example LINEARIZE
4040
using ModelingToolkit: inputs, outputs
41-
[states(simplified_sys); inputs(simplified_sys); outputs(simplified_sys)]
41+
[unknowns(simplified_sys); inputs(simplified_sys); outputs(simplified_sys)]
4242
```
4343

4444
## Operating point
4545

46-
The operating point to linearize around can be specified with the keyword argument `op` like this: `op = Dict(x => 1, r => 2)`. The operating point may include specification of state variables, input variables and parameters. For variables that are not specified in `op`, the default value specified in the model will be used if available, if no value is specified, an error is thrown.
46+
The operating point to linearize around can be specified with the keyword argument `op` like this: `op = Dict(x => 1, r => 2)`. The operating point may include specification of unknown variables, input variables and parameters. For variables that are not specified in `op`, the default value specified in the model will be used if available, if no value is specified, an error is thrown.
4747

4848
## Batch linearization and algebraic variables
4949

docs/src/basics/MTKModel_Connector.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ ModelingToolkit.Model
1010

1111
## Components
1212

13-
Components are models from various domains. These models contain states and their
13+
Components are models from various domains. These models contain unknowns and their
1414
equations.
1515

1616
### [Defining components with `@mtkmodel`](@id mtkmodel)
@@ -25,11 +25,11 @@ equations.
2525

2626
- `@components`: for listing sub-components of the system
2727
- `@equations`: for the list of equations
28-
- `@extend`: for extending a base system and unpacking its states
28+
- `@extend`: for extending a base system and unpacking its unknowns
2929
- `@icon` : for embedding the model icon
3030
- `@parameters`: for specifying the symbolic parameters
3131
- `@structural_parameters`: for specifying non-symbolic parameters
32-
- `@variables`: for specifying the states
32+
- `@variables`: for specifying the unknowns
3333

3434
Let's explore these in more detail with the following example:
3535

@@ -171,7 +171,7 @@ getdefault(model_c4.model_a.k_array[2])
171171
Connectors are special models that can be used to connect different components together.
172172
MTK provides 3 distinct connectors:
173173

174-
- `DomainConnector`: A connector which has only one state which is of `Flow` type,
174+
- `DomainConnector`: A connector which has only one unknown which is of `Flow` type,
175175
specified by `[connect = Flow]`.
176176
- `StreamConnector`: A connector which has atleast one stream variable, specified by
177177
`[connect = Stream]`. A `StreamConnector` must have exactly one flow variable.
@@ -228,7 +228,7 @@ end
228228
`structure` stores metadata that describes composition of a model. It includes:
229229

230230
- `:components`: List of sub-components in the form of [[name, sub_component_name],...].
231-
- `:extend`: The list of extended states, name given to the base system, and name of the base system.
231+
- `:extend`: The list of extended unknowns, name given to the base system, and name of the base system.
232232
- `:structural_parameters`: Dictionary of structural parameters mapped to their default values.
233233
- `:parameters`: Dictionary of symbolic parameters mapped to their metadata. For
234234
parameter arrays, length is added to the metadata as `:size`.

docs/src/examples/modelingtoolkitize_index_reduction.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ traced_sys = modelingtoolkitize(pendulum_prob)
3232
pendulum_sys = structural_simplify(dae_index_lowering(traced_sys))
3333
prob = ODAEProblem(pendulum_sys, [], tspan)
3434
sol = solve(prob, Tsit5(), abstol = 1e-8, reltol = 1e-8)
35-
plot(sol, idxs = states(traced_sys))
35+
plot(sol, idxs = unknowns(traced_sys))
3636
```
3737

3838
## Explanation
@@ -81,7 +81,7 @@ However, one will quickly be greeted with the unfortunate message:
8181
└ @ OrdinaryDiffEq C:\Users\accou\.julia\packages\OrdinaryDiffEq\yCczp\src\initdt.jl:76
8282
┌ Warning: Automatic dt set the starting dt as NaN, causing instability.
8383
└ @ OrdinaryDiffEq C:\Users\accou\.julia\packages\OrdinaryDiffEq\yCczp\src\solve.jl:485
84-
┌ Warning: NaN dt detected. Likely a NaN value in the state, parameters, or derivative value caused this outcome.
84+
┌ Warning: NaN dt detected. Likely a NaN value in the unknowns, parameters, or derivative value caused this outcome.
8585
└ @ SciMLBase C:\Users\accou\.julia\packages\SciMLBase\DrPil\src\integrator_interface.jl:325
8686
```
8787

@@ -154,17 +154,17 @@ prob = ODEProblem(pendulum_sys, Pair[], tspan)
154154
sol = solve(prob, Rodas4())
155155
156156
using Plots
157-
plot(sol, idxs = states(traced_sys))
157+
plot(sol, idxs = unknowns(traced_sys))
158158
```
159159

160-
Note that plotting using `states(traced_sys)` is done so that any
160+
Note that plotting using `unknowns(traced_sys)` is done so that any
161161
variables which are symbolically eliminated, or any variable reordering
162162
done for enhanced parallelism/performance, still show up in the resulting
163163
plot and the plot is shown in the same order as the original numerical
164164
code.
165165

166166
Note that we can even go a bit further. If we use the `ODAEProblem`
167-
constructor, we can remove the algebraic equations from the states of the
167+
constructor, we can remove the algebraic equations from the unknowns of the
168168
system and fully transform the index-3 DAE into an index-0 ODE which can
169169
be solved via an explicit Runge-Kutta method:
170170

@@ -173,7 +173,7 @@ traced_sys = modelingtoolkitize(pendulum_prob)
173173
pendulum_sys = structural_simplify(dae_index_lowering(traced_sys))
174174
prob = ODAEProblem(pendulum_sys, Pair[], tspan)
175175
sol = solve(prob, Tsit5(), abstol = 1e-8, reltol = 1e-8)
176-
plot(sol, idxs = states(traced_sys))
176+
plot(sol, idxs = unknowns(traced_sys))
177177
```
178178

179179
And there you go: this has transformed the model from being too hard to

docs/src/examples/perturbation.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ using ModelingToolkit, DifferentialEquations
9494

9595
@named sys = ODESystem(eqs, t)
9696
sys = structural_simplify(sys)
97-
states(sys)
97+
unknowns(sys)
9898
```
9999

100100
```julia

docs/src/examples/spring_mass.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,10 @@ We can take a look at the equations in the model using the `equations` function.
141141
equations(model)
142142
```
143143

144-
The states of this model are:
144+
The unknowns of this model are:
145145

146146
```@example component
147-
states(model)
147+
unknowns(model)
148148
```
149149

150150
And the parameters of this model are:
@@ -162,7 +162,7 @@ sys = structural_simplify(model)
162162
equations(sys)
163163
```
164164

165-
We are left with only 4 equations involving 4 state variables (`mass.pos[1]`,
165+
We are left with only 4 equations involving 4 unknown variables (`mass.pos[1]`,
166166
`mass.pos[2]`, `mass.v[1]`, `mass.v[2]`). We can solve the system by converting
167167
it to an `ODEProblem`. Some observed variables are not expanded by default. To
168168
view the complete equations, one can do
@@ -179,13 +179,13 @@ sol = solve(prob, Rosenbrock23())
179179
plot(sol)
180180
```
181181

182-
What if we want the timeseries of a different variable? That information is not lost! Instead, `structural_simplify` simply changes state variables into `observed` variables.
182+
What if we want the timeseries of a different variable? That information is not lost! Instead, `structural_simplify` simply changes unknown variables into `observed` variables.
183183

184184
```@example component
185185
observed(sys)
186186
```
187187

188-
These are explicit algebraic equations which can be used to reconstruct the required variables on the fly. This leads to dramatic computational savings since implicitly solving an ODE scales as O(n^3), so fewer states are significantly better!
188+
These are explicit algebraic equations which can be used to reconstruct the required variables on the fly. This leads to dramatic computational savings since implicitly solving an ODE scales as O(n^3), so fewer unknowns are significantly better!
189189

190190
We can access these variables using the solution object. For example, let's retrieve the x-position of the mass over time:
191191

docs/src/internals.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ contributors to the library.
66
## Observables and Variable Elimination
77

88
In the variable “elimination” algorithms, what is actually done is that variables
9-
are removed from being states and equations are moved into the `observed` category
9+
are removed from being unknowns and equations are moved into the `observed` category
1010
of the system. The `observed` equations are explicit algebraic equations which
1111
are then substituted out to completely eliminate these variables from the other
1212
equations, allowing the system to act as though these variables no longer exist.

docs/src/systems/JumpSystem.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ JumpSystem
99
## Composition and Accessor Functions
1010

1111
- `get_eqs(sys)` or `equations(sys)`: The equations that define the jump system.
12-
- `get_states(sys)` or `states(sys)`: The set of states in the jump system.
12+
- `get_unknowns(sys)` or `unknowns(sys)`: The set of unknowns in the jump system.
1313
- `get_ps(sys)` or `parameters(sys)`: The parameters of the jump system.
1414
- `get_iv(sys)`: The independent variable of the jump system.
1515

docs/src/systems/NonlinearSystem.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ NonlinearSystem
99
## Composition and Accessor Functions
1010

1111
- `get_eqs(sys)` or `equations(sys)`: The equations that define the nonlinear system.
12-
- `get_states(sys)` or `states(sys)`: The set of states in the nonlinear system.
12+
- `get_unknowns(sys)` or `unknowns(sys)`: The set of unknowns in the nonlinear system.
1313
- `get_ps(sys)` or `parameters(sys)`: The parameters of the nonlinear system.
1414
- `get_u0_p(sys, u0map, parammap)` Numeric arrays for the initial condition and parameters given `var => value` maps.
1515

docs/src/systems/ODESystem.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ODESystem
99
## Composition and Accessor Functions
1010

1111
- `get_eqs(sys)` or `equations(sys)`: The equations that define the ODE.
12-
- `get_states(sys)` or `states(sys)`: The set of states in the ODE.
12+
- `get_unknowns(sys)` or `unknowns(sys)`: The set of unknowns in the ODE.
1313
- `get_ps(sys)` or `parameters(sys)`: The parameters of the ODE.
1414
- `get_iv(sys)`: The independent variable of the ODE.
1515
- `get_u0_p(sys, u0map, parammap)` Numeric arrays for the initial condition and parameters given `var => value` maps.

0 commit comments

Comments
 (0)