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

Error with vector arguments #954

Closed
TorkelE opened this issue Jun 13, 2024 · 5 comments
Closed

Error with vector arguments #954

TorkelE opened this issue Jun 13, 2024 · 5 comments

Comments

@TorkelE
Copy link
Member

TorkelE commented Jun 13, 2024

There are currently some problems with vector arguments for parameters/initial conditions. I think this worked previously (I had some old tests which I think were mostly fine, but waited due to another issue and then forgot about).

Example using both Catalyst and MTK.

using Catalyst, OrdinaryDiffEq

@variables t
D = Differential(t)
@parameters k[1:4]
@species (X(t))[1:2]
@variables (V(t))[1:2]

rxs = [
    Reaction(k[1], [], [X[1]]),
    Reaction(k[2], [], [X[2]]),
    Reaction(k[3], [X[1]], []),
    Reaction(k[4], [X[2]], [])
]
eqs = [
    D(V[1]) ~ k[1] - k[2]*V[1],
    D(V[2]) ~ k[3] - k[4]*V[2]
]

@named rs = ReactionSystem(rxs, t)
rs = complete(rs)
@mtkbuild osys = ODESystem(eqs, t)

u0_rs = [X => [10.0, 20.0]]
u0_alt_rs = [X[1] => 10.0, X[2] => 20.0]
u0_osys = [V => [10.0, 20.0]]
u0_alt_osys = [V[1] => 10.0, V[2] => 20.0]
ps = [k => [1.0, 2.0, 3.0, 4.0]]
ps_alt = [k[1] => 1.0, k[2] => 2.0, k[3] => 3.0, k[4] => 4.0]

# Not sure why scalarised parameter values are no longer permitted, but seems funny they work for Catalyst.
oprob_rs = ODEProblem(rs, u0_rs, 1.0, ps) # Works
oprob_rs = ODEProblem(rs, u0_alt_rs, 1.0, ps) # Works
oprob_rs = ODEProblem(rs, u0_rs, 1.0, ps_alt) # Works/ Should probably yield an error.
oprob_osys = ODEProblem(osys, u0_osys, 1.0, ps) # Works
oprob_osys = ODEProblem(osys, u0_alt_osys, 1.0, ps) # Works
oprob_osys = ODEProblem(osys, u0_osys, 1.0, ps_alt) # ERROR: Scalarized parameter values (k[3]) are not supported. Instead of `[p[1] => 1.0, p[2] => 2.0]` use `[p => [1.0, 2.0]]`

# Problem with Catalyst.
remake(oprob_rs, u0 = u0_rs, p = ps) # ERROR: type Nothing has no field portion
remake(oprob_rs, u0 = u0_alt_rs, p = ps) # ERROR: type Nothing has no field portion
remake(oprob_rs, u0 = u0_rs, p = ps_alt) # Works
remake(oprob_osys, u0 = u0_osys, p = ps) # Works
remake(oprob_osys, u0 = u0_alt_osys, p = ps) # Works
remake(oprob_osys, u0 = u0_osys, p = ps_alt) # `ERROR: UndefRefError: access to undefined reference` (maybe a better error message.)

An expanded version of Catalyst remake error. Never actually passes Catalyst code, not sure why.

ERROR: type Nothing has no field portion
Stacktrace:
  [1] getproperty(x::Nothing, f::Symbol)
    @ Base ./Base.jl:37
  [2] validate_parameter_type(ic::ModelingToolkit.IndexCache, p::Symbolics.Arr{Num, 1}, index::Nothing, val::Vector{Float64})
    @ ModelingToolkit ~/.julia/packages/ModelingToolkit/3Suzf/src/systems/parameter_buffer.jl:424
  [3] remake_buffer(indp::ODEProblem{…}, oldbuf::ModelingToolkit.MTKParameters{…}, vals::Dict{…})
    @ ModelingToolkit ~/.julia/packages/ModelingToolkit/3Suzf/src/systems/parameter_buffer.jl:487
  [4] _updated_u0_p_symmap(prob::ODEProblem{…}, u0::Dict{…}, ::Val{…}, p::Dict{…}, ::Val{…})
    @ SciMLBase ~/.julia/packages/SciMLBase/roUH9/src/remake.jl:511
  [5] _updated_u0_p_internal(prob::ODEProblem{…}, u0::Vector{…}, p::Vector{…}; interpret_symbolicmap::Bool, use_defaults::Bool)
    @ SciMLBase ~/.julia/packages/SciMLBase/roUH9/src/remake.jl:427
  [6] _updated_u0_p_internal
    @ ~/.julia/packages/SciMLBase/roUH9/src/remake.jl:412 [inlined]
  [7] #updated_u0_p#688
    @ ~/.julia/packages/SciMLBase/roUH9/src/remake.jl:551 [inlined]
  [8] updated_u0_p
    @ ~/.julia/packages/SciMLBase/roUH9/src/remake.jl:532 [inlined]
  [9] remake(prob::ODEProblem{…}; f::Missing, u0::Vector{…}, tspan::Missing, p::Vector{…}, kwargs::Missing, interpret_symbolicmap::Bool, use_defaults::Bool, _kwargs::@Kwargs{})
    @ SciMLBase ~/.julia/packages/SciMLBase/roUH9/src/remake.jl:95
 [10] top-level scope
    @ ~/Desktop/Julia Playground/Environment - Catalyst test/test_playground.jl:38
Some type information was truncated. Use `show(err)` to see complete types.
@TorkelE TorkelE added the bug label Jun 13, 2024
@isaacsas
Copy link
Member

So then from that error it sounds like we shouldn't be scalarizing parameters any more?

@isaacsas
Copy link
Member

Changing that would be breaking so if we should switch that should be done before V14.

@TorkelE
Copy link
Member Author

TorkelE commented Jun 13, 2024

Internally I think we can do whichever, but we might want to change what we permit in the input.

@TorkelE
Copy link
Member Author

TorkelE commented Jun 13, 2024

I will have to go back to see if I can find all the details about scalrization that I wrote and discussed with Aayush though

@TorkelE
Copy link
Member Author

TorkelE commented Jun 14, 2024

replaced by SciML/ModelingToolkit.jl#2804

@TorkelE TorkelE closed this as completed Jun 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants