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

Chloe lee doper #264

Closed
wants to merge 6 commits into from
Closed

Chloe lee doper #264

wants to merge 6 commits into from

Conversation

JiwooChloeLee
Copy link
Contributor

@JiwooChloeLee JiwooChloeLee commented Jun 12, 2024

Pull Request Template

Description

Now "Doper" class stores all possible dopants, and returns top n candidates as a return of "get_dopants" method. This is to use all candidates in plotting the periodic table heatmap with "plot_dopants" method.

Fixes # (issue)

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Test A
  • Test B

Test Configuration:

  • Python version: 3.9.7
  • Operating System: Mac OS

Reviewers

@mention individuals who you specifically want to involve in the discussion for this pull request and mention why they are needed in the discussion/why they are needed to review the pull request.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • I have checked my code and corrected any misspellings

Summary by CodeRabbit

  • Documentation

    • Updated documentation to include the "tabulate" module.
  • New Features

    • Included JSON files from the species_rep directory in the package.
  • Bug Fixes

    • Fixed NameError in the Jupyter notebook doper_example.ipynb.
    • Updated the default colour scheme for the heatmap plot.
  • Refactor

    • Refactored get_dopants function to return a modified dictionary with top results.
    • Adjusted colour mapping in the plot_dopants function.
  • Tests

    • Modified result handling in DopantPredictionTest.
  • Chores

    • Updated dependency specification for numpy to require a version less than 2.
    • Updated Python version information in the notebook to 3.9.7.

…ss to store all possible dopants and use all candidates for plotting.
Copy link
Contributor

coderabbitai bot commented Jun 12, 2024

Walkthrough

The updates encompass several areas: adding the "tabulate" module to the configuration for documentation, updating the packaging to include a new data directory and refining the dependency for numpy, refactoring functions and color mappings in the dopant prediction logic, modifying tests to align with the updated structure, and fixing errors and adjusting visuals in a Jupyter notebook example. These changes enhance functionality, maintainability, and clarity across the project.

Changes

Files Change Summary
docs/conf.py Added the "tabulate" module to the list of imported modules.
setup.py Included the species_rep directory in data files and updated numpy dependency to "numpy<2".
smact/dopant_prediction/doper.py Refactored get_dopants function to return a modified dictionary with top results and adjusted the color mapping in plot_dopants. Removed code for selecting top elements from dopants_lists.
smact/tests/test_doper.py Modified test_dopant_prediction method to align with new get_dopants function. Adjusted imports accordingly.
examples/Dopant_Prediction/doper_example.ipynb Updated color scheme in heatmap plot, fixed NameError for quaternary, and changed Python version information from 3.9.16 to 3.9.7.

Poem

🐰 In the land of code so bright,

There's a tale of change taking flight. 🍃

tabulate joins the doc's display,

While numpy now has a stricter say. 📏

Dopants dancing in colour new,

Tests align in a merry queue.

Cheers to progress, we hop with might! 🌟


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.

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

Outside diff range and nitpick comments (4)
setup.py (3)

Line range hint 14-14: Remove unused import: unittest.

- import unittest

Line range hint 16-16: Remove unused import: setuptools.Extension.

- from setuptools import Extension

Line range hint 25-25: Use a context manager for opening files to ensure proper resource management.

- long_description=open(os.path.join(module_dir, "README.md")).read(),
+ with open(os.path.join(module, "README.md"), "r") as f:
+     long_description=f.read(),
smact/dopant_prediction/doper.py (1)

Line range hint 316-316: Rename unused loop control variable dopant_type to _dopant_type to indicate it is intentionally unused.

- for dopant_type, dopants in self.results.items():
+ for _dopant_type, dopants in self.results.items():
Tools
Ruff

3-3: typing.Type imported but unused (F401)

Remove unused import: typing.Type

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 579e67c and 57c1c70.

Files selected for processing (4)
  • docs/conf.py (1 hunks)
  • setup.py (1 hunks)
  • smact/dopant_prediction/doper.py (13 hunks)
  • smact/tests/test_doper.py (2 hunks)
Files not summarized due to errors (2)
  • smact/tests/test_doper.py: Error: Server error. Please try again later.
  • smact/dopant_prediction/doper.py: Error: Server error. Please try again later.
Files skipped from review due to trivial changes (1)
  • docs/conf.py
Additional context used
Ruff
setup.py

14-14: unittest imported but unused (F401)

Remove unused import: unittest


16-16: setuptools.Extension imported but unused (F401)

Remove unused import: setuptools.Extension


25-25: Use context handler for opening files (SIM115)

smact/tests/test_doper.py

4-4: smact imported but unused (F401)

Remove unused import: smact


6-6: smact.structure_prediction.mutation imported but unused (F401)

Remove unused import: smact.structure_prediction.mutation


14-14: Local variable num_dopants is assigned to but never used (F841)

Remove assignment to unused variable num_dopants

smact/dopant_prediction/doper.py

3-3: typing.Type imported but unused (F401)

Remove unused import: typing.Type


316-316: Loop control variable dopant_type not used within loop body (B007)

Rename unused dopant_type to _dopant_type

Additional comments not posted (1)
setup.py (1)

46-46: Addition of new data directory for JSON files.

This inclusion will ensure that the new JSON files are packaged with the software, enhancing the functionality related to species representation.


class dopant_prediction_test(unittest.TestCase):

class DopantPredictionTest(unittest.TestCase):
def test_dopant_prediction(self):
num_dopants = 10
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove assignment to unused variable num_dopants.

- num_dopants = 10
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
num_dopants = 10
Tools
Ruff

14-14: Local variable num_dopants is assigned to but never used (F841)

Remove assignment to unused variable num_dopants

@@ -1,11 +1,15 @@
import os
import unittest

import smact
from smact.dopant_prediction import doper
from smact.structure_prediction import mutation, utilities
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove unused import: smact.structure_prediction.mutation.

- from smact.structure_prediction import mutation

Committable suggestion was skipped due to low confidence.

Tools
Ruff

6-6: smact.structure_prediction.mutation imported but unused (F401)

Remove unused import: smact.structure_prediction.mutation

@@ -1,11 +1,15 @@
import os
import unittest

import smact
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove unused import: smact.

- import smact
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import smact
Tools
Ruff

4-4: smact imported but unused (F401)

Remove unused import: smact

from itertools import groupby
from typing import Callable, List, Tuple, Type, Union
from typing import List, Optional, Tuple, Type
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove unused import: typing.Type.

- from typing import List, Optional, Tuple, Type
+ from typing import List, Optional, Tuple
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
from typing import List, Optional, Tuple, Type
from typing import List, Optional, Tuple
Tools
Ruff

3-3: typing.Type imported but unused (F401)

Remove unused import: typing.Type

@AntObi AntObi changed the base branch from master to develop June 18, 2024 11:58
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: 2

Outside diff range and nitpick comments (1)
smact/dopant_prediction/doper.py (1)

Line range hint 319-319: Rename unused loop control variable dopant_type to _dopant_type.

- for dopant_type, dopants in self.results.items():
+ for _dopant_type, dopants in self.results.items():
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 57c1c70 and db901d2.

Files selected for processing (2)
  • smact/dopant_prediction/doper.py (4 hunks)
  • smact/tests/test_doper.py (3 hunks)
Additional context used
Ruff
smact/tests/test_doper.py

26-26: Local variable dopants is assigned to but never used (F841)

Remove assignment to unused variable dopants


61-61: Local variable dopants is assigned to but never used (F841)

Remove assignment to unused variable dopants

smact/dopant_prediction/doper.py

319-319: Loop control variable dopant_type not used within loop body (B007)

Rename unused dopant_type to _dopant_type

Additional comments not posted (3)
smact/tests/test_doper.py (1)

1-1: The test method test_format_number is correctly implemented and covers its intended functionality.

smact/dopant_prediction/doper.py (2)

302-305: The refactored get_dopants method correctly returns the top results as intended.


1-1: The _format_number method is correctly implemented and handles number formatting as expected.

@@ -59,7 +58,8 @@ def test_dopant_prediction_skipspecies(self):
test = doper.Doper(
test_specie, embedding="skipspecies", use_probability=False
)
result = test.get_dopants()
dopants = test.get_dopants()
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove assignment to unused variable dopants.

- dopants = test.get_dopants()
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
dopants = test.get_dopants()
Tools
Ruff

61-61: Local variable dopants is assigned to but never used (F841)

Remove assignment to unused variable dopants

@@ -25,7 +23,8 @@
_, an_charge = utilities.parse_spec(anion_min_charge)

# Assert: Length of the list and return type (dictionary: list)
result = test.get_dopants()
dopants = test.get_dopants()
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove assignment to unused variable dopants.

- dopants = test.get_dopants()
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
dopants = test.get_dopants()
Tools
Ruff

26-26: Local variable dopants is assigned to but never used (F841)

Remove assignment to unused variable dopants

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 (3)
setup.py (3)

Line range hint 14-14: Remove unused import to clean up the code.

- import unittest

Line range hint 16-16: Remove unused import to clean up the code.

- from setuptools import Extension

Line range hint 25-25: Use a context manager to handle file operations safely and efficiently.

- long_description=open(os.path.join(module_dir, "README.md")).read(),
+ with open(os.path.join(module_dir, "README.md"), 'r') as file:
+     long_description=file.read(),
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between db901d2 and 1cb2db1.

Files selected for processing (1)
  • setup.py (1 hunks)
Additional context used
Ruff
setup.py

14-14: unittest imported but unused (F401)

Remove unused import: unittest


16-16: setuptools.Extension imported but unused (F401)

Remove unused import: setuptools.Extension


25-25: Use context handler for opening files (SIM115)

Additional comments not posted (1)
setup.py (1)

53-53: Ensure compatibility with future versions by specifying an upper limit on the numpy version.

Copy link

codecov bot commented Jun 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 74.49%. Comparing base (a8047e6) to head (1cb2db1).
Report is 1 commits behind head on develop.

Current head 1cb2db1 differs from pull request most recent head f3421a0

Please upload reports for the commit f3421a0 to get more accurate results.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #264      +/-   ##
===========================================
- Coverage    74.50%   74.49%   -0.02%     
===========================================
  Files           24       24              
  Lines         2083     2082       -1     
===========================================
- Hits          1552     1551       -1     
  Misses         531      531              

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

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)
smact/dopant_prediction/doper.py (1)

Line range hint 319-319: Unused loop control variable.

The loop variable dopant_type is not used within the loop body, which can be misleading. Consider renaming it to _ if its value is not needed.

- for dopant_type, dopants in self.results.items():
+ for _, dopants in self.results.items():
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1cb2db1 and f3421a0.

Files selected for processing (2)
  • examples/Dopant_Prediction/doper_example.ipynb (2 hunks)
  • smact/dopant_prediction/doper.py (4 hunks)
Additional context used
Ruff
smact/dopant_prediction/doper.py

319-319: Loop control variable dopant_type not used within loop body

Rename unused dopant_type to _dopant_type

(B007)

Additional comments not posted (6)
examples/Dopant_Prediction/doper_example.ipynb (3)

144-144: Clarification on default colormap.

The added note about the default color scheme 'YlOrRd' is helpful for users. It enhances the documentation by guiding users on how to change the colormap if needed.


159-159: Use of updated colormap parameter.

The change to use the 'Reds' colormap in the plot_dopants method is consistent with the PR's aim to enhance visualisation features. Ensure that this change is reflected in any related documentation or examples to maintain consistency.


221-221: Update Python version in metadata.

Updating the Python version in the notebook metadata from '3.9.16' to '3.9.7' should be verified to ensure compatibility with all dependencies and the overall environment setup.

Verification successful

Python version update verified.

The update of the Python version in the notebook metadata to '3.9.7' is compatible with the repository's setup, as the setup.py specifies python_requires=">=3.9" and no conflicting dependency constraints were found.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify Python version compatibility with dependencies.

# Test: List Python version requirements from setup.py and compare with notebook version.
rg --type py 'python_requires' setup.py

Length of output: 72



Script:

#!/bin/bash
# Description: Verify Python version compatibility with dependencies.

# Test: List all dependencies and their required versions from setup.py or equivalent files.
rg --type py 'install_requires' setup.py
rg --type py 'requirements' requirements.txt

Length of output: 112



Script:

#!/bin/bash
# Description: Verify Python version compatibility with dependencies.

# Test: Search for dependency specifications in other common configuration files.
rg --type toml 'dependencies' pyproject.toml
rg --type toml 'requires' Pipfile
rg --type yaml 'dependencies' conda.yml

Length of output: 216

smact/dopant_prediction/doper.py (3)

3-3: Maintain import consistency.

The import statement for List, Optional, Tuple from typing is correctly maintained. This is crucial for type hinting throughout the module, enhancing code readability and maintainability.


302-305: Refinement in get_dopants return logic.

The refactoring to return the top num_dopants results for each category using list slicing and dictionary comprehension is a clean and efficient approach. This change improves the readability and performance of the method.


Line range hint 307-338: Enhancements in plot_dopants method.

The adjustments to the color mapping and the handling of the heatmap plotting are well-implemented. However, ensure that the assert statement for checking if dopants are calculated is effective and that it doesn't interrupt user workflows negatively.

@JiwooChloeLee JiwooChloeLee closed this by deleting the head repository Jun 27, 2024
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