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

Unable to simualte SDEs with static array u0/ps #2814

Closed TorkelE closed 51 minutes ago

TorkelE commented 1 week ago

This is important since this is required for GPU simulations.

MWE:

using ModelingToolkit, StaticArrays, StochasticDiffEq

# Create SDE system.
@parameters p d 
@variables t X(t)
D = Differential(t)
eqs = [D(X) ~ p - d*X]
noise_eqs = [sqrt(p), sqrt(p - d*X)]
@named ssys = SDESystem(eqs, noise_eqs, t, [X], [p, d])
ssys = complete(ssys)

# Create SDEProblem
u0 = @SVector [X => 10.0f0]
tspan = (0.0f0, 10.0f0)
ps = @SVector [p => 2.0f0, d => 0.5f0]
sprob = SDEProblem(ssys, u0, tspan, ps)
solve(sprob, ImplicitEM())

Gives an ERROR: Initial condition incompatible with functional form. error.

For ODEs, this work:

using OrdinaryDiffEq
@named osys = ODESystem(eqs, t, [X], [p, d])
osys = complete(osys)

# Create SDEProblem
u0 = @SVector [X => 10.0f0]
tspan = (0.0f0, 10.0f0)
ps = @SVector [p => 2.0f0, d => 0.5f0]
oprob = ODEProblem(osys, u0, tspan, ps)
solve(oprob, Tsit5())