Skip to content
20 changes: 10 additions & 10 deletions docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"

[compat]
AdvancedHMC = "0.6, 0.7"
AdvancedHMC = "0.8"
BenchmarkTools = "1"
CSV = "0.10"
CUDA = "5"
Expand All @@ -70,24 +70,24 @@ DiffEqGPU = "3"
DifferentialEquations = "7"
Distributions = "0.25"
Documenter = "1"
DomainSets = "0.6, 0.7"
Flux = "0.13, 0.14, 0.15, 0.16"
DomainSets = "0.7"
Flux = "0.16"
ForwardDiff = "0.10, 1"
IncompleteLU = "0.2"
Integrals = "4"
LineSearches = "7"
LinearSolve = "2, 3"
LinearSolve = "3"
Lux = "1"
LuxCUDA = "0.3"
LuxCore = "1"
MCMCChains = "6"
MCMCChains = "7"
Measurements = "2"
MethodOfLines = "0.11"
ModelingToolkit = "9.9"
ModelingToolkitNeuralNets = "1"
MultiDocumenter = "0.7, 0.8"
ModelingToolkit = "10"
ModelingToolkitNeuralNets = "2"
MultiDocumenter = "0.8"
NeuralPDE = "5.15"
NonlinearSolve = "3, 4"
NonlinearSolve = "4"
Optimization = "4"
OptimizationBBO = "0.4"
OptimizationMOI = "0.5"
Expand All @@ -109,4 +109,4 @@ SymbolicIndexingInterface = "0.3"
SymbolicRegression = "1"
Symbolics = "6"
Unitful = "1"
Zygote = "0.6, 0.7"
Zygote = "0.7"
8 changes: 4 additions & 4 deletions docs/src/getting_started/find_root.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ With the parameter values ``\sigma = 10.0``, ``\rho = 26.0``, ``\beta = 8/3``.
# Import the packages
import ModelingToolkit as MTK
import NonlinearSolve as NLS
import ModelingToolkit: @variables, @parameters, @mtkbuild
import ModelingToolkit: @variables, @parameters, @mtkcompile, mtkcompile

# Define the nonlinear system
@variables x=1.0 y=0.0 z=0.0
Expand All @@ -49,7 +49,7 @@ import ModelingToolkit: @variables, @parameters, @mtkbuild
eqs = [0 ~ σ * (y - x),
0 ~ x * (ρ - z) - y,
0 ~ x * y - β * z]
@mtkbuild ns = MTK.NonlinearSystem(eqs, [x, y, z], [σ, ρ, β])
@mtkcompile ns = MTK.NonlinearSystem(eqs, [x, y, z], [σ, ρ, β])

# Convert the symbolic system into a numerical system
prob = NLS.NonlinearProblem(ns, [])
Expand Down Expand Up @@ -83,7 +83,7 @@ Now we're ready. Let's load in these packages:
# Import the packages
import ModelingToolkit as MTK
import NonlinearSolve as NLS
import ModelingToolkit: @variables, @parameters, @mtkbuild
import ModelingToolkit: @variables, @parameters, @mtkcompile, mtkcompile
```

### Step 2: Define the Nonlinear System
Expand Down Expand Up @@ -126,7 +126,7 @@ Finally, we bring these pieces together, the equation along with its states and
define our `NonlinearSystem`:

```@example first_rootfind
@mtkbuild ns = MTK.NonlinearSystem(eqs, [x, y, z], [σ, ρ, β])
@mtkcompile ns = MTK.NonlinearSystem(eqs, [x, y, z], [σ, ρ, β])
```

### Step 3: Convert the Symbolic Problem to a Numerical Problem
Expand Down
10 changes: 5 additions & 5 deletions docs/src/getting_started/first_simulation.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import DifferentialEquations as DE
import ModelingToolkit as MTK
import Plots
import ModelingToolkit: t_nounits as t, D_nounits as D,
@variables, @parameters, @named, @mtkbuild
@variables, @parameters, @named, @mtkcompile, mtkcompile

# Define our state variables: state(t) = initial condition
@variables x(t)=1 y(t)=1 z(t)
Expand All @@ -67,7 +67,7 @@ eqs = [D(x) ~ α * x - β * x * y
z ~ x + y]

# Bring these pieces together into an ODESystem with independent variable t
@mtkbuild sys = MTK.ODESystem(eqs, t)
@mtkcompile sys = MTK.ODESystem(eqs, t)

# Convert from a symbolic to a numerical problem to simulate
tspan = (0.0, 10.0)
Expand Down Expand Up @@ -106,7 +106,7 @@ Now we're ready. Let's load in these packages:
import DifferentialEquations as DE
import ModelingToolkit as MTK
import Plots
import ModelingToolkit: t_nounits as t, D_nounits as D, @variables, @parameters, @named, @mtkbuild
import ModelingToolkit: t_nounits as t, D_nounits as D, @variables, @parameters, @named, @mtkcompile, mtkcompile
```

### Step 2: Define our ODE Equations
Expand Down Expand Up @@ -170,7 +170,7 @@ to represent an `ODESystem` with the following:

```@example first_sim
# Bring these pieces together into an ODESystem with independent variable t
@mtkbuild sys = MTK.ODESystem(eqs, t)
@mtkcompile sys = MTK.ODESystem(eqs, t)
```

Notice that in our equations we have an algebraic equation `z ~ x + y`. This is not a
Expand Down Expand Up @@ -274,7 +274,7 @@ D = MTK.Differential(t)
eqs = [D(🐰) ~ α * 🐰 - β * 🐰 * 🐺,
D(🐺) ~ -γ * 🐺 + δ * 🐰 * 🐺]

@mtkbuild sys = MTK.ODESystem(eqs, t)
@mtkcompile sys = MTK.ODESystem(eqs, t)
prob = DE.ODEProblem(sys, [], (0.0, 10.0))
sol = DE.solve(prob)
```
Expand Down
16 changes: 10 additions & 6 deletions docs/src/showcase/brusselator.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ import MethodOfLines
import OrdinaryDiffEq as ODE
import LinearSolve as LS
import DomainSets
using ModelingToolkit: @parameters, @variables, Differential, Interval, PDESystem
using ModelingToolkit: @named, @parameters, @variables, Differential, Interval, PDESystem

@parameters x y t
@variables u(..) v(..)
Expand Down Expand Up @@ -234,6 +234,10 @@ Plots.gif(anim, "plots/Brusselator2Dsol_v.gif", fps = 8)

## Improving the Solution Process

!!! warn
This section was disabled temporarily and will be re-enabled after major improvements
with SymbolicUtils v4.

Now, if all we needed was a single solution, then we're done. Budda bing budda boom, we
got a solution, we're outta here. But if for example we're solving an inverse problem
on a PDE, or we need to bump it up to higher accuracy, then we will need to make sure
Expand All @@ -247,33 +251,33 @@ let's do that!
In order to enable such options, we simply need to pass the ModelingToolkit.jl problem
construction options to the `discretize` call. This looks like:

```@example bruss
```julia
# Analytical Jacobian expression and sparse Jacobian
prob_sparse = MethodOfLines.discretize(pdesys, discretization; jac = true, sparse = true)
```

Now when we solve the problem it will be a lot faster. We can use BenchmarkTools.jl to
assess this performance difference:

```@example bruss
```julia
import BenchmarkTools as BT
BT.@btime sol = ODE.solve(prob, ODE.TRBDF2(), saveat = 0.1);
```
```@example bruss
```julia
BT.@btime sol = ODE.solve(prob_sparse, ODE.TRBDF2(), saveat = 0.1);
```

But we can further improve this as well. Instead of just using the default linear solver,
we can change this to a Newton-Krylov method by passing in the GMRES method:

```@example bruss
```julia
BT.@btime sol = ODE.solve(prob_sparse, ODE.TRBDF2(linsolve = LS.KrylovJL_GMRES()), saveat = 0.1);
```

But to further improve performance, we can use an iLU preconditioner. This looks like
as follows:

```@example bruss
```julia
import IncompleteLU
function incompletelu(W, du, u, p, t, newW, Plprev, Prprev, solverdata)
if newW === nothing || newW
Expand Down
16 changes: 8 additions & 8 deletions docs/src/showcase/optimal_data_gathering_for_missing_physics.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ To this end, we will rely on the following packages:
using Random; Random.seed!(984519674645)
using StableRNGs; rng = StableRNG(845652695)
import ModelingToolkit as MTK
import ModelingToolkit: t_nounits as t, D_nounits as D
import ModelingToolkit: t_nounits as t, D_nounits as D, @mtkcompile, mtkcompile
import ModelingToolkitNeuralNets
import OrdinaryDiffEqRosenbrock as ODE
import SymbolicIndexingInterface
Expand Down Expand Up @@ -145,11 +145,11 @@ We also add some noise to the simulated data, to make it more realistic:
```@example DoE
optimization_state = zeros(15)
optimization_initial = optimization_state[1] # HACK CAN'T GET THIS TO WORK WITHOUT SEPARATE SCALAR
@mtkbuild true_bioreactor = TrueBioreactor()
@mtkcompile true_bioreactor = TrueBioreactor()
prob = ODE.ODEProblem(true_bioreactor, [], (0.0, 15.0), [], tstops = 0:15, save_everystep=false)
sol = ODE.solve(prob, ODE.Rodas5P())

@mtkbuild ude_bioreactor = UDEBioreactor()
@mtkcompile ude_bioreactor = UDEBioreactor()
ude_prob = ODE.ODEProblem(ude_bioreactor, [], (0.0, 15.0), [], tstops = 0:15, save_everystep=false)
ude_sol = ODE.solve(ude_prob, ODE.Rodas5P())

Expand Down Expand Up @@ -283,7 +283,7 @@ function get_probs_and_caches(model_structures)
μ ~ model_structures[i](C_s)
end
end
@mtkbuild plausible_bioreactor = PlausibleBioreactor()
@mtkcompile plausible_bioreactor = PlausibleBioreactor()
plausible_prob = ODE.ODEProblem(plausible_bioreactor, [], (0.0, 15.0), [], tstops=0:15, saveat=0:15)
probs_plausible[i] = plausible_prob

Expand Down Expand Up @@ -401,10 +401,10 @@ This causes the two aforementioned groups in the model structures to be easily d

We now gather a second dataset and perform the same exercise.
```@example DoE
@mtkbuild true_bioreactor2 = TrueBioreactor()
@mtkcompile true_bioreactor2 = TrueBioreactor()
prob2 = ODE.ODEProblem(true_bioreactor2, [], (0.0, 15.0), [], tstops=0:15, save_everystep=false)
sol2 = ODE.solve(prob2, ODE.Rodas5P())
@mtkbuild ude_bioreactor2 = UDEBioreactor()
@mtkcompile ude_bioreactor2 = UDEBioreactor()
ude_prob2 = ODE.ODEProblem(ude_bioreactor2, [], (0.0, 15.0), [ude_bioreactor2.Q_in => optimization_initial], tstops=0:15, save_everystep=false)
ude_sol2 = ODE.solve(ude_prob2, ODE.Rodas5P())
plot(ude_sol2[3,:])
Expand Down Expand Up @@ -516,10 +516,10 @@ After the staircase reaches the maximal control value, a zero control is used.
Some model structures decrease more rapidly in substrate concentration than others.

```@example DoE
@mtkbuild true_bioreactor3 = TrueBioreactor()
@mtkcompile true_bioreactor3 = TrueBioreactor()
prob3 = ODE.ODEProblem(true_bioreactor3, [], (0.0, 15.0), [], tstops=0:15, save_everystep=false)
sol3 = ODE.solve(prob3, ODE.Rodas5P())
@mtkbuild ude_bioreactor3 = UDEBioreactor()
@mtkcompile ude_bioreactor3 = UDEBioreactor()
ude_prob3 = ODE.ODEProblem(ude_bioreactor3, [], (0.0, 15.0), tstops=0:15, save_everystep=false)

x0 = reduce(vcat, getindex.((default_values(ude_bioreactor3),), tunable_parameters(ude_bioreactor3)))
Expand Down