SciML / ModelingToolkit.jl

An acausal modeling framework for automatically parallelized scientific machine learning (SciML) in Julia. A computer algebra system for integrated symbolics for physics-informed machine learning and automated transformations of differential equations
https://mtk.sciml.ai/dev/
Other
1.38k stars 196 forks source link

SDEs with brownian motions requires `structural_simplify` #2831

Open TorkelE opened 2 days ago

TorkelE commented 2 days ago

In this example: https://docs.sciml.ai/ModelingToolkit/stable/tutorials/stochastic_diffeq/, if I change

@mtkbuild de = System(eqs, t)

to

@named de = System(eqs, t)
de = complete(de)

then I receive a

ERROR: No methods were found for the model function passed to the equation solver.
The function `f` needs to have dispatches, for example, for an ODEProblem
`f` must define either `f(u,p,t)` or `f(du,u,p,t)`. For more information
on how the model function `f` should be defined, consult the docstring for
the appropriate `AbstractSciMLFunction`.

Offending function: f
Stacktrace:
 [1] 
   @ SciMLBase ~/.julia/packages/SciMLBase/sakPO/src/utils.jl:250
 [2] isinplace (repeats 2 times)
   @ ~/.julia/packages/SciMLBase/sakPO/src/utils.jl:243 [inlined]
 [3] SDEProblem(f::ODESystem, g::Vector{…}, u0::Tuple{…}, tspan::Vector{…}, p::SciMLBase.NullParameters; kwargs::@Kwargs{})
   @ SciMLBase ~/.julia/packages/SciMLBase/sakPO/src/problems/sde_problems.jl:124
 [4] SDEProblem
   @ ~/.julia/packages/SciMLBase/sakPO/src/problems/sde_problems.jl:123 [inlined]
 [5] SDEProblem(f::ODESystem, g::Vector{Pair{Num, Float64}}, u0::Tuple{Float64, Float64}, tspan::Vector{Pair{Num, Float64}})
   @ SciMLBase ~/.julia/packages/SciMLBase/sakPO/src/problems/sde_problems.jl:123
 [6] top-level scope
   @ ~/Desktop/Julia Playground/Environment - Catalyst test/test_playground.jl:108
Some type information was truncated. Use `show(err)` to see complete types.

when I run

prob = SDEProblem(de, u0map, (0.0, 100.0), parammap)

Full code:

using ModelingToolkit, StochasticDiffEq
using ModelingToolkit: t_nounits as t, D_nounits as D

# Define some variables
@parameters σ ρ β
@variables x(t) y(t) z(t)
@brownian a
eqs = [D(x) ~ σ * (y - x) + 0.1a * x,
    D(y) ~ x * (ρ - z) - y + 0.1a * y,
    D(z) ~ x * y - β * z + 0.1a * z]

@named de = System(eqs, t)
de = complete(de)

u0map = [
    x => 1.0,
    y => 0.0,
    z => 0.0
]

parammap = [
    σ => 10.0,
    β => 26.0,
    ρ => 2.33
]

prob = SDEProblem(de, u0map, (0.0, 100.0), parammap)
sol = solve(prob, LambaEulerHeun())
ChrisRackauckas commented 2 days ago

Yes it does require a structural simplify. We should throw a better error about that.