-
Notifications
You must be signed in to change notification settings - Fork 11
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
update functions.py #13
Conversation
yucongalicechen
commented
Apr 6, 2024
- Update functions.py: modify the algorithm to select the correct grid point by comparing the two y-coordinates of points on the circle instead of comparing them with the y-coordinate of the grid point.
… and set distances at angle
|
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.
this looks great, nice job.
- I wonder if we should check intermediate points in the gridding, so go from 3 to 5 on the grid as right now we are only testing points at the center and on the circumference.
- Also for the angle, do we want to test points coming from different quadrants to be sure about the results?
- Please also see my inline comment
The PR is failing CI. Did you sync your main and then merge main into this branch? If you did, then there is something else wrong. You can see by clicking on "details" and see where it failed.
I see that you are failing a bunch of pre-commit tests too. This should not happen if the pre-commit is passing on your local. Please run |
|
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.
please see inline comments.
ideally we would have one test per branch and it would be easier to merge these. Just decide if you want to close this PR and do that, or just continue with this PR.
Also, quick question, did you manage to merge upstream main?
|
||
params1 = [ | ||
[[1, 3, 1, {(0.0, -1.0), (0.0, 0.0), (-1.0, 0.0), (1.0, 0.0), (0.0, 1.0)}, 5]], | ||
[[0.2, 8, 1, {(-0.08571428571428572, -0.14285714285714285), (-0.02857142857142858, -0.14285714285714285), (0.02857142857142858, -0.14285714285714285), (0.08571428571428574, -0.14285714285714285), (-0.14285714285714285, -0.08571428571428572), (-0.08571428571428572, -0.08571428571428572), (-0.02857142857142858, -0.08571428571428572), (0.02857142857142858, -0.08571428571428572), (0.08571428571428574, -0.08571428571428572), (0.14285714285714285, -0.08571428571428572), (-0.14285714285714285, -0.02857142857142858), (-0.08571428571428572, -0.02857142857142858), (-0.02857142857142858, -0.02857142857142858), (0.02857142857142858, -0.02857142857142858), (0.08571428571428574, -0.02857142857142858), (0.14285714285714285, -0.02857142857142858), (-0.14285714285714285, 0.02857142857142858), (-0.08571428571428572, 0.02857142857142858), (-0.02857142857142858, 0.02857142857142858), (0.02857142857142858, 0.02857142857142858), (0.08571428571428574, 0.02857142857142858), (0.14285714285714285, 0.02857142857142858), (-0.14285714285714285, 0.08571428571428574), (-0.08571428571428572, 0.08571428571428574), (-0.02857142857142858, 0.08571428571428574), (0.02857142857142858, 0.08571428571428574), (0.08571428571428574, 0.08571428571428574), (0.14285714285714285, 0.08571428571428574), (-0.08571428571428572, 0.14285714285714285), (-0.02857142857142858, 0.14285714285714285), (0.02857142857142858, 0.14285714285714285), (0.08571428571428574, 0.14285714285714285)}, 32]] |
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.
this set of values seems to be very specific. How did you generate them and how do you know they are correct? A better test is one where you know the right answer and generate without using the function. For an odd number of points use 0.5.
The even number of points specified is harder to test, so do it with a very small number of points, say 2 on each axis and then the points shold presumably be something like 1/3, 2/3.
from diffpy.labpdfproc.functions import Gridded_circle | ||
|
||
params1 = [ | ||
[[1, 3, 1, {(0.0, -1.0), (0.0, 0.0), (-1.0, 0.0), (1.0, 0.0), (0.0, 1.0)}, 5]], |
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.
these are easier to read if they are a list of tuples, one for each test, then this tuple has two lists which are for the inputs and outputs. So in this case it would be
params1 = [
( [1, 3, 1], [{(...), (...), (...)}, 9] ),
(...)
]
@pytest.mark.paramaterize("inputs, expected", params1)
def test_...():
circle = Griddedcircle(inputs[0], inputs[1])
and so on. This is much easier to read.
I may not have the syntax from pytest.mark.paramatrize()
quite right so please look it up, but we would like the intent of hte tests to be easier to read in all your tests.
|
||
@pytest.mark.parametrize('params1', params1) | ||
def test_get_grid_points(params1): | ||
for param_set in params1: |
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.
this is not how paramatrize works, you don't need this.
|
||
|
||
|
||
# values of distances are correct but im a bit confused about the order of distances |
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.
Decide in your test what behavior you want. Do you care about order? If not, you could use a set, or stick with a list but sort it by value before doing the assert, something like that. If you care about order in the function then test this.
|
||
# values of distances are correct but im a bit confused about the order of distances | ||
params2 = [ | ||
[[1, 3, 1, [25, 90, 140], |
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.
you need to run black
on everything to get the layout right. But when you install pre-commit
it will do it for you when you commit. You will have to run the commit multiple times as when it runs black the commit fails, so just rerun it (if flake8 fails you have to fix the errors manually then rerun the commit).
[[1, 3, 1, [25, 90, 140], | ||
[[0, 2, 1.81261557406, 2, 0.845236523481399], | ||
[0, 2, 0, 2, 2], | ||
[0, 2, 0, 3.5320888862379562, 1.2855752193730785]]]], |
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.
many of these numbers seem magical and too high in precision (is it important for your function that it gets a number correct to 11 significant figures?). Can you manually compute a few special cases and use those as the test? It may be harder here than for the grid points, so just find a reasonable balance, but don't use the function to compute these.
|
||
@pytest.mark.parametrize('params2', params2) | ||
def test_set_distances_at_angle(params2): | ||
for param_set in params2: |
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.
remove this for loop.
radius, n_points_on_diameter, mu, angles, expected_muls = params3 | ||
actual_gs = Gridded_circle(radius=radius, n_points_on_diameter=n_points_on_diameter, mu=mu) | ||
for angle, expected_mul in zip(angles, expected_muls): | ||
# here it seems like I need to set distances first (can't assign distances only using set muls) |
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.
remember, figure out what you want your function to do then write the test to do it. What does this function do and how is it used, and so what behavior do you want in different circumstances, then write the test to check that. Don't be distracted by what the function actually does at the moment. Let's just write the tests first, then we can rewrite any functions to make them have that behavior.
I htink this PR can be closed as it is replaced with other PRs. If you agree, please can you close it? |