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 test issues #660

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

Conversation

zz11ss11zz
Copy link
Contributor

Summary

Major changes:

  • feature 1: ...
  • fix 1: ...

Todos

If this is work in progress, what else needs to be done?

  • feature 2: ...
  • fix 2:

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

Signed-off-by: Zishen Wang <[email protected]>
Signed-off-by: Zishen Wang <[email protected]>
Signed-off-by: Zishen Wang <[email protected]>
Signed-off-by: Zishen Wang <[email protected]>
Signed-off-by: Zishen Wang <[email protected]>
Signed-off-by: Zishen Wang <[email protected]>
Signed-off-by: Zishen Wang <[email protected]>
Signed-off-by: Zishen Wang <[email protected]>
Signed-off-by: Zishen Wang <[email protected]>
Copy link

coderabbitai bot commented Sep 26, 2024

Warning

Rate limit exceeded

@zz11ss11zz has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 13 minutes and 55 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 df87393 and c10381d.

Walkthrough

The pull request introduces several modifications across multiple files. Key changes include updates to the lint.ignore list in pyproject.toml to expand the ignored linting rules, the addition of a new dependency mp-api==0.42.2 in requirements.txt, and the inclusion of type ignore comments in various functions across several Python files. These type ignore comments aim to suppress type-checking errors without altering the existing functionality of the code.

Changes

File Change Summary
pyproject.toml Updated lint.ignore list to include new entries: "D103", "D200", "D415", "E501", "E741", "RET504".
requirements.txt Added new dependency: mp-api==0.42.2.
src/maml/apps/bowsr/model/dft.py Added # type: ignore comment to the predict_energy method to suppress type checking for a specific line.
src/maml/apps/gbe/describer.py Added # type: ignore comments in get_structural_feature and get_elemental_feature functions to suppress type checking for specific lines.
src/maml/apps/gbe/utils.py Added # type: ignore comment in the get_b0 function to suppress type checking for a line retrieving a structure by material ID.
src/maml/data/_mp.py Added # type: ignore comment in the get method to suppress type checking for the line assigning the data variable.

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.

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

🧹 Outside diff range and nitpick comments (3)
src/maml/data/_mp.py (2)

Line range hint 24-32: Add Google format docstrings to the get method.

As per the PR objectives, Google format docstrings should be added. Please update the method's docstring to include more detailed information about the parameters and return value. Here's a suggested format:

def get(self, criteria: str | dict, properties: list[str]) -> pd.DataFrame:
    """
    Retrieve data from the Materials Project based on given criteria and properties.

    Args:
        criteria (Union[str, dict]): The search criteria for querying materials.
            Can be a string (e.g., material formula) or a dictionary of properties.
        properties (List[str]): A list of properties to retrieve for each material.

    Returns:
        pd.DataFrame: A pandas DataFrame containing the requested properties
            for materials matching the given criteria.

    Raises:
        TypeError: If the input types are incorrect.
        ConnectionError: If there's an issue connecting to the Materials Project API.
    """
    # Method implementation...

Also, consider adding a Examples section to the docstring to demonstrate how to use this method.


Line range hint 1-32: Summary of review and next steps

  1. The addition of # type: ignore comments contradicts the PR objective of using mypy for type checking. Consider addressing the underlying type issues instead of suppressing them.

  2. The method lacks Google format docstrings as required by the PR objectives. Add detailed docstrings to improve code documentation.

  3. The overall structure and functionality of the MaterialsProject class appear correct, but there's room for improvement in terms of type annotations and documentation.

Next steps:

  1. Run mypy on this file to identify specific type issues and address them properly.
  2. Add Google format docstrings to all methods in this class.
  3. Consider adding examples in the docstrings to demonstrate usage.
  4. If you haven't already, apply these improvements to other files changed in this PR as well.
src/maml/apps/gbe/describer.py (1)

Line range hint 1-477: Address PR objectives: Add Google format docstrings and type annotations

The current changes do not fully address the PR objectives. Please consider the following points:

  1. Google format docstrings: Add Google format docstrings to all functions and classes in this file. This will improve code documentation and readability.

  2. Type annotations: Instead of using # type: ignore comments, add proper type annotations throughout the file. This includes function parameters, return types, and variable annotations where necessary.

  3. Use ruff and mypy: Ensure that you've run ruff for linting and mypy for type checking on this file. Address any issues they raise, rather than suppressing them with # type: ignore.

Here's an example of how you might improve a function with Google format docstrings and type annotations:

from typing import List, Dict, Any

def get_structural_feature(db_entry: Dict[str, Any], features: List[Any] | None = None) -> pd.DataFrame:
    """
    Get the structural features from a database entry.

    Args:
        db_entry: A dictionary containing the database entry information.
        features: A list of features to extract. If None, default features will be used.

    Returns:
        A pandas DataFrame containing the extracted structural features.

    Raises:
        ValueError: If an invalid feature is requested.
    """
    # Function implementation...

Please apply similar improvements throughout the file to meet the PR objectives.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 252636c and df87393.

📒 Files selected for processing (6)
  • pyproject.toml (1 hunks)
  • requirements.txt (1 hunks)
  • src/maml/apps/bowsr/model/dft.py (1 hunks)
  • src/maml/apps/gbe/describer.py (2 hunks)
  • src/maml/apps/gbe/utils.py (1 hunks)
  • src/maml/data/_mp.py (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/maml/apps/bowsr/model/dft.py
🔇 Additional comments (6)
requirements.txt (1)

7-7: Verify the necessity and compatibility of the new dependency.

The addition of mp-api==0.42.2 to the requirements file introduces a new dependency to the project. While this package might be necessary for addressing test issues or implementing new features, there are a few points to consider:

  1. Relevance: Ensure that this package is directly related to fixing the test issues mentioned in the PR objectives or is essential for the project's functionality.

  2. Version compatibility: Verify that version 0.42.2 is compatible with the other packages in the project, especially pymatgen==2024.9.17.1, as both seem to be related to materials science.

  3. Minimal version specification: Consider if it's necessary to pin the exact version (==0.42.2) or if a more flexible version specification (e.g., >=0.42.2,<0.43) would be more appropriate to allow for minor updates and bug fixes.

  4. Documentation: Ensure that the reason for adding this dependency is documented, either in the code comments, PR description, or project documentation.

To help verify the necessity and impact of this new dependency, you can run the following commands:

These commands will help identify where mp-api is used in the project, check for any potential version conflicts, and list any packages that depend on mp-api.

src/maml/data/_mp.py (1)

30-30: ⚠️ Potential issue

Reconsider the use of # type: ignore comments.

The addition of # type: ignore comments, both on the method signature and the search method call, goes against the PR objective of checking type annotations with mypy. While these comments suppress type-checking warnings, they may hide potential issues in the code.

Instead of ignoring type checks, consider the following alternatives:

  1. Add proper type annotations to resolve the type-checking errors.
  2. If the MPRester.materials.search method is incorrectly typed in the library, consider creating a stub file or submitting a PR to the pymatgen library to fix the type annotations.
  3. If the type ignore is absolutely necessary, add a comment explaining why it's needed and consider using a more specific ignore comment (e.g., # type: ignore[attr-defined]) to target the specific issue.

To help identify the specific type issues, please run the following command and provide the output:

src/maml/apps/gbe/utils.py (2)

78-78: Investigate the need for type ignore comment

The addition of # type: ignore to the rester.get_structure_by_material_id() call suggests a type-related issue. While this comment bypasses the type checker, it's important to understand and address the underlying cause.

Could you provide more information about why this type ignore was necessary? Consider the following steps:

  1. Investigate the exact type error that was being raised.
  2. Check if the pymatgen library has proper type annotations for this method.
  3. If possible, add appropriate type annotations to resolve the issue without using # type: ignore.

This approach will help maintain type safety and improve code quality in the long run.

To help investigate this issue, you can run the following command to check for type errors in this file:

This will help identify any other type-related issues in the file and provide more context for the necessary fix.


Line range hint 1-89: Address PR objectives and improve overall code quality

To align with the PR objectives and enhance code quality, consider the following improvements:

  1. Add Google format docstrings:
    The PR objectives mention adding Google format docstrings. Please update all function docstrings to follow this format. For example, the load_data function could be updated as follows:

    def load_data(filename: str | None = None) -> list:
        """
        Helper function to load the data.
    
        Args:
            filename (str | None): The filename of the data. If None, loads the default 361 data.
    
        Returns:
            list: The loaded data.
    
        Raises:
            FileNotFoundError: If the specified file doesn't exist.
        """
  2. Complete type annotations:
    While some functions have type annotations, others are missing them. Please add type annotations to all functions and variables. For example:

    def load_b0_dict() -> dict[str, float]:
        """
        Helper function to retrieve the b0 data.
    
        Returns:
            dict[str, float]: A dictionary mapping elements to their b0 values.
    
        Raises:
            MPRestError: If no MAPI_KEY is found in the environment.
        """
  3. Improve error handling:
    Consider adding more specific error handling. For example, in the load_b0_dict function:

    if not os.getenv("MAPI_KEY"):
        raise ValueError("No MAPI_KEY found in environment variables")
  4. Code organization:
    Consider grouping related functions together and adding comments to separate different sections of the file.

  5. Add duecredit decorators:
    If any of these functions are based on academic papers, add duecredit decorators as mentioned in the PR objectives.

To verify the current state of docstrings and type annotations, you can run:

These commands will help identify areas that need improvement to meet the PR objectives.

pyproject.toml (2)

115-122: Changes align with PR objectives but require careful consideration.

The additions to the lint.ignore list are consistent with the PR objectives, particularly the mention of adding Google format docstrings and using ruff for verification. However, it's crucial to ensure that these changes don't compromise code quality in the long term.

Consider the following recommendations:

  1. Document the rationale for ignoring each rule in a comment within the pyproject.toml file.
  2. Set up a plan to gradually address and remove these ignore rules in future iterations, if possible.
  3. Ensure that the team is aware of these changes and understands the implications for code reviews and maintenance.

Also applies to: 129-129


115-122: Consider the implications of ignoring additional linting rules.

The following linting rules have been added to the ignore list:

  1. D103: Missing docstring in public function
  2. D200: One-line docstring should fit on one line with quotes
  3. D415: First line should end with a period, question mark, or exclamation point
  4. E501: Line too long
  5. E741: Do not use variables named 'l', 'O', or 'I'
  6. RET504: Unnecessary assignment before return statement

While ignoring these rules may simplify development in the short term, it could lead to reduced code documentation quality, potential readability issues, and slightly less efficient code.

To ensure this change aligns with the project's goals, please run the following script to check the prevalence of these issues in the codebase:

This script will help quantify the impact of ignoring these rules and inform whether this change is justified.

Also applies to: 129-129

@@ -206,7 +206,7 @@ def get_structural_feature(db_entry: dict, features: list | None = None) -> pd.D
if gb_plane.shape[0] == 4:
gb_plane = convert_hcp_plane(list(gb_plane))
rotation_axis = convert_hcp_direction(rotation_axis, lat_type=sg.get_crystal_system())
d_gb = bulk_conv.lattice.d_hkl(gb_plane)
d_gb = bulk_conv.lattice.d_hkl(gb_plane) # type: ignore
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Investigate and fix the type issue instead of using # type: ignore

The addition of # type: ignore suggests there's a type-related issue with bulk_conv.lattice.d_hkl(gb_plane). Instead of suppressing the type checker, it would be better to investigate and fix the underlying issue. This aligns with the PR objective of adding proper type annotations.

Consider the following steps:

  1. Check the return type of bulk_conv.lattice.d_hkl().
  2. Ensure that gb_plane is of the correct type expected by the method.
  3. Add appropriate type annotations to resolve the issue.

If you need assistance in resolving this, please provide more context about the d_hkl method and the expected types.

@@ -266,15 +266,15 @@
rester = MPRester(mp_api)
else:
raise MPRestError("Please provide API key to access Materials Project")
bulk = rester.materials.search(material_ids=[db_entry["material_id"]])[0]
bulk = rester.materials.search(material_ids=[db_entry["material_id"]])[0] # type: ignore
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add explicit type annotation instead of using # type: ignore

Rather than suppressing the type checker with # type: ignore, it would be more appropriate to add an explicit type annotation for the bulk variable. This approach aligns with the PR objective of adding proper type annotations.

Consider the following steps:

  1. Determine the expected return type of rester.materials.search().
  2. Add an explicit type annotation for the bulk variable.

For example, if the expected type is Material, you could write:

bulk: Material = rester.materials.search(material_ids=[db_entry["material_id"]])[0]

If you're unsure about the correct type, please consult the documentation for the MPRester class or the return type of the materials.search() method.

bulk_s = rester.get_structure_by_material_id(db_entry["material_id"]) # type: ignore
if bulk:
f_dict[preset.bdensity.str_name] = bulk[0]["density"]
f_dict[preset.G.str_name] = bulk[0]["elasticity"]["G_VRH"]
el = Element(db_entry["pretty_formula"])
f_dict[preset.ar.str_name] = el.atomic_radius
f_dict[preset.a0.str_name] = bulk_s.lattice.a
f_dict[preset.e_coh.str_name] = rester.get_cohesive_energy(db_entry["material_id"])
f_dict[preset.e_coh.str_name] = rester.get_cohesive_energy(db_entry["material_id"]) # type: ignore
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add explicit type annotation instead of using # type: ignore

Instead of using # type: ignore to suppress the type checker, it would be better to add an explicit type annotation for the return value of rester.get_cohesive_energy(). This approach is in line with the PR objective of adding proper type annotations.

Consider the following steps:

  1. Determine the expected return type of rester.get_cohesive_energy().
  2. Add an explicit type annotation for the return value.

For example, if the expected type is float, you could write:

cohesive_energy: float = rester.get_cohesive_energy(db_entry["material_id"])
f_dict[preset.e_coh.str_name] = cohesive_energy

If you're unsure about the correct return type, please consult the documentation for the MPRester class or the get_cohesive_energy() method.

Signed-off-by: Zishen Wang <[email protected]>
Signed-off-by: Zishen Wang <[email protected]>
Signed-off-by: Zishen Wang <[email protected]>
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.

1 participant