Skip to content

Type inference failure in trivial remake(::ODEProblem...) #981

@SebastianM-C

Description

@SebastianM-C

Describe the bug 🐞

Type inference fails for remake(prob) with a prob created via MTK. This does not happen for purely numeric ODEProblems.

Expected behavior

This should be inferred.

Minimal Reproducible Example 👇

Without MRE, we would only be able to help you to a limited extent, and attention to the issue would be limited. to know more about MRE refer to wikipedia and stackoverflow.

using SciMLBase

prob = ODEProblem((u, p, t) -> -u, [1.0], (0.0, 1.0))
@code_warntype remake(prob) # no issues

using ModelingToolkit
using ModelingToolkit: t_nounits as t, D_nounits as D

@parameters α=1 β=1 γ=1 δ=1
@variables x(t)=1 y(t)=1
eqs = [D(x) ~ α * x - β * x * y, D(y) ~ -δ * y + γ * x * y]
@named sys = ODESystem(eqs, t)
prob = ODEProblem(complete(sys), [], (0.,1))

@code_warntype remake(prob) # ::Any

Error & Stacktrace ⚠️

MethodInstance for remake(::ODEProblem{Vector{Float64}, Tuple{Float64, Float64}, true, MTKParameters{Vector{Float64}, Vector{Float64}, Tuple{}, Tuple{}, Tuple{}, Tuple{}}, ODEFunction{true, SciMLBase.AutoSpecialize, ModelingToolkit.GeneratedFunctionWrapper{(2, 3, true), RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:__mtk_arg_1, :___mtkparameters___, :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x42dc2497, 0x45642c41, 0x10ed7100, 0x37cb3c7b, 0x39fcf7e9), Nothing}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋out, :__mtk_arg_1, :___mtkparameters___, :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x00f7494c, 0x1d4dc422, 0xd4b8b833, 0xca7f69f5, 0x2249aa1c), Nothing}}, LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, ModelingToolkit.ObservedFunctionCache{ODESystem}, Nothing, ODESystem, SciMLBase.OverrideInitData{NonlinearProblem{Nothing, true, MTKParameters{Vector{Float64}, StaticArraysCore.SizedVector{0, Float64, Vector{Float64}}, Tuple{}, Tuple{}, Tuple{}, Tuple{}}, NonlinearFunction{true, SciMLBase.FullSpecialize, ModelingToolkit.GeneratedFunctionWrapper{(2, 2, true), RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:__mtk_arg_1, :___mtkparameters___), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x85e41679, 0xe3baaf69, 0x36273733, 0xfa33874a, 0x6249a58a), Nothing}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋out, :__mtk_arg_1, :___mtkparameters___), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0xa427c4e8, 0x725f824c, 0xe49d1abc, 0x4f823061, 0x3d8f5fff), Nothing}}, LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, ModelingToolkit.ObservedFunctionCache{NonlinearSystem}, Nothing, NonlinearSystem, Nothing, Nothing}, Base.Pairs{Symbol, Union{}, Tuple{}, @NamedTuple{}}, ModelingToolkit.InitializationSystemMetadata}, ModelingToolkit.UpdateInitializeprob{SymbolicIndexingInterface.MultipleGetters{SymbolicIndexingInterface.ContinuousTimeseries, Vector{SymbolicIndexingInterface.AbstractGetIndexer}}, SymbolicIndexingInterface.MultipleSetters{Vector{SymbolicIndexingInterface.ParameterHookWrapper{S, SymbolicUtils.BasicSymbolic{Real}} where S}}}, ComposedFunction{typeof(identity), SymbolicIndexingInterface.TimeIndependentObservedFunction{ModelingToolkit.GeneratedFunctionWrapper{(2, 2, true), RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:__mtk_arg_1, :___mtkparameters___), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x5f868037, 0x304dd4dd, 0x241b9f4c, 0x397ff673, 0x8f8c291c), Nothing}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋out, :__mtk_arg_1, :___mtkparameters___), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0xa4f3792c, 0xe09a2216, 0x2879d8cf, 0x162a193c, 0x82d48992), Nothing}}}}, Nothing}, Nothing}, Base.Pairs{Symbol, Union{}, Tuple{}, @NamedTuple{}}, SciMLBase.StandardODEProblem})
  from remake(prob::ODEProblem; f, u0, tspan, p, kwargs, interpret_symbolicmap, build_initializeprob, use_defaults, lazy_initialization, _kwargs...) @ SciMLBase ~/.julia/dev/SciMLBase/src/remake.jl:214
Arguments
  #self#::Core.Const(SciMLBase.remake)
  prob::ODEProblem{Vector{Float64}, Tuple{Float64, Float64}, true, MTKParameters{Vector{Float64}, Vector{Float64}, Tuple{}, Tuple{}, Tuple{}, Tuple{}}, ODEFunction{true, SciMLBase.AutoSpecialize, ModelingToolkit.GeneratedFunctionWrapper{(2, 3, true), RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:__mtk_arg_1, :___mtkparameters___, :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x42dc2497, 0x45642c41, 0x10ed7100, 0x37cb3c7b, 0x39fcf7e9), Nothing}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋out, :__mtk_arg_1, :___mtkparameters___, :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x00f7494c, 0x1d4dc422, 0xd4b8b833, 0xca7f69f5, 0x2249aa1c), Nothing}}, LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, ModelingToolkit.ObservedFunctionCache{ODESystem}, Nothing, ODESystem, SciMLBase.OverrideInitData{NonlinearProblem{Nothing, true, MTKParameters{Vector{Float64}, StaticArraysCore.SizedVector{0, Float64, Vector{Float64}}, Tuple{}, Tuple{}, Tuple{}, Tuple{}}, NonlinearFunction{true, SciMLBase.FullSpecialize, ModelingToolkit.GeneratedFunctionWrapper{(2, 2, true), RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:__mtk_arg_1, :___mtkparameters___), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x85e41679, 0xe3baaf69, 0x36273733, 0xfa33874a, 0x6249a58a), Nothing}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋out, :__mtk_arg_1, :___mtkparameters___), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0xa427c4e8, 0x725f824c, 0xe49d1abc, 0x4f823061, 0x3d8f5fff), Nothing}}, LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, ModelingToolkit.ObservedFunctionCache{NonlinearSystem}, Nothing, NonlinearSystem, Nothing, Nothing}, Base.Pairs{Symbol, Union{}, Tuple{}, @NamedTuple{}}, ModelingToolkit.InitializationSystemMetadata}, ModelingToolkit.UpdateInitializeprob{SymbolicIndexingInterface.MultipleGetters{SymbolicIndexingInterface.ContinuousTimeseries, Vector{SymbolicIndexingInterface.AbstractGetIndexer}}, SymbolicIndexingInterface.MultipleSetters{Vector{SymbolicIndexingInterface.ParameterHookWrapper{S, SymbolicUtils.BasicSymbolic{Real}} where S}}}, ComposedFunction{typeof(identity), SymbolicIndexingInterface.TimeIndependentObservedFunction{ModelingToolkit.GeneratedFunctionWrapper{(2, 2, true), RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:__mtk_arg_1, :___mtkparameters___), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x5f868037, 0x304dd4dd, 0x241b9f4c, 0x397ff673, 0x8f8c291c), Nothing}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋out, :__mtk_arg_1, :___mtkparameters___), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0xa4f3792c, 0xe09a2216, 0x2879d8cf, 0x162a193c, 0x82d48992), Nothing}}}}, Nothing}, Nothing}, Base.Pairs{Symbol, Union{}, Tuple{}, @NamedTuple{}}, SciMLBase.StandardODEProblem}
Body::Any
1%1  = SciMLBase.:(var"#remake#735")::Core.Const(SciMLBase.var"#remake#735")
│   %2  = SciMLBase.missing::Core.Const(missing)
│   %3  = SciMLBase.missing::Core.Const(missing)
│   %4  = SciMLBase.missing::Core.Const(missing)
│   %5  = SciMLBase.missing::Core.Const(missing)
│   %6  = SciMLBase.missing::Core.Const(missing)
│   %7  = SciMLBase.nothing::Core.Const(nothing)
│   %8  = Core.NamedTuple()::Core.Const(NamedTuple())
│   %9  = Base.pairs(%8)::Core.Const(Base.Pairs{Symbol, Union{}, Tuple{}, @NamedTuple{}}())
│   %10 = (%1)(%2, %3, %4, %5, %6, true, true, false, %7, %9, #self#, prob)::Any
└──       return %10

Environment (please complete the following information):

  • Output of using Pkg; Pkg.status()
[0bca4576] SciMLBase v2.82.1
  • Output of using Pkg; Pkg.status(; mode = PKGMODE_MANIFEST)
  • Output of versioninfo()

Additional context

I think that for more complex types const prop fails for if build_initializeprob since if I replace the boolean value with a Val{T} to do the computation in the type domain, it works.

Using Cthulhu shows

Image

for the

f = remake(prob.f; f, initialization_data)

line in remake.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions