Skip to content

Commit c4fe363

Browse files
Merge pull request #3316 from vyudu/add-SDESystem-error
Add better SDESystem error when it hasn't been `structural_simplify`
2 parents 8936c97 + ea95965 commit c4fe363

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/systems/diffeqs/sdesystem.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,7 @@ function DiffEqBase.SDEProblem{iip, specialize}(
737737
if !iscomplete(sys)
738738
error("A completed `SDESystem` is required. Call `complete` or `structural_simplify` on the system before creating an `SDEProblem`")
739739
end
740+
740741
f, u0, p = process_SciMLProblem(
741742
SDEFunction{iip, specialize}, sys, u0map, parammap; check_length,
742743
t = tspan === nothing ? nothing : tspan[1], kwargs...)
@@ -767,6 +768,15 @@ function DiffEqBase.SDEProblem{iip, specialize}(
767768
noise_rate_prototype = noise_rate_prototype, kwargs...)
768769
end
769770

771+
function DiffEqBase.SDEProblem(sys::ODESystem, args...; kwargs...)
772+
773+
if any(ModelingToolkit.isbrownian, unknowns(sys))
774+
error("SDESystem constructed by defining Brownian variables with @brownian must be simplified by calling `structural_simplify` before a SDEProblem can be constructed.")
775+
else
776+
error("Cannot construct SDEProblem from a normal ODESystem.")
777+
end
778+
end
779+
770780
"""
771781
```julia
772782
DiffEqBase.SDEProblem{iip}(sys::SDESystem, u0map, tspan, p = parammap;

test/sdesystem.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,3 +868,22 @@ end
868868
@test length(ModelingToolkit.get_noiseeqs(sys)) == 1
869869
@test length(observed(sys)) == 1
870870
end
871+
872+
@testset "Error when constructing SDESystem without `structural_simplify`" begin
873+
@parameters σ ρ β
874+
@variables x(tt) y(tt) z(tt)
875+
@brownian a
876+
eqs = [D(x) ~ σ * (y - x) + 0.1a * x,
877+
D(y) ~ x *- z) - y + 0.1a * y,
878+
D(z) ~ x * y - β * z + 0.1a * z]
879+
880+
@named de = System(eqs, t)
881+
de = complete(de)
882+
883+
u0map = [x => 1.0, y => 0.0, z => 0.0]
884+
parammap ==> 10.0, β => 26.0, ρ => 2.33]
885+
886+
@test_throws ErrorException("SDESystem constructed by defining Brownian variables with @brownian must be simplified by calling `structural_simplify` before a SDEProblem can be constructed.") SDEProblem(de, u0map, (0.0, 100.0), parammap)
887+
de = structural_simplify(de)
888+
@test SDEProblem(de, u0map, (0.0, 100.0), parammap) isa SDEProblem
889+
end

0 commit comments

Comments
 (0)