Skip to content

Commit

Permalink
Merge branch 'master' into careful-event-affects
Browse files Browse the repository at this point in the history
  • Loading branch information
BenChung committed Dec 3, 2024
2 parents 3c6b37e + 1f669d9 commit 5fcf864
Show file tree
Hide file tree
Showing 48 changed files with 1,863 additions and 338 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/Documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ jobs:
JULIA_DEBUG: "Documenter"
run: DISPLAY=:0 xvfb-run -s '-screen 0 1024x768x24' julia --project=docs/ --code-coverage=user docs/make.jl
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v4
- uses: codecov/codecov-action@v5
with:
file: lcov.info
files: lcov.info
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
6 changes: 3 additions & 3 deletions .github/workflows/Downstream.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ jobs:
exit(0) # Exit immediately, as a success
end
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v4
- uses: codecov/codecov-action@v5
with:
file: lcov.info
files: lcov.info
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
fail_ci_if_error: false
1 change: 1 addition & 0 deletions .github/workflows/Tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
group:
- InterfaceI
- InterfaceII
- Initialization
- SymbolicIndexingInterface
- Extended
- Extensions
Expand Down
11 changes: 7 additions & 4 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 = "9.50.0"
version = "9.54.0"

[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
Expand Down Expand Up @@ -64,6 +64,7 @@ BifurcationKit = "0f109fa4-8a5d-4b75-95aa-f515264e7665"
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
DeepDiffs = "ab62b9b5-e342-54a8-a765-a90f495de1a6"
HomotopyContinuation = "f213a82b-91d6-5c5d-acf7-10f1c761b327"
InfiniteOpt = "20393b10-9daf-11e9-18c9-8db751c92c57"
LabelledArrays = "2ee39098-c373-598a-b85f-a56591580800"

[extensions]
Expand All @@ -72,6 +73,7 @@ MTKChainRulesCoreExt = "ChainRulesCore"
MTKDeepDiffsExt = "DeepDiffs"
MTKHomotopyContinuationExt = "HomotopyContinuation"
MTKLabelledArraysExt = "LabelledArrays"
MTKInfiniteOptExt = "InfiniteOpt"

[compat]
AbstractTrees = "0.3, 0.4"
Expand Down Expand Up @@ -104,6 +106,7 @@ FunctionWrappers = "1.1"
FunctionWrappersWrappers = "0.1"
Graphs = "1.5.2"
HomotopyContinuation = "2.11"
InfiniteOpt = "0.5"
InteractiveUtils = "1"
JuliaFormatter = "1.0.47"
JumpProcesses = "9.13.1"
Expand All @@ -123,17 +126,17 @@ REPL = "1"
RecursiveArrayTools = "3.26"
Reexport = "0.2, 1"
RuntimeGeneratedFunctions = "0.5.9"
SciMLBase = "2.57.1"
SciMLBase = "2.64"
SciMLStructures = "1.0"
Serialization = "1"
Setfield = "0.7, 0.8, 1"
SimpleNonlinearSolve = "0.1.0, 1, 2"
SparseArrays = "1"
SpecialFunctions = "0.7, 0.8, 0.9, 0.10, 1.0, 2"
StaticArrays = "0.10, 0.11, 0.12, 1.0"
SymbolicIndexingInterface = "0.3.31"
SymbolicIndexingInterface = "0.3.35"
SymbolicUtils = "3.7"
Symbolics = "6.15.4"
Symbolics = "6.19"
URIs = "1"
UnPack = "0.1, 1.0"
Unitful = "1.1"
Expand Down
4 changes: 2 additions & 2 deletions docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ DynamicQuantities = "^0.11.2, 0.12, 1"
ModelingToolkit = "8.33, 9"
NonlinearSolve = "3, 4"
Optim = "1.7"
Optimization = "3.9"
OptimizationOptimJL = "0.1"
Optimization = "3.9, 4"
OptimizationOptimJL = "0.1, 0.4"
OrdinaryDiffEq = "6.31"
Plots = "1.36"
SciMLStructures = "1.1"
Expand Down
10 changes: 10 additions & 0 deletions docs/src/basics/FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ parameter_index(sys, sym)
Note that while the variable index will be an integer, the parameter index is a struct of
type `ParameterIndex` whose internals should not be relied upon.

## Can I index with strings?

Strings are not considered symbolic variables, and thus cannot directly be used for symbolic
indexing. However, ModelingToolkit does provide a method to parse the string representation of
a variable, given the system in which that variable exists.

```@docs
ModelingToolkit.parse_variable
```

## Transforming value maps to arrays

ModelingToolkit.jl allows (and recommends) input maps like `[x => 2.0, y => 3.0]`
Expand Down
38 changes: 38 additions & 0 deletions docs/src/basics/Variable_metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,44 @@ hasbounds(u)
getbounds(u)
```

Bounds can also be specified for array variables. A scalar array bound is applied to each
element of the array. A bound may also be specified as an array, in which case the size of
the array must match the size of the symbolic variable.

```@example metadata
@variables x[1:2, 1:2] [bounds = (-1, 1)]
hasbounds(x)
```

```@example metadata
getbounds(x)
```

```@example metadata
getbounds(x[1, 1])
```

```@example metadata
getbounds(x[1:2, 1])
```

```@example metadata
@variables x[1:2] [bounds = (-Inf, [1.0, Inf])]
hasbounds(x)
```

```@example metadata
getbounds(x)
```

```@example metadata
getbounds(x[2])
```

```@example metadata
hasbounds(x[2])
```

## Guess

Specify an initial guess for custom initial conditions of an `ODESystem`.
Expand Down
55 changes: 28 additions & 27 deletions docs/src/examples/higher_order.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
ModelingToolkit has a system for transformations of mathematical
systems. These transformations allow for symbolically changing
the representation of the model to problems that are easier to
numerically solve. One simple to demonstrate transformation is the
numerically solve. One simple to demonstrate transformation, is
`structural_simplify`, which does a lot of tricks, one being the
transformation that turns an Nth order ODE into N
coupled 1st order ODEs.
Expand All @@ -15,16 +15,28 @@ We utilize the derivative operator twice here to define the second order:
using ModelingToolkit, OrdinaryDiffEq
using ModelingToolkit: t_nounits as t, D_nounits as D
@parameters σ ρ β
@variables x(t) y(t) z(t)
eqs = [D(D(x)) ~ σ * (y - x),
D(y) ~ x * (ρ - z) - y,
D(z) ~ x * y - β * z]
@named sys = ODESystem(eqs, t)
@mtkmodel SECOND_ORDER begin
@parameters begin
σ = 28.0
ρ = 10.0
β = 8 / 3
end
@variables begin
x(t) = 1.0
y(t) = 0.0
z(t) = 0.0
end
@equations begin
D(D(x)) ~ σ * (y - x)
D(y) ~ x * (ρ - z) - y
D(z) ~ x * y - β * z
end
end
@mtkbuild sys = SECOND_ORDER()
```

The second order ODE has been automatically transformed to two first order ODEs.

Note that we could've used an alternative syntax for 2nd order, i.e.
`D = Differential(t)^2` and then `D(x)` would be the second derivative,
and this syntax extends to `N`-th order. Also, we can use `*` or `` to compose
Expand All @@ -33,28 +45,17 @@ and this syntax extends to `N`-th order. Also, we can use `*` or `∘` to compos
Now let's transform this into the `ODESystem` of first order components.
We do this by calling `structural_simplify`:

```@example orderlowering
sys = structural_simplify(sys)
```

Now we can directly numerically solve the lowered system. Note that,
following the original problem, the solution requires knowing the
initial condition for `x'`, and thus we include that in our input
specification:
initial condition for both `x` and `D(x)`.
The former already got assigned a default value in the `@mtkmodel`,
but we still have to provide a value for the latter.

```@example orderlowering
u0 = [D(x) => 2.0,
x => 1.0,
y => 0.0,
z => 0.0]
p = [σ => 28.0,
ρ => 10.0,
β => 8 / 3]
u0 = [D(sys.x) => 2.0]
tspan = (0.0, 100.0)
prob = ODEProblem(sys, u0, tspan, p, jac = true)
prob = ODEProblem(sys, u0, tspan, [], jac = true)
sol = solve(prob, Tsit5())
using Plots;
plot(sol, idxs = (x, y));
using Plots
plot(sol, idxs = (sys.x, sys.y))
```
3 changes: 2 additions & 1 deletion docs/src/examples/perturbation.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ eqs_pert = taylor_coeff(eq_pert, ϵ, 0:2)
!!! note

The 0-th order equation can be solved analytically, but ModelingToolkit does currently not feature automatic analytical solution of ODEs, so we proceed with solving it numerically.
These are the ODEs we want to solve. Now construct an `ODESystem`, which automatically inserts dummy derivatives for the velocities:

These are the ODEs we want to solve. Now construct an `ODESystem`, which automatically inserts dummy derivatives for the velocities:

```@example perturbation
@mtkbuild sys = ODESystem(eqs_pert, t)
Expand Down
2 changes: 1 addition & 1 deletion docs/src/tutorials/initialization.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ the `initialization_eqs` keyword argument, for example:

```@example init
prob = ODEProblem(pend, [x => 1], (0.0, 1.5), [g => 1], guesses = [λ => 0, y => 1],
initialization_eqs = [y ~ 1])
initialization_eqs = [y ~ 0])
sol = solve(prob, Rodas5P())
plot(sol, idxs = (x, y))
```
Expand Down
Loading

0 comments on commit 5fcf864

Please sign in to comment.