Skip to content

Commit 89beb2a

Browse files
major doc update
1 parent e0b02d0 commit 89beb2a

File tree

6 files changed

+180
-106
lines changed

6 files changed

+180
-106
lines changed

docs/make.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@ makedocs(
1616
"tutorials/nonlinear.md",
1717
"tutorials/modelingtoolkitize.md",
1818
],
19-
"Systems" => Any[
20-
"systems/AbstractSystem.md",
19+
"Basics" => Any[
20+
"basics/AbstractSystem.md",
21+
"basics/ContextualVariables.md",
22+
"basics/DependencyGraphs.md"
23+
],
24+
"Systems Types" => Any[
2125
"systems/ODESystem.md",
2226
"systems/SDESystem.md",
2327
"systems/JumpSystem.md",
@@ -26,7 +30,6 @@ makedocs(
2630
"systems/ControlSystem.md",
2731
"systems/ReactionSystem.md",
2832
"systems/PDESystem.md",
29-
"systems/DependencyGraphs.md"
3033
]
3134
]
3235
)
Lines changed: 114 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,114 @@
1-
# The AbstractSystem Interface
2-
3-
## Overview
4-
5-
The `AbstractSystem` interface is the core of the system level of ModelingToolkit.jl.
6-
It establishes a common set of functionality that is used between systems
7-
from ODEs and chemical reactions, allowing users to have a common framework for
8-
model manipulation and compilation.
9-
10-
## Composition and Accessor Functions
11-
12-
Each `AbstractSystem` has lists of variables in context, such as distinguishing
13-
parameters vs states. In addition, an `AbstractSystem` also can hold other
14-
`AbstractSystem` types. Direct accessing of the values, such as `sys.states`,
15-
gives the immediate list, while the accessor functions `states(sys)` gives the
16-
total set, which includes that of all systems held inside.
17-
18-
The values which are common to all `AbstractSystem`s are:
19-
20-
- `equations(sys)`: All equations that define the system and its subsystems.
21-
- `states(sys)`: All the states in the system and its subsystems.
22-
- `parameters(sys)`: All parameters of the system and its subsystems.
23-
- `nameof(sys)`: The name of the current-level system.
24-
- `get_eqs(sys)`: Equations that define the current-level system.
25-
- `get_states(sys)`: States that are in the current-level system.
26-
- `get_ps(sys)`: Parameters that are in the current-level system.
27-
- `get_systems(sys)`: Subsystems of the current-level system.
28-
29-
Optionally, a system could have:
30-
31-
- `observed(sys)`: All observed equations of the system and its subsystems.
32-
- `get_observed(sys)`: Observed equations of the current-level system.
33-
- `get_default_u0(sys)`: A `Dict` that maps states into their default initial
34-
condition.
35-
- `get_default_p(sys)`: A `Dict` that maps parameters into their default value.
36-
- `independent_variable(sys)`: The independent variable of a system.
37-
- `get_noiseeqs(sys)`: Noise equations of the current-level system.
38-
39-
Note that there's `get_iv(sys)`, but it is not advised to use, since it errors
40-
when the system has no field `iv`. `independent_variable(sys)` returns `nothing`
41-
for `NonlinearSystem`s.
42-
43-
A system could also have caches:
44-
45-
- `get_jac(sys)`: The Jacobian of a system.
46-
- `get_tgrad(sys)`: The gradient with respect to time of a system.
47-
48-
## Transformations
49-
50-
Transformations are functions which send a valid `AbstractSystem` definition to
51-
another `AbstractSystem`. These are passes, like optimizations (e.g., Block-Lower
52-
Triangle transformations), or changes to the representation, which allow for
53-
alternative numerical methods to be utilized on the model (e.g., DAE index reduction).
54-
55-
## Function Calculation and Generation
56-
57-
The calculation and generation functions allow for calculating additional
58-
quantities to enhance the numerical methods applied to the resulting system.
59-
The calculations, like `calculate_jacobian`, generate ModelingToolkit IR for
60-
the Jacobian of the system, while the generations, like `generate_jacobian`,
61-
generate compiled output for the numerical solvers by applying `build_function`
62-
to the generated code. Additionally, many systems have function-type outputs,
63-
which cobble together the generation functionality for a system, for example,
64-
`ODEFunction` can be used to generate a DifferentialEquations-based `ODEFunction`
65-
with compiled version of the ODE itself, the Jacobian, the mass matrix, etc.
66-
67-
Below are the possible calculation and generation functions:
68-
69-
```@docs
70-
calculate_tgrad
71-
calculate_gradient
72-
calculate_jacobian
73-
calculate_factorized_W
74-
calculate_hessian
75-
generate_tgrad
76-
generate_gradient
77-
generate_jacobian
78-
generate_factorized_W
79-
generate_hessian
80-
```
81-
82-
Additionally, `jacobian_sparsity(sys)` and `hessian_sparsity(sys)`
83-
exist on the appropriate systems for fast generation of the sparsity
84-
patterns via an abstract interpretation without requiring differentiation.
85-
86-
## Problem Constructors
87-
88-
At the end, the system types have `DEProblem` constructors, like `ODEProblem`,
89-
which allow for directly generating the problem types required for numerical
90-
methods. The first argument is always the `AbstractSystem`, and the proceeding
91-
arguments match the argument order of their original constructors. Whenever an
92-
array would normally be provided, such as `u0` the initial condition of an
93-
`ODEProblem`, it is instead replaced with a variable map, i.e., an array of
94-
pairs `var=>value`, which allows the user to designate the values without having
95-
to know the order that ModelingToolkit is internally using.
1+
# The AbstractSystem Interface
2+
3+
## Overview
4+
5+
The `AbstractSystem` interface is the core of the system level of ModelingToolkit.jl.
6+
It establishes a common set of functionality that is used between systems
7+
from ODEs and chemical reactions, allowing users to have a common framework for
8+
model manipulation and compilation.
9+
10+
## Constructors and Naming
11+
12+
The `AbstractSystem` interface has a consistent method for constructing systems.
13+
Generally it follows the order of:
14+
15+
1. Equations
16+
2. Independent Variables
17+
3. Dependent Variables (or States)
18+
4. Parameters
19+
20+
All other pieces are handled via keyword arguments. `AbstractSystem`s share the
21+
same keyword arguments, which are:
22+
23+
- `system`: This is used for specifying subsystems for hierarchical modeling with
24+
reusable components. For more information, see the [components page](@ref components)
25+
- Defaults: Keyword arguments like `default_u0` are used for specifying default
26+
values which are used. If a value is not given at the `SciMLProblem` construction
27+
time, its numerical value will be the default.
28+
29+
## Composition and Accessor Functions
30+
31+
Each `AbstractSystem` has lists of variables in context, such as distinguishing
32+
parameters vs states. In addition, an `AbstractSystem` also can hold other
33+
`AbstractSystem` types. Direct accessing of the values, such as `sys.states`,
34+
gives the immediate list, while the accessor functions `states(sys)` gives the
35+
total set, which includes that of all systems held inside.
36+
37+
The values which are common to all `AbstractSystem`s are:
38+
39+
- `equations(sys)`: All equations that define the system and its subsystems.
40+
- `states(sys)`: All the states in the system and its subsystems.
41+
- `parameters(sys)`: All parameters of the system and its subsystems.
42+
- `nameof(sys)`: The name of the current-level system.
43+
- `get_eqs(sys)`: Equations that define the current-level system.
44+
- `get_states(sys)`: States that are in the current-level system.
45+
- `get_ps(sys)`: Parameters that are in the current-level system.
46+
- `get_systems(sys)`: Subsystems of the current-level system.
47+
48+
Optionally, a system could have:
49+
50+
- `observed(sys)`: All observed equations of the system and its subsystems.
51+
- `get_observed(sys)`: Observed equations of the current-level system.
52+
- `get_default_u0(sys)`: A `Dict` that maps states into their default initial
53+
condition.
54+
- `get_default_p(sys)`: A `Dict` that maps parameters into their default value.
55+
- `independent_variable(sys)`: The independent variable of a system.
56+
- `get_noiseeqs(sys)`: Noise equations of the current-level system.
57+
58+
Note that there's `get_iv(sys)`, but it is not advised to use, since it errors
59+
when the system has no field `iv`. `independent_variable(sys)` returns `nothing`
60+
for `NonlinearSystem`s.
61+
62+
A system could also have caches:
63+
64+
- `get_jac(sys)`: The Jacobian of a system.
65+
- `get_tgrad(sys)`: The gradient with respect to time of a system.
66+
67+
## Transformations
68+
69+
Transformations are functions which send a valid `AbstractSystem` definition to
70+
another `AbstractSystem`. These are passes, like optimizations (e.g., Block-Lower
71+
Triangle transformations), or changes to the representation, which allow for
72+
alternative numerical methods to be utilized on the model (e.g., DAE index reduction).
73+
74+
## Function Calculation and Generation
75+
76+
The calculation and generation functions allow for calculating additional
77+
quantities to enhance the numerical methods applied to the resulting system.
78+
The calculations, like `calculate_jacobian`, generate ModelingToolkit IR for
79+
the Jacobian of the system, while the generations, like `generate_jacobian`,
80+
generate compiled output for the numerical solvers by applying `build_function`
81+
to the generated code. Additionally, many systems have function-type outputs,
82+
which cobble together the generation functionality for a system, for example,
83+
`ODEFunction` can be used to generate a DifferentialEquations-based `ODEFunction`
84+
with compiled version of the ODE itself, the Jacobian, the mass matrix, etc.
85+
86+
Below are the possible calculation and generation functions:
87+
88+
```@docs
89+
calculate_tgrad
90+
calculate_gradient
91+
calculate_jacobian
92+
calculate_factorized_W
93+
calculate_hessian
94+
generate_tgrad
95+
generate_gradient
96+
generate_jacobian
97+
generate_factorized_W
98+
generate_hessian
99+
```
100+
101+
Additionally, `jacobian_sparsity(sys)` and `hessian_sparsity(sys)`
102+
exist on the appropriate systems for fast generation of the sparsity
103+
patterns via an abstract interpretation without requiring differentiation.
104+
105+
## Problem Constructors
106+
107+
At the end, the system types have `DEProblem` constructors, like `ODEProblem`,
108+
which allow for directly generating the problem types required for numerical
109+
methods. The first argument is always the `AbstractSystem`, and the proceeding
110+
arguments match the argument order of their original constructors. Whenever an
111+
array would normally be provided, such as `u0` the initial condition of an
112+
`ODEProblem`, it is instead replaced with a variable map, i.e., an array of
113+
pairs `var=>value`, which allows the user to designate the values without having
114+
to know the order that ModelingToolkit is internally using.

docs/src/basics/Composition.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# [Composing Models and Building Reusable Components](@ref components)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Contextual Variable Types
2+
3+
ModelingToolkit.jl has a system of contextual variable types which allows for
4+
helping the system transformation machinery do complex manipulations and
5+
automatic detection. The standard variable definition in ModelingToolkit.jl is
6+
the `@variable` which is defined by
7+
[Symbolics.jl](https://github.com/JuliaSymbolics/Symbolics.jl). For example:
8+
9+
```julia
10+
@variabes x y(x)
11+
```
12+
13+
This is used for the "normal" variable of a given system, like the states of a
14+
differential equation or objective function. All of the macros below support
15+
the same syntax as `@variables`.
16+
17+
## Parameters
18+
19+
All modeling projects have some form of parameters. `@parameters` marks a variable
20+
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.
22+
23+
## Flow Variables (TODO)
24+
25+
In many engineering systems some variables act like "flows" while others do not.
26+
For example, in circuit models you have current which flows, and the related
27+
voltage which does not. Or in thermal models you have heat flows. In these cases,
28+
the `connect` statement enforces conservation of flow between all of the connected
29+
components.
30+
31+
For example, the following specifies that `x` is a 2x2 matrix of flow variables:
32+
33+
```julia
34+
@variables x[1:2,1:2] type=flow
35+
```
36+
37+
## Stream Variables
38+
39+
TODO
40+
41+
## Brownian Variables
42+
43+
TODO
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
# Dependency Graphs
22

33
# Types
4+
45
```@docs
56
BipartiteGraph
67
```
78

89
# Utility functions for `BiPartiteGraph`s
10+
911
```@docs
1012
Base.isequal
1113
```
1214

1315
# Functions for calculating dependency graphs
16+
1417
```@docs
1518
equation_dependencies
1619
asgraph
1720
variable_dependencies
1821
asdigraph
1922
eqeq_dependencies
2023
varvar_dependencies
21-
```
24+
```

docs/src/index.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,13 @@ before generating code.
4141
efficiently numerically handling large-scale systems of equations
4242
- The ability to use the entire Symbolics.jl Computer Algebra System (CAS) as
4343
part of the modeling process.
44+
- Import models from common formats like SBML, CellML, BioNetGen, and more.
4445
- Extendability: the whole system is written in pure Julia, so adding new
4546
functions, simplification rules, and model transformations has no barrier.
4647

4748
For information on how to use the Symbolics.jl CAS system that ModelingToolkit.jl
48-
is built on, consult the [Symbolics.jl documentation](https://github.com/JuliaSymbolics/Symbolics.jl)
49+
is built on, consult the
50+
[Symbolics.jl documentation](https://github.com/JuliaSymbolics/Symbolics.jl)
4951

5052
### Equation Types
5153

@@ -78,6 +80,15 @@ Below is an incomplete list of extension libraries one may want to be aware of:
7880
- [MomentClosure.jl](https://github.com/augustinas1/MomentClosure.jl): Automatic transformation of ReactionSystems into deterministic systems
7981
- Generates ODESystems for the moment closures
8082
- Allows for geometrically-distributed random reaction rates
83+
- [ReactionMechanismSimulator.jl](https://github.com/ReactionMechanismGenerator/ReactionMechanismSimulator.jl): simulating and analyzing large chemical reaction mechanisms
84+
- Ideal gas and dilute liquid phases.
85+
- Constant T and P and constant V adiabatic ideal gas reactors.
86+
- Constant T and V dilute liquid reactors.
87+
- Diffusion limited rates. Sensitivity analysis for all reactors.
88+
- Flux diagrams with molecular images (if molecular information is provided).
89+
90+
## Model Import Formats
91+
8192
- [CellMLToolkit.jl](https://github.com/SciML/CellMLToolkit.jl): Import [CellML](https://www.cellml.org/) models into ModelingToolkit
8293
- Repository of more than a thousand pre-made models
8394
- Focus on biomedical models in areas such as: Calcium Dynamics,
@@ -88,12 +99,6 @@ Below is an incomplete list of extension libraries one may want to be aware of:
8899
Protein Modules, Signal Transduction, and Synthetic Biology.
89100
- [SbmlInterface.jl](https://github.com/paulflang/SbmlInterface.jl): Import [SBML](http://sbml.org/Main_Page) models into ModelingToolkit
90101
- Uses the robust libsbml library for parsing and transforming the SBML
91-
- [ReactionMechanismSimulator.jl](https://github.com/ReactionMechanismGenerator/ReactionMechanismSimulator.jl): simulating and analyzing large chemical reaction mechanisms
92-
- Ideal gas and dilute liquid phases.
93-
- Constant T and P and constant V adiabatic ideal gas reactors.
94-
- Constant T and V dilute liquid reactors.
95-
- Diffusion limited rates. Sensitivity analysis for all reactors.
96-
- Flux diagrams with molecular images (if molecular information is provided).
97102
- [ReactionNetworkImporters.jl](https://github.com/isaacsas/ReactionNetworkImporters.jl): Import various models into ModelingToolkit
98103
- Supports the BioNetGen `.net` file
99104
- Supports importing networks specified by stoichiometric matrices

0 commit comments

Comments
 (0)