Skip to content

Conversation

amruthesht
Copy link

@amruthesht amruthesht commented Feb 19, 2025

Fixes #4827

This draft PR addresses the feature request discussed in #4827.

Note:
The IMDReader feature which was previously a part of the imdclient package has been moved into MDAnalysis below. Any other modules have been in retained in imdclient, which has been added as an optional dependency here. We are currently in the process of splitting the imdclient package as mentioned above. (Issue, PR)

Major changes made in this Pull Request:

  • IMDReader, other associated base classes and a utility function were added to coordinates in the main package.
  • Appropriate test cases for the reader were added as a part of test-imd.py
  • Other corresponding changes were made to CI and environment *.yaml files
  • imdclient was added as an optional dependency

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--4923.org.readthedocs.build/en/4923/

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.

Copy link

codecov bot commented Feb 19, 2025

Codecov Report

❌ Patch coverage is 67.05202% with 57 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.89%. Comparing base (5d48c5c) to head (cd21d6b).

Files with missing lines Patch % Lines
package/MDAnalysis/coordinates/IMD.py 48.83% 43 Missing and 1 partial ⚠️
package/MDAnalysis/coordinates/base.py 84.88% 8 Missing and 5 partials ⚠️

❗ There is a different number of reports uploaded between BASE (5d48c5c) and HEAD (cd21d6b). Click for more details.

HEAD has 3 uploads less than BASE
Flag BASE (5d48c5c) HEAD (cd21d6b)
6 3
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4923      +/-   ##
===========================================
- Coverage    93.86%   85.89%   -7.98%     
===========================================
  Files          179      180       +1     
  Lines        22249    22422     +173     
  Branches      3161     3186      +25     
===========================================
- Hits         20885    19260    -1625     
- Misses         902     2704    +1802     
+ Partials       462      458       -4     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@amruthesht
Copy link
Author

Your thoughts on this are appreciated - @orbeckst

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.

Thanks for the initial PR.

  • The first big step is to get the tests running properly so that the CI uses an imdclient without IMDReader. Otherwise we are not sure we're testing the code here.
  • Minor initial comments while I skimmed.
  • Simple thing: run black over all files to get the formatting and ordering of imports right

@orbeckst orbeckst marked this pull request as draft February 19, 2025 23:48
@orbeckst
Copy link
Member

I set the PR to Work in progress for the time being, just to indicate that we're not yet at the stage where the CI is working. Once the tests run properly, we can update the status.

Obviously, this shouldn't discourage anyone from contributing and commenting.

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.

A first quick look

Copy link
Contributor

@jaclark5 jaclark5 left a comment

Choose a reason for hiding this comment

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

I read through and nothing jumped out at me that wasn't already mentioned, except that I didn't see these changes in the documentation that was linked. The following needs to be added:

Add doc/sphinx/source/documentation_pages/coordinates/IMD.rst
.. automodule:: MDAnalysis.coordinates.IMD

doc/sphinx/source/documentation_pages/coordinate_modules.rst
coordinates/IMD

doc/sphinx/source/documentation_pages/references.rst
If you use IMD capability...

Copy link
Member

@hmacdope hmacdope left a comment

Choose a reason for hiding this comment

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

Sorry for the delay, had a lookover, I will try and push some changes addressing some of these myself also, but would be good to pick up the momentum here again if possible.

@hmacdope
Copy link
Member

@amruthesht do we have a plan for pushing ahead with suggested changes?

@amruthesht
Copy link
Author

@amruthesht do we have a plan for pushing ahead with suggested changes?

Working on the imdclient repository right now. I had a few small issues there with using the IMDReader, but getting them fixed soon.
And then I'll wrap up some small changes on the mdanalysis end and we should be good to go!

amruthesht and others added 2 commits April 9, 2025 17:12
1. Moved `parse_host_port` to `IMD.py` and deleted `util.py`
2. Cleaned up `test_imd.py` - changes to `assert_*` functions and simplified non-applicable test to pass automatically
@hmacdope
Copy link
Member

hmacdope commented May 5, 2025

@amruthesht kicking CI here.

@hmacdope
Copy link
Member

hmacdope commented May 5, 2025

@yuxuanzhuang would you be able to have a run through?

@hmacdope hmacdope requested a review from yuxuanzhuang May 5, 2025 15:12
@yuxuanzhuang
Copy link
Contributor

I will have another look at the PR this week. One immediate thing is to add documentation.

Please refer to the comments below.

I read through and nothing jumped out at me that wasn't already mentioned, except that I didn't see these changes in the documentation that was linked. The following needs to be added:

Add doc/sphinx/source/documentation_pages/coordinates/IMD.rst .. automodule:: MDAnalysis.coordinates.IMD

doc/sphinx/source/documentation_pages/coordinate_modules.rst coordinates/IMD

doc/sphinx/source/documentation_pages/references.rst If you use IMD capability...

@hmacdope
Copy link
Member

hmacdope commented May 5, 2025

Need to figure out tests also @amruthesht

@jaclark5 jaclark5 self-requested a review May 24, 2025 23:52
@amruthesht amruthesht requested a review from orbeckst August 13, 2025 05:15
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.

Good work, only one remaining test!

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.

Need to clean up the test_imd.py::test_IMDCLIENT_import test.

)


class IMDModuleStateManager:
Copy link
Member

Choose a reason for hiding this comment

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

There may well be a neater way to do this using mock/monkeypatch without a custom class.

However, this one is now working locally where the other approach failed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, my friend ChatGPT proposed to use monkeypatch, but I didn't manage to make it work (seems like you have a better friend :)

Copy link
Member

Choose a reason for hiding this comment

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

I used cursor where I can choose my friends. Also, I first had to convince it that using subprocess was too ugly...

Copy link
Author

Choose a reason for hiding this comment

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

I implemented a simpler approach using monkeypatch without using IMDModuleStateManager custom class, with some help from a freind :)
@orbeckst, @yuxuanzhuang - Please have a look when you can, thank you. If it doesn't seem good, please feel free to revert the commit

- testing imports of IMD/imdclient module is now isolated from other tests
- testing different versions of imdclient and IMD.HAS_IMDCLIENT is now done in separate tests
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.

Coverage is now good and all new functionality seems to be covered.

All tests are passing.

Great work @amruthesht , @ljwoods2 and everyone else!

🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉

@orbeckst
Copy link
Member

@yuxuanzhuang @IAlibay could you please check if your comments have been addressed and if that's the case, approve the PR?

@orbeckst
Copy link
Member

@hmacdope @jaclark5 do you have any remaining questions or are you happy to move forward with merging the functionality?

(I assume that @jpkrowe would also be happy if he could use the develop branch directly in his GSOC streaming project).

Copy link
Contributor

@yuxuanzhuang yuxuanzhuang left a comment

Choose a reason for hiding this comment

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

lgtm! great work everyone!!!

Copy link
Member

@hmacdope hmacdope left a comment

Choose a reason for hiding this comment

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

LGTM! Well done everyone (particularly @amruthesht and @ljwoods2)

Copy link
Contributor

@jaclark5 jaclark5 left a comment

Choose a reason for hiding this comment

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

Looks great! I have a couple comments you likely have quick answers for

else:
return False

def close(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

Above it says: \

  • No independent copies: Cannot create separate reader instances for the same stream

Does that mean that if the IMDReader is not closed gracefully with this function that it will stay active and prevent another connection to the stream? I ask because this can be an issue with Jupyter notebooks where people are in the habit of restarting the kernel which will not close the IMDReader gracefully.

This is an active issue I have with python interfacing with postgres

Copy link
Author

@amruthesht amruthesht Aug 28, 2025

Choose a reason for hiding this comment

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

Yes, the socket connection would saty active unless terminated properly.

The IMDReader does have automatic cleanup - it inherits a del method from ReaderBase that calls close(), which in turn calls self._imdclient.stop() to properly shut down the connection.
Jupyter kernel restarts are the exception. it is safer to use a try/excpet block when using a Jupyter notebook.

Side Note: But technically it is possible to form multiple conenctions to the same port address. This is however limited by the host. Currently only NAMD supports this. But each connection has its seperate socket and stream of data which would need to be processed sperately by each client object seperately. The distinction is that these data streams may not always necessarily have the same data, depending on how the host has been configured. So, one can't make an independent copy on the same stream of data but can open a new connection while an existing connection is present (at least in NAMD).

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 note to the docs on best practices for using IMDReader in notebooks.

Regarding connecting multiple streams to one MD engine port, mention that the behavior is MD engine implementation dependent (some may allow it, others may fail).

Copy link
Author

@amruthesht amruthesht Sep 2, 2025

Choose a reason for hiding this comment

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

@orbeckst, @jaclark5 - Done. Please resolve it if you think the documentaion is good enough

@amruthesht amruthesht requested a review from IAlibay August 28, 2025 18:04
1. API doc on multiple connections
2. Jupyter usage of `close()` for secure closure of connections
Replace `IMDModuleStateManager` with standard pytest patterns
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adopt a reader for live-streamed Interactive MD (IMD) version 3 trajectories
7 participants