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

refactor: Improve code readability and reducing code duplications #127

Merged
merged 11 commits into from
Nov 16, 2024

Conversation

Anselmoo
Copy link
Owner

@Anselmoo Anselmoo commented Nov 9, 2024

  • Using tuples to reperesent the non-diagonal elements via dictionary

Summary by Sourcery

Enhancements:

  • Refactor matrix construction by introducing a new method 'construct_matrix' to handle diagonal and off-diagonal elements, improving code readability and reducing duplication.

- Using tuples to reperesent the non-diagonal elements via dictionary
Copy link

semanticdiff-com bot commented Nov 9, 2024

Review changes with  SemanticDiff

Changed Files
File Status
  tanabesugano/test/test_front.py  100% smaller
  tanabesugano/batch.py  100% smaller
  tanabesugano/cmd.py  93% smaller
  tanabesugano/tools.py  76% smaller
  tanabesugano/matrices.py  42% smaller
  tanabesugano/test/test_num.py  2% smaller
  .github/dependabot.yml Unsupported file format
  .github/workflows/docker-image.yml Unsupported file format
  CHANGELOG.md Unsupported file format
  poetry.lock Unsupported file format
  pyproject.toml Unsupported file format
  tanabesugano/__init__.py  0% smaller
  tanabesugano/test/test_matrices.py  0% smaller

Copy link

sourcery-ai bot commented Nov 9, 2024

Reviewer's Guide by Sourcery

The pull request refactors matrix construction in ligand field theory calculations by introducing a new helper method construct_matrix that centralizes the creation of symmetric matrices from diagonal and off-diagonal elements. This change eliminates code duplication across multiple state calculation methods.

Class diagram for LigandFieldTheory refactor

classDiagram
    class LigandFieldTheory {
        +Dq: float
        +B: float
        +C: float
        +solver() Dict~str, Float64Array~
        +construct_matrix(diag_elements: List~float~, off_diag_elements: Dict~Tuple~int, int~, float~) Float64Array
    }
    class d2 {
        +A_1_1_states() Float64Array
        +E_1_states() Float64Array
        +T_1_2_states() Float64Array
        +T_3_1_states() Float64Array
        +solver() Dict~str, Float64Array~
    }
    LigandFieldTheory <|-- d2
    note for LigandFieldTheory "Added construct_matrix method to centralize matrix creation"
Loading

File-Level Changes

Change Details Files
Added a new helper method to construct symmetric matrices
  • Introduced construct_matrix method that takes diagonal and off-diagonal elements as input
  • Method automatically handles matrix symmetry by mirroring off-diagonal elements
  • Returns a numpy array representing the constructed matrix
tanabesugano/matrices.py
Refactored state calculation methods to use the new matrix construction helper
  • Replaced direct matrix construction with calls to construct_matrix
  • Separated diagonal and off-diagonal elements into distinct dictionaries
  • Removed redundant symmetric element assignments
  • Simplified matrix construction code across all state calculation methods
tanabesugano/matrices.py
Improved code organization and readability
  • Removed redundant comments marking diagonal and non-diagonal sections
  • Eliminated duplicate variable assignments for symmetric matrix elements
  • Standardized the structure of state calculation methods
tanabesugano/matrices.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @Anselmoo - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@@ -65,6 +65,20 @@ def solver(self) -> Dict[str, Float64Array]:
msg = "Subclasses should implement this method."
raise NotImplementedError(msg)

def construct_matrix(
Copy link

Choose a reason for hiding this comment

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

suggestion: Document the symmetry assumption and consider skipping zero elements

The docstring should mention that the method assumes off_diag_elements contains values for a symmetric matrix. Also, consider skipping zero values in off_diag_elements to avoid unnecessary operations.

@Anselmoo Anselmoo merged commit 6a2dae6 into master Nov 16, 2024
9 checks passed
@Anselmoo Anselmoo deleted the refactor/via-o1 branch November 16, 2024 19:30
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.

1 participant