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

Fix NoJump transformation error when applied outside the first frame … #4918

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from

Conversation

TejasNangru
Copy link

@TejasNangru TejasNangru commented Feb 18, 2025

Fixes #4915

This PR fixes issue #4915, where the NoJump transformation failed with an unintuitive TypeError when applied outside the first frame.
Changes made in this Pull Request:

  1. Added an explicit ValueError when NoJump is applied outside the first frame.
  2. Improved warning messages for better readability.
  3. Ensured the fix is minimal while maintaining the original logic and comments.

PR Checklist

  • Issue raised/referenced?
  • Tests updated/added?
  • Documentation updated/added?
  • package/CHANGELOG file updated?
  • Is your name in package/AUTHORS? (If it is not, add it!)

Developers Certificate of Origin

I certify that I can submit this code contribution as described in the Developer Certificate of Origin, under the MDAnalysis LICENSE.


📚 Documentation preview 📚: https://mdanalysis--4918.org.readthedocs.build/en/4918/

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Hello there first time contributor! Welcome to the MDAnalysis community! We ask that all contributors abide by our Code of Conduct and that first time contributors introduce themselves on GitHub Discussions so we can get to know you. You can learn more about participating here. Please also add yourself to package/AUTHORS as part of this PR.

@TejasNangru
Copy link
Author

@orbeckst @IAlibay please review my PR.

@orbeckst
Copy link
Member

@TejasNangru thank you for your PR. Developers will review but please aware that this may take some time because everybody is quite busy and nobody gets paid to review.

The first thing you should make sure is that the tests all pass, i.e., there should be no failing checks. If you have specific questions then please ask.

@TejasNangru
Copy link
Author

As of now, I dont have any specific question.
I understand that everyone is busy, please review it as per your convenience.

@RMeli
Copy link
Member

RMeli commented Feb 18, 2025

please review it as per your convenience

Before a proper review, the tests need to pass. They likely need to be modified, since you changed the warning.

See here, for example.

@TejasNangru
Copy link
Author

@orbeckst @RMeli i have changed the expected warning message in tests

@TejasNangru
Copy link
Author

I don't know why still some of tests are failing.
Please help

Copy link
Member

@IAlibay IAlibay left a comment

Choose a reason for hiding this comment

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

Here's an initial review to hopefully help with the PR process.

@TejasNangru
Copy link
Author

Thanks sir for the review, I will do the required changes.

@TejasNangru
Copy link
Author

@IAlibay Please re-review it.
Thanks.

@@ -322,8 +322,8 @@ def test_nojump_constantvel_stride_2(nojump_universes_fromfile):
"""
Test if the nojump transform warning is emitted.
"""
match = "Currently jumping between frames with a step of more than 1."
with pytest.warns(UserWarning, match=match):
match = "NoJump transformation must be applied from the first frame onward."
Copy link
Member

Choose a reason for hiding this comment

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

please don't overwrite the existing test, keep the old test and add a new one that tests specifically the error being raised

match = "Currently jumping between frames with a step of more than 1."
with pytest.warns(UserWarning, match=match):
match = "NoJump transformation must be applied from the first frame onward."
with pytest.raises(ValueError, match=match):
u = nojump_universes_fromfile
for ts in u.trajectory[::2]: # Exercises the warning.
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't trigger the ValueError because it starts from 0 and skips by 2. Please write a separate test for the ValueError failure

Copy link
Author

@TejasNangru TejasNangru Feb 19, 2025

Choose a reason for hiding this comment

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

def test_nojump_raises_valueerror_outside_first_frame(nojump_universes_fromfile):
    """
    Test if NoJump transformation raises ValueError when applied outside the first frame.
    """
    match = "NoJump transformation must be applied from the first frame onward."
    with pytest.raises(ValueError, match=match):
        u = nojump_universes_fromfile
        u.trajectory[-1]  # Move to the last frame
        u.trajectory.add_transformations(NoJump())  # Add NoJump transformation
        next(u.trajectory)  # Trigger the transformation by iterating

Sir, It works fine? @IAlibay

@IAlibay
Copy link
Member

IAlibay commented Feb 19, 2025

I unfortunately don't have time to do more reviews, hopefully this is enough to get you on the path towards a merge. Can anyone from @MDAnalysis/coredevs take over here?

@TejasNangru
Copy link
Author

TejasNangru commented Feb 19, 2025

@orbeckst @RMeli Please review it and tell me if i have to make some more modifications to my PR.

@RMeli
Copy link
Member

RMeli commented Feb 19, 2025

Please review it and tell me if i have to make some more modifications to my PR.

As you can see, tests are still failing (which automatically implies the PR needs indeed more modifications). Please have a look at the test failures.

Feel free to ask specific questions should you need to.

@TejasNangru
Copy link
Author

TejasNangru commented Feb 19, 2025

As you can see, tests are still failing (which automatically implies the PR needs indeed more modifications). Please have a look at the test failures.

It's my first time working with Github tests, can you please explain briefly what i have to do for each test which fails?
and after all tests passes, will we be good to go for merging pr?

Copy link

codecov bot commented Feb 19, 2025

Codecov Report

Attention: Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.

Project coverage is 93.63%. Comparing base (b79c77d) to head (291ddc9).
Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
package/MDAnalysis/transformations/nojump.py 0.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4918      +/-   ##
===========================================
- Coverage    93.66%   93.63%   -0.04%     
===========================================
  Files          177      189      +12     
  Lines        21850    22918    +1068     
  Branches      3079     3080       +1     
===========================================
+ Hits         20466    21459     +993     
- Misses         933     1007      +74     
- Partials       451      452       +1     

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

@TejasNangru
Copy link
Author

@RMeli @orbeckst I was on 6 successful tests earlier, now I did some changes and on 21 successful tests,
Still I have 3 failing tests, 1 of this 3 tests, is related to 'black' formatting which i corrected here locally,
so i am left with only 2 failing tests, codecov/patch and codecov/project. I need some guidance on these two.
Thanks

@orbeckst
Copy link
Member

Please push your latest changes.

The codecov patch test failure with 0% coverage is a bit odd, I'll have a look.

Copy link
Member

@orbeckst orbeckst left a comment

Choose a reason for hiding this comment

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

Codecov shows 0% coverage because your test does not test your code. Look at the original issue and write code that triggers the problem that you're catching with your code in nojump.py.

@@ -328,6 +328,17 @@ def test_nojump_constantvel_stride_2(nojump_universes_fromfile):
for ts in u.trajectory[::2]: # Exercises the warning.
pass

def test_nojump_raises_valueerror_outside_first_frame(nojump_universes_fromfile):
Copy link
Member

Choose a reason for hiding this comment

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

Good that you wrote a separate test. However, this test does not trigger the failure that you're testing for and that's why code coverage is 0%.

You have to write code here that generates the failure case.

You also must match the error message for the failure ("NoJump transformation must be applied from the first frame onward.").

Copy link
Member

Choose a reason for hiding this comment

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

@TejasNangru this test you wrote was nearly correct, but you should use the nojump_universe fixture rather than nojump_universes_fromfile . nojump_universes_fromfile is already applying the transformation, so an error is raised when you try to apply the transformation again in your test


# Ensure NoJump is applied from the first frame onwards
if ts.frame > 0 and self.prev is None:
raise ValueError(
Copy link
Member

Choose a reason for hiding this comment

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

From the codecov comment below you can see that the raise ValueError is never triggered by the tests. Thus, you have to improve your test.

@orbeckst orbeckst self-assigned this Feb 19, 2025
@TejasNangru
Copy link
Author

@orbeckst @RMeli The 'black' formatting test has passed, but still I am facing problems in two codecoverage tests.
I tried to write the test code for ValueError but it still fails, Please provide me the code for ValueError

@TejasNangru
Copy link
Author

@p-j-smith I did changes you told, but still codecov is getting failed.

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.

NoJump transformation fails in a non intuitive way when applied outside of the first frame
5 participants