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

#66 loosen tolerance for comparing memory consumption #67

Merged
merged 7 commits into from
Jul 23, 2024

Conversation

jschneidereit
Copy link
Contributor

@jschneidereit jschneidereit commented Jul 21, 2024

Not sure how I feel about the actual fix to the test here, order of magnitude for the memory requested is 1 and 10^2 is just 10 which feels better than 5 to me 😛.

Not sure why this M chip is using up one more megabyte but the tests pass on osx-arm64 now!

(fixes #66)

@elevans elevans self-assigned this Jul 22, 2024
Copy link
Member

@elevans elevans left a comment

Choose a reason for hiding this comment

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

Hi @jschneidereit. thanks for this PR. Overall I like the changes your suggest. My main critique that I have is that you added a new dependency for assertpy which I'm generally not in favor for. Can you implement your memory consumption relaxation without this new package?

Also please run the black code formatter to resolve the clean code failures.

@@ -28,11 +28,11 @@ dependencies:
- numpy
- pandas
# Developer tools
- assertpy
Copy link
Member

Choose a reason for hiding this comment

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

Do we need this package for this fix? I appreciate that it cleans up some of the test code for readability, however I would prefer to not add another dependency to scyjava.

Copy link
Member

Choose a reason for hiding this comment

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

@elevans If it were a transitive dependency for the main codebase I'd fully agree, but since it's only a developer dependency... I think I feel less strongly than you do about it. 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can I interest you in the power of readable test failure messages?

This is the original error message:

assert abs(mb_total - mb_initial) < 5, f"{mb_total=} {mb_initial=}"
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: mb_total=56 mb_initial=50

While this is th error message using assertpy:

AssertionError: [total mb should be close to initial] Expected <56> to be close to <50> within tolerance <5>, but was not.

The value becomes more clear when you write tests checking more complex things than number comparisons, take a scroll through their README to see if you recognize any patterns 😎

A more concrete example is near the end of test_arrays.py:

for i in range(len(nums_delta)):
    for j in range(len(nums_delta[i])):
        assert nums_delta[i][j] == pdoubles[i][j]

If you used assertpy you'd get a nice error message displaying both lists showing how they differ instead of just "false"

for i in range(len(nums_delta)):
    assert_that(nums_delta[i]).is_equal_to(pdoubles[i])

Copy link
Member

@elevans elevans Jul 23, 2024

Choose a reason for hiding this comment

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

Persuasion successful! Curtis is right and perhaps I was too against adding a new dependency. Since this would just be in the development config and not the main code base I have no problems here and in fact I think we could use assertpy in pyimagej and perhaps imglyb!

# Most of that memory should still be free; i.e.,
# we should not be using more than a few MB yet.
assert mb_used <= 5, f"{mb_used=}"
tolerance = pow(10, magnitude(mb_initial))
Copy link
Member

Choose a reason for hiding this comment

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

Add a comment about what tolerance does here.

Copy link
Member

Choose a reason for hiding this comment

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

This logic feels like overkill to me... I would have just changed the 5 to 10 and called it good 😆

Copy link
Contributor Author

Choose a reason for hiding this comment

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

😂 you're not wrong, somehow felt better than just "10" - I'll change it to that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll wait to add the comment on the above discussion, in test assertion frameworks they generally let you say how close two numbers should be to each other within some magnitude. This is that, but if y'all put the kibosh on assertpy then it would just be < 10 (which I would still rename to tolerance or delta or something as opposed to an inlined number)

Copy link
Member

Choose a reason for hiding this comment

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

We will keep assertpy but I also agree with @ctrueden that this does feel a bit much. I say just set the tolerance to <10.

Copy link
Member

@ctrueden ctrueden left a comment

Choose a reason for hiding this comment

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

I kinda like the elegance of the assert_that calls. I would personally suggest to leave off the magnitude reasoning though, in favor of just hardcoding the tolerance to 10.

@elevans I defer to you on both decisions to be made here:

  • Do we keep the new assertpy dev dependency, or stick with built-in Python asserts?
  • Do we keep the magnitude reasoning, or just set it to 10 (or 15 or whatever)?

@@ -28,11 +28,11 @@ dependencies:
- numpy
- pandas
# Developer tools
- assertpy
Copy link
Member

Choose a reason for hiding this comment

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

@elevans If it were a transitive dependency for the main codebase I'd fully agree, but since it's only a developer dependency... I think I feel less strongly than you do about it. 😅

# Most of that memory should still be free; i.e.,
# we should not be using more than a few MB yet.
assert mb_used <= 5, f"{mb_used=}"
tolerance = pow(10, magnitude(mb_initial))
Copy link
Member

Choose a reason for hiding this comment

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

This logic feels like overkill to me... I would have just changed the 5 to 10 and called it good 😆

@elevans
Copy link
Member

elevans commented Jul 23, 2024

Do we keep the new assertpy dev dependency, or stick with built-in Python asserts?

I agree that assertpy makes the tests and error outputs easier to read. The make or break for me was making sure we do not add more dependencies to main code base, which as you pointed out this would not. Thus I say we keep assertpy and perhaps apply it to pyimagej and imglyb down the road 🚀!

Do we keep the magnitude reasoning, or just set it to 10 (or 15 or whatever)?

I think the magnitude reasoning is more complicated than what we need it to be. I prefer that the desired tolerance is
just set. @jschneidereit Is there some good reasoning that I'm not thinking about about keeping the magnitude function?

@ctrueden ctrueden force-pushed the jschneidereit/66-fix-osx-arm64 branch from 433abae to 88769c4 Compare July 23, 2024 21:53
@ctrueden
Copy link
Member

I took the liberty of pushing commits fixing the linting errors and simplifying the tolerance logic.

ctrueden added 2 commits July 23, 2024 16:56
But still only three Pythons. Five Pythons is too many Pythons.
@ctrueden ctrueden force-pushed the jschneidereit/66-fix-osx-arm64 branch from 88769c4 to b414c55 Compare July 23, 2024 21:57
Copy link

codecov bot commented Jul 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 53.15%. Comparing base (4ef3781) to head (b414c55).
Report is 5 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #67   +/-   ##
=======================================
  Coverage   53.15%   53.15%           
=======================================
  Files          12       12           
  Lines        1285     1285           
=======================================
  Hits          683      683           
  Misses        602      602           

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

@ctrueden ctrueden merged commit bf5910e into scijava:main Jul 23, 2024
13 checks passed
@ctrueden
Copy link
Member

Thank you @jschneidereit for the very tidy contribution!

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.

Several issues running make test on osx-arm64 machine
3 participants