Skip to content

Commit 1b2d474

Browse files
docs: use @mtkbuild instead of manually calling complete
1 parent 28fee62 commit 1b2d474

11 files changed

+32
-41
lines changed

docs/src/basics/Events.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ function UnitMassWithFriction(k; name)
7272
D(v) ~ sin(t) - k * sign(v)]
7373
ODESystem(eqs, t; continuous_events = [v ~ 0], name) # when v = 0 there is a discontinuity
7474
end
75-
@named m = UnitMassWithFriction(0.7)
76-
prob = ODEProblem(complete(m), Pair[], (0, 10pi))
75+
@mtkbuild m = UnitMassWithFriction(0.7)
76+
prob = ODEProblem(m, Pair[], (0, 10pi))
7777
sol = solve(prob, Tsit5())
7878
plot(sol)
7979
```
@@ -243,8 +243,8 @@ injection = (t == tinject) => [N ~ N + M]
243243
u0 = [N => 0.0]
244244
tspan = (0.0, 20.0)
245245
p = [α => 100.0, tinject => 10.0, M => 50]
246-
@named osys = ODESystem(eqs, t, [N], [α, M, tinject]; discrete_events = injection)
247-
oprob = ODEProblem(complete(osys), u0, tspan, p)
246+
@mtkbuild osys = ODESystem(eqs, t, [N], [α, M, tinject]; discrete_events = injection)
247+
oprob = ODEProblem(osys, u0, tspan, p)
248248
sol = solve(oprob, Tsit5(); tstops = 10.0)
249249
plot(sol)
250250
```
@@ -262,7 +262,7 @@ to
262262
```@example events
263263
injection = ((t == tinject) & (N < 50)) => [N ~ N + M]
264264
265-
@named osys = ODESystem(eqs, t, [N], [M, tinject, α]; discrete_events = injection)
265+
@mtkbuild osys = ODESystem(eqs, t, [N], [M, tinject, α]; discrete_events = injection)
266266
oprob = ODEProblem(osys, u0, tspan, p)
267267
sol = solve(oprob, Tsit5(); tstops = 10.0)
268268
plot(sol)
@@ -287,7 +287,7 @@ killing = (t == tkill) => [α ~ 0.0]
287287
288288
tspan = (0.0, 30.0)
289289
p = [α => 100.0, tinject => 10.0, M => 50, tkill => 20.0]
290-
@named osys = ODESystem(eqs, t, [N], [α, M, tinject, tkill];
290+
@mtkbuild osys = ODESystem(eqs, t, [N], [α, M, tinject, tkill];
291291
discrete_events = [injection, killing])
292292
oprob = ODEProblem(osys, u0, tspan, p)
293293
sol = solve(oprob, Tsit5(); tstops = [10.0, 20.0])
@@ -315,7 +315,7 @@ injection = [10.0] => [N ~ N + M]
315315
killing = [20.0] => [α ~ 0.0]
316316
317317
p = [α => 100.0, M => 50]
318-
@named osys = ODESystem(eqs, t, [N], [α, M];
318+
@mtkbuild osys = ODESystem(eqs, t, [N], [α, M];
319319
discrete_events = [injection, killing])
320320
oprob = ODEProblem(osys, u0, tspan, p)
321321
sol = solve(oprob, Tsit5())

docs/src/examples/parsing.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ nonlinear solve:
2525
```@example parsing
2626
using ModelingToolkit, NonlinearSolve
2727
vars = union(ModelingToolkit.vars.(eqs)...)
28-
@named ns = NonlinearSystem(eqs, vars, [])
28+
@mtkbuild ns = NonlinearSystem(eqs, vars, [])
2929
30-
prob = NonlinearProblem(complete(ns), [1.0, 1.0, 1.0])
30+
prob = NonlinearProblem(ns, [1.0, 1.0, 1.0])
3131
sol = solve(prob, NewtonRaphson())
3232
```

docs/src/examples/sparse_jacobians.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ prob = ODEProblem(brusselator_2d_loop, u0, (0.0, 11.5), p)
5454
Now let's use `modelingtoolkitize` to generate the symbolic version:
5555

5656
```@example sparsejac
57-
sys = modelingtoolkitize(prob);
58-
sys = complete(sys);
57+
@mtkbuild sys = modelingtoolkitize(prob);
5958
nothing # hide
6059
```
6160

docs/src/tutorials/bifurcation_diagram_computation.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ using ModelingToolkit
1212
@parameters μ α
1313
eqs = [0 ~ μ * x - x^3 + α * y,
1414
0 ~ -y]
15-
@named nsys = NonlinearSystem(eqs, [x, y], [μ, α])
16-
nsys = complete(nsys)
15+
@mtkbuild nsys = NonlinearSystem(eqs, [x, y], [μ, α])
1716
```
1817

1918
we wish to compute a bifurcation diagram for this system as we vary the parameter `μ`. For this, we need to provide the following information:
@@ -94,8 +93,7 @@ using BifurcationKit, ModelingToolkit, Plots
9493
D = Differential(t)
9594
eqs = [D(x) ~ μ * x - y - x * (x^2 + y^2),
9695
D(y) ~ x + μ * y - y * (x^2 + y^2)]
97-
@named osys = ODESystem(eqs, t)
98-
osys = complete(osys)
96+
@mtkbuild osys = ODESystem(eqs, t)
9997
10098
bif_par = μ
10199
plot_var = x

docs/src/tutorials/domain_connections.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ To see how the domain works, we can examine the set parameter values for each of
135135

136136
```@repl domain
137137
sys = structural_simplify(odesys)
138-
ModelingToolkit.defaults(sys)[complete(odesys).vol.port.ρ]
138+
ModelingToolkit.defaults(sys)[odesys.vol.port.ρ]
139139
```
140140

141141
## Multiple Domain Networks
@@ -280,8 +280,7 @@ Adding the `Restrictor` to the original system example will cause a break in the
280280
ODESystem(eqs, t, [], []; systems, name)
281281
end
282282
283-
@named ressys = RestrictorSystem()
284-
sys = structural_simplify(ressys)
283+
@mtkbuild ressys = RestrictorSystem()
285284
nothing #hide
286285
```
287286

@@ -296,9 +295,9 @@ nothing #hide
296295
When `structural_simplify()` is applied to this system it can be seen that the defaults are missing for `res.port_b` and `vol.port`.
297296

298297
```@repl domain
299-
ModelingToolkit.defaults(sys)[complete(ressys).res.port_a.ρ]
300-
ModelingToolkit.defaults(sys)[complete(ressys).res.port_b.ρ]
301-
ModelingToolkit.defaults(sys)[complete(ressys).vol.port.ρ]
298+
ModelingToolkit.defaults(ressys)[ressys.res.port_a.ρ]
299+
ModelingToolkit.defaults(ressys)[ressys.res.port_b.ρ]
300+
ModelingToolkit.defaults(ressys)[ressys.vol.port.ρ]
302301
```
303302

304303
To ensure that the `Restrictor` component does not disrupt the domain network, the [`domain_connect()`](@ref) function can be used, which explicitly only connects the domain network and not the unknown variables.
@@ -322,15 +321,14 @@ To ensure that the `Restrictor` component does not disrupt the domain network, t
322321
ODESystem(eqs, t, [], pars; systems, name)
323322
end
324323
325-
@named ressys = RestrictorSystem()
326-
sys = structural_simplify(ressys)
324+
@mtkbuild ressys = RestrictorSystem()
327325
nothing #hide
328326
```
329327

330328
Now that the `Restrictor` component is properly defined using `domain_connect()`, the defaults for `res.port_b` and `vol.port` are properly defined.
331329

332330
```@repl domain
333-
ModelingToolkit.defaults(sys)[complete(ressys).res.port_a.ρ]
334-
ModelingToolkit.defaults(sys)[complete(ressys).res.port_b.ρ]
335-
ModelingToolkit.defaults(sys)[complete(ressys).vol.port.ρ]
331+
ModelingToolkit.defaults(ressys)[ressys.res.port_a.ρ]
332+
ModelingToolkit.defaults(ressys)[ressys.res.port_b.ρ]
333+
ModelingToolkit.defaults(ressys)[ressys.vol.port.ρ]
336334
```

docs/src/tutorials/modelingtoolkitize.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ If we want to get a symbolic representation, we can simply call `modelingtoolkit
5252
on the `prob`, which will return an `ODESystem`:
5353

5454
```@example mtkize
55-
sys = modelingtoolkitize(prob)
55+
@mtkbuild sys = modelingtoolkitize(prob)
5656
```
5757

5858
Using this, we can symbolically build the Jacobian and then rebuild the ODEProblem:
5959

6060
```@example mtkize
61-
prob_jac = ODEProblem(complete(sys), [], (0.0, 1e5), jac = true)
61+
prob_jac = ODEProblem(sys, [], (0.0, 1e5), jac = true)
6262
```

docs/src/tutorials/nonlinear.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ using ModelingToolkit, NonlinearSolve
1616
eqs = [0 ~ σ * (y - x),
1717
0 ~ x * (ρ - z) - y,
1818
0 ~ x * y - β * z]
19-
@named ns = NonlinearSystem(eqs, [x, y, z], [σ, ρ, β])
20-
ns = complete(ns)
19+
@mtkbuild ns = NonlinearSystem(eqs, [x, y, z], [σ, ρ, β])
2120
2221
guess = [x => 1.0,
2322
y => 0.0,

docs/src/tutorials/optimization.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Now we can define our optimization problem.
1919
end
2020
@parameters a=1 b=1
2121
loss = (a - x)^2 + b * (y - x^2)^2
22-
@named sys = OptimizationSystem(loss, [x, y], [a, b])
22+
@mtkbuild sys = OptimizationSystem(loss, [x, y], [a, b])
2323
```
2424

2525
A visualization of the objective function is depicted below.
@@ -50,7 +50,7 @@ u0 = [x => 1.0
5050
p = [a => 1.0
5151
b => 100.0]
5252
53-
prob = OptimizationProblem(complete(sys), u0, p, grad = true, hess = true)
53+
prob = OptimizationProblem(sys, u0, p, grad = true, hess = true)
5454
solve(prob, GradientDescent())
5555
```
5656

@@ -68,10 +68,10 @@ loss = (a - x)^2 + b * (y - x^2)^2
6868
cons = [
6969
x^2 + y^2 ≲ 1,
7070
]
71-
@named sys = OptimizationSystem(loss, [x, y], [a, b], constraints = cons)
71+
@mtkbuild sys = OptimizationSystem(loss, [x, y], [a, b], constraints = cons)
7272
u0 = [x => 0.14
7373
y => 0.14]
74-
prob = OptimizationProblem(complete(sys),
74+
prob = OptimizationProblem(sys,
7575
u0,
7676
grad = true,
7777
hess = true,

docs/src/tutorials/parameter_identifiability.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ D = Differential(t)
6363
end
6464
6565
# define the system
66-
@named de = Biohydrogenation()
67-
de = complete(de)
66+
@mtkbuild de = Biohydrogenation()
6867
```
6968

7069
After that, we are ready to check the system for local identifiability:
@@ -185,8 +184,7 @@ D = Differential(t)
185184
end
186185
end
187186
188-
@named ode = GoodwinOscillator()
189-
ode = complete(ode)
187+
@mtkbuild ode = GoodwinOscillator()
190188
191189
# check only 2 parameters
192190
to_check = [ode.b, ode.c]

docs/src/tutorials/programmatically_generating.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ eqs = [D(x) ~ (h - x) / τ] # create an array of equations
4444
4545
# Perform the standard transformations and mark the model complete
4646
# Note: Complete models cannot be subsystems of other models!
47-
fol_model = complete(structural_simplify(fol_model))
47+
fol_model = structural_simplify(model)
4848
```
4949

5050
As you can see, generating an ODESystem is as simple as creating the array of equations

0 commit comments

Comments
 (0)