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

parameter splitting tries to convert to Union #2815

Open baggepinnen opened 1 week ago

baggepinnen commented 1 week ago

The following example, which used to work in MTKv8, now fails with no method matching Union{Float64, Particles{Float64, 2000}}(::Int64)

If I try with split=false, I get a solution.

using ModelingToolkit
using ModelingToolkitStandardLibrary: Blocks
using ControlSystemsMTK
using ModelingToolkit, MonteCarloMeasurements, Plots, OrdinaryDiffEq

T = typeof(1 ± 1)
@parameters t k::T d
@variables x(t)::T v(t)::T
D = Differential(t)
eqs = [D(x) ~ v, D(v) ~ -k*x - d*v - 9.82]
@named sys = ODESystem(eqs, t)
prob = ODEProblem(complete(sys), [x => 0.0 ± 0.1, v => 0.0, k => 10 ± 1, d => 1], (0.0, 10.0))
# sol = solve(prob, Tsit5()) # Works
# plot(sol, ri=false, N=1000) # works

W = makeweight(0.1, 1, 0.9)
T = typeof(-1..1)
@parameters Δ::T=(-1..1) # The uncertain element is between -1 and 1
@variables y(t)=0
@named Wsys = ODESystem(W)
connections = [
    Wsys.input.u ~ sys.x
    y ~ sys.x + Wsys.output.u*Δ
]
@named uncertain_sys = ODESystem(connections, t, systems=[sys, Wsys])
initial_condition = [sys.x => zero(T), sys.v => 0, sys.k => 10, sys.d =>1]
prob = ODEProblem(structural_simplify(uncertain_sys, split=true), initial_condition, (0.0, 10.0))
sol = solve(prob, Tsit5())

plot(sol, ri=false, N=500, idxs=[sys.x, sys.v, y], layout=2, sp=[1 2 1], l=[3 3 1])