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

Using assert in airo-mono #67

Open
adverley opened this issue Jul 5, 2023 · 3 comments
Open

Using assert in airo-mono #67

adverley opened this issue Jul 5, 2023 · 3 comments
Labels
question Further information is requested

Comments

@adverley
Copy link
Contributor

adverley commented Jul 5, 2023

If python is called with the optimized flag python -O, assert statements are disabled. Is this problematic the way assert statements are currently used in the codebase?

@tlpss
Copy link
Contributor

tlpss commented Jul 5, 2023

for me that is actually a feature, not an issue

assert statements are afaik used in the codebase to throw errors with a descriptive message before python throws a runtime error that can be hard to debug. If you really need the speed (but still want to use python), you can then run with the -O flag and all asserts will be skipped.

Do you foresee issues with this @adverley?

@adverley
Copy link
Contributor Author

adverley commented Jul 5, 2023

I did not phrase my question accurately. When are we using assert instead of raising Exceptions? I think we need to determine when we use assert and when we raise Exception. In the cases of using asserts, did we consider what happens when somebody is running python -O?

These checks are an asserts that are input-based. If we give it an image (which you could consider something that comes from an user) of corrupted dimensions, we get an assertion error from which we cannot recover and which might be disabled due to -O.

This also checks matrix formats but does it with an Exception instead of an assert. The data for this check eventually also boils down to an input image provided by an end-user.

I've always viewed assert statements in Python more as a development tool and exception throwing something more of library building thing. It is not my intention to start this type of discussion, I'm actually just interested whether there is a rational here. In case there is, is it documented and shared by all the devs here?

@tlpss
Copy link
Contributor

tlpss commented Jul 7, 2023

've always viewed assert statements in Python more as a development tool and exception throwing something more of library building thing

yes I agree, asserts are also sanity checks for me, but in ML frameworks I also use them to validate inputs (e.g. is this batch well-formed), because I know it is easy to disable them if you need that extra speed.

These checks are an asserts that are input-based. If we give it an image (which you could consider something that comes from an user) of corrupted dimensions, we get an assertion error from which we cannot recover and which might be disabled due to -O.

In this case, I agree Exceptions would be more appropriate! But until now I haven't really thought this true very well.

Long story short, there are no explicit conventions we use. No clue how the python community does this usually. But I agree with the sentiment dat asserts are more like debug sanity checks and not to validate user input. a valid exception for me is if you expect something to run multiple times, in which case a user can do a check first and then run it in optimized mode (though I've never done that myself).

@Victorlouisdg Victorlouisdg added the question Further information is requested label Aug 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants