-
Notifications
You must be signed in to change notification settings - Fork 5
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
Fix get_thermo #352
Conversation
WalkthroughThe Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes Poem
Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. ✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)) |
There was a problem hiding this comment.
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:
- Is this the intended behavior for thermodynamic data access in your LAMMPS MPI setup?
- Should other similar functions also remove their rank restrictions for consistency?
- 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.
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
@raynol-dsouza This fixes the |
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: |
@jan-janssen it works now. Thanks for the quick fix! |
Summary by CodeRabbit