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 #164

Merged
merged 7 commits into from
Feb 21, 2020
Merged

Error handling for repeated variable names #164

merged 7 commits into from
Feb 21, 2020

Conversation

mforets
Copy link
Member

@mforets mforets commented Feb 11, 2020

From discussion on gitter, consider this PR in place of #155.

@schillic schillic changed the title Error handling for repated variable names Error handling for repeated variable names Feb 12, 2020
src/macros.jl Outdated Show resolved Hide resolved
src/macros.jl Outdated Show resolved Hide resolved
src/macros.jl Outdated Show resolved Hide resolved
src/macros.jl Outdated Show resolved Hide resolved
mforets and others added 3 commits February 12, 2020 08:16
Co-Authored-By: Christian Schilling <[email protected]>
Co-Authored-By: Christian Schilling <[email protected]>
Co-Authored-By: Christian Schilling <[email protected]>
Copy link
Member

@schillic schillic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I accept but I do not think this is a good solution.

@mforets mforets merged commit 54c5c63 into master Feb 21, 2020
@mforets mforets deleted the mforets/133b branch February 21, 2020 14:50
@ueliwechsler
Copy link
Collaborator

ueliwechsler 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 🙈🤷‍♂️

@mforets
Copy link
Member Author

mforets commented Feb 21, 2020

Maybe throwing the error at a later stage, where we no the
exact system types and all the variables.

Yes, that is what i thought (but i haven't tried it).

👍 i moved your comment to the follow up issue, #181

@ueliwechsler
Copy link
Collaborator

Thanks! But 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.

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

Successfully merging this pull request may close these issues.

3 participants