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

feat(pt): support complete form energy loss #3782

Merged
merged 3 commits into from
May 16, 2024

Conversation

iProzd
Copy link
Collaborator

@iProzd iProzd commented May 14, 2024

Support atomic energy, atomic prefactor force, generalized force, relative_f, enable_atom_ener_coeff for EnergyStdLoss.
Support atomic energy, enable_atom_ener_coeff for EnergySpinLoss.

virial support for EnergySpinLoss needs discussion and another PR.

Summary by CodeRabbit

  • New Features

    • Introduced new parameters for enhanced energy loss computation, including relative_f, enable_atom_ener_coeff, and numb_generalized_coord.
    • Improved handling of atomic energy loss with the addition of pref_ae calculation.
  • Bug Fixes

    • Refined conditional logic for energy computation to ensure accurate handling of new parameters.
  • Tests

    • Expanded test coverage with new classes and methods to validate the new features and ensure consistency.

Copy link

coderabbitai bot commented May 14, 2024

Walkthrough

The update enhances the energy loss computation in the deepmd library by introducing new parameters and attributes for improved functionality. These changes impact ener.py and ener_spin.py, enabling support for relative forces, atomic energy coefficients, and generalized coordinates. The test suite has been expanded to validate these enhancements thoroughly.

Changes

File Change Summary
deepmd/pt/loss/ener.py Added new parameters and attributes for relative forces, atomic energy coefficients, and generalized coordinates. Enhanced class logic accordingly.
deepmd/pt/loss/ener_spin.py Introduced atomic energy coefficient handling and updated energy computation logic in the forward method. Removed outdated parameters.
source/tests/pt/test_loss.py Renamed existing test class, added new test classes, and methods to validate the new features and parameters.

Possibly related issues


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

Out of diff range and nitpick comments (1)
source/tests/pt/test_loss.py (1)

Line range hint 132-197: The TensorFlow placeholder initialization can be extracted into a separate method to improve readability and maintainability.

# tf
self.g = tf.Graph()
with self.g.as_default():
    t_cur_lr, t_natoms, t_penergy, t_pforce, t_pvirial, t_patom_energy, t_lenergy, t_lforce, t_lvirial, t_latom_energy, t_atom_pref, t_atom_ener_coeff, t_drdq, find_energy, find_force, find_virial, find_atom_energy, find_atom_pref, find_drdq, find_atom_ener_coeff = self._initialize_tf_placeholders()
    model_dict = {
        "energy": t_penergy,
        "force": t_pforce,
        "virial": t_pvirial,
        "atom_ener": t_patom_energy,
    }
    label_dict = {
        "energy": t_lenergy,
        "force": t_lforce,
        "virial": t_lvirial,
        "atom_ener": t_latom_energy,
        "atom_pref": t_atom_pref,
        "drdq": t_drdq,
        "atom_ener_coeff": t_atom_ener_coeff,
        "find_energy": find_energy,
        "find_force": find_force,
        "find_virial": find_virial,
        "find_atom_ener": find_atom_energy,
        "find_atom_pref": find_atom_pref,
        "find_drdq": find_drdq,
        "find_atom_ener_coeff": find_atom_ener_coeff,
    }
    self.tf_loss_sess = self.tf_loss.build(
        t_cur_lr, t_natoms, model_dict, label_dict, ""
    )

source/tests/pt/test_loss.py Show resolved Hide resolved
source/tests/pt/test_loss.py Show resolved Hide resolved
source/tests/pt/test_loss.py Outdated Show resolved Hide resolved
source/tests/pt/test_loss.py Show resolved Hide resolved
source/tests/pt/test_loss.py Fixed Show fixed Hide fixed
source/tests/pt/test_loss.py Fixed Show fixed Hide fixed
source/tests/pt/test_loss.py Fixed Show fixed Hide fixed
source/tests/pt/test_loss.py Fixed Show fixed Hide fixed
source/tests/pt/test_loss.py Fixed Show fixed Hide fixed
source/tests/pt/test_loss.py Fixed Show fixed Hide fixed
source/tests/pt/test_loss.py Fixed Show fixed Hide fixed
source/tests/pt/test_loss.py Fixed Show fixed Hide fixed
source/tests/pt/test_loss.py Fixed Show fixed Hide fixed
source/tests/pt/test_loss.py Fixed Show fixed Hide fixed
Copy link

codecov bot commented May 14, 2024

Codecov Report

Attention: Patch coverage is 90.67797% with 11 lines in your changes are missing coverage. Please review.

Project coverage is 82.59%. Comparing base (2bf0769) to head (f4a3559).

Files Patch % Lines
deepmd/pt/loss/ener.py 90.10% 9 Missing ⚠️
deepmd/pt/loss/ener_spin.py 92.59% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            devel    #3782      +/-   ##
==========================================
+ Coverage   82.49%   82.59%   +0.09%     
==========================================
  Files         515      515              
  Lines       48642    48726      +84     
  Branches     2980     2979       -1     
==========================================
+ Hits        40126    40243     +117     
+ Misses       7605     7572      -33     
  Partials      911      911              

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

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

source/tests/pt/test_loss.py Show resolved Hide resolved
source/tests/pt/test_loss.py Show resolved Hide resolved
source/tests/pt/test_loss.py Show resolved Hide resolved
source/tests/pt/test_loss.py Show resolved Hide resolved
source/tests/pt/test_loss.py Show resolved Hide resolved
@wanghan-iapcm wanghan-iapcm added this pull request to the merge queue May 16, 2024
Merged via the queue into deepmodeling:devel with commit a676bf2 May 16, 2024
60 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants