Skip to content

calculate phonons with grace as part of the tests#516

Merged
jan-janssen merged 2 commits intomainfrom
grace_phonons
Aug 6, 2025
Merged

calculate phonons with grace as part of the tests#516
jan-janssen merged 2 commits intomainfrom
grace_phonons

Conversation

@jan-janssen
Copy link
Copy Markdown
Member

@jan-janssen jan-janssen commented Aug 6, 2025

Summary by CodeRabbit

  • Tests
    • Added new unit tests to verify phonon calculations and related outputs using the grace_fm calculator in the phonon analysis workflow.
    • Expanded automated testing pipeline to include phonon calculation tests for improved validation.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Aug 6, 2025

Walkthrough

A new unit test class, TestPhonons, has been added to verify phonon calculations using the grace_fm ASE calculator from the tensorpotential package. The test checks the correct computation and structure of phonon properties, including dynamical and Hessian matrices, density of states, and band structures, with assertions on their shapes and contents. Additionally, the GitHub Actions workflow was updated to include this new test in the unittest_grace job.

Changes

Cohort / File(s) Change Summary
Phonons ASE Grace Unit Test
tests/test_ase_interface/test_phonons_ase_grace.py
Added TestPhonons class with a method to test phonon calculations using the grace_fm ASE calculator.
GitHub Actions Workflow Update
.github/workflows/pipeline.yml
Extended unittest_grace job to run the new phonon calculation test test_phonons_ase_grace.py alongside existing tests.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • Disable Grace #427: Modifies the same GitHub Actions unittest_grace job, but disables it, contrasting with this PR which adds tests to it.
  • test phono workflow #421: Adds detailed phonon calculation assertions for ASE calculators, related to the new phonon test added here.

Poem

A rabbit hopped in, code to inspect,
With phonons and matrices, all to connect.
Aluminum danced in a simulated space,
While tests ensured calculations kept pace.
Eigenvectors checked, group velocities too—
All for science, and a carrot or two! 🥕

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 259df7c and 5fe1121.

📒 Files selected for processing (1)
  • .github/workflows/pipeline.yml (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .github/workflows/pipeline.yml
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch grace_phonons

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
  • 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 explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this 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
Copy Markdown
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

🧹 Nitpick comments (3)
tests/test_ase_interface/test_phonons_ase_grace.py (3)

18-20: Fix the skip message to accurately reflect the test.

The skip message mentions "mace tests" but this test is for grace_fm calculator.

Apply this diff to fix the message:

 @unittest.skipIf(
-    skip_grace_test, "grace is not installed, so the mace tests are skipped."
+    skip_grace_test, "grace is not installed, so the grace tests are skipped."
 )

50-50: Remove duplicate Hessian matrix shape assertion.

This assertion is duplicated by the more comprehensive check on lines 61-63.

Apply this diff to remove the duplicate:

-        self.assertEqual((324, 324), get_hesse_matrix(phonopy=phonopy_obj).shape)

64-77: Consider making band structure validations more robust.

The hardcoded expected shapes [34, 39, 78, 101, 95] in the band structure validations might be brittle and specific to the current test setup. Consider using more general validation approaches.

Consider this approach for more robust validation:

-        for vec in band_dict['qpoints']:
-            self.assertTrue(vec.shape[0] in [34, 39, 78, 101, 95])
-            self.assertEqual(vec.shape[1], 3)
+        for vec in band_dict['qpoints']:
+            self.assertGreater(vec.shape[0], 0)  # Has points
+            self.assertEqual(vec.shape[1], 3)    # 3D qpoints

Apply similar changes to the distances and frequencies validations to make them less dependent on specific values.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6e0a7ca and 259df7c.

📒 Files selected for processing (1)
  • tests/test_ase_interface/test_phonons_ase_grace.py (1 hunks)
🔇 Additional comments (6)
tests/test_ase_interface/test_phonons_ase_grace.py (6)

1-8: LGTM! Imports are well-organized and necessary.

The imports are logically grouped (standard library, third-party, local) and all appear to be used in the test implementation.


10-16: LGTM! Proper handling of optional dependency.

The conditional import pattern correctly handles the case where the tensorpotential package is not installed, preventing test failures due to missing optional dependencies.


22-31: LGTM! Structure optimization setup is correct.

The test properly creates a bulk Al structure and optimizes it using LBFGS with appropriate convergence criteria.


32-48: LGTM! Harmonic approximation workflow is well-implemented.

The harmonic approximation setup uses reasonable parameters and follows the expected workflow pattern for phonon calculations.


51-57: LGTM! Mesh and DOS dictionary key validation is thorough.

The assertions properly verify the presence of expected keys in the mesh and DOS dictionaries.


58-63: LGTM! Matrix shape validations are correct.

The dynamical matrix and Hessian matrix shape assertions validate the expected dimensions for the phonon calculations.

@codecov
Copy link
Copy Markdown

codecov bot commented Aug 6, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.75%. Comparing base (f88d032) to head (5fe1121).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #516      +/-   ##
==========================================
+ Coverage   85.34%   85.75%   +0.41%     
==========================================
  Files          43       43              
  Lines        2586     2570      -16     
==========================================
- Hits         2207     2204       -3     
+ Misses        379      366      -13     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jan-janssen jan-janssen merged commit e9c7a6e into main Aug 6, 2025
48 of 49 checks passed
@jan-janssen jan-janssen deleted the grace_phonons branch August 6, 2025 10:39
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