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

add validation using assert sample and rtype #356

Conversation

sbidari
Copy link
Collaborator

@sbidari sbidari commented Aug 1, 2024

This PR aims to adds validation of RandomVariables using _assert_sample_and_rtype function. The validation methods currently implemented varies between checking something is a random variable using isinstance and checking that the random variable is valid (i.e check tuple return type).

Based on the comments here #341 (comment), I think @damonbayer would like to keep the current implementation of assert isinstance and maybe add further check with _assert_sample_and_rtype? I wanted to confirm my understanding before adding more to this PR

…n-the-validation-methods-for-randomvariables
Copy link

codecov bot commented Aug 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.47%. Comparing base (87a5960) to head (81665bf).
Report is 24 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #356      +/-   ##
==========================================
+ Coverage   93.24%   93.47%   +0.23%     
==========================================
  Files          39       39              
  Lines         918      920       +2     
==========================================
+ Hits          856      860       +4     
+ Misses         62       60       -2     
Flag Coverage Δ
unittests 93.47% <100.00%> (+0.23%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@damonbayer
Copy link
Collaborator

damonbayer commented Aug 2, 2024

I would like it so that any time we have some function f(x: RandomVariable), we validate that x is a RandomVariable using _assert_type.

Separately, any time we instantiate a RandomVariable, we check that it is valid via something like _assert_sample_and_rtype.

So if you have code like this

my_non_rv = y
f(x=my_non_rv)

f will error because x is not a RandomVariable.

But if you have code like this

my_rv = some_way_to_make_an_rv_with_the_wrong_return_type()
f(x=my_rv)

some_way_to_make_an_rv_with_the_wrong_return_type will error because it has the wrong return type and we won't even try to call f.

cc @dylanhmorris and @gvegayon for thoughts.

@sbidari sbidari self-assigned this Aug 6, 2024
@sbidari
Copy link
Collaborator Author

sbidari commented Aug 15, 2024

I would like it so that any time we have some function f(x: RandomVariable), we validate that x is a RandomVariable using _assert_type.

This can be done in #354

Separately, any time we instantiate a RandomVariable, we check that it is valid via something like _assert_sample_and_rtype.

I don't think _assert_sample_and_rtype is useful for this. But happy to hear if you have ideas for it.

I think this PR and associated issue can be closed? @damonbayer

@sbidari
Copy link
Collaborator Author

sbidari commented Aug 16, 2024

Note for clarification: shelving this for now after discussion with Damon. Potential design changes may affect this in the future.

@damonbayer damonbayer mentioned this pull request Aug 23, 2024
2 tasks
@damonbayer
Copy link
Collaborator

Note for clarification: shelving this for now after discussion with Damon. Potential design changes may affect this in the future.

Closing for now.

@damonbayer damonbayer closed this Aug 23, 2024
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.

Extend use of _assert_sample_and_rtype in the validation methods for RandomVariables
2 participants