Skip to content

Conversation

@njzjz
Copy link
Member

@njzjz njzjz commented Mar 20, 2025

Summary by CodeRabbit

  • Chores
    • Updated developer tooling configurations to use a newer linting hook version.
  • Refactor
    • Streamlined structure processing so that magnetic data is included only when defined, resulting in cleaner output.
    • Optimized coordinate adjustments with vectorized operations for improved performance.
  • Tests
    • Cleaned up test data by removing redundant magnetic moment fields from atomic position entries.

njzjz and others added 7 commits February 20, 2025 23:50
<!--pre-commit.ci start-->
updates:
- [github.com/astral-sh/ruff-pre-commit: v0.9.6 →
v0.9.7](astral-sh/ruff-pre-commit@v0.9.6...v0.9.7)
<!--pre-commit.ci end-->

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
<!--pre-commit.ci start-->
updates:
- [github.com/astral-sh/ruff-pre-commit: v0.9.7 →
v0.9.9](astral-sh/ruff-pre-commit@v0.9.7...v0.9.9)
<!--pre-commit.ci end-->

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
…ed (deepmodeling#800)

The old version will induce a bug that dpdata will always store the spin
information, and when dpdata save it to lammps format, the spin
information will also be written, which is invalid for a non-spin lammps
job.
Now, the spin information is saved to dpdata only when the magnetic
moment of one atom is specified, which is necessary for a spin job.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Spin data is now processed to include only explicitly defined moments,
ensuring accurate output.
- **Documentation**
- User-facing documentation has been updated to clarify when spin
information appears.
- **Tests**
- Test entries for atomic positions have been streamlined by removing
redundant markers.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: root <pxlxingliang>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
<!--pre-commit.ci start-->
updates:
- [github.com/astral-sh/ruff-pre-commit: v0.9.9 →
v0.9.10](astral-sh/ruff-pre-commit@v0.9.9...v0.9.10)
<!--pre-commit.ci end-->

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Hi,

I think this part of the code was attempting to modify local variables
(`ii`) rather than the actual array elements in `self.data["coords"]`.

Before:
```
@post_funcs.register("shift_orig_zero")
    def _shift_orig_zero(self):
        for ff in self.data["coords"]:
             for ii in ff:
                 ii = ii - self.data["orig"]
                 ...
```
After:
```
...
self.data["coords"] = self.data["coords"] - self.data["orig"]
```

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Refactor**
- Enhanced the efficiency of coordinate adjustments for improved
performance on larger datasets.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Signed-off-by: .Del <10773382+zrzrv5@users.noreply.github.com>
<!--pre-commit.ci start-->
updates:
- [github.com/astral-sh/ruff-pre-commit: v0.9.10 →
v0.11.0](astral-sh/ruff-pre-commit@v0.9.10...v0.11.0)
<!--pre-commit.ci end-->

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
@njzjz njzjz requested review from pxlxingliang and removed request for pxlxingliang March 20, 2025 03:23
@codspeed-hq
Copy link

codspeed-hq bot commented Mar 20, 2025

CodSpeed Performance Report

Merging #808 will not alter performance

Comparing njzjz:master-0.2.24 (a96b305) with master (35a0af0)

Summary

✅ 2 untouched benchmarks

@coderabbitai
Copy link

coderabbitai bot commented Mar 20, 2025

📝 Walkthrough

Walkthrough

This update modifies several aspects of the codebase. The Ruff pre-commit hook version in the configuration file is bumped from v0.9.6 to v0.11.0. In the abacus structure file, a boolean flag is introduced in the parse_pos function to conditionally handle atomic magnetic moments, and the output of get_frame_from_stru is adjusted accordingly. The system file now uses a vectorized NumPy operation in _shift_orig_zero instead of nested loops. Additionally, the test file is updated to remove redundant magnetic moment data from atomic position entries.

Changes

Files Change Summary
.pre-commit-config.yaml Updated Ruff pre-commit hook version from v0.9.6 to v0.11.0.
dpdata/abacus/stru.py, tests/abacus.scf/stru_test In stru.py, introduced define_atom_mag to conditionally populate magnetic moment data and modified the inclusion of the spins key; corresponding test entries have the "mag" keyword removed.
dpdata/system.py Refactored the _shift_orig_zero method to use a vectorized NumPy subtraction instead of iterating over coordinates with nested loops.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant parse_pos
    participant get_frame_from_stru

    Caller->>parse_pos: Call parse_pos with atomic positions
    parse_pos->>parse_pos: Initialize define_atom_mag = False
    parse_pos->>parse_pos: Iterate over positions to check for non-None imagmom
    alt Magnetic moment found
        parse_pos->>parse_pos: Set define_atom_mag = True and populate mags
    else No magnetic moments
        parse_pos->>parse_pos: Leave mags empty
    end
    parse_pos-->>Caller: Return parsed positions and mags
    Caller->>get_frame_from_stru: Request frame construction
    get_frame_from_stru->>get_frame_from_stru: Include 'spins' key only if mags is not empty
    get_frame_from_stru-->>Caller: Return frame data
Loading

Possibly related PRs

✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ 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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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

🧹 Nitpick comments (2)
dpdata/system.py (1)

713-713: Optimization: Replaced loops with vectorized operation

Great optimization! Using NumPy's vectorized operations to subtract the origin from coordinates is much more efficient than using nested loops, which was likely the previous implementation.

The remaining operations like setting self.data["orig"] and the assertion check are kept intact, ensuring the method's functionality is preserved while improving performance.

dpdata/abacus/stru.py (1)

417-421: Conditional handling of magnetic moment data

This change improves the function by only returning magnetic moment data when it's explicitly defined in the input, avoiding empty or default values when not needed.

Minor style improvement opportunity:

-    # here return the magnetic moment only when the atom magnetic moment is specified.
-    if not define_atom_mag:
-        mags = []
-    else:
-        mags = np.array(mags)
+    # here return the magnetic moment only when the atom magnetic moment is specified.
+    mags = [] if not define_atom_mag else np.array(mags)
🧰 Tools
🪛 Ruff (0.8.2)

417-420: Use ternary operator mags = [] if not define_atom_mag else np.array(mags) instead of if-else-block

Replace if-else-block with mags = [] if not define_atom_mag else np.array(mags)

(SIM108)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 35a0af0 and a96b305.

📒 Files selected for processing (4)
  • .pre-commit-config.yaml (1 hunks)
  • dpdata/abacus/stru.py (5 hunks)
  • dpdata/system.py (1 hunks)
  • tests/abacus.scf/stru_test (1 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
dpdata/abacus/stru.py

417-420: Use ternary operator mags = [] if not define_atom_mag else np.array(mags) instead of if-else-block

Replace if-else-block with mags = [] if not define_atom_mag else np.array(mags)

(SIM108)

🔇 Additional comments (5)
.pre-commit-config.yaml (1)

24-24: Ruff pre-commit hook version updated to v0.11.0

Upgrading the Ruff linter from v0.9.6 to v0.11.0 ensures the project benefits from the latest linting improvements and bug fixes.

dpdata/abacus/stru.py (3)

365-365: Good addition: Flag to track magnetic moment definitions

Adding the define_atom_mag flag is a good approach to track whether any magnetic moments are defined during parsing.


394-396: Improved logic for tracking defined magnetic moments

This code properly updates the flag when actual magnetic moments are defined in the input, rather than just assuming defaults.


449-456: Improved documentation for spins behavior

The documentation for the spins return value is much clearer now, explaining that it's only returned when magnetic moments are explicitly defined in the STRU file. This helps users understand when to expect this data in the output.

tests/abacus.scf/stru_test (1)

25-32: Removed redundant magnetic moment data from test file

This change aligns the test data with the code changes in stru.py by removing the unnecessary magnetic moment definitions (mag 0.000000000000 0.000000000000 0.000000000000). This is consistent with the new approach of only including magnetic moment data when it's actually defined with non-default values.

@njzjz njzjz merged commit 08aefba into deepmodeling:master Mar 20, 2025
21 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Jun 4, 2025
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