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

_mtp.py from_config() feature update #618

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

dsun980701
Copy link

@dsun980701 dsun980701 commented Apr 24, 2024

Summary

Major changes:

  • Feature 1: Added a default element ordering mechanism to the 'MTPotential.from_config()' method, based on the convention of Pauling electronegativity. Currently, when a trained MTP is loaded from a '.mtp' file using the 'MTPotential.from_config()' method, users must specify the elements in the correct order. However, there are no safeguards to ensure that the element order matches that of the trained MTP; inputting the elements in the wrong order renders the trained '.mtp' file irrelevant. The new feature automatically orders elements by their electronegativity, providing a relevant default ordering mechanism. Users can still specify their own order if desired.

Checklist

  • Google format doc strings added. Check with ruff.
  • Type annotations included. Check with mypy.
  • Tests added for new features/fixes.
  • If applicable, new classes/functions/modules have duecredit @due.dcite decorators to reference relevant papers by DOI (example)

Tip: Install pre-commit hooks to auto-check types and linting before every commit:

pip install -U pre-commit
pre-commit install

Summary by CodeRabbit

  • New Features

    • Introduced a configurable element ordering option in the MTPotential class based on Pauling electronegativity, enhancing consistency in molecular simulations.
  • Bug Fixes

    • Updated the get_sp_method function in the signal processing module to accept a more flexible range of callable types, improving its utility and compatibility.
  • Tests

    • Expanded test coverage for various configurations of the MTPotential class to ensure robustness and reliability.

Copy link

coderabbitai bot commented Apr 24, 2024

Walkthrough

The recent updates focus on improving element ordering control in MTPotential and enhancing flexibility in signal processing utilities. These changes aim to provide users with more options and improved functionality in these areas.

Changes

File Path Change Summary
maml/apps/pes/.../_mtp.py Added default_element_ordering to control element order based on electronegativity in MTPotential.
tests/apps/pes/.../test_mtp.py Extended tests for new configurations in MTPotential.
maml/utils/.../_signal_processing.py Updated get_sp_method to accept a Callable with any arguments, enhancing flexibility.

🐰✨
In the realm of code, where rabbits play,
Elements dance in a brand new way.
Flexibility blooms, signals now sing,
CodeRabbit's touch, a magical swing.
With a hop and a code, the world's a stage,
Where changes unfold, in a whimsical sage.
🌟🐾


Recent Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 5a68e0a and d8994c5.
Files selected for processing (1)
  • maml/utils/_signal_processing.py (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • maml/utils/_signal_processing.py

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: 7

Out of diff range and nitpick comments (9)
tests/apps/pes/test_mtp.py (9)

Line range hint 1-1: Add a module-level docstring to provide an overview of the module's purpose and functionality.


Line range hint 25-25: Add a docstring to the setUpClass method to explain its functionality, particularly how it sets up the test environment.


Line range hint 31-31: Add a docstring to the tearDownClass method to describe its role in cleaning up after tests are run.


Line range hint 35-35: Add a docstring to the setUp method to explain how it initializes the conditions for each test.


Line range hint 49-49: Add a docstring to the test_write_read_cfgs method to describe what this test verifies.


Line range hint 60-60: Replace assertAlmostEqual with a regular assert for consistency with other tests and to simplify the code.

- self.assertAlmostEqual(energy1, energy2)
+ assert energy1 == energy2

Line range hint 66-66: Add a docstring to the test_train method to explain what aspects of the train method it tests.


Line range hint 79-79: Add a docstring to the test_evaluate method to describe its purpose and the conditions under which it operates.


Line range hint 99-99: Add a docstring to the test_predict_efs method to explain what this test checks and how it uses the predict_efs method.

tests/apps/pes/test_mtp.py Show resolved Hide resolved
tests/apps/pes/test_mtp.py Show resolved Hide resolved
@@ -112,6 +113,10 @@
def test_from_config(self):
mtp = MTPotential.from_config(config_file, elements=["Mo"])
assert mtp.param is not None
mtp = MTPotential.from_config(config_file_4, elements=['Nb','O','Li','Cl'])
assert mtp.param is not None and mtp.elements == ['Li','Nb','Cl','O']
Copy link

Choose a reason for hiding this comment

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

Break down the assertion into multiple parts for clarity and to isolate which part of the assertion might fail.

- assert mtp.param is not None and mtp.elements == ['Li','Nb','Cl','O']
+ assert mtp.param is not None
+ assert mtp.elements == ['Li','Nb','Cl','O']

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
assert mtp.param is not None and mtp.elements == ['Li','Nb','Cl','O']
assert mtp.param is not None
assert mtp.elements == ['Li','Nb','Cl','O']

mtp = MTPotential.from_config(config_file_4, elements=['Nb','O','Li','Cl'])
assert mtp.param is not None and mtp.elements == ['Li','Nb','Cl','O']
mtp = MTPotential.from_config(config_file_4, elements=['Nb','O','Li','Cl'], default_element_ordering=False)
assert mtp.param is not None and mtp.elements == ['Nb','O','Li','Cl']
Copy link

Choose a reason for hiding this comment

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

Break down the assertion into multiple parts for clarity and to isolate which part of the assertion might fail.

- assert mtp.param is not None and mtp.elements == ['Nb','O','Li','Cl']
+ assert mtp.param is not None
+ assert mtp.elements == ['Nb','O','Li','Cl']

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
assert mtp.param is not None and mtp.elements == ['Nb','O','Li','Cl']
assert mtp.param is not None
assert mtp.elements == ['Nb','O','Li','Cl']

maml/apps/pes/_mtp.py Show resolved Hide resolved
maml/apps/pes/_mtp.py Outdated Show resolved Hide resolved
maml/apps/pes/_mtp.py Show resolved Hide resolved
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: 1

Out of diff range and nitpick comments (1)
tests/apps/pes/test_mtp.py (1)

20-20: Add a docstring to the config_file_4 declaration to explain its purpose and usage.

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: 1

maml/apps/pes/_mtp.py Outdated Show resolved Hide resolved
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: 1

Comment on lines 818 to 819
f"Order for the elements has been altered from {elements} to {ordered_elements} to ensure"
+ " consistency with default element ordering in maml during MTP fitting. Change the"
Copy link

Choose a reason for hiding this comment

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

Consider using implicit string concatenation for better readability.

-                    f"Order for the elements has been altered from {elements} to {ordered_elements} to ensure"
-                    + " consistency with default element ordering in maml during MTP fitting. Change the"
+                    f"Order for the elements has been altered from {elements} to {ordered_elements} to ensure consistency with default element ordering in maml during MTP fitting. Change the"

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
f"Order for the elements has been altered from {elements} to {ordered_elements} to ensure"
+ " consistency with default element ordering in maml during MTP fitting. Change the"
f"Order for the elements has been altered from {elements} to {ordered_elements} to ensure consistency with default element ordering in maml during MTP fitting. Change the"

@JiQi535
Copy link
Collaborator

JiQi535 commented Apr 24, 2024

Thanks for the PR David @dsun980701. Please try to make the linting tests pass, and then we can ask Shyue Ping for a review.

Signed-off-by: David <[email protected]>
@dsun980701
Copy link
Author

dsun980701 commented Apr 24, 2024

Thank you for reviewing @JiQi535. I have changed my code to address the linting issue. However, as of now, the linting is failing not from my changes, but from "maml/apps/symbolic/init." and "maml/utils/_signal_processing.py". Please let me know if there is anything that I can do about these issues!

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: 0

Out of diff range and nitpick comments (1)
maml/utils/_signal_processing.py (1)

Line range hint 3-12: Consider sorting and formatting the import statements to improve readability and maintainability.

@kenko911
Copy link
Contributor

Hi @dsun980701, can you please try to pull the latest changes from the main branch? I think I have fixed the united tests and now at least the pytest should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants