Skip to content

Commit 5367f60

Browse files
authored
Merge branch 'SciML:master' into master
2 parents 7d5e915 + 34a4afd commit 5367f60

Some content is hidden

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

74 files changed

+2150
-1373
lines changed

.github/workflows/benchmark.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Benchmark this PR
2+
on:
3+
pull_request:
4+
branches:
5+
- master
6+
paths-ignore:
7+
- 'docs/**'
8+
9+
permissions:
10+
pull-requests: write # needed to post comments
11+
12+
jobs:
13+
bench:
14+
name: "Benchmarks"
15+
strategy:
16+
matrix:
17+
version:
18+
- "1"
19+
- "lts"
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: MilesCranmer/AirspeedVelocity.jl@action-v1
23+
with:
24+
julia-version: "${{ matrix.version }}"

Project.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ModelingToolkit"
22
uuid = "961ee093-0014-501f-94e3-6117800e7a78"
33
authors = ["Yingbo Ma <mayingbo5@gmail.com>", "Chris Rackauckas <accounts@chrisrackauckas.com> and contributors"]
4-
version = "10.1.0"
4+
version = "10.2.0"
55

66
[deps]
77
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
@@ -73,6 +73,7 @@ DeepDiffs = "ab62b9b5-e342-54a8-a765-a90f495de1a6"
7373
FMI = "14a09403-18e3-468f-ad8a-74f8dda2d9ac"
7474
InfiniteOpt = "20393b10-9daf-11e9-18c9-8db751c92c57"
7575
LabelledArrays = "2ee39098-c373-598a-b85f-a56591580800"
76+
Pyomo = "0e8e1daf-01b5-4eba-a626-3897743a3816"
7677

7778
[extensions]
7879
MTKBifurcationKitExt = "BifurcationKit"
@@ -81,6 +82,7 @@ MTKDeepDiffsExt = "DeepDiffs"
8182
MTKFMIExt = "FMI"
8283
MTKInfiniteOptExt = "InfiniteOpt"
8384
MTKLabelledArraysExt = "LabelledArrays"
85+
MTKPyomoDynamicOptExt = "Pyomo"
8486

8587
[compat]
8688
ADTypes = "1.14.0"
@@ -140,6 +142,7 @@ OrdinaryDiffEqCore = "1.15.0"
140142
OrdinaryDiffEqDefault = "1.2"
141143
OrdinaryDiffEqNonlinearSolve = "1.5.0"
142144
PrecompileTools = "1"
145+
Pyomo = "0.1.0"
143146
REPL = "1"
144147
RecursiveArrayTools = "3.26"
145148
Reexport = "0.2, 1"

benchmark/Project.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[deps]
2+
ModelingToolkitStandardLibrary = "16a59e39-deab-5bd0-87e4-056b12336739"
3+
OrdinaryDiffEqDefault = "50262376-6c5a-4cf5-baba-aaf4f84d72d7"

benchmark/benchmarks.jl

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using ModelingToolkit, BenchmarkTools
2+
using ModelingToolkitStandardLibrary
3+
using ModelingToolkitStandardLibrary.Thermal
4+
using OrdinaryDiffEqDefault
5+
6+
const SUITE = BenchmarkGroup()
7+
8+
@mtkmodel DCMotor begin
9+
@structural_parameters begin
10+
R = 0.5
11+
L = 4.5e-3
12+
k = 0.5
13+
J = 0.02
14+
f = 0.01
15+
V_step = 10
16+
tau_L_step = -3
17+
end
18+
@components begin
19+
ground = Ground()
20+
source = Voltage()
21+
voltage_step = Blocks.Step(height = V_step, start_time = 0)
22+
R1 = Resistor(R = R)
23+
L1 = Inductor(L = L, i = 0.0)
24+
emf = EMF(k = k)
25+
fixed = Fixed()
26+
load = Torque()
27+
load_step = Blocks.Step(height = tau_L_step, start_time = 3)
28+
inertia = Inertia(J = J)
29+
friction = Damper(d = f)
30+
end
31+
@equations begin
32+
connect(fixed.flange, emf.support, friction.flange_b)
33+
connect(emf.flange, friction.flange_a, inertia.flange_a)
34+
connect(inertia.flange_b, load.flange)
35+
connect(load_step.output, load.tau)
36+
connect(voltage_step.output, source.V)
37+
connect(source.p, R1.p)
38+
connect(R1.n, L1.p)
39+
connect(L1.n, emf.p)
40+
connect(emf.n, source.n, ground.g)
41+
end
42+
end
43+
44+
@named model = DCMotor()
45+
46+
SUITE["mtkcompile"] = @benchmarkable mtkcompile($model)
47+
48+
model = mtkcompile(model)
49+
u0 = unknowns(model) .=> 0.0
50+
tspan = (0.0, 6.0)
51+
SUITE["ODEProblem"] = @benchmarkable ODEProblem($model, $u0, $tspan)
52+
53+
prob = ODEProblem(model, u0, tspan)
54+
SUITE["init"] = init($prob)

docs/Project.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,18 @@ Attractors = "f3fd9213-ca85-4dba-9dfd-7fc91308fec7"
33
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
44
BifurcationKit = "0f109fa4-8a5d-4b75-95aa-f515264e7665"
55
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
6+
CommonSolve = "38540f10-b2f7-11e9-35d8-d573e4eb0ff2"
67
ControlSystemsBase = "aaaaaaaa-a6ca-5380-bf3e-84a91bcd477e"
78
DataInterpolations = "82cc6244-b520-54b8-b5a6-8a565e85f1d0"
9+
DiffEqDevTools = "f3b72e0c-5b89-59e1-b016-84e28bfd966d"
810
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
911
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
1012
DynamicQuantities = "06fc5a27-2a28-4c7c-a15d-362465fb6821"
1113
FMI = "14a09403-18e3-468f-ad8a-74f8dda2d9ac"
1214
FMIZoo = "724179cf-c260-40a9-bd27-cccc6fe2f195"
15+
InfiniteOpt = "20393b10-9daf-11e9-18c9-8db751c92c57"
16+
Ipopt = "b6b21f68-93f8-5de0-b562-5493be1d77c9"
17+
JumpProcesses = "ccbc3e58-028d-4f4c-8cd5-9ae44345cda5"
1318
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1419
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"
1520
ModelingToolkitStandardLibrary = "16a59e39-deab-5bd0-87e4-056b12336739"
@@ -31,12 +36,17 @@ Attractors = "1.24"
3136
BenchmarkTools = "1.3"
3237
BifurcationKit = "0.4"
3338
CairoMakie = "0.13"
39+
CommonSolve = "0.2"
3440
DataInterpolations = "6.5, 8"
41+
DiffEqDevTools = "2"
3542
Distributions = "0.25"
3643
Documenter = "1"
3744
DynamicQuantities = "^0.11.2, 0.12, 1"
3845
FMI = "0.14"
3946
FMIZoo = "1"
47+
InfiniteOpt = "0.5"
48+
Ipopt = "1"
49+
JumpProcesses = "9"
4050
ModelingToolkit = "10"
4151
ModelingToolkitStandardLibrary = "2.19"
4252
NonlinearSolve = "3, 4"

docs/make.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
using Documenter, ModelingToolkit
22
using ModelingToolkit: SciMLBase
3+
# To load docstring from extension
4+
import FMI, CommonSolve, JumpProcesses
5+
6+
MTKFMIExt = Base.get_extension(ModelingToolkit, :MTKFMIExt)
37

48
# Make sure that plots don't throw a bunch of warnings / errors!
59
ENV["GKSwstype"] = "100"
@@ -22,7 +26,7 @@ mathengine = MathJax3(Dict(:loader => Dict("load" => ["[tex]/require", "[tex]/ma
2226

2327
makedocs(sitename = "ModelingToolkit.jl",
2428
authors = "Chris Rackauckas",
25-
modules = [ModelingToolkit],
29+
modules = [ModelingToolkit, MTKFMIExt],
2630
clean = true, doctest = false, linkcheck = true,
2731
warnonly = [:docs_block, :missing_docs, :cross_references],
2832
linkcheck_ignore = [
@@ -35,7 +39,9 @@ makedocs(sitename = "ModelingToolkit.jl",
3539
assets = ["assets/favicon.ico"],
3640
mathengine,
3741
canonical = "https://docs.sciml.ai/ModelingToolkit/stable/",
38-
prettyurls = (get(ENV, "CI", nothing) == "true")),
42+
prettyurls = (get(ENV, "CI", nothing) == "true"),
43+
# This page gets especially big with all the problem docstrings
44+
size_threshold_ignore = ["API/problems.md"]),
3945
pages = pages)
4046

4147
deploydocs(repo = "github.com/SciML/ModelingToolkit.jl.git";

docs/pages.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pages = [
88
"tutorials/modelingtoolkitize.md",
99
"tutorials/programmatically_generating.md",
1010
"tutorials/stochastic_diffeq.md",
11+
"tutorials/dynamic_optimization.md",
1112
"tutorials/discrete_system.md",
1213
"tutorials/parameter_identifiability.md",
1314
"tutorials/change_independent_variable.md",
@@ -31,6 +32,7 @@ pages = [
3132
"API/variables.md",
3233
"API/model_building.md",
3334
"API/problems.md",
35+
"API/dynamic_opt.md",
3436
"API/codegen.md",
3537
"API/PDESystem.md"],
3638
"Basics" => Any[

docs/src/API/System.md

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ or analysis points of the hierarchical system.
3232
ModelingToolkit.has_eqs
3333
ModelingToolkit.get_eqs
3434
equations
35-
equations_toplevel
35+
ModelingToolkit.equations_toplevel
3636
full_equations
3737
ModelingToolkit.has_noise_eqs
3838
ModelingToolkit.get_noise_eqs
@@ -44,17 +44,17 @@ ModelingToolkit.get_constraints
4444
constraints
4545
ModelingToolkit.has_costs
4646
ModelingToolkit.get_costs
47-
costs
47+
cost
4848
ModelingToolkit.has_consolidate
4949
ModelingToolkit.get_consolidate
5050
ModelingToolkit.has_unknowns
5151
ModelingToolkit.get_unknowns
5252
unknowns
53-
unknowns_toplevel
53+
ModelingToolkit.unknowns_toplevel
5454
ModelingToolkit.has_ps
5555
ModelingToolkit.get_ps
5656
parameters
57-
parameters_toplevel
57+
ModelingToolkit.parameters_toplevel
5858
tunable_parameters
5959
ModelingToolkit.has_brownians
6060
ModelingToolkit.get_brownians
@@ -77,19 +77,20 @@ defaults
7777
ModelingToolkit.has_guesses
7878
ModelingToolkit.get_guesses
7979
guesses
80+
ModelingToolkit.get_systems
8081
ModelingToolkit.has_initialization_eqs
8182
ModelingToolkit.get_initialization_eqs
8283
initialization_equations
8384
ModelingToolkit.has_continuous_events
8485
ModelingToolkit.get_continuous_events
8586
continuous_events
86-
continuous_events_toplevel
87+
ModelingToolkit.continuous_events_toplevel
8788
ModelingToolkit.has_discrete_events
8889
ModelingToolkit.get_discrete_events
89-
discrete_events_toplevel
90+
ModelingToolkit.discrete_events_toplevel
9091
ModelingToolkit.has_assertions
9192
ModelingToolkit.get_assertions
92-
assertions
93+
ModelingToolkit.assertions
9394
ModelingToolkit.has_metadata
9495
ModelingToolkit.get_metadata
9596
SymbolicUtils.getmetadata(::ModelingToolkit.AbstractSystem, ::DataType, ::Any)
@@ -144,8 +145,8 @@ has_diff_equations
144145
has_alg_equations
145146
diff_equations
146147
alg_equations
147-
is_alg_equation
148-
is_diff_equation
148+
ModelingToolkit.is_alg_equation
149+
ModelingToolkit.is_diff_equation
149150
```
150151

151152
## String parsing
@@ -167,6 +168,18 @@ ModelingToolkit.dump_parameters
167168
ModelingToolkit.dump_variable_metadata
168169
```
169170

171+
## Inputs and outputs
172+
173+
```@docs
174+
ModelingToolkit.inputs
175+
ModelingToolkit.outputs
176+
ModelingToolkit.bound_inputs
177+
ModelingToolkit.unbound_inputs
178+
ModelingToolkit.bound_outputs
179+
ModelingToolkit.unbound_outputs
180+
ModelingToolkit.is_bound
181+
```
182+
170183
## Debugging utilities
171184

172185
```@docs

docs/src/API/codegen.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ ModelingToolkit.generate_rhs
88
ModelingToolkit.generate_diffusion_function
99
ModelingToolkit.generate_jacobian
1010
ModelingToolkit.generate_tgrad
11-
ModelingToolkit.generate_hessian
1211
ModelingToolkit.generate_W
1312
ModelingToolkit.generate_dae_jacobian
1413
ModelingToolkit.generate_history
@@ -21,6 +20,7 @@ ModelingToolkit.generate_constraint_jacobian
2120
ModelingToolkit.generate_constraint_hessian
2221
ModelingToolkit.generate_control_jacobian
2322
ModelingToolkit.build_explicit_observed_function
23+
ModelingToolkit.generate_control_function
2424
```
2525

2626
For functions such as jacobian calculation which require symbolic computation, there
@@ -43,3 +43,9 @@ ModelingToolkit.calculate_constraint_jacobian
4343
ModelingToolkit.calculate_constraint_hessian
4444
ModelingToolkit.calculate_control_jacobian
4545
```
46+
47+
All code generation eventually calls `build_function_wrapper`.
48+
49+
```@docs
50+
build_function_wrapper
51+
```

docs/src/API/dynamic_opt.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
### Solvers
2+
3+
Currently 4 backends are exposed for solving dynamic optimization problems using collocation: JuMP, InfiniteOpt, CasADi, and Pyomo.
4+
5+
Please note that there are differences in how to construct the collocation solver for the different cases. For example, the Python based ones, CasADi and Pyomo, expect the solver to be passed in as a string (CasADi and Pyomo come pre-loaded with Ipopt, but other solvers may need to be manually installed using `pip` or `conda`), while JuMP/InfiniteOpt expect the optimizer object to be passed in directly:
6+
7+
```
8+
JuMPCollocation(Ipopt.Optimizer, constructRK4())
9+
CasADiCollocation("ipopt", constructRK4())
10+
```
11+
12+
**JuMP** and **CasADi** collocation require an ODE tableau to be passed in. These can be constructed by calling the `constructX()` functions from DiffEqDevTools. The list of tableaus can be found [here](https://docs.sciml.ai/DiffEqDevDocs/dev/internals/tableaus/). If none is passed in, both solvers will default to using Radau second-order with five collocation points.
13+
14+
**Pyomo** and **InfiniteOpt** each have their own built-in collocation methods.
15+
16+
1. **InfiniteOpt**: The list of InfiniteOpt collocation methods can be found [in the table on this page](https://infiniteopt.github.io/InfiniteOpt.jl/stable/guide/derivative/). If none is passed in, the solver defaults to `FiniteDifference(Backward())`, which is effectively implicit Euler.
17+
2. **Pyomo**: The list of Pyomo collocation methods can be found [at the bottom of this page](https://github.com/SciML/Pyomo.jl). If none is passed in, the solver defaults to a `LagrangeRadau(3)`.
18+
19+
Some examples of the latter two collocations:
20+
21+
```julia
22+
PyomoCollocation("ipopt", LagrangeRadau(2))
23+
InfiniteOptCollocation(Ipopt.Optimizer, OrthogonalCollocation(3))
24+
```
25+
26+
```@docs; canonical = false
27+
JuMPCollocation
28+
InfiniteOptCollocation
29+
CasADiCollocation
30+
PyomoCollocation
31+
CommonSolve.solve(::AbstractDynamicOptProblem)
32+
```
33+
34+
### Problem constructors
35+
36+
```@docs; canonical = false
37+
JuMPDynamicOptProblem
38+
InfiniteOptDynamicOptProblem
39+
CasADiDynamicOptProblem
40+
PyomoDynamicOptProblem
41+
```

0 commit comments

Comments
 (0)