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

BoundsError with DAE system when defining t as a variable instead of parameter #609

Closed
valentinsulzer opened this issue Oct 16, 2020 · 6 comments

Comments

@valentinsulzer
Copy link
Contributor

Defining t with the variables instead of with the parameters works fine if making an ODE model, but leads to errors if some equations are algebraic.
Should an error be raised if t is defined as a variable instead of as a parameter?

Works

@parameters t
@variables x1(t) x2(t)
@derivatives D'~t

eqs = [
   D(x1) ~ -x1,
   0 ~ x1 - x2,
]
sys = ODESystem(eqs, t)

u0 = [
   x1 => 1.0,
   x2 => 1.0,
]
prob = ODEProblem(sys,u0,tspan)
sol = solve(prob,Rodas5())

Fails

@variables t x1(t) x2(t)
@derivatives D'~t

eqs = [
   D(x1) ~ -x1,
   0 ~ x1 - x2,
]
sys = ODESystem(eqs, t)

u0 = [
   x1 => 1.0,
   x2 => 1.0,
]
prob = ODEProblem(sys,u0,tspan)
sol = solve(prob,Rodas5())

with message

BoundsError: attempt to access 2-element Array{Float64,1} at index [3]

Stacktrace:
 [1] setindex! at ./array.jl:847 [inlined]
 [2] varmap_to_vars(::Array{Pair{Operation,Float64},1}, ::Array{Variable,1}) at /Users/vsulzer/.julia/packages/ModelingToolkit/4JKjD/src/variables.jl:254
 [3] ODEProblem{true,tType,isinplace,P,F,K,PT} where PT where K where F where P where isinplace where tType(::ODESystem, ::Array{Pair{Operation,Float64},1}, ::Tuple{Float64,Float64}, ::DiffEqBase.NullParameters; version::Nothing, tgrad::Bool, jac::Bool, checkbounds::Bool, sparse::Bool, simplify::Bool, linenumbers::Bool, parallel::ModelingToolkit.SerialForm, eval_expression::Bool, kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at /Users/vsulzer/.julia/packages/ModelingToolkit/4JKjD/src/systems/diffeqs/abstractodesystem.jl:260
 [4] ODEProblem at /Users/vsulzer/.julia/packages/ModelingToolkit/4JKjD/src/systems/diffeqs/abstractodesystem.jl:258 [inlined] (repeats 2 times)
 [5] ODEProblem(::ODESystem, ::Array{Pair{Operation,Float64},1}, ::Vararg{Any,N} where N; kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at /Users/vsulzer/.julia/packages/ModelingToolkit/4JKjD/src/systems/diffeqs/abstractodesystem.jl:231
 [6] ODEProblem(::ODESystem, ::Array{Pair{Operation,Float64},1}, ::Vararg{Any,N} where N) at /Users/vsulzer/.julia/packages/ModelingToolkit/4JKjD/src/systems/diffeqs/abstractodesystem.jl:231
 [7] top-level scope at In[81]:15
 [8] include_string(::Function, ::Module, ::String, ::String) at ./loading.jl:1091
@valentinsulzer valentinsulzer changed the title Defining t as a variable instead of parameter BoundsError with DAE system when defining t as a variable instead of parameter Oct 16, 2020
@ChrisRackauckas
Copy link
Member

We need to revisit this whole part of the interface after #518 merges @shashi @YingboMa

@YingboMa
Copy link
Member

YingboMa commented Jan 8, 2021

Using @variables to define independent variable is not expected to always work.

@YingboMa YingboMa added the wontfix This will not be worked on label Jan 8, 2021
@ChrisRackauckas
Copy link
Member

Is there a reason why discovery is hard in this case? Seems odd to have to label it a parameter.

@YingboMa
Copy link
Member

YingboMa commented Jan 8, 2021

This particular issue isn't hard to fix, but I think it could break some assumptions in passes.

@ChrisRackauckas
Copy link
Member

Which passes assume that t is a Parameter?

@YingboMa
Copy link
Member

YingboMa commented Jan 8, 2021

Oh, I did a grep on the source. There seems to be none.

@YingboMa YingboMa removed the wontfix This will not be worked on label Jan 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants