Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot solve remake problem with vector parameter of non-Real #3024

Open
cstjean opened this issue Sep 6, 2024 · 0 comments
Open

Cannot solve remake problem with vector parameter of non-Real #3024

cstjean opened this issue Sep 6, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@cstjean
Copy link

cstjean commented Sep 6, 2024

Describe the bug 🐞

prob_vec = ODEProblem(model2, u0, (0.0, 18.0), ps_vector);
prob_vec_remade = remake(prob_vec; p=ps_vector)

solve(prob_vec)         # works
solve(prob_vec_remade)  # fails, BoundsError: attempt to access 0-element Vector{Float64} at index [1]

Expected behavior

As far as I understand, remaking the problem with the same parameter vector should yield an identical/equivalent Problem.

Minimal Reproducible Example 👇

using ModelingToolkit
using ModelingToolkit: t_nounits as t, D_nounits as D
using DifferentialEquations: solve, Euler, ImplicitEuler
using SymbolicIndexingInterface,SciMLStructures
using DataInterpolations
using Symbolics
using ModelingToolkit:remake

const ConstantFun = typeof(ConstantInterpolation([10.0, 12, 13], [0, 6, 12]))
I_inputs_0 = ConstantFun[ConstantInterpolation([10.0, 12, 13, 13], [0, 6, 12, 18]),
                         ConstantInterpolation([15.0, 14, 13, 13], [0, 6, 12, 18])]

eval_interpolation(interp, t) = interp(t)
@register_symbolic eval_interpolation(interp::ConstantFun, t)

@variables I(t)[1:2] Z(t)[1:2]
@parameters I_input[1:2]::ConstantFun
eqs = [I[1] ~ eval_interpolation(I_input[1], t),
       D(Z[1]) ~ I[1],
       I[2] ~ eval_interpolation(I_input[2], t),
       D(Z[2]) ~ I[2]]

@named model = ODESystem(eqs, t)
model2 = structural_simplify(model)

u0 = [Z => [0.0011, 0.0011]]
ps_vector = [I_input => I_inputs_0]

prob_vec = ODEProblem(model2, u0, (0.0, 18.0), ps_vector);
prob_vec_remade = remake(prob_vec; p=ps_vector)

solve(prob_vec)         # works
solve(prob_vec_remade)  # fails

Error & Stacktrace ⚠️

BoundsError: attempt to access 0-element Vector{Float64} at index [1]
getindex @ essentials.jl:13
macro expansion @ code.jl:387
macro expansion @ RuntimeGeneratedFunctions.jl:163
macro expansion @ 
generated_callfunc @ 
(::RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋out, :ˍ₋arg1, :ˍ₋arg2, :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x3c596f08, 0xeb569af2, 0x04a44ef9, 0x7a64445b, 0x0034cd95), Nothing})(::Vector{Float64}, ::Vector{Float64}, ::Vector{Float64}, ::Vector{Vector{DataInterpolations.ConstantInterpolation{Vector{Float64}, Vector{Int64}, Vector{Float64}, Float64}}}, ::Float64) @ RuntimeGeneratedFunctions.jl:150
(::ModelingToolkit.var"#f#813"{RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋arg1, :ˍ₋arg2, :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0xedb50c16, 0x3df29d90, 0xd2cd6390, 0x734b4a96, 0x638b6d0f), Nothing}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋out, :ˍ₋arg1, :ˍ₋arg2, :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x3c596f08, 0xeb569af2, 0x04a44ef9, 0x7a64445b, 0x0034cd95), Nothing}})(du::Vector{Float64}, u::Vector{Float64}, p::ModelingToolkit.MTKParameters{Vector{Float64}, Tuple{}, Tuple{}, Tuple{Vector{Vector{DataInterpolations.ConstantInterpolation{Vector{Float64}, Vector{Int64}, Vector{Float64}, Float64}}}}}, t::Float64) @ abstractodesystem.jl:351
(::SciMLBase.Void{ModelingToolkit.var"#f#813"{RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋arg1, :ˍ₋arg2, :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0xedb50c16, 0x3df29d90, 0xd2cd6390, 0x734b4a96, 0x638b6d0f), Nothing}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋out, :ˍ₋arg1, :ˍ₋arg2, :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x3c596f08, 0xeb569af2, 0x04a44ef9, 0x7a64445b, 0x0034cd95), Nothing}}})(::Vector{Float64}, ::Vararg{Any}) @ utils.jl:486
(::FunctionWrappers.CallWrapper{Nothing})(f::SciMLBase.Void{ModelingToolkit.var"#f#813"{RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋arg1, :ˍ₋arg2, :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0xedb50c16, 0x3df29d90, 0xd2cd6390, 0x734b4a96, 0x638b6d0f), Nothing}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋out, :ˍ₋arg1, :ˍ₋arg2, :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x3c596f08, 0xeb569af2, 0x04a44ef9, 0x7a64445b, 0x0034cd95), Nothing}}}, arg1::Vector{Float64}, arg2::Vector{Float64}, arg3::ModelingToolkit.MTKParameters{Vector{Float64}, Tuple{}, Tuple{}, Tuple{Vector{Vector{DataInterpolations.ConstantInterpolation{Vector{Float64}, Vector{Int64}, Vector{Float64}, Float64}}}}}, arg4::Float64) @ FunctionWrappers.jl:65
macro expansion @ FunctionWrappers.jl:137
do_ccall @ FunctionWrappers.jl:125
FunctionWrapper @ FunctionWrappers.jl:144
_call @ FunctionWrappersWrappers.jl:12
FunctionWrappersWrapper @ FunctionWrappersWrappers.jl:10
Void @ utils.jl:486
(::FunctionWrappers.CallWrapper{Nothing})(f::SciMLBase.Void{FunctionWrappersWrappers.FunctionWrappersWrapper{Tuple{FunctionWrappers.FunctionWrapper{Nothing, Tuple{Vector{Float64}, Vector{Float64}, ModelingToolkit.MTKParameters{Vector{Float64}, Tuple{}, Tuple{}, Tuple{Vector{Vector{DataInterpolations.ConstantInterpolation{Vector{Float64}, Vector{Int64}, Vector{Float64}, Float64}}}}}, Float64}}, FunctionWrappers.FunctionWrapper{Nothing, Tuple{Vector{ForwardDiff.Dual{ForwardDiff.Tag{DiffEqBase.OrdinaryDiffEqTag, Float64}, Float64, 1}}, Vector{ForwardDiff.Dual{ForwardDiff.Tag{DiffEqBase.OrdinaryDiffEqTag, Float64}, Float64, 1}}, ModelingToolkit.MTKParameters{Vector{Float64}, Tuple{}, Tuple{}, Tuple{Vector{Vector{DataInterpolations.ConstantInterpolation{Vector{Float64}, Vector{Int64}, Vector{Float64}, Float64}}}}}, Float64}}, FunctionWrappers.FunctionWrapper{Nothing, Tuple{Vector{ForwardDiff.Dual{ForwardDiff.Tag{DiffEqBase.OrdinaryDiffEqTag, Float64}, Float64, 1}}, Vector{Float64}, ModelingToolkit.MTKParameters{Vector{Float64}, Tuple{}, Tuple{}, Tuple{Vector{Vector{DataInterpolations.ConstantInterpolation{Vector{Float64}, Vector{Int64}, Vector{Float64}, Float64}}}}}, ForwardDiff.Dual{ForwardDiff.Tag{DiffEqBase.OrdinaryDiffEqTag, Float64}, Float64, 1}}}, FunctionWrappers.FunctionWrapper{Nothing, Tuple{Vector{ForwardDiff.Dual{ForwardDiff.Tag{DiffEqBase.OrdinaryDiffEqTag, Float64}, Float64, 1}}, Vector{ForwardDiff.Dual{ForwardDiff.Tag{DiffEqBase.OrdinaryDiffEqTag, Float64}, Float64, 1}}, ModelingToolkit.MTKParameters{Vector{Float64}, Tuple{}, Tuple{}, Tuple{Vector{Vector{DataInterpolations.ConstantInterpolation{Vector{Float64}, Vector{Int64}, Vector{Float64}, Float64}}}}}, ForwardDiff.Dual{ForwardDiff.Tag{DiffEqBase.OrdinaryDiffEqTag, Float64}, Float64, 1}}}}, false}}, arg1::Vector{Float64}, arg2::Vector{Float64}, arg3::ModelingToolkit.MTKParameters{Vector{Float64}, Tuple{}, Tuple{}, Tuple{Vector{Vector{DataInterpolations.ConstantInterpolation{Vector{Float64}, Vector{Int64}, Vector{Float64}, Float64}}}}}, arg4::Float64) @ FunctionWrappers.jl:65
macro expansion @ FunctionWrappers.jl:137
do_ccall @ FunctionWrappers.jl:125
FunctionWrapper @ FunctionWrappers.jl:144
_call @ FunctionWrappersWrappers.jl:12
FunctionWrappersWrapper @ FunctionWrappersWrappers.jl:10
ODEFunction @ scimlfunctions.jl:2335
initialize!(integrator::OrdinaryDiffEqCore.ODEIntegrator{OrdinaryDiffEqCore.CompositeAlgorithm{1, Tuple{OrdinaryDiffEqTsit5.Tsit5{typeof(OrdinaryDiffEqCore.trivial_limiter!), typeof(OrdinaryDiffEqCore.trivial_limiter!), Static.False}, OrdinaryDiffEqVerner.Vern7{typeof(OrdinaryDiffEqCore.trivial_limiter!), typeof(OrdinaryDiffEqCore.trivial_limiter!), Static.False}, OrdinaryDiffEqRosenbrock.Rosenbrock23{1, false, Nothing, typeof(OrdinaryDiffEqCore.DEFAULT_PRECS), Val{:forward}, true, nothing, typeof(OrdinaryDiffEqCore.trivial_limiter!), typeof(OrdinaryDiffEqCore.trivial_limiter!)}, OrdinaryDiffEqRosenbrock.Rodas5P{1, false, Nothing, typeof(OrdinaryDiffEqCore.DEFAULT_PRECS), Val{:forward}, true, nothing, typeof(OrdinaryDiffEqCore.trivial_limiter!), typeof(OrdinaryDiffEqCore.trivial_limiter!)}, OrdinaryDiffEqBDF.FBDF{5, 1, false, Nothing, OrdinaryDiffEqNonlinearSolve.NLNewton{Rational{Int64}, Rational{Int64}, Rational{Int64}, Rational{Int64}}, typeof(OrdinaryDiffEqCore.DEFAULT_PRECS), Val{:forward}, true, nothing, Nothing, Nothing, typeof(OrdinaryDiffEqCore.trivial_limiter!)}, OrdinaryDiffEqBDF.FBDF{5, 1, false, LinearSolve.KrylovJL{typeof(Krylov.gmres!), Int64, Nothing, Tuple{}, @Kwargs{}}, OrdinaryDiffEqNonlinearSolve.NLNewton{Rational{Int64}, Rational{Int64}, Rational{Int64}, Rational{Int64}}, typeof(OrdinaryDiffEqCore.DEFAULT_PRECS), Val{:forward}, true, nothing, Nothing, Nothing, typeof(OrdinaryDiffEqCore.trivial_limiter!)}}, OrdinaryDiffEqCore.AutoSwitchCache{Tuple{OrdinaryDiffEqTsit5.Tsit5{typeof(OrdinaryDiffEqCore.trivial_limiter!), typeof(OrdinaryDiffEqCore.trivial_limiter!), Static.False}, OrdinaryDiffEqVerner.Vern7{typeof(OrdinaryDiffEqCore.trivial_limiter!), typeof(OrdinaryDiffEqCore.trivial_limiter!), Static.False}}, Tuple{OrdinaryDiffEqRosenbrock.Rosenbrock23{0, false, Nothing, typeof(OrdinaryDiffEqCore.DEFAULT_PRECS), Val{:forward}, true, nothing, typeof(OrdinaryDiffEqCore.trivial_limiter!), typeof(OrdinaryDiffEqCore.trivial_limiter!)}, OrdinaryDiffEqRosenbrock.Rodas5P{0, false, Nothing, typeof(OrdinaryDiffEqCore.DEFAULT_PRECS), Val{:forward}, true, nothing, typeof(OrdinaryDiffEqCore.trivial_limiter!), typeof(OrdinaryDiffEqCore.trivial_limiter!)}, OrdinaryDiffEqBDF.FBDF{5, 0, false, Nothing, OrdinaryDiffEqNonlinearSolve.NLNewton{Rational{Int64}, Rational{Int64}, Rational{Int64}, Rational{Int64}}, typeof(OrdinaryDiffEqCore.DEFAULT_PRECS), Val{:forward}, true, nothing, Nothing, Nothing, typeof(OrdinaryDiffEqCore.trivial_limiter!)}, OrdinaryDiffEqBDF.FBDF{5, 0, false, LinearSolve.KrylovJL{typeof(Krylov.gmres!), Int64, Nothing, Tuple{}, @Kwargs{}}, OrdinaryDiffEqNonlinearSolve.NLNewton{Rational{Int64}, Rational{Int64}, Rational{Int64}, Rational{Int64}}, typeof(OrdinaryDiffEqCore.DEFAULT_PRECS), Val{:forward}, true, nothing, Nothing, Nothing, typeof(OrdinaryDiffEqCore.trivial_limiter!)}}, Rational{Int64}, Int64}}, true, Vector{Float64}, Nothing, Float64, ModelingToolkit.MTKParameters{Vector{Float64}, Tuple{}, Tuple{}, Tuple{Vector{Vector{DataInterpolations.ConstantInterpolation{Vector{Float64}, Vector{Int64}, Vector{Float64}, Float64}}}}}, Float64, Float64, Float64, Float64, Vector{Vector{Float64}}, SciMLBase.ODESolution{Float64, 2, Vector{Vector{Float64}}, Nothing, Nothing, Vector{Float64}, Vector{Vector{Vector{Float64}}}, Nothing, SciMLBase.ODEProblem{Vector{Float64}, Tuple{Float64, Float64}, true, ModelingToolkit.MTKParameters{Vector{Float64}, Tuple{}, Tuple{}, Tuple{Vector{Vector{DataInterpolations.ConstantInterpolation{Vector{Float64}, Vector{Int64}, Vector{Float64}, Float64}}}}}, SciMLBase.ODEFunction{true, SciMLBase.AutoSpecialize, FunctionWrappersWrappers.FunctionWrappersWrapper{Tuple{FunctionWrappers.FunctionWrapper{Nothing, Tuple{Vector{Float64}, Vector{Float64}, ModelingToolkit.MTKParameters{Vector{Float64}, Tuple{}, Tuple{}, Tuple{Vector{Vector{DataInterpolations.ConstantInterpolation{Vector{Float64}, Vector{Int64}, Vector{Float64}, Float64}}}}}, Float64}}, FunctionWrappers.FunctionWrapper{Nothing, Tuple{Vector{ForwardDiff.Dual{ForwardDiff.Tag{DiffEqBase.OrdinaryDiffEqTag, Float64}, Float64, 1}}, Vector{ForwardDiff.Dual{ForwardDiff.Tag{DiffEqBase.OrdinaryDiffEqTag, Float64}, Float64, 1}}, ModelingToolkit.MTKParameters{Vector{Float64}, Tuple{}, Tuple{}, Tuple{Vector{Vector{DataInterpolations.ConstantInterpolation{Vector{Float64}, Vector{Int64}, Vector{Float64}, Float64}}}}}, Float64}}, FunctionWrappers.FunctionWrapper{Nothing, Tuple{Vector{ForwardDiff.Dual{ForwardDiff.Tag{DiffEqBase.OrdinaryDiffEqTag, Float64}, Float64, 1}}, Vector{Float64}, ModelingToolkit.MTKParameters{Vector{Float64}, Tuple{}, Tuple{}, Tuple{Vector{Vector{DataInterpolations.ConstantInterpolation{Vector{Float64}, Vector{Int64}, Vector{Float64}, Float64}}}}}, ForwardDiff.Dual{ForwardDiff.Tag{DiffEqBase.OrdinaryDiffEqTag, Float64}, Float64, 1}}}, FunctionWrappers.FunctionWrapper{Nothing, Tuple{Vector{ForwardDiff.Dual{ForwardDiff.Tag{DiffEqBase.OrdinaryDiffEqTag, Float64}, Float64, 1}}, Vector{ForwardDiff.Dual{ForwardDiff.Tag{DiffEqBase.OrdinaryDiffEqTag, Float64}, Float64, 1}}, ModelingToolkit.MTKParameters{Vector{Float64}, Tuple{}, Tuple{}, Tuple{Vector{Vector{DataInterpolations.ConstantInterpolation{Vector{Float64}, Vector{Int64}, Vector{Float64}, Float64}}}}}, ForwardDiff.Dual{ForwardDiff.Tag{DiffEqBase.OrdinaryDiffEqTag, Float64}, Float64, 1}}}}, false}, 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}, OrdinaryDiffEqCore.CompositeAlgorithm{1, 

Environment (please complete the following information):

  • Output of using Pkg; Pkg.status()
MTK 9.36.0
  • Output of versioninfo()
1.10.5, Windows
@cstjean cstjean added the bug Something isn't working label Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants