-
Notifications
You must be signed in to change notification settings - Fork 584
fix(ase): aviod duplicate stress calculation for ase calculator #4633
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
📝 WalkthroughWalkthroughThe PR modifies the Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant DP as DP.calculate
Client->>DP: Call calculate(properties)
alt cell is provided
DP->>DP: Compute stress (using virial & volume)
DP-->>Client: Return stress result
else
alt "stress" in properties
DP-->>Client: Raise PropertyNotImplementedError
else
DP-->>Client: No action
end
end
Possibly related PRs
Suggested labels
Suggested reviewers
✨ Finishing Touches
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:
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 (
|
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
deepmd/calculator.py (1)
141-150: Control flow improvement avoids duplicate stress calculationThe restructured logic now first checks for the presence of the
cellvariable before considering whether to calculate stress. This is a good optimization as it:
- Prevents unnecessary condition checking when
cellis available- Properly handles the case where stress calculation is requested but not possible
- Maintains the same functionality while making the code more efficient
Minor suggestion: Consider adding a brief comment explaining why stress calculation is only possible with a valid cell (i.e., when periodic boundary conditions are applied). This would make the logic clearer for future developers.
if cell is not None: # the usual convention (tensile stress is positive) # stress = -virial / volume + # stress calculation requires periodic boundary conditions (valid cell) stress = -0.5 * (v[0].copy() + v[0].copy().T) / atoms.get_volume() # Voigt notation self.results["stress"] = stress.flat[[0, 4, 8, 5, 2, 1]]
njzjz
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.
I don't get the point of this PR... Why is stress calculated when it is not in properties? And what is the relationship between the title and the change?
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## devel #4633 +/- ##
=======================================
Coverage 84.78% 84.78%
=======================================
Files 688 688
Lines 66089 66088 -1
Branches 3540 3540
=======================================
+ Hits 56032 56033 +1
+ Misses 8916 8914 -2
Partials 1141 1141 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
@njzjz It's may be some tricky point in ase calling. during one-step calculation, the calculator will magically be called twice, even if you explictly add 'stress' keyword in So I guess the ase will first call calculator with This PR fixes this and meets the efficiency test. |
|
The behavior is related to this piece of code:
|
So it's better to store all properties in results, anyway. |
…modeling#4633) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Refactor** - Revised the logic behind stress evaluation to ensure results are produced reliably when complete input is provided, and error notifications are triggered appropriately when essential data is missing. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
…modeling#4633) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Refactor** - Revised the logic behind stress evaluation to ensure results are produced reliably when complete input is provided, and error notifications are triggered appropriately when essential data is missing. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
…modeling#4633) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Refactor** - Revised the logic behind stress evaluation to ensure results are produced reliably when complete input is provided, and error notifications are triggered appropriately when essential data is missing. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
…modeling#4633) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Refactor** - Revised the logic behind stress evaluation to ensure results are produced reliably when complete input is provided, and error notifications are triggered appropriately when essential data is missing. <!-- end of auto-generated comment: release notes by coderabbit.ai --> (cherry picked from commit 5aa7a8f)
…modeling#4633) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Refactor** - Revised the logic behind stress evaluation to ensure results are produced reliably when complete input is provided, and error notifications are triggered appropriately when essential data is missing. <!-- end of auto-generated comment: release notes by coderabbit.ai --> (cherry picked from commit 5aa7a8f)
Summary by CodeRabbit