Closed acertain closed 3 days ago
Can you post a reproducer?
I think I have the same issue?
prob = ODEProblem(model2, [y_input => y_inputs_0], (0.0, 12.0), []);
prob2 = remake(prob; p=[y_input => y_inputs_0])
should work, right? But on the second line, I'm hitting the narrow_buffer_type_and_fallback_undefs
error above.
MWE:
using ModelingToolkit
using ModelingToolkit: t_nounits as t, D_nounits as D
using DifferentialEquations: solve, remake
using DataInterpolations
using Symbolics, Test
const ConstantFun = typeof(ConstantInterpolation([10.0, 12, 13], [0, 6, 12]))
y_inputs_0 = ConstantInterpolation([10.0, 12, 13], [0, 6, 12])
eval_interpolation(interp, t) = interp(t)
@register_symbolic eval_interpolation(interp::ConstantFun, t)
@variables y(t)
@parameters y_input::ConstantFun
eqs = [y ~ eval_interpolation(y_input, t)]
@named model = ODESystem(eqs, t)
model2 = structural_simplify(model)
prob = ODEProblem(model2, [y_input => y_inputs_0], (0.0, 12.0), []);
prob2 = remake(prob; p=[y_input => y_inputs_0])
yields
MethodError: no method matching narrow_buffer_type_and_fallback_undefs(::StaticArraysCore.SizedVector{0, Float64, Vector{Float64}}, ::Vector{Any})
Closest candidates are:
narrow_buffer_type_and_fallback_undefs(!Matched::Vector, ::Vector)
@ ModelingToolkit C:\Users\a1058035\.julia\packages\ModelingToolkit\GJiqn\src\systems\parameter_buffer.jl:485
Stack trace
Here is what happened, the most recent locations are first:
macro expansion @ sugar.jl:197
remake_buffer(indp::SciMLBase.ODEProblem{Nothing, Tuple{Float64, Float64}, true, ModelingToolkit.MTKParameters{StaticArraysCore.SizedVector{0, Float64, Vector{Float64}}, StaticArraysCore.SizedVector{0, Any, Vector{Any}}, Tuple{}, Tuple{}, Tuple{Vector{DataInterpolations.ConstantInterpolation{ReadOnlyArrays.ReadOnlyVector{Float64, Vector{Float64}}, ReadOnlyArrays.ReadOnlyVector{Int64, Vector{Int64}}, Vector{Float64}, Float64}}}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋out, :ˍ₋arg1), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x33b3bda3, 0xd089b82e, 0xfedcd84c, 0x4037599c, 0x2848c6f6), Nothing}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋arg1,), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0xb8b89fef, 0x1b0590a0, 0x8801a652, 0xfeb6172b, 0xb8db857d), Nothing}}, SciMLBase.ODEFunction{true, SciMLBase.AutoSpecialize, ModelingToolkit.var"#f#781"{RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋arg1, :ˍ₋arg2, :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0xf484e4ce, 0x5b83a833, 0x33551c77, 0x7c352bb5, 0xdac54478), Nothing}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋out, :ˍ₋arg1, :ˍ₋arg2, :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x3c38bd43, 0x235c9731, 0xcd5da351, 0xf995747b, 0x31daffa0), Nothing}}, LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, ModelingToolkit.ObservedFunctionCache{ModelingToolkit.ODESystem}, Nothing, ModelingToolkit.ODESystem, Nothing, Nothing}, @Kwargs{}, SciMLBase.StandardODEProblem}, oldbuf::ModelingToolkit.MTKParameters{StaticArraysCore.SizedVector{0, Float64, Vector{Float64}}, StaticArraysCore.SizedVector{0, Any, Vector{Any}}, Tuple{}, Tuple{}, Tuple{Vector{DataInterpolations.ConstantInterpolation{ReadOnlyArrays.ReadOnlyVector{Float64, Vector{Float64}}, ReadOnlyArrays.ReadOnlyVector{Int64, Vector{Int64}}, Vector{Float64}, Float64}}}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋out, :ˍ₋arg1), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x33b3bda3, 0xd089b82e, 0xfedcd84c, 0x4037599c, 0x2848c6f6), Nothing}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋arg1,), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0xb8b89fef, 0x1b0590a0, 0x8801a652, 0xfeb6172b, 0xb8db857d), Nothing}}, vals::Dict{Any, Any}) @ parameter_buffer.jl:602
_updated_u0_p_symmap(prob::SciMLBase.ODEProblem{Nothing, Tuple{Float64, Float64}, true, ModelingToolkit.MTKParameters{StaticArraysCore.SizedVector{0, Float64, Vector{Float64}}, StaticArraysCore.SizedVector{0, Any, Vector{Any}}, Tuple{}, Tuple{}, Tuple{Vector{DataInterpolations.ConstantInterpolation{ReadOnlyArrays.ReadOnlyVector{Float64, Vector{Float64}}, ReadOnlyArrays.ReadOnlyVector{Int64, Vector{Int64}}, Vector{Float64}, Float64}}}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋out, :ˍ₋arg1), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x33b3bda3, 0xd089b82e, 0xfedcd84c, 0x4037599c, 0x2848c6f6), Nothing}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋arg1,), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0xb8b89fef, 0x1b0590a0, 0x8801a652, 0xfeb6172b, 0xb8db857d), Nothing}}, SciMLBase.ODEFunction{true, SciMLBase.AutoSpecialize, ModelingToolkit.var"#f#781"{RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋arg1, :ˍ₋arg2, :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0xf484e4ce, 0x5b83a833, 0x33551c77, 0x7c352bb5, 0xdac54478), Nothing}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋out, :ˍ₋arg1, :ˍ₋arg2, :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x3c38bd43, 0x235c9731, 0xcd5da351, 0xf995747b, 0x31daffa0), Nothing}}, LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, ModelingToolkit.ObservedFunctionCache{ModelingToolkit.ODESystem}, Nothing, ModelingToolkit.ODESystem, Nothing, Nothing}, @Kwargs{}, SciMLBase.StandardODEProblem}, u0::Nothing, ::Val{false}, p::Dict{Any, Any}, ::Val{true}) @ remake.jl:603
_updated_u0_p_internal(prob::SciMLBase.ODEProblem{Nothing, Tuple{Float64, Float64}, true, ModelingToolkit.MTKParameters{StaticArraysCore.SizedVector{0, Float64, Vector{Float64}}, StaticArraysCore.SizedVector{0, Any, Vector{Any}}, Tuple{}, Tuple{}, Tuple{Vector{DataInterpolations.ConstantInterpolation{ReadOnlyArrays.ReadOnlyVector{Float64, Vector{Float64}}, ReadOnlyArrays.ReadOnlyVector{Int64, Vector{Int64}}, Vector{Float64}, Float64}}}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋out, :ˍ₋arg1), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x33b3bda3, 0xd089b82e, 0xfedcd84c, 0x4037599c, 0x2848c6f6), Nothing}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋arg1,), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0xb8b89fef, 0x1b0590a0, 0x8801a652, 0xfeb6172b, 0xb8db857d), Nothing}}, SciMLBase.ODEFunction{true, SciMLBase.AutoSpecialize, ModelingToolkit.var"#f#781"{RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋arg1, :ˍ₋arg2, :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0xf484e4ce, 0x5b83a833, 0x33551c77, 0x7c352bb5, 0xdac54478), Nothing}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋out, :ˍ₋arg1, :ˍ₋arg2, :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x3c38bd43, 0x235c9731, 0xcd5da351, 0xf995747b, 0x31daffa0), Nothing}}, LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, ModelingToolkit.ObservedFunctionCache{ModelingToolkit.ODESystem}, Nothing, ModelingToolkit.ODESystem, Nothing, Nothing}, @Kwargs{}, SciMLBase.StandardODEProblem}, ::Missing, p::Vector{Pair{SymbolicUtils.BasicSymbolic{DataInterpolations.ConstantInterpolation{ReadOnlyArrays.ReadOnlyVector{Float64, Vector{Float64}}, ReadOnlyArrays.ReadOnlyVector{Int64, Vector{Int64}}, Vector{Float64}, Float64}}, DataInterpolations.ConstantInterpolation{ReadOnlyArrays.ReadOnlyVector{Float64, Vector{Float64}}, ReadOnlyArrays.ReadOnlyVector{Int64, Vector{Int64}}, Vector{Float64}, Float64}}}; interpret_symbolicmap::Bool, use_defaults::Bool) @ remake.jl:513
_updated_u0_p_internal @ remake.jl:502
#updated_u0_p#713 @ remake.jl:665
updated_u0_p @ remake.jl:646
#remake#676 @ remake.jl:121
remake @ remake.jl:109
@cstjean your MWE works on the latest MTK/SciMLBase.
@acertain since you didn't provide an MWE, I ran the following:
julia> @variables x(t)
julia> @parameters p::Bool q::Bool r
julia> @mtkbuild sys = ODESystem(D(x) ~ x + r, t, [x], [p,q,r])
julia> prob = ODEProblem(sys, [x => 1.0], (0.0, 1.0), [p => true, q => false, r => 1.0])
julia> prob.p # contains a `BitVector`
MTKParameters{Vector{Float64}, Tuple{}, Tuple{BitVector}, Tuple{}}([1.0], (), (Bool[1, 0],), ())
julia> prob2 = remake(prob, p = [q => true])
julia> prob2.p # still contains a `BitVector` and has updated values
MTKParameters{Vector{Float64}, Tuple{}, Tuple{Vector{Bool}}, Tuple{}}([1.0], (), (Bool[1, 1],), ())
Which also works.
I think this is just an issue with the type of narrow_buffer_type_and_fallback_undefs, replacing
oldbuf::Vector
witholdbuf
seems to fix itStacktrace:
Additional context
Add any other context about the problem here.