-
Notifications
You must be signed in to change notification settings - Fork 38
Classify all variables of a SimState as per-node, per-system, and global features #227
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
Conversation
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the ✨ Finishing Touches🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
HI @curtischong, this is something I thought about a fair amount and I am happy to revisit. I am not convinced I made the right decision to make everything implicit. I have a few thoughts here:
|
Thank you for your response Orion. The main reason why I'm doing this is because I'm trying to get type safety in torchsim. Having type safety can catch many bugs which is why it's important. If we do not explicitly define the attributes we cannot guarantee type safely. (e.g. when we call Like you said, by removing I agree that manually typing out the getters/setters is ugly as it covers many lines. I'll research to see if I can make it simpler. But having getters/setters does have more benefits:
I agree with the |
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.
Generally, I am a big fan of typing and would support implementing ty
for static type analysis. Runtime type checking, however, will add both code complexity and (a tiny bit) of computational cost.
Even if we decided that was worth it (maybe it is), I am not sure consolidating the variables into three attributes is the best approach. It makes it a bit less readable and removes the assurance that all necessary attributes are defined. It would also make the autocomplete engines less reliable at inferring what attributes are valid. We could instead:
- leave all the attributes as is, no need for getters
- run a method in the post_init that adds setters for every attribute that check for shape and type.
I agree. The three variable thing isn't very nice. I think your suggestion works. _atom_features: tuple[str] = ("positions", "masses", "atomic_numbers")
_system_features: tuple[str] = ("cell", "system_idx")
_global_features: tuple[str] = ("pbc") |
closing in favor of #228 |
Summary
This PR makes handling SimStates much simpler. Rather than guessing if an attribute is per-node/system/global, we just know. My solution is to use a dictionary to store ALL of a State's attributes:
For ease of access to these "standard" properties, I've added custom getters/setters for these properties:
Checklist
Before a pull request can be merged, the following items must be checked:
Run ruff on your code.
We highly recommended installing the pre-commit hooks running in CI locally to speedup the development process. Simply run
pip install pre-commit && pre-commit install
to install the hooks which will check your code before each commit.