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: support array API #3922

Merged
merged 3 commits into from
Jun 28, 2024
Merged

feat: support array API #3922

merged 3 commits into from
Jun 28, 2024

Conversation

njzjz
Copy link
Member

@njzjz njzjz commented Jun 28, 2024

Fix #3430.
This PR sets up the basic support for the array API, and make an example function (compute_smooth_weight) to support the array API. I believe NumPy and JAX have supported it (or through array-api-compat), so we don't need to write things twice for NumPy and JAX (although we can write them using the ChatGPT, it's still better to maintain only one thing). There are some challeging to use it in the TorchScript, so I give it up. Supporting more function can be implemented in the following PRs.

Summary by CodeRabbit

  • New Features

    • Introduced testing for compute_smooth_weight function using array_api_strict for enhanced array operations.
  • Chores

    • Updated dependencies to include 'array-api-compat' and 'array-api-strict>=2' for improved compatibility and testing capabilities.

Fix deepmodeling#3430.
This PR sets up the basic support for the array API, and make an example function (`compute_smooth_weight`) to support the array API.
I believe NumPy and JAX have supported it (or through `array-api-compat`), so we don't need to write things twice for NumPy and JAX (although we can write them using the ChatGPT, it's still better to maintain only one thing). There are some challeging to use it in the TorchScript, so I give it up.
Supporting more function can be implemented in the following PRs.

Signed-off-by: Jinzhe Zeng <jinzhe.zeng@rutgers.edu>
Copy link
Contributor

coderabbitai bot commented Jun 28, 2024

Warning

Rate limit exceeded

@njzjz has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 23 minutes and 49 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between 40ad145 and c9616a0.

Walkthrough

The changes introduce array API compatibility within the codebase. This includes adding dependencies related to array API and a new test case to verify array operations using array-api-compat and array-api-strict.

Changes

Files Change Summaries
pyproject.toml Added 'array-api-compat' to the dependencies list and 'array-api-strict>=2' to the test list.
source/tests/common/dpmodel/array_api/test_env_mat.py Introduced a test case TestEnvMat for the compute_smooth_weight function using array API strict

Assessment against linked issues

Objective Addressed Explanation
Add array API-compatible methods (#3430)
Ensure code uses array API compatibility packages (array-api-compat)
Verify functionality through automated tests (#3430)

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.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @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.

@njzjz njzjz linked an issue Jun 28, 2024 that may be closed by this pull request
Copy link
Contributor

@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

Outside diff range and nitpick comments (1)
deepmd/dpmodel/utils/env_mat.py (1)

Line range hint 69-72: Consider simplifying conditional logic with a ternary operator.

- if radial_only:
-     env_mat = t0 * weight
- else:
-     env_mat = np.concatenate([t0, t1], axis=-1) * weight
+ env_mat = t0 * weight if radial_only else np.concatenate([t0, t1], axis=-1) * weight

This simplification reduces the lines of code and enhances readability by using a ternary operator instead of a full if-else block.

Signed-off-by: Jinzhe Zeng <jinzhe.zeng@rutgers.edu>
Copy link

codecov bot commented Jun 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.73%. Comparing base (949c3b8) to head (c9616a0).
Report is 114 commits behind head on devel.

Additional details and impacted files
@@           Coverage Diff           @@
##            devel    #3922   +/-   ##
=======================================
  Coverage   82.73%   82.73%           
=======================================
  Files         519      520    +1     
  Lines       50539    50549   +10     
  Branches     3015     3015           
=======================================
+ Hits        41812    41821    +9     
- Misses       7791     7792    +1     
  Partials      936      936           

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

@wanghan-iapcm wanghan-iapcm added this pull request to the merge queue Jun 28, 2024
Merged via the queue into deepmodeling:devel with commit 56c3e17 Jun 28, 2024
61 checks passed
mtaillefumier pushed a commit to mtaillefumier/deepmd-kit that referenced this pull request Sep 18, 2024
Fix deepmodeling#3430.
This PR sets up the basic support for the array API, and make an example
function (`compute_smooth_weight`) to support the array API. I believe
NumPy and JAX have supported it (or through `array-api-compat`), so we
don't need to write things twice for NumPy and JAX (although we can
write them using the ChatGPT, it's still better to maintain only one
thing). There are some challeging to use it in the TorchScript, so I
give it up. Supporting more function can be implemented in the following
PRs.

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

- **New Features**
- Introduced testing for `compute_smooth_weight` function using
`array_api_strict` for enhanced array operations.

- **Chores**
- Updated dependencies to include `'array-api-compat'` and
`'array-api-strict>=2'` for improved compatibility and testing
capabilities.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Jinzhe Zeng <jinzhe.zeng@rutgers.edu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request] Add array API-compatible methods
2 participants