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

chore: ban module-level import of pymatgen #1597

Merged
merged 1 commit into from
Jul 19, 2024

Conversation

njzjz
Copy link
Member

@njzjz njzjz commented Jul 18, 2024

Pymatgen is still imcompatbile with NumPy 2. Move the import into runtime to fix the documentation builds and prevent potential errors when one uses dpgen without using pymatgen.

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

Summary by CodeRabbit

  • Chores
    • Reorganized import statements across multiple files to improve code readability and maintainability.
    • Localized imports within specific methods for better encapsulation and efficient module loading.
    • Updated linting configurations in pyproject.toml to include new rules and per-file exceptions.

Pymatgen is still imcompatbile with NumPy 2. Move the import into runtime to fix the documentation builds and prevent potential errors when one uses dpgen without using pymatgen.

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

coderabbitai bot commented Jul 18, 2024

Walkthrough

Walkthrough

The updates primarily involved restructuring import statements to improve code readability and maintainability. Imports were moved from the global scope to within specific methods or functions, localizing dependencies where they are used. This change impacts various files related to elasticity calculations, VASP input/output handling, crystal structure generation, and defect generation. The codebase now ensures more modular and efficient import management.

Changes

File Path Change Summary
dpgen/auto_test/Elastic.py Reorganized imports within methods for elasticity calculations and VASP handling.
dpgen/auto_test/Gamma.py Moved imports to within make_confs and __gen_slab_ase, added path existence check in make_confs.
dpgen/auto_test/Interstitial.py Localized imports within make_confs method.
dpgen/auto_test/Surface.py Moved imports into make_confs method.
dpgen/auto_test/VASP.py Localized imports within make_potential_files and make_input_file methods.
dpgen/auto_test/Vacancy.py Localized imports within make_confs method.
dpgen/auto_test/gen_confs.py Localized imports within test_fit, gen_element, and gen_alloy functions.
dpgen/auto_test/lib/abacus.py Removed unused import, localized import within stru2Structure function.
dpgen/auto_test/lib/crys.py Localized imports within various functions for creating crystal structures.
dpgen/auto_test/lib/vasp.py Localized imports within make_vasp_kpoints_from_incar function.
dpgen/auto_test/mpdb.py Localized imports within check_apikey function.
dpgen/data/gen.py Localized imports within various functions for generating supercells and VASP input files.
dpgen/data/surf.py Localized imports within poscar_elong and make_super_cell_pymatgen functions.
dpgen/database/entry.py Localized import within __init__ method of Entry class.
dpgen/database/vasp.py Localized imports within methods related to VASP input files handling.
dpgen/generator/lib/ele_temp.py Localized imports within _get_incar_ele_temp and _get_incar_nbands methods.
dpgen/generator/lib/vasp.py Localized import within incar_upper function.
dpgen/generator/run.py Localized imports within make_vasp_incar_ele_temp and make_fp_vasp_kp functions.
pyproject.toml Updated linting configurations, added banned module-level import for pymatgen, and extended per-file ignores for rule TID253.

Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8f78294 and 8c541b7.

Files selected for processing (19)
  • dpgen/auto_test/Elastic.py (4 hunks)
  • dpgen/auto_test/Gamma.py (3 hunks)
  • dpgen/auto_test/Interstitial.py (2 hunks)
  • dpgen/auto_test/Surface.py (2 hunks)
  • dpgen/auto_test/VASP.py (3 hunks)
  • dpgen/auto_test/Vacancy.py (2 hunks)
  • dpgen/auto_test/gen_confs.py (4 hunks)
  • dpgen/auto_test/lib/abacus.py (2 hunks)
  • dpgen/auto_test/lib/crys.py (5 hunks)
  • dpgen/auto_test/lib/vasp.py (2 hunks)
  • dpgen/auto_test/mpdb.py (1 hunks)
  • dpgen/data/gen.py (4 hunks)
  • dpgen/data/surf.py (4 hunks)
  • dpgen/database/entry.py (2 hunks)
  • dpgen/database/vasp.py (4 hunks)
  • dpgen/generator/lib/ele_temp.py (2 hunks)
  • dpgen/generator/lib/vasp.py (2 hunks)
  • dpgen/generator/run.py (3 hunks)
  • pyproject.toml (2 hunks)
Files skipped from review due to trivial changes (1)
  • dpgen/auto_test/lib/abacus.py
Additional comments not posted (41)
dpgen/auto_test/mpdb.py (1)

9-10: LGTM! Import localized within the function.

The import of MPRester and MPRestError within the function scope improves module loading efficiency and avoids unnecessary imports when the function is not called.

dpgen/auto_test/lib/crys.py (7)

5-6: LGTM! Import localized within the function.

The import of Structure within the function scope improves module loading efficiency and avoids unnecessary imports when the function is not called.


13-15: LGTM! Imports localized within the function.

The imports of Lattice and Structure within the function scope improve module loading efficiency and avoid unnecessary imports when the function is not called.


25-27: LGTM! Imports localized within the function.

The imports of Lattice and Structure within the function scope improve module loading efficiency and avoid unnecessary imports when the function is not called.


33-35: LGTM! Imports localized within the function.

The imports of Lattice and Structure within the function scope improve module loading efficiency and avoid unnecessary imports when the function is not called.


50-52: LGTM! Imports localized within the function.

The imports of Lattice and Structure within the function scope improve module loading efficiency and avoid unnecessary imports when the function is not called.


66-68: LGTM! Imports localized within the function.

The imports of Lattice and Structure within the function scope improve module loading efficiency and avoid unnecessary imports when the function is not called.


87-89: LGTM! Imports localized within the function.

The imports of Lattice and Structure within the function scope improve module loading efficiency and avoid unnecessary imports when the function is not called.

dpgen/generator/lib/ele_temp.py (2)

88-89: LGTM! Import localized within the method.

The import of Incar within the method scope improves module loading efficiency and avoids unnecessary imports when the method is not called.


95-96: LGTM! Import localized within the method.

The import of Incar within the method scope improves module loading efficiency and avoids unnecessary imports when the method is not called.

dpgen/generator/lib/vasp.py (1)

133-134: LGTM! Import localized within the function.

The import of Incar within the function scope improves module loading efficiency and avoids unnecessary imports when the function is not called.

dpgen/database/entry.py (1)

54-55: Good practice: Localized import.

Moving the import of Composition to within the __init__ method ensures that pymatgen is only imported when an instance of Entry is created. This can help avoid unnecessary imports and potential import errors if pymatgen is not installed.

pyproject.toml (3)

92-92: Good practice: Enforcing linting rules.

Adding the linting rule TID253 to the select list ensures that module-level imports of banned modules are flagged by the linter, promoting better import practices.


116-119: Good practice: Banning module-level imports.

Adding pymatgen to the banned-module-level-imports list ensures that module-level imports of pymatgen are flagged, aligning with the PR objective to move such imports to runtime.


121-122: Good practice: Extending per-file ignores.

Adding the rule TID253 to the per-file ignores for files under tests/ ensures that test files are not flagged for module-level imports, which might be necessary for testing purposes.

dpgen/auto_test/gen_confs.py (3)

20-21: Good practice: Localized import.

Moving the import of StructureMatcher to within the test_fit function ensures that pymatgen is only imported when the function is called. This can help avoid unnecessary imports if the function is not used.


52-54: Good practice: Localized imports.

Moving the imports of StructureMatcher and MPRester to within the gen_element function ensures that pymatgen is only imported when the function is called. This can help avoid unnecessary imports if the function is not used.


98-99: Good practice: Localized import.

Moving the import of MPRester to within the gen_alloy function ensures that pymatgen is only imported when the function is called. This can help avoid unnecessary imports if the function is not used.

dpgen/database/vasp.py (3)

20-21: Good practice: Localized imports.

Moving the imports of Potcar and PotcarSingle to within the __init__ method ensures that pymatgen is only imported when an instance of DPPotcar is created. This can help avoid unnecessary imports if the class is not used.


83-84: Good practice: Localized import.

Moving the import of Potcar to within the from_file method ensures that pymatgen is only imported when the method is called. This can help avoid unnecessary imports if the method is not used.


183-184: Good practice: Localized imports.

Moving the imports of Incar, Kpoints, and Poscar to within the from_directory method ensures that pymatgen is only imported when the method is called. This can help avoid unnecessary imports if the method is not used.

dpgen/auto_test/VASP.py (2)

23-24: LGTM! Localized import for Structure.

The import of Structure has been moved to within the method, which is a good practice for optimizing imports.


72-73: LGTM! Localized imports for Incar and Kpoints.

The imports of Incar and Kpoints have been moved to within the method, which is a good practice for optimizing imports.

dpgen/auto_test/Vacancy.py (1)

78-80: LGTM! Localized imports for VacancyGenerator and Structure.

The imports of VacancyGenerator and Structure have been moved to within the method, which is a good practice for optimizing imports.

dpgen/auto_test/Elastic.py (3)

51-53: LGTM! Localized imports for DeformedStructureSet, Strain, and Structure.

The imports of DeformedStructureSet, Strain, and Structure have been moved to within the method, which is a good practice for optimizing imports.


190-191: LGTM! Localized imports for Incar and Kpoints.

The imports of Incar and Kpoints have been moved to within the method, which is a good practice for optimizing imports.


253-255: LGTM! Localized imports for ElasticTensor and Stress.

The imports of ElasticTensor and Stress have been moved to within the method, which is a good practice for optimizing imports.

dpgen/auto_test/Surface.py (1)

86-88: LGTM! Localized imports for Structure and generate_all_slabs.

The imports of Structure and generate_all_slabs have been moved to within the method, which is a good practice for optimizing imports.

dpgen/auto_test/lib/vasp.py (1)

505-506: LGTM! Imports moved inside the function.

The import statements for Incar and Kpoints were moved inside the make_vasp_kpoints_from_incar function to avoid module-level imports of pymatgen. This change ensures that the import is only done when necessary.

dpgen/auto_test/Gamma.py (2)

95-96: LGTM! Import moved inside the method.

The import statement for Structure was moved inside the make_confs method to avoid module-level imports of pymatgen. This change ensures that the import is only done when necessary.


290-291: LGTM! Import moved inside the method.

The import statement for AseAtomsAdaptor was moved inside the __gen_slab_ase method to avoid module-level imports of pymatgen. This change ensures that the import is only done when necessary.

dpgen/data/surf.py (3)

166-167: LGTM! Import moved inside the function.

The import statement for Structure was moved inside the poscar_elong function to avoid module-level imports of pymatgen. This change ensures that the import is only done when necessary.


215-217: LGTM! Imports moved inside the function.

The import statements for Element, Structure, and AseAtomsAdaptor were moved inside the make_super_cell_pymatgen function to avoid module-level imports of pymatgen. This change ensures that the imports are only done when necessary.


404-405: LGTM! Import moved inside the function.

The import statement for Poscar was moved inside the poscar_scale function to avoid module-level imports of pymatgen. This change ensures that the import is only done when necessary.

dpgen/auto_test/Interstitial.py (1)

79-81: LGTM! Imports moved inside the method.

The import statements for InterstitialGenerator and Structure were moved inside the make_confs method to avoid module-level imports of pymatgen. This change ensures that the imports are only done when necessary.

dpgen/data/gen.py (4)

301-302: LGTM! Import moved to runtime.

The import of Structure from pymatgen.core has been moved to runtime, which is appropriate to avoid module-level import issues.


345-346: LGTM! Import moved to runtime.

The import of Structure from pymatgen.core has been moved to runtime, which is appropriate to avoid module-level import issues.


1449-1450: LGTM! Import moved to runtime.

The import of Incar from pymatgen.io.vasp has been moved to runtime, which is appropriate to avoid module-level import issues.


1449-1450: LGTM! Import moved to runtime.

The import of Incar from pymatgen.io.vasp has been moved to runtime, which is appropriate to avoid module-level import issues.

dpgen/generator/run.py (2)

3080-3081: LGTM!

The import statement for Incar is correctly moved to within the function to avoid unnecessary module-level imports.


3159-3160: LGTM!

The import statements for Incar and Kpoints are correctly moved to within the function to avoid unnecessary module-level imports.


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

codecov bot commented Jul 18, 2024

Codecov Report

Attention: Patch coverage is 54.90196% with 23 lines in your changes missing coverage. Please review.

Project coverage is 49.51%. Comparing base (a33e270) to head (8c541b7).
Report is 25 commits behind head on devel.

Files with missing lines Patch % Lines
dpgen/auto_test/lib/crys.py 0.00% 13 Missing ⚠️
dpgen/auto_test/gen_confs.py 0.00% 4 Missing ⚠️
dpgen/auto_test/Elastic.py 60.00% 2 Missing ⚠️
dpgen/data/gen.py 33.33% 2 Missing ⚠️
dpgen/auto_test/lib/vasp.py 0.00% 1 Missing ⚠️
dpgen/auto_test/mpdb.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            devel    #1597      +/-   ##
==========================================
- Coverage   49.59%   49.51%   -0.08%     
==========================================
  Files          83       83              
  Lines       14851    14870      +19     
==========================================
- Hits         7365     7363       -2     
- Misses       7486     7507      +21     

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

@wanghan-iapcm wanghan-iapcm merged commit 3a1ed00 into deepmodeling:devel Jul 19, 2024
7 checks passed
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.

2 participants