Setting up a SDESystem, encountering an error while using structural_simplify

Setting up a SDESystem, encountering an error while using structural_simplify that I can’t quite understand.

using ModelingToolkit, Symbolics, Plots, DifferentialEquations, LogExpFunctions

e_0 = 2.5
ν_0 = 6
r = 0.56


@parameters t, a, A, b, B, C_0, C1, C2, C3, C4, p_0, f_s, p_s 
@variables y0(t), y1(t), y2(t), y3(t), y4(t), y5(t), y_output(t), p_noise(t)


D = Differential(t)

Sigm(x)= @. 1 / (1 + exp(-x))

@register Sigm(x)


eqs = [Equation(p_noise, sinpi(p_0 * t) + p_s * sinpi(2 * f_s * t)),
    D(y0) ~ y3,
    D(y1) ~ y4,
    D(y2) ~ y5,
    D(y3) ~ A * a * logistic(y_output) - 2 * a * y3 - a * a * y0,
    D(y4) ~ A * a * (p_noise + C2 * logistic(C1 * y0)) - 2 * a * y4 - a * a * y5,
    D(y5) ~ B * b * C4 * logistic(C3 * y0) - 2 * b * y5 - b * b * y2,
    y_output ~ y1 - y2
    ]

noiseeqs = [Equation(p_noise, 1.0)]

@named s_prob = SDESystem(eqs, noiseeqs, t, [y0, y1, y2, y3, y4, y5, y_output, p_noise], [a, A, b, B, C1, C2, C3, C4, p_0, f_s, p_s])
s_prob = structural_simplify(s_prob)

y_0 = [
    y[1] => 0.1,
    y[2] => 0.1,
    y[3] => 0.1,
    y[4] => 0.1,
    y[5] => 0.1,
    y[6] => 0.1,
]

The error encountered is as follows

 This should never happen. Trying to set DataType with NamedTuple{(:substitutions,), Tuple{ModelingToolkit.Substitutions}}.
Stacktrace:
  [1] error(s::String)
    @ Base ./error.jl:33
  [2] #s49#90
    @ ~/.julia/packages/ModelingToolkit/omJNc/src/systems/abstractsystem.jl:276 [inlined]
  [3] var"#s49#90"(::Any, obj::Any, patch::Any)
    @ ModelingToolkit ./none:0
  [4] (::Core.GeneratedFunctionStub)(::Any, ::Vararg{Any})
    @ Core ./boot.jl:580
  [5] set
    @ ~/.julia/packages/Setfield/AS2xF/src/lens.jl:122 [inlined]
  [6] macro expansion
    @ ~/.julia/packages/Setfield/AS2xF/src/sugar.jl:197 [inlined]
  [7] tearing_reassemble(state::TearingState{SDESystem}, var_eq_matching::ModelingToolkit.BipartiteGraphs.Matching{Union{ModelingToolkit.BipartiteGraphs.Unassigned, ModelingToolkit.StructuralTransformations.SelectedState}, Vector{Union{ModelingToolkit.BipartiteGraphs.Unassigned, ModelingToolkit.StructuralTransformations.SelectedState, Int64}}}; simplify::Bool)
    @ ModelingToolkit.StructuralTransformations ~/.julia/packages/ModelingToolkit/omJNc/src/structural_transformation/symbolics_tearing.jl:238
  [8] structural_simplify(sys::SDESystem; simplify::Bool, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ ModelingToolkit ~/.julia/packages/ModelingToolkit/omJNc/src/systems/abstractsystem.jl:936
  [9] structural_simplify(sys::SDESystem)
    @ ModelingToolkit ~/.julia/packages/ModelingToolkit/omJNc/src/systems/abstractsystem.jl:927
 [10] top-level scope
    @ ~/Documents/Julia/Jansen_rit_model.jl:32

Can anyone explain what this error is, and what is the suggested fix. Thank you very much.

Structural simplify currently does not have a specialization on SDESystem, so you’d need to build the ODESystem, structural simplify, and then add the noise terms. This has been something that has been very close to complete for awhile now. Open an issue so @yingboma can use it as a MWE.

Cheers Chris, thanks very much. I’ll open an issue.