Open
Description
I want to define ODE variables like
This greatly helps my application over using just
It works great for the most part, but I run into one failure when using getsym
with an observed variable:
using ModelingToolkit, SymbolicIndexingInterface, Test
using ModelingToolkit: t_nounits as t, D_nounits as D
@parameters k
@variables x(t, k) y(t, k) # want to write ODE variables in this form
@mtkbuild sys = System([D(x) ~ 0, y ~ x + 1], t)
prob = ODEProblem(sys, [x => 0.0], (0.0, 1.0))
@test getsym(prob, x)(prob) == 0.0 # works (unknown)
@test getsym(prob, y)(prob) == 1.0 # fails (observed)
Error During Test at c:\Users\herma\.julia\dev\SymBoltz\bug.jl:9
Test threw exception
Expression: (getsym(prob, y))(prob) == 1.0
Tuple{Real} is not a subtype of Tuple{Any, Any}.
Stacktrace:
[1] error(s::String)
@ Base .\error.jl:35
[2] promote_symtype(f::SymbolicUtils.BasicSymbolic{SymbolicUtils.FnType{Tuple{Any, Any}, Real}}, args::Type)
@ SymbolicUtils C:\Users\herma\.julia\packages\SymbolicUtils\aooYZ\src\types.jl:1213
[3] (::SymbolicUtils.BasicSymbolic{SymbolicUtils.FnType{Tuple{Any, Any}, Real}})(::SymbolicUtils.BasicSymbolic{Real}, ::Vararg{SymbolicUtils.BasicSymbolic{Real}})
@ SymbolicUtils C:\Users\herma\.julia\packages\SymbolicUtils\aooYZ\src\types.jl:1191
[4] _all_ts_idxs!(ts_idxs::Set{Any}, ::ScalarSymbolic, sys::System, sym::Num)
@ ModelingToolkit C:\Users\herma\.julia\dev\ModelingToolkit\src\systems\abstractsystem.jl:322
[5] _all_ts_idxs!
@ C:\Users\herma\.julia\dev\ModelingToolkit\src\systems\abstractsystem.jl:359 [inlined]
[6] get_all_timeseries_indexes
@ C:\Users\herma\.julia\dev\ModelingToolkit\src\systems\abstractsystem.jl:366 [inlined]
[7] get_all_timeseries_indexes (repeats 2 times)
@ C:\Users\herma\.julia\packages\SymbolicIndexingInterface\vXqJR\src\index_provider_interface.jl:156 [inlined]
[8] _getsym(sys::ODEProblem{Vector{Float64}, Tuple{Float64, Float64}, true, MTKParameters{StaticArraysCore.SizedVector{0, Float64, Vector{Float64}}, Vector{Float64}, Tuple{}, Tuple{}, Tuple{}, Tuple{}}, ODEFunction{true, SciMLBase.FullSpecialize, ModelingToolkit.GeneratedFunctionWrapper{(2, 3, true), RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:__mtk_arg_1, :___mtkparameters___, :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x617a43cb, 0x7f52f236, 0x165cefa5, 0xfd591f67, 0xfe380c95), Nothing}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋out, :__mtk_arg_1, :___mtkparameters___, :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x54e38df4, 0x19f648d9, 0xefb83b31, 0xc666a160, 0xfd19ea7e), Nothing}}, LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, ModelingToolkit.ObservedFunctionCache{System}, Nothing, System, 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", (0xf6fe821e, 0x3045ed3a, 0x79c85221, 0x86eee4f8, 0xafa75ea5), Nothing}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋out, :__mtk_arg_1, :___mtkparameters___), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0xde4f097d, 0x959b6864, 0x55ddd319, 0xca6f480a, 0x9dcae5ca), Nothing}}, LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, ModelingToolkit.ObservedFunctionCache{System}, Nothing, System, Nothing, Nothing}, @Kwargs{}, SciMLBase.StandardNonlinearProblem}, typeof(ModelingToolkit.update_initializeprob!), ComposedFunction{typeof(identity), SymbolicIndexingInterface.TimeIndependentObservedFunction{ModelingToolkit.GeneratedFunctionWrapper{(2, 2, true), RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:__mtk_arg_1, :___mtkparameters___), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x401f5bd8, 0xddb176b3, 0x0ab86ab5, 0x13bd3177, 0x40f34ee7), Nothing}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋out, :__mtk_arg_1, :___mtkparameters___), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0xf8979e8b, 0x2494ba44, 0x158eddf0, 0x980929af, 0x6d51f58f), Nothing}}}}, ModelingToolkit.var"#initprobpmap_split#910"{ModelingToolkit.var"#_getter#906"{Tuple{Returns{StaticArraysCore.SizedVector{0, Float64, Vector{Float64}}}, ComposedFunction{ModelingToolkit.PConstructorApplicator{typeof(identity)}, ModelingToolkit.ObservedWrapper{false, ModelingToolkit.GeneratedFunctionWrapper{(2, 2, true), RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:__mtk_arg_1, :___mtkparameters___), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x81da7c5a, 0xfdaf0c97, 0x287a016c, 0x42726326, 0x4da29d50), Nothing}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋out, :__mtk_arg_1, :___mtkparameters___), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x423f2428, 0x3e694fdc, 0x5266d7dc, 0x76e6d9a2, 0x693def01), Nothing}}}}, Returns{Tuple{}}, Returns{Tuple{}}, Returns{Tuple{}}}}}, ModelingToolkit.InitializationMetadata{ModelingToolkit.ReconstructInitializeprob{ModelingToolkit.var"#_getter#906"{Tuple{ComposedFunction{ModelingToolkit.PConstructorApplicator{typeof(identity)}, ModelingToolkit.ObservedWrapper{true, ModelingToolkit.GeneratedFunctionWrapper{(2, 3, true), RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:__mtk_arg_1, :___mtkparameters___, :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x069c313e, 0xad37d64c, 0x79a926b9, 0xc4328e05, 0xcda4754e), Nothing}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋out, :__mtk_arg_1, :___mtkparameters___, :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x70432732, 0x3b3bf9e4, 0x87bf6bc1, 0xa242b6fc, 0xa44a0725), Nothing}}}}, Returns{StaticArraysCore.SizedVector{0, Float64, Vector{Float64}}}, Returns{Tuple{}}, Returns{Tuple{}}, Returns{Tuple{}}}}, ComposedFunction{typeof(identity), SymbolicIndexingInterface.MultipleGetters{ContinuousTimeseries, Vector{Any}}}}, ModelingToolkit.GetUpdatedU0{SymbolicIndexingInterface.MultipleGetters{ContinuousTimeseries, Vector{SymbolicUtils.BasicSymbolic{Real}}}, SymbolicIndexingInterface.MultipleParametersGetter{SymbolicIndexingInterface.IndexerNotTimeseries, Vector{SymbolicIndexingInterface.GetParameterIndex{ModelingToolkit.ParameterIndex{SciMLStructures.Initials, Int64}}}, Nothing}}, ModelingToolkit.SetInitialUnknowns{SymbolicIndexingInterface.MultipleSetters{Vector{SymbolicIndexingInterface.ParameterHookWrapper{SymbolicIndexingInterface.SetParameterIndex{ModelingToolkit.ParameterIndex{SciMLStructures.Initials, Int64}}, SymbolicUtils.BasicSymbolic{Real}}}}}}, Val{true}}, Nothing}, @Kwargs{}, SciMLBase.StandardODEProblem}, ::ScalarSymbolic, ::ScalarSymbolic, sym::Num)
@ SymbolicIndexingInterface C:\Users\herma\.julia\packages\SymbolicIndexingInterface\vXqJR\src\state_indexing.jl:158
[9] getsym(sys::ODEProblem{Vector{Float64}, Tuple{Float64, Float64}, true, MTKParameters{StaticArraysCore.SizedVector{0, Float64, Vector{Float64}}, Vector{Float64}, Tuple{}, Tuple{}, Tuple{}, Tuple{}}, ODEFunction{true, SciMLBase.FullSpecialize, ModelingToolkit.GeneratedFunctionWrapper{(2, 3, true), RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:__mtk_arg_1, :___mtkparameters___, :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x617a43cb, 0x7f52f236, 0x165cefa5, 0xfd591f67, 0xfe380c95), Nothing}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋out, :__mtk_arg_1, :___mtkparameters___, :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x54e38df4, 0x19f648d9, 0xefb83b31, 0xc666a160, 0xfd19ea7e), Nothing}}, LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, ModelingToolkit.ObservedFunctionCache{System}, Nothing, System, 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", (0xf6fe821e, 0x3045ed3a, 0x79c85221, 0x86eee4f8, 0xafa75ea5), Nothing}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋out, :__mtk_arg_1, :___mtkparameters___), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0xde4f097d, 0x959b6864, 0x55ddd319, 0xca6f480a, 0x9dcae5ca), Nothing}}, LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, ModelingToolkit.ObservedFunctionCache{System}, Nothing, System, Nothing, Nothing}, @Kwargs{}, SciMLBase.StandardNonlinearProblem}, typeof(ModelingToolkit.update_initializeprob!), ComposedFunction{typeof(identity), SymbolicIndexingInterface.TimeIndependentObservedFunction{ModelingToolkit.GeneratedFunctionWrapper{(2, 2, true), RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:__mtk_arg_1, :___mtkparameters___), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x401f5bd8, 0xddb176b3, 0x0ab86ab5, 0x13bd3177, 0x40f34ee7), Nothing}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋out, :__mtk_arg_1, :___mtkparameters___), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0xf8979e8b, 0x2494ba44, 0x158eddf0, 0x980929af, 0x6d51f58f), Nothing}}}}, ModelingToolkit.var"#initprobpmap_split#910"{ModelingToolkit.var"#_getter#906"{Tuple{Returns{StaticArraysCore.SizedVector{0, Float64, Vector{Float64}}}, ComposedFunction{ModelingToolkit.PConstructorApplicator{typeof(identity)}, ModelingToolkit.ObservedWrapper{false, ModelingToolkit.GeneratedFunctionWrapper{(2, 2, true), RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:__mtk_arg_1, :___mtkparameters___), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x81da7c5a, 0xfdaf0c97, 0x287a016c, 0x42726326, 0x4da29d50), Nothing}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋out, :__mtk_arg_1, :___mtkparameters___), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x423f2428, 0x3e694fdc, 0x5266d7dc, 0x76e6d9a2, 0x693def01), Nothing}}}}, Returns{Tuple{}}, Returns{Tuple{}}, Returns{Tuple{}}}}}, ModelingToolkit.InitializationMetadata{ModelingToolkit.ReconstructInitializeprob{ModelingToolkit.var"#_getter#906"{Tuple{ComposedFunction{ModelingToolkit.PConstructorApplicator{typeof(identity)}, ModelingToolkit.ObservedWrapper{true, ModelingToolkit.GeneratedFunctionWrapper{(2, 3, true), RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:__mtk_arg_1, :___mtkparameters___, :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x069c313e, 0xad37d64c, 0x79a926b9, 0xc4328e05, 0xcda4754e), Nothing}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋out, :__mtk_arg_1, :___mtkparameters___, :t), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x70432732, 0x3b3bf9e4, 0x87bf6bc1, 0xa242b6fc, 0xa44a0725), Nothing}}}}, Returns{StaticArraysCore.SizedVector{0, Float64, Vector{Float64}}}, Returns{Tuple{}}, Returns{Tuple{}}, Returns{Tuple{}}}}, ComposedFunction{typeof(identity), SymbolicIndexingInterface.MultipleGetters{ContinuousTimeseries, Vector{Any}}}}, ModelingToolkit.GetUpdatedU0{SymbolicIndexingInterface.MultipleGetters{ContinuousTimeseries, Vector{SymbolicUtils.BasicSymbolic{Real}}}, SymbolicIndexingInterface.MultipleParametersGetter{SymbolicIndexingInterface.IndexerNotTimeseries, Vector{SymbolicIndexingInterface.GetParameterIndex{ModelingToolkit.ParameterIndex{SciMLStructures.Initials, Int64}}}, Nothing}}, ModelingToolkit.SetInitialUnknowns{SymbolicIndexingInterface.MultipleSetters{Vector{SymbolicIndexingInterface.ParameterHookWrapper{SymbolicIndexingInterface.SetParameterIndex{ModelingToolkit.ParameterIndex{SciMLStructures.Initials, Int64}}, SymbolicUtils.BasicSymbolic{Real}}}}}}, Val{true}}, Nothing}, @Kwargs{}, SciMLBase.StandardODEProblem}, sym::Num)
@ SymbolicIndexingInterface C:\Users\herma\.julia\packages\SymbolicIndexingInterface\vXqJR\src\state_indexing.jl:31
[10] macro expansion
@ C:\Users\herma\.julia\juliaup\julia-1.11.5+0.x64.w64.mingw32\share\julia\stdlib\v1.11\Test\src\Test.jl:676 [inlined]
[11] top-level scope
@ c:\Users\herma\.julia\dev\SymBoltz\bug.jl:9
ERROR: There was an error during testing
Is this fixable? That would greatly help my use case. This is with the latest MTK v10.2.0 and SII v0.3.40.