Skip to content

Fix get_thermo #352

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

Merged
merged 1 commit into from
Aug 4, 2025
Merged

Fix get_thermo #352

merged 1 commit into from
Aug 4, 2025

Conversation

jan-janssen
Copy link
Member

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

Summary by CodeRabbit

  • Bug Fixes
    • Resolved an issue where only one process would retrieve simulation results; now all processes retrieve results as expected.

Copy link

coderabbitai bot commented Aug 1, 2025

Walkthrough

The get_thermo function in pylammpsmpi/mpi/lmpmpi.py was updated to remove the restriction that limited execution to only the MPI rank 0 process. Now, all MPI processes execute job.get_thermo and return its result, changing the function's internal behavior but not its signature.

Changes

Cohort / File(s) Change Summary
MPI Thermo Retrieval Logic
pylammpsmpi/mpi/lmpmpi.py
Removed MPI rank 0 conditional from get_thermo; now all ranks call job.get_thermo and return result as NumPy array.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

A bunny hopped through MPI code,
Where only rank zero once strode.
Now all ranks may roam,
And fetch thermo home—
United, their data bestowed!
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

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

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch get_thermo

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.
    • @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 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.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

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

@jan-janssen jan-janssen linked an issue Aug 1, 2025 that may be closed by this pull request
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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a8d280c and 5ad271b.

📒 Files selected for processing (1)
  • pylammpsmpi/mpi/lmpmpi.py (1 hunks)

Comment on lines 335 to +336
def get_thermo(job, funct_args):
if MPI.COMM_WORLD.rank == 0:
return np.array(job.get_thermo(*funct_args))
return np.array(job.get_thermo(*funct_args))
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Verify the intended MPI behavior change and ensure consistency.

The removal of the if MPI.COMM_WORLD.rank == 0: check makes get_thermo inconsistent with other similar functions in this file (e.g., get_version, extract_setting, extract_global, etc.). This change means all MPI processes will now execute job.get_thermo(*funct_args), but only rank 0 will send the result back to the client.

Please verify:

  1. Is this the intended behavior for thermodynamic data access in your LAMMPS MPI setup?
  2. Should other similar functions also remove their rank restrictions for consistency?
  3. Are there any synchronization concerns with all ranks executing this call?

🏁 Script executed:

#!/bin/bash
# Search for other functions with similar MPI rank 0 restrictions
echo "Functions with MPI rank 0 restrictions:"
rg -A 2 "if MPI\.COMM_WORLD\.rank == 0:" --type py

echo -e "\nFunctions without MPI rank restrictions (excluding get_thermo):"
rg -B 2 -A 5 "def \w+\(job, funct_args\):" --type py | grep -A 7 -B 2 "return.*job\." | grep -v "if MPI.COMM_WORLD.rank == 0" | grep -v "get_thermo"

Length of output: 9369


Guard get_thermo with an MPI rank-0 check for consistency

Our scan of pylammpsmpi/mpi/lmpmpi.py shows that nearly every data-returning wrapper (e.g., get_version, extract_setting, extract_global, extract_box, get_natoms, the various neighbor-list getters, etc.) is guarded by:

if MPI.COMM_WORLD.rank == 0:
    return job.<>

However, get_thermo at lines 335–336 currently reads:

def get_thermo(job, funct_args):
    return np.array(job.get_thermo(*funct_args))

Without the rank check:

  • All MPI ranks will redundantly call job.get_thermo
  • Only rank 0 will send back results, risking confusion or deadlocks if get_thermo itself uses MPI
  • The pattern diverges from the rest of the file

Please update get_thermo to:

 def get_thermo(job, funct_args):
-    return np.array(job.get_thermo(*funct_args))
+    if MPI.COMM_WORLD.rank == 0:
+        return np.array(job.get_thermo(*funct_args))

Or, if the removal was intentional, document why get_thermo should run on all ranks and adjust other wrappers to match.

🤖 Prompt for AI Agents
In pylammpsmpi/mpi/lmpmpi.py at lines 335 to 336, the get_thermo function lacks
the MPI rank-0 guard present in other data-returning wrappers, causing all ranks
to call job.get_thermo redundantly. To fix this, wrap the call to job.get_thermo
inside an if statement checking if MPI.COMM_WORLD.rank == 0, returning the numpy
array only on rank 0 and returning None or an appropriate default on other ranks
to maintain consistency and avoid redundant calls.

Copy link

codecov bot commented Aug 1, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.12%. Comparing base (a8d280c) to head (5ad271b).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #352   +/-   ##
=======================================
  Coverage   81.12%   81.12%           
=======================================
  Files           5        5           
  Lines         551      551           
=======================================
  Hits          447      447           
  Misses        104      104           

☔ 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
Copy link
Member Author

@raynol-dsouza This fixes the get_thermo() issue for me, but I am still surprised that it does work without the dump command. @srmnitc Did you face this issue before?

@jan-janssen
Copy link
Member Author

We can even remove all the restrictions to mpi rank zero and the tests still work. This is not a very convincing sign. Still it might be the more reliable option:
#353

@raynol-dsouza
Copy link

@jan-janssen it works now. Thanks for the quick fix!

@jan-janssen jan-janssen merged commit 15ec161 into main Aug 4, 2025
19 checks passed
@jan-janssen jan-janssen deleted the get_thermo branch August 4, 2025 13:41
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.

"dump" causes get_thermo() to hang on cores > 1
2 participants