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

ArgumentError in gearbox #18

Closed
nikos-kekatos opened this issue May 9, 2018 · 4 comments
Closed

ArgumentError in gearbox #18

nikos-kekatos opened this issue May 9, 2018 · 4 comments

Comments

@nikos-kekatos
Copy link
Collaborator

The following error occurs when we parse the gearbox benchmark.

ArgumentError: Second argument must be of Symbol type

@mforets mforets changed the title One more parsing error ArgumentError in gearbox May 9, 2018
@mforets
Copy link
Member

mforets commented May 19, 2018

To parse SX_Mesh_automatically.xml we need at least #27, see Gearbox.ipynb.

As a workaround i've renamed the variable I to II in the new file SX_Mesh_manual.xml.

There is now a different error,

julia> file = "SX_Mesh_manual.xml";
julia> H = readsxmodel(file, ST=ConstrainedLinearControlContinuousSystem);

DimensionMismatch("tried to assign 6-element array to 1×1 destination")

Stacktrace:
 [1] throw_setindex_mismatch(::Array{Float64,1}, ::Tuple{Int64,Int64}) at ./indices.jl:94
 [2] setindex_shape_check(::Array{Float64,1}, ::Int64, ::Int64) at ./indices.jl:146
 [3] macro expansion at ./multidimensional.jl:554 [inlined]
 [4] _unsafe_setindex!(::IndexLinear, ::Array{Float64,2}, ::Array{Float64,1}, ::Int64, ::Base.Slice{Base.OneTo{Int64}}) at ./multidimensional.jl:549
 [5] macro expansion at ./multidimensional.jl:541 [inlined]
 [6] _setindex! at ./multidimensional.jl:537 [inlined]
 [7] setindex!(::Array{Float64,2}, ::Array{Float64,1}, ::Int64, ::Colon) at ./abstractarray.jl:968
 [8] #linearHS#25(::Type{T} where T, ::Type{T} where T, ::Type{T} where T, ::Array{Any,1}, ::Function, ::Dict{String,Any}) at /Users/forets/.julia/v0.6/SX/src/symbolic.jl:109
 [9] (::SX.#kw##linearHS)(::Array{Any,1}, ::SX.#linearHS, ::Dict{String,Any}) at ./<missing>:0
 [10] #readsxmodel#1(::Bool, ::Type{T} where T, ::Type{T} where T, ::Array{Any,1}, ::Function, ::String) at /Users/forets/.julia/v0.6/SX/src/io.jl:149
 [11] (::SX.#kw##readsxmodel)(::Array{Any,1}, ::SX.#readsxmodel, ::String) at ./<missing>:0
 [12] include_string(::String, ::String) at ./loading.jl:522

@mforets
Copy link
Member

mforets commented May 19, 2018

Further debugging shows that this error exposes a wrong assumption in #13.

Although parameters are defined "globally" for all locations in a given component (via <param .../>), nothing says that the flow equation in a given location should involve all state variables.

As it is the case in this model, we have:

julia> file = "SX_Mesh_manual.xml";

julia> HDict = readsxmodel(file, raw_dict=true);

julia> HDict["flows"][1]
6-element Array{Expr,1}:
 :(t' = 1)         
 :(vx' = 21.875)   
 :(vy' = -0.114285)
 :(px' = vx)       
 :(py' = vy)       
 :(II' = 0)        

julia> HDict["flows"][2]
1-element Array{Expr,1}:
 :(t' = 0)

You see, the set of equations of the second location affects only a subset of the variables defined in this component. Hence i think we need to pull in the loop for id_location in eachindex(flows) a vector of local_state_variables, otherwise an operation such as

ex = diff.(RHS, state_variables)
A[i, :] = convert.(N, ex)

is going to crash, because the dimension on the right (in this case, 6) does not match the number of columns of A (which is 1, since n = length(flows[id_location])).

@mforets
Copy link
Member

mforets commented May 19, 2018

Done in this commit, which fixes the problem.

I doubted if the same fix applies to discrete transitions, and finally decided to add it. Basically, in an assignment you don't necessarily won't affect all state variables defined in the component.

IIRC, SpaceEx automatically adds the missing variables in an assignment, we see this for example in bball_flattened.xml

 <assignment>x' == x &amp; v' == -0.75*v</assignment>

compare to the original network bball.xml:

<assignment>v := -c*v</assignment>

...

    <bind component="ball_template" as="ball" x="238.0" y="106.0">
 ...
      <map key="c">0.75</map>
...
    </bind>

@nikos-kekatos
Copy link
Collaborator Author

great! you have been super-efficient :) :)

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

2 participants