-
Notifications
You must be signed in to change notification settings - Fork 70
NPTLangevinState inherits from MDState #299
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
Merged
CompRhys
merged 6 commits into
TorchSim:main
from
hholb:hholb/npt-langevin-state-to-mdstate
Oct 20, 2025
Merged
NPTLangevinState inherits from MDState #299
CompRhys
merged 6 commits into
TorchSim:main
from
hholb:hholb/npt-langevin-state-to-mdstate
Oct 20, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
When inheriting from MDState (which ultimately inherits from SimState with a field that has a default value), Python's dataclass mechanism requires all fields without defaults to come before fields with defaults. Using kw_only=True resolves this ordering constraint while maintaining backward compatibility since all existing instantiations already use keyword arguments.
NPTLangevinState now follows the same pattern as MDState (its parent class): - Store momenta as a field - Compute velocities as a property (inherited from MDState) This makes NPTLangevinState consistent with other MD integrator states and properly leverages the MDState inheritance hierarchy. Changes: - Remove velocities field from NPTLangevinState dataclass - Remove custom momenta property (now inherited from MDState) - Update all step functions to work with momenta: - Convert momenta to velocities where needed: momenta / masses.unsqueeze(-1) - Convert velocities back to momenta for updates: velocities * masses.unsqueeze(-1) - Update noise generation to match momenta shape - Update npt_langevin_init to pass momenta instead of velocities - Update test fixture to use momenta field
CompRhys
reviewed
Oct 20, 2025
CompRhys
reviewed
Oct 20, 2025
CompRhys
reviewed
Oct 20, 2025
CompRhys
requested changes
Oct 20, 2025
Member
CompRhys
left a comment
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.
Thanks for the fixes! A few nit comments that should be fixed before merging.
Contributor
Author
|
Thanks for the review! Tweaks made! |
CompRhys
reviewed
Oct 20, 2025
Signed-off-by: Rhys Goodall <rhys.goodall@outlook.com>
CompRhys
approved these changes
Oct 20, 2025
Member
CompRhys
left a comment
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.
lgtm
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Resolves: #291
This updates the
NPTLangevinStateto inherit fromMDStateinstead ofSimState. Updated the state calculations to use momenta instead of velocities to match other MD integrators.Checklist
Before a pull request can be merged, the following items must be checked:
We highly recommended installing the
prekhooks running in CI locally to speedup the development process. Simply runpip install prek && prek installto install the hooks which will check your code before each commit.