diff --git a/src/systems/diffeqs/odesystem.jl b/src/systems/diffeqs/odesystem.jl index 34312563e2..a1fb333092 100644 --- a/src/systems/diffeqs/odesystem.jl +++ b/src/systems/diffeqs/odesystem.jl @@ -487,14 +487,14 @@ function build_explicit_observed_function(sys, ts; end _ps = ps if ps isa Tuple - ps = DestructuredArgs.(ps, inbounds = !checkbounds) + ps = DestructuredArgs.(unwrap.(ps), inbounds = !checkbounds) elseif has_index_cache(sys) && get_index_cache(sys) !== nothing - ps = DestructuredArgs.(reorder_parameters(get_index_cache(sys), ps)) + ps = DestructuredArgs.(reorder_parameters(get_index_cache(sys), unwrap.(ps))) if isempty(ps) && inputs !== nothing ps = (:EMPTY,) end else - ps = (DestructuredArgs(ps, inbounds = !checkbounds),) + ps = (DestructuredArgs(unwrap.(ps), inbounds = !checkbounds),) end dvs = DestructuredArgs(unknowns(sys), inbounds = !checkbounds) if inputs === nothing diff --git a/test/odesystem.jl b/test/odesystem.jl index 58d22367a0..e39649c1c2 100644 --- a/test/odesystem.jl +++ b/test/odesystem.jl @@ -1367,3 +1367,23 @@ end @test length(ModelingToolkit.guesses(sys2)) == 3 @test ModelingToolkit.guesses(sys2)[p5] == 10.0 end + +@testset "Observed with inputs" begin + @variables u(t)[1:2] x(t)[1:2] o(t)[1:2] + @parameters p[1:4] + + eqs = [D(u[1]) ~ p[1] * u[1] - p[2] * u[1] * u[2] + x[1] + 0.1 + D(u[2]) ~ p[4] * u[1] * u[2] - p[3] * u[2] - x[2] + o[1] ~ sum(p) * sum(u) + o[2] ~ sum(p) * sum(x)] + + @named sys = ODESystem(eqs, t, [u..., x..., o], [p...]) + sys1, = structural_simplify(sys, ([x...], [o...]), split = false) + + @test_nowarn ModelingToolkit.build_explicit_observed_function(sys1, u; inputs = [x...]) + + obsfn = ModelingToolkit.build_explicit_observed_function( + sys1, u + x + p[1:2]; inputs = [x...]) + + @test obsfn(ones(2), 2ones(2), 3ones(4), 4.0) == 6ones(2) +end