-
Notifications
You must be signed in to change notification settings - Fork 64
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 a workflow to check for examples in docs #459
Conversation
To do: If I locally run We don't want to add these files. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #459 +/- ##
======================================
Coverage 98.1% 98.1%
======================================
Files 160 160
Lines 3107 3108 +1
Branches 749 749
======================================
+ Hits 3048 3049 +1
Misses 37 37
Partials 22 22 ☔ View full report in Codecov by Sentry. |
7a1ccdf
to
edaaffe
Compare
This should be fixed with 9813786. Apparently, All the examples are correctly identified now. The issue that I am running into is that the Github Actions environment can't find any of the installed packages. |
5f28965
to
9230ed8
Compare
@vprusso heads up! This PR is going to have a huge diff. I can't run Do you want me to ping you every time I finish up with 1 module? It will be a bit of a tedious process. With my 2 commits below, you can see the number of failing tests have been reduced compared to the screenshot in my other comment. I do not know why the number of tests also decreased unless |
This comment has been fixed with a workaround in aaf0f9d There are other options linked in this comment if the chosen workaround is not ideal.
use regex? https://documenter.juliadocs.org/stable/man/doctests/#Filtering-Doctests Or use available doctest options: https://github.com/scientific-python/pytest-doctestplus?tab=readme-ov-file#floating-point-comparison |
>>> max_mixed(2, is_sparse=True) | ||
<2x2 sparse matrix of type '<class 'numpy.float64'>' | ||
>>> max_mixed(2, is_sparse=True) # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE | ||
<2x2 sparse matrix of type '<class 'numpy.float64'>' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to use # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
here because I couldn't figure out what the difference between the expected output vs. what doctest got was even after I made sure the indentation for both was the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. I see. Wonder if this will not be an issue when/if we switch from matrix
to np.array
objects universally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wonder if this will not be an issue when/if we switch from matrix to np.array objects universally.
Don't know.
Although doctest was being very particular about the whitespace. Maybe 1 is supposed to be a tab while the other is not. ruff
did not like it when I used tab to create the whitespace.
b3cf766
to
69f1ab0
Compare
@vprusso This PR is ready for a review. Feel free to take your time. Except for some of the outstanding comments in this PR, there were some last-minute failures that I chose to skip for now. 6d8ddf1 , 5add9a0 I also use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few minor comments, but overall, looks good!
@@ -308,8 +308,8 @@ def quantum_value_lower_bound( | |||
... pred_mat[a_alice, b_bob, x_alice, y_bob] = 1 | |||
>>> | |||
>>> chsh = NonlocalGame(prob_mat, pred_mat) | |||
>>> chsh.quantum_value_lower_bound() | |||
0.8535533840915605 | |||
>>> chsh.quantum_value_lower_bound() # doctest: +SKIP |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we have the skip here or just truncate the value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The very first thing I tried was truncating the value. Unfortunately, this function was calculating two different values: 0.75 or 0.85
whenever make doctest
was run multiple times.
Easier option was to make doctest skip this.
@@ -39,7 +39,7 @@ def is_unextendible_product_basis(vecs: list[np.ndarray], dims: list[int]) -> tu | |||
>>> | |||
>>> non_upb_tiles = np.array([tile(i) for i in range(4)]) | |||
>>> dims = np.array([3, 3]) | |||
>>> is_unextendible_product_basis(non_upb_tiles, dims) | |||
>>> is_unextendible_product_basis(non_upb_tiles, dims) # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, are these comments needed here (i.e. the doctest
stuff)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, otherwise the test would fail even when I made sure I copied & pasted the expected output. Plus, in this particular example, the output also contains float values which already causes issues with doctest.
That was my issue with these scenarios as well. How to make it clear to a user that they don't have to use the doctest stuff?
@@ -21,12 +21,12 @@ def bb84() -> np.ndarray: | |||
|
|||
>>> from toqito.states import bb84 | |||
>>> x = bb84() | |||
>>> print(f"|0> = {x[0][0].T}, \n |1> = {x[0][1].T}") | |||
>>> print(f"|+> = {x[1][0].T}, \n |-> = {x[1][1].T}") | |||
>>> print(f"|0> = {x[0][0].T}, \n |1> = {x[0][1].T}") # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, same here. I'm wondering if we just need to change something to remove this ignore we're doing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
>>> max_mixed(2, is_sparse=True) | ||
<2x2 sparse matrix of type '<class 'numpy.float64'>' | ||
>>> max_mixed(2, is_sparse=True) # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE | ||
<2x2 sparse matrix of type '<class 'numpy.float64'>' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. I see. Wonder if this will not be an issue when/if we switch from matrix
to np.array
objects universally.
cdac790
to
c832892
Compare
Why are the following tests failing at random? Locally, if I see these 3 failures, I will run rebasing this branch does not help either. The job did pass for
|
6348be9
to
534046e
Compare
[-0. -0.j 0. +0.j -0. -0.j -0. -0.j] | ||
[ 0. -0.j -0. +0.j 0. +0.j 0. -0.j] | ||
[ 0.5+0.j -0. +0.j 0. +0.j 0.5+0.j]] | ||
>>> np.around(measurements[0], decimals=5) # doctest: +SKIP |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
c1aef00
to
3be51d8
Compare
Description
Fixes #289
Todos
Notable points that this PR has either accomplished or will accomplish.
Questions
Status