Skip to content

Remake fails with mixed variable and parameter defaults #2715

@hersle

Description

@hersle

Mixing variables and parameters in the defaults of the simple remake example

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

@testset "remake with mixed variable+parameter defaults" begin
    @parameters P
    @variables X(t) Y(t)
    @named sys = ODESystem([D(X) ~ 0, D(Y) ~ 0], t, [X, Y], [P]; defaults = [X => P + 1])
    sys = complete(sys)
    u0 = [Y => 1]
    p = [P => 1]
    prob1 = @test_nowarn ODEProblem(sys, u0, (0, 1), p) # works
    prob2 = @test_nowarn remake(prob1; u0, p, use_defaults = true) # fails
    @test prob1.u0 == prob2.u0 && prob1.ps[P] == prob2.ps[P]
end

fails with

  MethodError: no method matching getindex(::Nothing, ::Int64)
  Stacktrace:
    [1] macro expansion
      @ ~/.julia/packages/SymbolicUtils/qyMYa/src/code.jl:375 [inlined]
    [2] macro expansion
      @ ~/.julia/packages/RuntimeGeneratedFunctions/M9ZX8/src/RuntimeGeneratedFunctions.jl:163 [inlined]
    [3] macro expansion
      @ ./none:0 [inlined]
    [4] generated_callfunc
      @ ./none:0 [inlined]
    [5] (::RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(Symbol("##arg#8067804339927430471"), Symbol("##arg#17444850679067948697"), :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0xfc28c8d1, 0x9ecdc14a, 0xe40d0d57, 0xc99db895, 0x6e00db3e), Nothing})(::Nothing, ::Vector{Int64}, ::Nothing)
      @ RuntimeGeneratedFunctions ~/.julia/packages/RuntimeGeneratedFunctions/M9ZX8/src/RuntimeGeneratedFunctions.jl:150
    [6] (::ModelingToolkit.var"#709#722"{RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(Symbol("##arg#8067804339927430471"), Symbol("##arg#17444850679067948697"), :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0xfc28c8d1, 0x9ecdc14a, 0xe40d0d57, 0xc99db895, 0x6e00db3e), Nothing}, DataType})(u::Nothing, p::ModelingToolkit.MTKParameters{Tuple{Vector{Int64}}, Tuple{}, Tuple{}, Tuple{}, Tuple{}, Nothing, Nothing}, t::Nothing)
      @ ModelingToolkit ~/.julia/packages/ModelingToolkit/w72sG/src/systems/diffeqs/abstractodesystem.jl:464
    [7] (::SymbolicIndexingInterface.TimeDependentObservedFunction{ModelingToolkit.var"#709#722"{RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(Symbol("##arg#8067804339927430471"), Symbol("##arg#17444850679067948697"), :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0xfc28c8d1, 0x9ecdc14a, 0xe40d0d57, 0xc99db895, 0x6e00db3e), Nothing}, DataType}})(::SymbolicIndexingInterface.NotTimeseries, prob::SymbolicIndexingInterface.ProblemState{Nothing, ModelingToolkit.MTKParameters{Tuple{Vector{Int64}}, Tuple{}, Tuple{}, Tuple{}, Tuple{}, Nothing, Nothing}, Nothing})
      @ SymbolicIndexingInterface ~/.julia/packages/SymbolicIndexingInterface/SzZz3/src/state_indexing.jl:88
    [8] (::SymbolicIndexingInterface.TimeDependentObservedFunction{ModelingToolkit.var"#709#722"{RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(Symbol("##arg#8067804339927430471"), Symbol("##arg#17444850679067948697"), :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0xfc28c8d1, 0x9ecdc14a, 0xe40d0d57, 0xc99db895, 0x6e00db3e), Nothing}, DataType}})(prob::SymbolicIndexingInterface.ProblemState{Nothing, ModelingToolkit.MTKParameters{Tuple{Vector{Int64}}, Tuple{}, Tuple{}, Tuple{}, Tuple{}, Nothing, Nothing}, Nothing})
      @ SymbolicIndexingInterface ~/.julia/packages/SymbolicIndexingInterface/SzZz3/src/value_provider_interface.jl:144
    [9] (::SciMLBase.var"#667#671"{ODEProblem{Vector{Float64}, Tuple{Int64, Int64}, true, ModelingToolkit.MTKParameters{Tuple{Vector{Float64}}, Tuple{}, Tuple{}, Tuple{}, Tuple{}, Nothing, Nothing}, ODEFunction{true, SciMLBase.AutoSpecialize, ModelingToolkit.var"#f#711"{RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋arg1, :ˍ₋arg2, :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x8ac58eb2, 0x73d0426c, 0x7f1230d6, 0x964553a4, 0x063c7a8a), Nothing}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋out, :ˍ₋arg1, :ˍ₋arg2, :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0xb74839f3, 0x7ae30fb5, 0xfd3fa0d5, 0x291a1b6f, 0x26fc5a5a), Nothing}}, LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, ModelingToolkit.var"#883#generated_observed#720"{Bool, ODESystem, Dict{Any, Any}, Vector{Any}}, Nothing, ODESystem, Nothing, Nothing}, @Kwargs{}, SciMLBase.StandardODEProblem}, SymbolicIndexingInterface.ProblemState{Nothing, ModelingToolkit.MTKParameters{Tuple{Vector{Int64}}, Tuple{}, Tuple{}, Tuple{}, Tuple{}, Nothing, Nothing}, Nothing}})(::Pair{Any, Any})
      @ SciMLBase ./none:0
   [10] iterate
      @ ./generator.jl:47 [inlined]
   [11] Dict{Any, Any}(kv::Base.Generator{Dict{Any, Any}, SciMLBase.var"#667#671"{ODEProblem{Vector{Float64}, Tuple{Int64, Int64}, true, ModelingToolkit.MTKParameters{Tuple{Vector{Float64}}, Tuple{}, Tuple{}, Tuple{}, Tuple{}, Nothing, Nothing}, ODEFunction{true, SciMLBase.AutoSpecialize, ModelingToolkit.var"#f#711"{RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋arg1, :ˍ₋arg2, :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x8ac58eb2, 0x73d0426c, 0x7f1230d6, 0x964553a4, 0x063c7a8a), Nothing}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋out, :ˍ₋arg1, :ˍ₋arg2, :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0xb74839f3, 0x7ae30fb5, 0xfd3fa0d5, 0x291a1b6f, 0x26fc5a5a), Nothing}}, LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, ModelingToolkit.var"#883#generated_observed#720"{Bool, ODESystem, Dict{Any, Any}, Vector{Any}}, Nothing, ODESystem, Nothing, Nothing}, @Kwargs{}, SciMLBase.StandardODEProblem}, SymbolicIndexingInterface.ProblemState{Nothing, ModelingToolkit.MTKParameters{Tuple{Vector{Int64}}, Tuple{}, Tuple{}, Tuple{}, Tuple{}, Nothing, Nothing}, Nothing}}})
      @ Base ./dict.jl:85
   [12] anydict(d::Base.Generator{Dict{Any, Any}, SciMLBase.var"#667#671"{ODEProblem{Vector{Float64}, Tuple{Int64, Int64}, true, ModelingToolkit.MTKParameters{Tuple{Vector{Float64}}, Tuple{}, Tuple{}, Tuple{}, Tuple{}, Nothing, Nothing}, ODEFunction{true, SciMLBase.AutoSpecialize, ModelingToolkit.var"#f#711"{RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋arg1, :ˍ₋arg2, :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x8ac58eb2, 0x73d0426c, 0x7f1230d6, 0x964553a4, 0x063c7a8a), Nothing}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋out, :ˍ₋arg1, :ˍ₋arg2, :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0xb74839f3, 0x7ae30fb5, 0xfd3fa0d5, 0x291a1b6f, 0x26fc5a5a), Nothing}}, LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, ModelingToolkit.var"#883#generated_observed#720"{Bool, ODESystem, Dict{Any, Any}, Vector{Any}}, Nothing, ODESystem, Nothing, Nothing}, @Kwargs{}, SciMLBase.StandardODEProblem}, SymbolicIndexingInterface.ProblemState{Nothing, ModelingToolkit.MTKParameters{Tuple{Vector{Int64}}, Tuple{}, Tuple{}, Tuple{}, Tuple{}, Nothing, Nothing}, Nothing}}})
      @ SciMLBase ~/.julia/packages/SciMLBase/od80h/src/remake.jl:385
   [13] _updated_u0_p_symmap(prob::ODEProblem{Vector{Float64}, Tuple{Int64, Int64}, true, ModelingToolkit.MTKParameters{Tuple{Vector{Float64}}, Tuple{}, Tuple{}, Tuple{}, Tuple{}, Nothing, Nothing}, ODEFunction{true, SciMLBase.AutoSpecialize, ModelingToolkit.var"#f#711"{RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋arg1, :ˍ₋arg2, :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x8ac58eb2, 0x73d0426c, 0x7f1230d6, 0x964553a4, 0x063c7a8a), Nothing}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋out, :ˍ₋arg1, :ˍ₋arg2, :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0xb74839f3, 0x7ae30fb5, 0xfd3fa0d5, 0x291a1b6f, 0x26fc5a5a), Nothing}}, LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, ModelingToolkit.var"#883#generated_observed#720"{Bool, ODESystem, Dict{Any, Any}, Vector{Any}}, Nothing, ODESystem, Nothing, Nothing}, @Kwargs{}, SciMLBase.StandardODEProblem}, u0::Dict{Any, Any}, ::Val{true}, p::ModelingToolkit.MTKParameters{Tuple{Vector{Int64}}, Tuple{}, Tuple{}, Tuple{}, Tuple{}, Nothing, Nothing}, ::Val{false})
      @ SciMLBase ~/.julia/packages/SciMLBase/od80h/src/remake.jl:479
   [14] _updated_u0_p_symmap(prob::ODEProblem{Vector{Float64}, Tuple{Int64, Int64}, true, ModelingToolkit.MTKParameters{Tuple{Vector{Float64}}, Tuple{}, Tuple{}, Tuple{}, Tuple{}, Nothing, Nothing}, ODEFunction{true, SciMLBase.AutoSpecialize, ModelingToolkit.var"#f#711"{RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋arg1, :ˍ₋arg2, :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x8ac58eb2, 0x73d0426c, 0x7f1230d6, 0x964553a4, 0x063c7a8a), Nothing}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋out, :ˍ₋arg1, :ˍ₋arg2, :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0xb74839f3, 0x7ae30fb5, 0xfd3fa0d5, 0x291a1b6f, 0x26fc5a5a), Nothing}}, LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, ModelingToolkit.var"#883#generated_observed#720"{Bool, ODESystem, Dict{Any, Any}, Vector{Any}}, Nothing, ODESystem, Nothing, Nothing}, @Kwargs{}, SciMLBase.StandardODEProblem}, u0::Dict{Any, Any}, ::Val{true}, p::Dict{Any, Any}, ::Val{true})
      @ SciMLBase ~/.julia/packages/SciMLBase/od80h/src/remake.jl:517
   [15] _updated_u0_p_internal(prob::ODEProblem{Vector{Float64}, Tuple{Int64, Int64}, true, ModelingToolkit.MTKParameters{Tuple{Vector{Float64}}, Tuple{}, Tuple{}, Tuple{}, Tuple{}, Nothing, Nothing}, ODEFunction{true, SciMLBase.AutoSpecialize, ModelingToolkit.var"#f#711"{RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋arg1, :ˍ₋arg2, :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x8ac58eb2, 0x73d0426c, 0x7f1230d6, 0x964553a4, 0x063c7a8a), Nothing}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋out, :ˍ₋arg1, :ˍ₋arg2, :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0xb74839f3, 0x7ae30fb5, 0xfd3fa0d5, 0x291a1b6f, 0x26fc5a5a), Nothing}}, LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, ModelingToolkit.var"#883#generated_observed#720"{Bool, ODESystem, Dict{Any, Any}, Vector{Any}}, Nothing, ODESystem, Nothing, Nothing}, @Kwargs{}, SciMLBase.StandardODEProblem}, u0::Vector{Pair{Num, Int64}}, p::Vector{Pair{Num, Int64}}; interpret_symbolicmap::Bool, use_defaults::Bool)
      @ SciMLBase ~/.julia/packages/SciMLBase/od80h/src/remake.jl:427
   [16] _updated_u0_p_internal
      @ ~/.julia/packages/SciMLBase/od80h/src/remake.jl:412 [inlined]
   [17] #updated_u0_p#688
      @ ~/.julia/packages/SciMLBase/od80h/src/remake.jl:548 [inlined]
   [18] updated_u0_p
      @ ~/.julia/packages/SciMLBase/od80h/src/remake.jl:529 [inlined]
   [19] remake(prob::ODEProblem{Vector{Float64}, Tuple{Int64, Int64}, true, ModelingToolkit.MTKParameters{Tuple{Vector{Float64}}, Tuple{}, Tuple{}, Tuple{}, Tuple{}, Nothing, Nothing}, ODEFunction{true, SciMLBase.AutoSpecialize, ModelingToolkit.var"#f#711"{RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋arg1, :ˍ₋arg2, :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x8ac58eb2, 0x73d0426c, 0x7f1230d6, 0x964553a4, 0x063c7a8a), Nothing}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋out, :ˍ₋arg1, :ˍ₋arg2, :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0xb74839f3, 0x7ae30fb5, 0xfd3fa0d5, 0x291a1b6f, 0x26fc5a5a), Nothing}}, LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, ModelingToolkit.var"#883#generated_observed#720"{Bool, ODESystem, Dict{Any, Any}, Vector{Any}}, Nothing, ODESystem, Nothing, Nothing}, @Kwargs{}, SciMLBase.StandardODEProblem}; f::Missing, u0::Vector{Pair{Num, Int64}}, tspan::Missing, p::Vector{Pair{Num, Int64}}, kwargs::Missing, interpret_symbolicmap::Bool, use_defaults::Bool, _kwargs::@Kwargs{})
      @ SciMLBase ~/.julia/packages/SciMLBase/od80h/src/remake.jl:95
   [20] remake
      @ ~/.julia/packages/SciMLBase/od80h/src/remake.jl:83 [inlined]
    ....

Should this work?

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