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

decrease tol for camera test due to MacOS #2836

Merged
merged 5 commits into from
Jun 25, 2022
Merged

Conversation

akaszynski
Copy link
Member

We recently had a test failure in this run.

=================================== FAILURES ===================================
________________________________ test_distance _________________________________
camera = <Camera at 0x1348840c0>
    def test_distance(camera):
        focal_point = np.random.random(3)
        position = np.random.random(3)
        camera.position = position
        camera.focal_point = focal_point
        assert np.isclose(camera.distance, np.linalg.norm(focal_point - position, ord=2), rtol=1e-8)
        distance = np.random.random()
        camera.distance = distance
>       assert np.isclose(camera.distance, distance)
E       assert False
E        +  where False = <function isclose at 0x118bb1200>(0.0002, 0.00016663273706207793)
E        +    where <function isclose at 0x118bb1200> = np.isclose
E        +    and   0.0002 = <Camera at 0x1348840c0>.distance
tests/test_camera.py:59: AssertionError

This PR simply increases the tolerance for this.

@github-actions github-actions bot added the bug Uh-oh! Something isn't working as expected. label Jun 21, 2022
@codecov
Copy link

codecov bot commented Jun 21, 2022

Codecov Report

Merging #2836 (0bcd1e8) into main (5f3da83) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main    #2836   +/-   ##
=======================================
  Coverage   94.03%   94.03%           
=======================================
  Files          76       76           
  Lines       16399    16399           
=======================================
  Hits        15420    15420           
  Misses        979      979           

@MatthewFlamm
Copy link
Contributor

I'm not quite sure whether this is a MacOS thing or some pathological combination of random numbers. If the latter, we could use specified values for the test.

@adeak
Copy link
Member

adeak commented Jun 21, 2022

There's some really creepy thing going on. Notice that the error comes from this assert:

camera.distance = distance
assert np.isclose(camera.distance, distance)

In any sane setup I'd expect those two be very close! Instead this is what I see, on Linux:

>>> import pyvista as pv
>>> cam = pv.Camera()
>>> cam.distance
1.0
>>> cam.distance = 0.00016663273706207793
>>> cam.distance
0.0002
>>> type(cam.distance)
<class 'float'>
>>> cam.distance - 0.00016663273706207793
3.336726293792208e-05

What's up with this?? This can only be VTK's fault, right? Considering

@distance.setter
def distance(self, distance):
"""Set the distance from the camera position to the focal point."""
self.SetDistance(distance)

@adeak
Copy link
Member

adeak commented Jun 21, 2022

VTK seems to set a hard lower bound...

>>> cam.distance = 0.001
>>> cam.distance
0.001
>>> cam.distance = 0.0001
>>> cam.distance
0.0002
>>> cam.distance = 0.00001
>>> cam.distance
0.0002

@MatthewFlamm
Copy link
Contributor

Good catch. It indeed has a limit:

https://github.com/Kitware/VTK/blob/5f855ff8f1237cbb5e5fa55a5ace48149237006e/Rendering/Core/vtkCamera.cxx#L563-L577

This confirms that it is a pathological random number. We should pick a number greater than this limit.

tests/test_camera.py Outdated Show resolved Hide resolved
@akaszynski
Copy link
Member Author

Good catch. It indeed has a limit:

https://github.com/Kitware/VTK/blob/5f855ff8f1237cbb5e5fa55a5ace48149237006e/Rendering/Core/vtkCamera.cxx#L563-L577

This confirms that it is a pathological random number. We should pick a number greater than this limit.

This works:

>>> np.isclose(0.0002, 0, atol=0.0002)
True

Since the smallest possible value for distance is 0 and VTK's smallest is 0.0002.

@adeak
Copy link
Member

adeak commented Jun 23, 2022

This works:

>>> np.isclose(0.0002, 0, atol=0.0002)
True

Since the smallest possible value for distance is 0 and VTK's smallest is 0.0002.

Yeah, I think this can work.

tests/test_camera.py Outdated Show resolved Hide resolved
Co-authored-by: Andras Deak <adeak@users.noreply.github.com>
Copy link
Member

@adeak adeak left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Member

@adeak adeak left a comment

Choose a reason for hiding this comment

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

Let's see if re-approving adds the label.

Edit: nevermind, the labelling action is not merged yet, right?

@akaszynski
Copy link
Member Author

nevermind, the labelling action is not merged yet, right?

It is, but it needs an additional PR.

@tkoyama010 tkoyama010 enabled auto-merge (squash) June 25, 2022 21:37
@tkoyama010 tkoyama010 merged commit 36fbc18 into main Jun 25, 2022
@tkoyama010 tkoyama010 deleted the fix/camera_mac_stability branch June 25, 2022 22:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Uh-oh! Something isn't working as expected.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants