Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bifurcation kit extension #2300

Closed
wants to merge 63 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
e56de20
split parameters linearize bug
Sep 25, 2023
cee69ed
added old MatrixGain definition for comparison
Sep 25, 2023
b4f821e
new promote_to_concrete
Sep 25, 2023
e62e3ee
improvements to protmote_to_concrete
Sep 26, 2023
ee4deb9
remake issue
Sep 26, 2023
a9c56b6
Suppose heterogeneous parameters for linearize and remake
YingboMa Sep 26, 2023
1a96915
Fix zero_dummy_der
YingboMa Sep 26, 2023
023e024
Relax tests
YingboMa Sep 26, 2023
119cb27
Don't use SciMLBase 2
YingboMa Sep 26, 2023
6bb0b2e
Merge branch 'master' into bgc/split_params_bug
YingboMa Oct 2, 2023
29aec7b
Fix eq ordering
YingboMa Oct 2, 2023
addf335
Change bounds back
YingboMa Oct 2, 2023
2e4c1bb
Format
YingboMa Oct 2, 2023
2a553a7
Be careful with string sorting
YingboMa Oct 2, 2023
f9ea3a6
Update LaTeXify ref tests
YingboMa Oct 2, 2023
c2f92f1
init
TorkelE Oct 4, 2023
b05bc5f
makefunction
TorkelE Oct 4, 2023
f2d80b0
1.6 has a different term ordering
YingboMa Oct 4, 2023
ae05041
Fix DiscreteProblem construction
YingboMa Oct 4, 2023
2309f9f
Merge pull request #2283 from SciML/bgc/split_params_bug
YingboMa Oct 4, 2023
fb7c3af
Update Project.toml
YingboMa Oct 4, 2023
6e795b8
Fix recursive structure and setup precompilation
ChrisRackauckas Oct 6, 2023
7949761
Merge pull request #2301 from SciML/precompile_workload
ChrisRackauckas Oct 6, 2023
c5bd821
docs(refactor): update acausal components tutorial with `@mtkmodel`
ven-k Sep 27, 2023
6ac545d
docs(refactor): update structural identifiability tutorial with `@mtk…
ven-k Sep 27, 2023
278698b
docs(fix): set a `u0` within the constraint for the optimization problem
ven-k Sep 28, 2023
94fb749
docs(refactor): refactor "Getting Started" section with `@mtkmodel`
ven-k Oct 3, 2023
438a225
docs(refactor): rename the `@mtkmodel` docs page as "Defining compone…
ven-k Oct 3, 2023
ff2a778
docs: reword Components and Connectors and elaborate Connectors and M…
ven-k Oct 3, 2023
2ef4752
docs: add `connect` section to Variable metadata
ven-k Oct 3, 2023
3034c9f
Merge pull request #2286 from ven-k/vkb/mtkmodel-examples
ChrisRackauckas Oct 8, 2023
c4868e3
Add `@mtkbuild` greatly simplify the tutorials
ChrisRackauckas Oct 8, 2023
ac75e77
Add `parent` to hierarchical systems and set it in `structural_simplify`
YingboMa Oct 8, 2023
b0c2938
Format
YingboMa Oct 8, 2023
c3c030e
Add "docs/src/assets/*.toml" to gitignore
YingboMa Oct 8, 2023
cd0f04a
Add tests
YingboMa Oct 8, 2023
0d5ab59
Fix CI
YingboMa Oct 8, 2023
7370a45
fix tutorial syntax
ChrisRackauckas Oct 8, 2023
137d3d1
Support implicit name unpack in `at extend`
YingboMa Oct 8, 2023
c679dd9
fix acausal tutorial
ChrisRackauckas Oct 8, 2023
17a3b6a
Merge pull request #2305 from SciML/mtkbuild
ChrisRackauckas Oct 8, 2023
3d83c4c
one more tutorial simplification
ChrisRackauckas Oct 8, 2023
0a9dca1
Merge branch 'master' into myb/extend
YingboMa Oct 8, 2023
73f9e0a
Stop using `at testset` macro
YingboMa Oct 8, 2023
718ae81
Remove ODAEProblem from acausal tutorial
ChrisRackauckas Oct 8, 2023
0bcdee8
Merge pull request #2308 from SciML/odaeproblem
YingboMa Oct 8, 2023
379161f
Merge pull request #2307 from SciML/tuts
YingboMa Oct 8, 2023
314bb1d
Merge pull request #2306 from SciML/myb/extend
YingboMa Oct 9, 2023
298a9a5
patch system names
ChrisRackauckas Oct 9, 2023
bdc45d1
Simplify `at extend`
YingboMa Oct 9, 2023
1152f30
update docs for new extension syntax
ChrisRackauckas Oct 9, 2023
9e45fee
fix for simplified extend
ChrisRackauckas Oct 9, 2023
563f04f
Merge pull request #2310 from SciML/myb/extend
ChrisRackauckas Oct 9, 2023
2c17d63
Merge pull request #2309 from SciML/extend
ChrisRackauckas Oct 9, 2023
d4239a7
Update Project.toml
ChrisRackauckas Oct 9, 2023
bc93796
non canonical docstrings
ArnoStrouwen Oct 14, 2023
b54b05b
update contributing docs
ArnoStrouwen Oct 14, 2023
0ef0bb4
Merge pull request #2315 from ArnoStrouwen/docs
ChrisRackauckas Oct 14, 2023
2c86306
updates
TorkelE Oct 14, 2023
3249aeb
init
TorkelE Oct 4, 2023
7f5d8be
makefunction
TorkelE Oct 4, 2023
c4a1a20
updates
TorkelE Oct 14, 2023
918f5e6
Merge remote-tracking branch 'TorkelE/BifurcationKitExtension' into B…
TorkelE Oct 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
Manifest.toml
.vscode
.vscode/*
docs/src/assets/Project.toml
docs/src/assets/Manifest.toml
7 changes: 5 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ModelingToolkit"
uuid = "961ee093-0014-501f-94e3-6117800e7a78"
authors = ["Yingbo Ma <[email protected]>", "Chris Rackauckas <[email protected]> and contributors"]
version = "8.71.1"
version = "8.72.2"

[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
Expand Down Expand Up @@ -51,9 +51,11 @@ UnPack = "3a884ed6-31ef-47d7-9d2a-63182c4928ed"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"

[weakdeps]
BifurcationKit = "0f109fa4-8a5d-4b75-95aa-f515264e7665"
DeepDiffs = "ab62b9b5-e342-54a8-a765-a90f495de1a6"

[extensions]
MTKBifurcationKitExt = "BifurcationKit"
MTKDeepDiffsExt = "DeepDiffs"

[compat]
Expand Down Expand Up @@ -100,6 +102,7 @@ julia = "1.6"

[extras]
AmplNLWriter = "7c4d4715-977e-5154-bfe0-e096adeac482"
BifurcationKit = "0f109fa4-8a5d-4b75-95aa-f515264e7665"
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
ControlSystemsMTK = "687d7614-c7e5-45fc-bfc3-9ee385575c88"
DeepDiffs = "ab62b9b5-e342-54a8-a765-a90f495de1a6"
Expand All @@ -123,4 +126,4 @@ Sundials = "c3572dad-4567-51f8-b174-8c6c989267f4"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["AmplNLWriter", "BenchmarkTools", "ControlSystemsMTK", "NonlinearSolve", "ForwardDiff", "Ipopt", "Ipopt_jll", "ModelingToolkitStandardLibrary", "Optimization", "OptimizationOptimJL", "OptimizationMOI", "Random", "ReferenceTests", "SafeTestsets", "StableRNGs", "Statistics", "SteadyStateDiffEq", "Test", "StochasticDiffEq", "Sundials", "StochasticDelayDiffEq"]
test = ["AmplNLWriter", "BifurcationKit", "BenchmarkTools", "ControlSystemsMTK", "NonlinearSolve", "ForwardDiff", "Ipopt", "Ipopt_jll", "ModelingToolkitStandardLibrary", "Optimization", "OptimizationOptimJL", "OptimizationMOI", "Random", "ReferenceTests", "SafeTestsets", "StableRNGs", "Statistics", "SteadyStateDiffEq", "Test", "StochasticDiffEq", "Sundials", "StochasticDelayDiffEq"]
1 change: 1 addition & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[deps]
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
BifurcationKit = "0f109fa4-8a5d-4b75-95aa-f515264e7665"
DifferentialEquations = "0c46a032-eb83-5123-abaf-570d42b7fbaa"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
Expand Down
2 changes: 2 additions & 0 deletions docs/pages.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ pages = [
"tutorials/nonlinear.md",
"tutorials/optimization.md",
"tutorials/modelingtoolkitize.md",
"tutorials/programmatically_generating.md",
"tutorials/stochastic_diffeq.md",
"tutorials/parameter_identifiability.md",
"tutorials/bifurcation_diagram_computation.md",
"tutorials/domain_connections.md"],
"Examples" => Any["Basic Examples" => Any["examples/higher_order.md",
"examples/spring_mass.md",
Expand Down
12 changes: 7 additions & 5 deletions docs/src/basics/ContextualVariables.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ for which its arguments must be specified each time it is used. This is useful w
PDEs for example, where one may need to use `u(t, x)` in the equations, but will
need to be able to write `u(t, 0.0)` to define a boundary condition at `x = 0`.

## Variable metadata [Experimental/TODO]
## Variable metadata

In many engineering systems, some variables act like “flows” while others do not.
For example, in circuit models you have current which flows, and the related
Expand All @@ -69,15 +69,17 @@ the metadata. One can get and set metadata by
```julia
julia> @variables x [unit = u"m^3/s"];

julia> hasmetadata(x, Symbolics.option_to_metadata_type(Val(:unit)))
julia> hasmetadata(x, VariableUnit)
true

julia> getmetadata(x, Symbolics.option_to_metadata_type(Val(:unit)))
julia> ModelingToolkit.get_unit(x)
m³ s⁻¹

julia> x = setmetadata(x, Symbolics.option_to_metadata_type(Val(:unit)), u"m/s")
julia> x = setmetadata(x, VariableUnit, u"m/s")
x

julia> getmetadata(x, Symbolics.option_to_metadata_type(Val(:unit)))
julia> ModelingToolkit.get_unit(x)
m s⁻¹
```

See [Symbolic Metadata](@ref symbolic_metadata) for more details on variable metadata.
88 changes: 75 additions & 13 deletions docs/src/basics/MTKModel_Connector.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
# Defining components with `@mtkmodel`
# [Components and Connectors](@id mtkmodel_connector)

`@mtkmodel` is a convenience macro to define ModelingToolkit components. It returns `ModelingToolkit.Model`, which includes a constructor that returns an ODESystem, a `structure` dictionary with metadata and flag `isconnector` which is set to `false`.
## MTK Model

MTK represents components and connectors with `Model`.

```@docs
ModelingToolkit.Model
```

## Components

Components are models from various domains. These models contain states and their
equations.

### [Defining components with `@mtkmodel`](@id mtkmodel)

`@mtkmodel` is a convenience macro to define components. It returns
`ModelingToolkit.Model`, which includes a constructor that returns the ODESystem, a
`structure` dictionary with metadata, and flag `isconnector` which is set to `false`.

## What can an MTK-Model definition have?

Expand Down Expand Up @@ -56,9 +73,9 @@ end

- Parameters and variables are declared with respective begin blocks.
- Variables must be functions of an independent variable.
- Optionally, default values and metadata can be specified for these parameters and variables. See `ModelB` in the above example.
- Optionally, initial guess and metadata can be specified for these parameters and variables. See `ModelB` in the above example.
- Along with creating parameters and variables, keyword arguments of same name with default value `nothing` are created.
- Whenever a parameter or variable has default value, for example `v(t) = 0.0`, a symbolic variable named `v` with default value 0.0 and a keyword argument `v`, with default value `nothing` are created. <br> This way, users can optionally pass new value of `v` while creating a component.
- Whenever a parameter or variable has initial value, for example `v(t) = 0.0`, a symbolic variable named `v` with initial value 0.0 and a keyword argument `v`, with default value `nothing` are created. <br> This way, users can optionally pass new value of `v` while creating a component.

```julia
julia > @named model_c = ModelC(; v = 2.0);
Expand All @@ -72,7 +89,7 @@ julia > ModelingToolkit.getdefault(model_c.v)
- This block is for non symbolic input arguements. These are for inputs that usually are not meant to be part of components; but influence how they are defined. One can list inputs like boolean flags, functions etc... here.
- Whenever default values are specified, unlike parameters/variables, they are reflected in the keyword argument list.

### `@extend` block
#### `@extend` begin block

To extend a partial system,

Expand All @@ -86,7 +103,8 @@ julia> @named model_c = ModelC(; p1 = 2.0)

```

However, as `p2` isn't listed in the model definition, its default can't be modified by users.
However, as `p2` isn't listed in the model definition, its initial guess can't
specified while creating an instance of `ModelC`.

### `@components` begin block

Expand All @@ -110,13 +128,26 @@ And as `k2` isn't listed in the sub-component definition of `ModelC`, its defaul

- Any other Julia operations can be included with dedicated begin blocks.

## Defining connectors with `@connector`
## Connectors

Connectors are special models that can be used to connect different components together.
MTK provides 3 distinct connectors:

- `DomainConnector`: A connector which has only one state which is of `Flow` type,
specified by `[connect = Flow]`.
- `StreamConnector`: A connector which has atleast one stream variable, specified by
`[connect = Stream]`. A `StreamConnector` must have exactly one flow variable.
- `RegularConnector`: Connectors that don't fall under above categories.

`@connector` returns `ModelingToolkit.Model`. It includes a constructor that returns a connector ODESystem, a `structure` dictionary with metadata and flag `isconnector` which is set to `true`.
### [Defining connectors with `@connector`](@id connector)

`@connector` returns `ModelingToolkit.Model`. It includes a constructor that returns
a connector ODESystem, a `structure` dictionary with metadata, and flag `isconnector`
which is set to `true`.

A simple connector can be defined with syntax similar to following example:

```julia
```@example connector
using ModelingToolkit

@connector Pin begin
Expand All @@ -125,16 +156,47 @@ using ModelingToolkit
end
```

- Variables (as function of independent variable) are listed out in the definition. These variables can optionally have default values and metadata like `descrption`, `connect` and so on.
Variables (as functions of independent variable) are listed out in the definition. These variables can optionally have initial values and metadata like `description`, `connect` and so on. For more details on setting metadata, check out [Symbolic Metadata](@ref symbolic_metadata).

`@connector`s accepts begin blocks of `@components`, `@equations`, `@extend`, `@parameters`, `@structural_parameters`, `@variables`. These keywords mean the same as described above for `@mtkmodel`.
Similar to `@mtkmodel`, `@connector` accepts begin blocks of `@components`, `@equations`, `@extend`, `@parameters`, `@structural_parameters`, `@variables`. These keywords mean the same as described above for `@mtkmodel`.
For example, the following `HydraulicFluid` connector is defined with parameters, variables and equations.

```@example connector
@connector HydraulicFluid begin
@parameters begin
ρ = 997
β = 2.09e9
μ = 0.0010016
n = 1
let_gas = 1
ρ_gas = 0.0073955
p_gas = -1000
end
@variables begin
dm(t) = 0.0, [connect = Flow]
end
@equations begin
dm ~ 0
end
end
```

!!! note

For more examples of usage, checkout [ModelingToolkitStandardLibrary.jl](https://github.com/SciML/ModelingToolkitStandardLibrary.jl/)

### What's a `structure` dictionary?
## More on `Model.structure`

`structure` stores metadata that describes composition of a model. It includes:

For components defined with `@mtkmodel` or `@connector`, a dictionary with metadata is created. It lists `:components` (sub-component list), `:extend` (the extended states and base system), `:parameters`, `:variables`, ``:kwargs`` (list of keyword arguments), `:independent_variable`, `:equations`.
- `:components`: List of sub-components in the form of [[name, sub_component_name],...].
- `:extend`: The list of extended states, name given to the base system, and name of the base system.
- `:structural_parameters`: Dictionary of structural parameters mapped to their default values.
- `:parameters`: Dictionary of symbolic parameters mapped to their metadata.
- `:variables`: Dictionary of symbolic variables mapped to their metadata.
- `:kwargs`: Dictionary of keyword arguments mapped to their default values.
- `:independent_variable`: Independent variable, which is added while generating the Model.
- `:equations`: List of equations (represented as strings).

For example, the structure of `ModelC` is:

Expand Down
18 changes: 17 additions & 1 deletion docs/src/basics/Variable_metadata.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Symbolic metadata
# [Symbolic Metadata](@id symbolic_metadata)

It is possible to add metadata to symbolic variables, the metadata will be displayed when calling help on a variable.

Expand Down Expand Up @@ -39,6 +39,22 @@ help?> u
Symbolics.VariableSource: (:variables, :u)
```

## Connect

Variables in connectors can have `connect` metadata which describes the type of connections.

`Flow` is used for variables that represent physical quantities that "flow" ex:
current in a resistor. These variables sum up to zero in connections.

`Stream` can be specified for variables that flow bi-directionally.

```@example connect
using ModelingToolkit

@variables t, i(t) [connect = Flow]
@variables k(t) [connect = Stream]
```

## Input or output

Designate a variable as either an input or an output using the following
Expand Down
11 changes: 7 additions & 4 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,16 @@ system:

- Please refer to the
[SciML ColPrac: Contributor's Guide on Collaborative Practices for Community Packages](https://github.com/SciML/ColPrac/blob/master/README.md)
for guidance on PRs, issues, and other matters relating to contributing to ModelingToolkit.
for guidance on PRs, issues, and other matters relating to contributing to SciML.

- See the [SciML Style Guide](https://github.com/SciML/SciMLStyle) for common coding practices and other style decisions.
- There are a few community forums:

+ The #diffeq-bridged channel in the [Julia Slack](https://julialang.org/slack/)
+ [JuliaDiffEq](https://gitter.im/JuliaDiffEq/Lobby) on Gitter
+ On the Julia Discourse forums (look for the [modelingtoolkit tag](https://discourse.julialang.org/tag/modelingtoolkit))
+ The #diffeq-bridged and #sciml-bridged channels in the
[Julia Slack](https://julialang.org/slack/)
+ The #diffeq-bridged and #sciml-bridged channels in the
[Julia Zulip](https://julialang.zulipchat.com/#narrow/stream/279055-sciml-bridged)
+ On the [Julia Discourse forums](https://discourse.julialang.org)
+ See also [SciML Community page](https://sciml.ai/community/)

## Reproducibility
Expand Down
2 changes: 1 addition & 1 deletion docs/src/systems/DiscreteSystem.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ DiscreteSystem

```@docs
DiscreteFunction(sys::ModelingToolkit.DiscreteSystem, args...)
DiscreteProblem(sys::ModelingToolkit.DiscreteSystem, args...)
DiscreteProblem(sys::ModelingToolkit.DiscreteSystem, u0map, tspan)
```

## Expression Constructors
Expand Down
8 changes: 5 additions & 3 deletions docs/src/systems/JumpSystem.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@ JumpSystem

## Transformations

```@docs
```@docs; canonical=false
structural_simplify
```

## Analyses

## Problem Constructors

```@docs; canonical=false
DiscreteProblem(sys::ModelingToolkit.DiscreteSystem, u0map, tspan)
```
```@docs
SciMLBase.DiscreteProblem(sys::JumpSystem,args...)
JumpProcesses.JumpProblem(sys::JumpSystem,args...)
JumpProblem(sys::JumpSystem, prob, aggregator)
```
6 changes: 3 additions & 3 deletions docs/src/systems/NonlinearSystem.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@ NonlinearSystem

## Transformations

```@docs
```@docs; canonical=false
structural_simplify
alias_elimination
tearing
```

## Analyses

```@docs
```@docs; canonical=false
ModelingToolkit.isaffine
ModelingToolkit.islinear
```

## Applicable Calculation and Generation Functions

```julia
```@docs; canonical=false
calculate_jacobian
generate_jacobian
jacobian_sparsity
Expand Down
4 changes: 2 additions & 2 deletions docs/src/systems/ODESystem.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ ModelingToolkit.isaffine

## Applicable Calculation and Generation Functions

```julia
```@docs; canonical=false
calculate_jacobian
calculate_tgrad
calculate_factorized_W
Expand All @@ -56,7 +56,7 @@ SteadyStateProblem(sys::ModelingToolkit.AbstractODESystem, args...)
## Torn Problem Constructors

```@docs
ODAEProblem(sys::ModelingToolkit.AbstractODESystem, args...)
ODAEProblem
```

## Expression Constructors
Expand Down
8 changes: 5 additions & 3 deletions docs/src/systems/SDESystem.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,19 @@ sde = SDESystem(ode, noiseeqs)

## Transformations

```@docs
```@docs; canonical=false
structural_simplify
alias_elimination
Girsanov_transform
```
```@docs
ModelingToolkit.Girsanov_transform
```

## Analyses

## Applicable Calculation and Generation Functions

```julia
```@docs; canonical=false
calculate_jacobian
calculate_tgrad
calculate_factorized_W
Expand Down
Loading
Loading