Skip to content

Commit

Permalink
docs: call complete where required in documentation before creating…
Browse files Browse the repository at this point in the history
… `XProblem`s
  • Loading branch information
AayushSabharwal committed Jan 29, 2024
1 parent 039a45d commit aaed089
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 11 deletions.
4 changes: 2 additions & 2 deletions docs/src/basics/Events.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function UnitMassWithFriction(k; name)
ODESystem(eqs, t; continuous_events = [v ~ 0], name) # when v = 0 there is a discontinuity
end
@named m = UnitMassWithFriction(0.7)
prob = ODEProblem(m, Pair[], (0, 10pi))
prob = ODEProblem(complete(m), Pair[], (0, 10pi))
sol = solve(prob, Tsit5())
plot(sol)
```
Expand Down Expand Up @@ -244,7 +244,7 @@ u0 = [N => 0.0]
tspan = (0.0, 20.0)
p = [α => 100.0, tinject => 10.0, M => 50]
@named osys = ODESystem(eqs, t, [N], [α, M, tinject]; discrete_events = injection)
oprob = ODEProblem(osys, u0, tspan, p)
oprob = ODEProblem(complete(osys), u0, tspan, p)
sol = solve(oprob, Tsit5(); tstops = 10.0)
plot(sol)
```
Expand Down
2 changes: 1 addition & 1 deletion docs/src/examples/parsing.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ using ModelingToolkit, NonlinearSolve
vars = union(ModelingToolkit.vars.(eqs)...)
@named ns = NonlinearSystem(eqs, vars, [])
prob = NonlinearProblem(ns, [1.0, 1.0, 1.0])
prob = NonlinearProblem(complete(ns), [1.0, 1.0, 1.0])
sol = solve(prob, NewtonRaphson())
```
1 change: 1 addition & 0 deletions docs/src/examples/sparse_jacobians.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Now let's use `modelingtoolkitize` to generate the symbolic version:

```@example sparsejac
sys = modelingtoolkitize(prob);
sys = complete(sys);
nothing # hide
```

Expand Down
2 changes: 2 additions & 0 deletions docs/src/tutorials/bifurcation_diagram_computation.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ using ModelingToolkit
eqs = [0 ~ μ * x - x^3 + α * y,
0 ~ -y]
@named nsys = NonlinearSystem(eqs, [x, y], [μ, α])
nsys = complete(nsys)
```

we wish to compute a bifurcation diagram for this system as we vary the parameter `μ`. For this, we need to provide the following information:
Expand Down Expand Up @@ -97,6 +98,7 @@ D = Differential(t)
eqs = [D(x) ~ μ * x - y - x * (x^2 + y^2),
D(y) ~ x + μ * y - y * (x^2 + y^2)]
@named osys = ODESystem(eqs, t)
osys = complete(osys)
bif_par = μ
plot_var = x
Expand Down
2 changes: 1 addition & 1 deletion docs/src/tutorials/modelingtoolkitize.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,5 @@ sys = modelingtoolkitize(prob)
Using this, we can symbolically build the Jacobian and then rebuild the ODEProblem:

```@example mtkize
prob_jac = ODEProblem(sys, [], (0.0, 1e5), jac = true)
prob_jac = ODEProblem(complete(sys), [], (0.0, 1e5), jac = true)
```
1 change: 1 addition & 0 deletions docs/src/tutorials/nonlinear.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ eqs = [0 ~ σ * (y - x),
0 ~ x * (ρ - z) - y,
0 ~ x * y - β * z]
@named ns = NonlinearSystem(eqs, [x, y, z], [σ, ρ, β])
ns = complete(ns)
guess = [x => 1.0,
y => 0.0,
Expand Down
4 changes: 2 additions & 2 deletions docs/src/tutorials/optimization.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ u0 = [x => 1.0
p = [a => 1.0
b => 100.0]
prob = OptimizationProblem(sys, u0, p, grad = true, hess = true)
prob = OptimizationProblem(complete(sys), u0, p, grad = true, hess = true)
solve(prob, GradientDescent())
```

Expand All @@ -71,7 +71,7 @@ cons = [
@named sys = OptimizationSystem(loss, [x, y], [a, b], constraints = cons)
u0 = [x => 0.14
y => 0.14]
prob = OptimizationProblem(sys, u0, grad = true, hess = true, cons_j = true, cons_h = true)
prob = OptimizationProblem(complete(sys), u0, grad = true, hess = true, cons_j = true, cons_h = true)
solve(prob, IPNewton())
```

Expand Down
1 change: 1 addition & 0 deletions docs/src/tutorials/stochastic_diffeq.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ noiseeqs = [0.1 * x,
0.1 * z]
@named de = SDESystem(eqs, noiseeqs, t, [x, y, z], [σ, ρ, β])
de = complete(de)
u0map = [
x => 1.0,
Expand Down
2 changes: 2 additions & 0 deletions src/systems/abstractsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1330,6 +1330,8 @@ information. E.g.
```julia-repl
julia> sys = debug_system(sys);
julia> sys = complete(sys);
julia> prob = ODEProblem(sys, [], (0, 1.0));
julia> du = zero(prob.u0);
Expand Down
2 changes: 1 addition & 1 deletion src/systems/diffeqs/basic_transformations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ u0 = [x => 1.0,
y => 1.0,
trJ => 1.0]
prob = ODEProblem(sys2,u0,tspan,p)
prob = ODEProblem(complete(sys2),u0,tspan,p)
sol = solve(prob,Tsit5())
```
Expand Down
2 changes: 1 addition & 1 deletion src/systems/diffeqs/sdesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ parammap = [
β => 1.0
]
probmod = SDEProblem(demod,u0modmap,(0.0,1.0),parammap)
probmod = SDEProblem(complete(demod),u0modmap,(0.0,1.0),parammap)
ensemble_probmod = EnsembleProblem(probmod;
output_func = (sol,i) -> (g(sol[x,end])*sol[demod.weight,end],false),
)
Expand Down
6 changes: 3 additions & 3 deletions src/systems/jumps/jumpsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ using DiffEqBase, JumpProcesses
u₀map = [S => 999, I => 1, R => 0]
parammap = [β => 0.1 / 1000, γ => 0.01]
tspan = (0.0, 250.0)
dprob = DiscreteProblem(js, u₀map, tspan, parammap)
dprob = DiscreteProblem(complete(js), u₀map, tspan, parammap)
```
"""
function DiffEqBase.DiscreteProblem(sys::JumpSystem, u0map, tspan::Union{Tuple, Nothing},
Expand Down Expand Up @@ -347,7 +347,7 @@ using DiffEqBase, JumpProcesses
u₀map = [S => 999, I => 1, R => 0]
parammap = [β => 0.1 / 1000, γ => 0.01]
tspan = (0.0, 250.0)
dprob = DiscreteProblem(js, u₀map, tspan, parammap)
dprob = DiscreteProblem(complete(js), u₀map, tspan, parammap)
```
"""
struct DiscreteProblemExpr{iip} end
Expand Down Expand Up @@ -388,7 +388,7 @@ Generates a JumpProblem from a JumpSystem.
Continuing the example from the [`DiscreteProblem`](@ref) definition:
```julia
jprob = JumpProblem(js, dprob, Direct())
jprob = JumpProblem(complete(js), dprob, Direct())
sol = solve(jprob, SSAStepper())
```
"""
Expand Down

0 comments on commit aaed089

Please sign in to comment.