Open Snowd1n opened 2 months ago
Contradict on Discourse suggested using a semicolon at the end of the line as it appears that the REPL can't display the connected equation. However this then fails at tstructural_simplify(connected) with the same top level error. THe URL to that discussion is here: https://discourse.julialang.org/t/compose-vector-and-scalar-equations-together/118474
Reply from Contradict
OK, thats a different stack trace and a different problem. I am no longer sure if either of these is a bug, but you can fix both by broadcasting the equation in FOL!
using ModelingToolkit using ModelingToolkit: t_nounits as t, D_nounits as D using DifferentialEquations
function FOL(; name) @parameters begin τ[1:5] # parameters end @variables begin x(t)[1:5] = 0.0 a(t) # dependent variables end
eqs = D(x) .~ (a .- x) ./ τ # Changing this to .~
ODESystem(eqs, t; name)
end
function FOL_scal(; name) @parameters begin b = 0.5 c = 4.0 # parameters end @variables begin a(t) = 1.0 # dependent variables end
eqs = D(a) ~ (a - b) / c
ODESystem(eqs, t; name)
end
function test() @named fol = FOL() @named scal = FOL_scal() connected = compose( ODESystem( [scal.a ~ fol.a], t, name = :connected, defaults = Dict(), discrete_events = [], ), fol, scal, )
simp = complete(structural_simplify(connected)) # complete makes variable and parameter access easier.
prob = ODEProblem(simp, [], (0.0, 10.0), [simp.fol.τ=>ones(5)]) # I added this prameter value too
sol = solve(prob, Tsit5(); abstol = 1e-3, reltol = 1e-3)
end The reason I am no longer sure this is a bug is because I have seen other cases where removing all the broadcast operations and leaving equations as all vectors works too. When you get stack traces involving the broadcast machinery, it is worth trying both to see if one works.
That now works I agree. But in my real case, this doesn’t solve the problem and the broadcasting creates the Array has no term lhs error which I know from other threads is fixed via “eqs = Symbolics.scalarize(reduce(vcat, Symbolics.scalarize.(eqs)))”. However, this then leads back to the same structural_simplify error as before. I don’t really know where to proceed from here as I basically have now tried both variants and loop to the same point. I think it may be linked to scalarize
When I try to connect an equation of scalars with an equation of vectors, something on the compose step fails even though what is being connected is the same type (both scalar etc.). I am not sure why this is. An MWE is below
Error & Stacktrace ⚠️
Version 9.32.0 of ModelingToolkit and Version 1.10.4 of Julia
Additional context
Add any other context about the problem here.