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

fix: unmark eval_pd as abstractmethod #4438

Merged
merged 2 commits into from
Nov 28, 2024
Merged

Conversation

njzjz
Copy link
Member

@njzjz njzjz commented Nov 27, 2024

Many classes don't have this method and become abstract classes. It looks to me like these tests are skipped silently and don't throw errors.

Summary by CodeRabbit

Summary by CodeRabbit

  • Bug Fixes

    • Updated the eval_pd method to provide a clearer indication of its implementation status by raising a NotImplementedError.
    • Changed the skip_pd class variable to always skip Paddle-related tests.
  • Tests

    • Adjusted the skip_pd property in the TestSeA and TestEner classes to directly reflect the installation status of Paddle.

Many classes don't have this method and become abstract classes. It looks to me these tests are skipped cilently and don't throw errors.

Signed-off-by: Jinzhe Zeng <[email protected]>

Choose a reason for hiding this comment

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

Copilot reviewed 1 out of 1 changed files in this pull request and generated no suggestions.

Copy link
Contributor

coderabbitai bot commented Nov 27, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

This pull request modifies the CommonTest class in source/tests/consistent/common.py by setting the skip_pd class variable to True, ensuring the Paddle model is always skipped. The eval_pd method is updated to provide a default implementation that raises a NotImplementedError, while the eval_array_api_strict method remains abstract. Additionally, the TestSeA and TestEner classes in their respective files adjust their skip_pd logic to reflect the new behavior of the CommonTest class.

Changes

File Path Change Summary
source/tests/consistent/common.py skip_pd set to True; eval_pd modified to raise NotImplementedError instead of being abstract.
source/tests/consistent/descriptor/test_se_e2_a.py skip_pd logic updated to return the value of INSTALLED_PD instead of CommonTest.skip_pd.
source/tests/consistent/fitting/test_ener.py skip_pd logic changed to check INSTALLED_PD or precision "bfloat16", removing dependency on CommonTest.skip_pd.

Possibly related PRs

  • fix(tests): fix skip_dp #4111: The changes in this PR involve modifying the skip_pd logic in the TestSeA class, which is directly related to the changes made to the skip_pd class variable in the CommonTest class in the main PR.

Suggested reviewers

  • iProzd
  • wanghan-iapcm

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 0fa2c6d and 8882652.

📒 Files selected for processing (3)
  • source/tests/consistent/common.py (2 hunks)
  • source/tests/consistent/descriptor/test_se_e2_a.py (1 hunks)
  • source/tests/consistent/fitting/test_ener.py (1 hunks)
🔇 Additional comments (4)
source/tests/consistent/descriptor/test_se_e2_a.py (1)

139-139: LGTM! The skip_pd property change aligns with the PR objectives.

The modification correctly simplifies the skipping logic to depend solely on Paddle installation status, which aligns with the goal of unmarking eval_pd as an abstract method.

Let's verify the consistency of this change with other test files:

source/tests/consistent/fitting/test_ener.py (1)

138-138: LGTM! The skip_pd property implementation aligns with PR objectives.

The new implementation correctly determines when to skip Paddle tests based on installation status and precision, removing the dependency on CommonTest.skip_pd while maintaining the same functional behavior.

Let's verify that this change maintains consistent test skipping behavior:

✅ Verification successful

The skip_pd implementation is consistent with other test files and follows the established pattern

The verification shows that:

  • The INSTALLED_PD flag is consistently used across test files to control Paddle-related test execution
  • Both test_ener.py and test_se_e2_a.py implement their own skip_pd logic based on their specific requirements
  • The change in test_ener.py maintains consistency with the codebase's pattern of using INSTALLED_PD for Paddle test control
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that test skipping behavior remains consistent
# Look for other test classes that might be affected by this change

# Search for classes that inherit from CommonTest and implement skip_pd
rg -l "class.*\(.*CommonTest.*\)" | xargs rg "skip_pd"

# Search for references to CommonTest.skip_pd to ensure we haven't missed any
rg "CommonTest\.skip_pd"

Length of output: 633


Script:

#!/bin/bash
# Let's analyze the implementation of skip_pd in other test files to ensure consistency

# Check the implementation in test_se_e2_a.py
echo "=== Implementation in test_se_e2_a.py ==="
rg -A 3 "skip_pd.*bool" source/tests/consistent/descriptor/test_se_e2_a.py

# Check the base implementation in common.py
echo -e "\n=== Base implementation in common.py ==="
rg -A 3 "skip_pd.*bool" source/tests/consistent/common.py

# Check if there are any other files with skip_pd property
echo -e "\n=== Other skip_pd implementations ==="
rg -A 3 "skip_pd.*bool" --type py

Length of output: 1612


Script:

#!/bin/bash
# Let's see the complete implementation of skip_pd in both test files to ensure they follow similar patterns

echo "=== Complete skip_pd implementation in test_ener.py ==="
rg -B 2 -A 5 "@property.*skip_pd" source/tests/consistent/fitting/test_ener.py

echo -e "\n=== Complete skip_pd implementation in test_se_e2_a.py ==="
rg -B 2 -A 5 "@property.*skip_pd" source/tests/consistent/descriptor/test_se_e2_a.py

# Check if INSTALLED_PD is used consistently
echo -e "\n=== INSTALLED_PD usage across files ==="
rg "INSTALLED_PD" --type py

Length of output: 2342

source/tests/consistent/common.py (2)

196-196: LGTM! Change aligns with PR objectives.

Removing the abstract requirement from eval_pd and providing a default implementation that raises NotImplementedError is a good solution. This allows classes to inherit without implementing eval_pd while still clearly indicating when the method is not supported.


104-104: LGTM, but note the test coverage impact.

Setting skip_pd = True aligns with the PR objective to prevent abstract class issues. However, be aware that this means Paddle tests will always be skipped regardless of installation status, which could reduce test coverage.

Let's check how many tests this might affect:

✅ Verification successful

Setting skip_pd=True will skip tests for 5 Paddle implementations

The change will affect test coverage for the following Paddle implementations:

  • EnergyModelPD (tested in both TestEner and TestEnerLower)
  • EnerFittingPD (tested in TestEner)
  • DescrptSeAPD (tested in TestSeA)
  • TypeEmbedNetPD (tested in TestTypeEmbedding)

However, this is an acceptable trade-off as it aligns with the PR's objective to prevent abstract class issues, and these tests would have been skipped anyway when Paddle is not installed.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Find test classes that might be affected by skipping Paddle tests
rg -l "class.*\(CommonTest" | xargs rg -l "pd_class.*=.*"

Length of output: 245


Script:

#!/bin/bash
# Let's check the actual test methods in these files that might be affected
for file in source/tests/consistent/model/test_ener.py source/tests/consistent/fitting/test_ener.py source/tests/consistent/descriptor/test_se_e2_a.py source/tests/consistent/test_type_embedding.py; do
    echo "=== $file ==="
    # Look for test methods that might use Paddle
    rg "def test.*" "$file" -A 5 | rg -B 5 "pd|paddle" -i
done

Length of output: 1649


Script:

#!/bin/bash
# Let's check the class definitions in these files to understand the Paddle test setup
for file in source/tests/consistent/model/test_ener.py source/tests/consistent/fitting/test_ener.py source/tests/consistent/descriptor/test_se_e2_a.py source/tests/consistent/test_type_embedding.py; do
    echo "=== $file ==="
    # Look for class definition and pd_class attribute
    rg "class.*CommonTest" -A 10 "$file"
done

Length of output: 3287


Script:

#!/bin/bash
# Let's check if these test classes define pd_class in their class body or inherit it
for file in source/tests/consistent/model/test_ener.py source/tests/consistent/fitting/test_ener.py source/tests/consistent/descriptor/test_se_e2_a.py source/tests/consistent/test_type_embedding.py; do
    echo "=== $file ==="
    # Get the entire file content to see pd_class definitions
    cat "$file" | rg -A 2 "pd_class|class.*CommonTest"
done

Length of output: 2666


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>, 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 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
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)
source/tests/consistent/common.py (1)

196-196: LGTM! Consider adding docstring clarification.

The change correctly implements the intended behavior by raising NotImplementedError instead of being marked as abstract. This allows classes to optionally implement the method while providing a clear error for unimplemented cases.

Consider adding a note in the docstring to clarify that this method raises NotImplementedError by default:

    def eval_pd(self, pd_obj: Any) -> Any:
        """Evaluate the return value of PD.

        Parameters
        ----------
        pd_obj : Any
            The object of PD
+
+       Raises
+       ------
+       NotImplementedError
+           This method is not implemented by default and must be overridden if PD backend support is needed.
        """
        raise NotImplementedError("Not implemented")
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 4a45fe5 and 0fa2c6d.

📒 Files selected for processing (1)
  • source/tests/consistent/common.py (1 hunks)

@njzjz
Copy link
Member Author

njzjz commented Nov 27, 2024

cc @HydrogenSulfate

Signed-off-by: Jinzhe Zeng <[email protected]>
Copy link

codecov bot commented Nov 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.23%. Comparing base (4a45fe5) to head (8882652).
Report is 4 commits behind head on devel.

Additional details and impacted files
@@            Coverage Diff             @@
##            devel    #4438      +/-   ##
==========================================
+ Coverage   83.27%   84.23%   +0.96%     
==========================================
  Files         667      667              
  Lines       61445    61445              
  Branches     3486     3488       +2     
==========================================
+ Hits        51166    51757     +591     
+ Misses       9152     8560     -592     
- Partials     1127     1128       +1     

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

@njzjz njzjz added this pull request to the merge queue Nov 28, 2024
Merged via the queue into deepmodeling:devel with commit a852aa9 Nov 28, 2024
60 checks passed
@njzjz njzjz deleted the fix-eval-pd branch November 28, 2024 07:41
@njzjz njzjz mentioned this pull request Nov 30, 2024
9 tasks
@coderabbitai coderabbitai bot mentioned this pull request Dec 1, 2024
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants