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 handling for repeated variable names (cont.) #181

Open
mforets opened this issue Feb 21, 2020 · 3 comments
Open

Error handling for repeated variable names (cont.) #181

mforets opened this issue Feb 21, 2020 · 3 comments

Comments

@mforets
Copy link
Member

mforets commented Feb 21, 2020

In #164 we added default variable names in parse_system and an error message is sent in case of conflict. However, the noise variable is read a posteriori so there is still a possible conflict. As a consequence the following error is a bit cryptic and can be improved:

julia> @system(x⁺ = Ax + Bu + Du, input: u)
ERROR: ArgumentError: the entry (:A, :B, :B) does not match a `MathematicalSystems.jl` structure

ref: #164 (comment)

An approach suggested here is to make the error checks in extract_sum.

@mforets
Copy link
Member Author

mforets commented Feb 21, 2020

After thinking everything through more again more carefully, I think you are right.

In order for me to understand what is going on, I like to write everything I know down
(sorry for the long comment)

As far as i know, this PR should give reasonable error messages for cases where
a specified input or noise is added which does collide with another

A = B = D = rand(2,2)
@system(a⁺= Aa + Bw, input:a)
ERROR: ArgumentError: state and input variables have the same name `a`
# instead of the old error message
ERROR: ArgumentError: the entry (:A, :D) does not match a `MathematicalSystems.jl` structure
@system(x⁺= Ax + Bx, input:x)
ERROR: ArgumentError: state and input variables have the same name `x`
@system(x⁺= Ax + Bu + Bw, input:u, noise:u)
ERROR: ArgumentError: input and noise variables have the same name `u`

without throwing exceptions where the input is "overwritten" with the noise variable
(and the noise not defined) or vice versa where the input is overwritten

# we can use 
@system(x⁺= Ax + Bw, input:w) #creates a LinearControlDiscreteSystem system
system(x⁺= Ax + Bu, noise:u) # 
# instead of 
@system(x⁺= Ax + Bw, input:w, noisestr:evry_but_w)

in the @system(x⁺= Ax + Bw, input:w), the input and the noise variable are both :w but
since we do not "use" the noise variable we accept that "inconsistency" for shortness of the
macro.

However, this cases are not covered so far in this PR (but we also should add it)

@system(x⁺= Ax + Bw + Dw, input:w)
@system(x⁺= Ax + Bu + Bu,  noise:u)
@system(x⁺= Ax + Bx)
@system(x⁺= Ax + c + c)
# etc

which gives a non-sensical error messsage. (for which my aforementioned fix
should help).

Hoooowever, going through this logic it should also give the right error for

@system(x⁺= Ax + Bu + Bw,  noise:u)
ERROR: ArgumentError: the entry (:A, :B, :c) does not match a `MathematicalSystems.jl` structure
@system(x⁺= Ax + Bu + Bw,  input:w)
ERROR: ArgumentError: the entry (:A, :c, :B) does not match a `MathematicalSystems.jl` structure

which it does not, and also will not get caught by my solutions.

Sooo, too sum up, I am bit confused. I think we could do it better, you are right,
but I am not sure how. Maybe throwing the error at a later stage, where we no the
exact system types and all the variables.

EDIT: noo, it does not work to make the test later, because we will infer the wrong system types

originally posted in #164 (comment)

we still have to catch the error from @system(x⁺= Ax + Bu + Bw, noise:u) and @system(x⁺= Ax + Bu + Bw, input:w) I think this one could be caught after here after this line

sys_type = _corresponding_type(AT, field_names)
... it is getting quite ugly if we have 3 separate places for tests.

@ueliwechsler
Copy link
Collaborator

I found a new error, that the tests in parse_system introduce:

@system(x' = A*x + B*w, noise:w)
ERROR: ArgumentError: input and noise variables have the same name `w`

throws an error because we set the input here

 if @capture(stripped, (x_ = A_*x_ + B_*u_) |
                          (x_ = x_ + B_*u_) |
                          (x_ = A_*x_ + B_*u_ + c_) |
                          (x_ = x_ + B_*u_ + c_) |
                          (x_ = f_(x_, u_)) )
      input_var = u
 end

and then here

elseif got_input_var && got_noise_var && (input_var == noise_var)
         throw(ArgumentError("input and noise variables have the same name `$(input_var)`"))
end

it "breaks".

All the convenience functions and special cases are taking its toll.

@ueliwechsler
Copy link
Collaborator

ueliwechsler commented Mar 9, 2020

#186 (comment)

Summary:

Not properly working are:

  • @system(x' = A*x + B*w, noise:w)
    ERROR: ArgumentError: input and noise variables have the same name w
  • @system(x⁺= Ax + Bu + Bw, noise:u)
    ArgumentError: the entry (:A, :B, :c) does not match a MathematicalSystems.jl structure
  • @system(x⁺= Ax + Bu + Bw, input:w)

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